/* ==========================================================================
   Alienstech Support Portal — design system
   Modern, fresh, clean. Lapis-blue accent.
   ========================================================================== */

:root {
    /* Brand-blue accent system (Alienstech #3C7DB3) */
    --accent:        #3C7DB3;
    --accent-strong: #336E9E;
    --accent-soft:   rgba(60, 125, 179, 0.08);
    --accent-ring:   rgba(60, 125, 179, 0.20);

    /* Light theme */
    --bg:            #f7f8fb;
    --bg-card:       #ffffff;
    --bg-alt:        #f1f4f9;
    --border:        #e3e7ee;
    --border-strong: #cdd4e0;
    --text:          #1a2235;
    --text-dim:      #5b6473;
    --text-mute:     #8a93a3;
    --link:          #336E9E;

    /* Status palette */
    --green:  #047857;
    --green-bg: #d1fae5;
    --amber: #b45309;
    --amber-bg: #fef3c7;
    --red:   #b91c1c;
    --red-bg: #fee2e2;
    --slate: #475569;
    --slate-bg: #e2e8f0;
    --indigo: #4338ca;
    --indigo-bg: #e0e7ff;

    --radius: 10px;
    --radius-sm: 6px;
    --shadow-sm: 0 1px 2px rgba(15, 23, 42, .04);
    --shadow:    0 2px 6px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
    --shadow-lg: 0 12px 32px rgba(15, 23, 42, .12);

    --font-ui: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-display: "Inter", var(--font-ui);

    --container: 1180px;
    --nav-h: 64px;
}

[data-theme="dark"] {
    --bg:            #0f1729;
    --bg-card:       #182338;
    --bg-alt:        #1e2a42;
    --border:        #2a3654;
    --border-strong: #3b486a;
    --text:          #e6ebf6;
    --text-dim:      #9aa5bd;
    --text-mute:     #6a7593;
    --link:          #7fb1da;

    --accent-soft:   rgba(60, 125, 179, 0.18);
    --accent-ring:   rgba(60, 125, 179, 0.32);

    --green-bg:  rgba(4, 120, 87, .25);
    --amber-bg:  rgba(180, 83, 9, .28);
    --red-bg:    rgba(185, 28, 28, .25);
    --slate-bg:  rgba(71, 85, 105, .35);
    --indigo-bg: rgba(67, 56, 202, .30);

    --shadow:    0 4px 12px rgba(0, 0, 0, .4);
    --shadow-lg: 0 24px 48px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
    font-family: var(--font-ui);
    background: var(--bg);
    color: var(--text);
    line-height: 1.55;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--link); text-decoration: none; }
a:hover { text-decoration: underline; }

.container { max-width: var(--container); margin: 0 auto; padding: 0 24px; }
.muted { color: var(--text-dim); }
.mute  { color: var(--text-mute); }
.small { font-size: 13px; }
.center { text-align: center; }

/* --------------------------- Top navigation --------------------------- */
.topnav {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    min-height: var(--nav-h);
    position: sticky; top: 0; z-index: 50;
}
.topnav-inner {
    display: flex; align-items: center; gap: 16px;
    min-height: var(--nav-h); max-width: var(--container); margin: 0 auto; padding: 0 24px;
}
/* Admin chrome: align header edges with the shell (brand over the 240px sidebar
   at its 22px gutter; right cluster over the content's card edge). */
.topnav-admin .topnav-inner { max-width: none; margin: 0; padding-left: 22px; padding-right: 52px; }
.topnav-admin nav a { font-size: 13px; }
@media (max-width: 860px) {
    .topnav-admin .topnav-inner { padding-left: 12px; padding-right: 12px; gap: 8px; }
    .topnav-admin .topnav-viewsite { display: none; }
    .topnav-admin .hi-name { display: none; }
    .topnav-admin .topnav-actions { margin-left: auto; gap: 8px; }
}
@media (max-width: 480px) {
    .topnav-admin .brand-name, .topnav-admin .brand-badge { display: none; }
}
/* Action column flush to the card edge so row buttons line up with header buttons */
table.table.actions-right td:last-child,
table.table.actions-right th:last-child { padding-right: 0; }

/* Runbook vault entries */
.rb-entry { padding: 14px 16px; }
.rb-entry-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.rb-fields { display: flex; flex-direction: column; gap: 7px; }
.rb-field { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.rb-label { font-size: 12px; color: var(--text-mute); width: 78px; flex: none; }
.rb-val { font-size: 13.5px; color: var(--text); word-break: break-all; }
code.rb-val { background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; padding: 2px 8px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.rb-field .rb-secret[data-shown="1"] { color: var(--accent); }
.rb-cat { font-size: 15px; margin: 18px 0 8px; }
.rb-notes { align-items: flex-start; }
.rb-notes .rb-val { font-family: inherit; }
.rb-grid { display: grid; grid-template-columns: 1.3fr 1fr; gap: 20px; align-items: start; }
@media (max-width: 860px) { .rb-grid { grid-template-columns: 1fr; } }

/* Trix WYSIWYG editor */
trix-editor {
    min-height: 320px; border: 1px solid var(--border); border-radius: 0 0 8px 8px;
    padding: 12px 14px; background: var(--bg-card); color: var(--text);
    font-size: 14px; line-height: 1.6;
}
trix-editor:focus { outline: none; border-color: var(--accent); }
trix-toolbar .trix-button-group { border-color: var(--border); }
trix-toolbar .trix-button { border-bottom-color: var(--border); }
[data-theme="dark"] trix-toolbar .trix-button--icon::before { filter: invert(0.9); }
[data-theme="dark"] trix-toolbar .trix-button { background: var(--bg-alt); color: var(--text); }
trix-editor h1 { font-size: 1.5em; }
trix-editor a { color: var(--accent); }
/* Code blocks + inline code: themed so they stay readable in dark mode */
trix-editor pre, .article-body pre {
    background: var(--bg-alt); color: var(--text);
    border: 1px solid var(--border); border-radius: 6px;
    padding: 10px 12px; overflow-x: auto;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
}
trix-editor code, .article-body code {
    background: var(--bg-alt); color: var(--text);
    border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.92em;
}
trix-editor pre code, .article-body pre code { background: none; border: 0; padding: 0; }
.article-body img, trix-editor img { max-width: 100%; height: auto; border-radius: 8px; }

/* Two-factor auth */
.callout { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 18px; background: var(--bg-alt); }
.callout-accent { border-color: var(--accent); }
.recovery-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin-top: 10px; }
.recovery-grid code { background: var(--bg-card); border: 1px solid var(--border); border-radius: 6px; padding: 8px 10px; text-align: center; font-size: 15px; letter-spacing: 1px; }
.qr-box { padding: 12px; background: #fff; border-radius: 10px; display: block; width: -moz-fit-content; width: fit-content; margin: 12px auto; }
.qr-box img { display: block; }
.totp-secret { display: inline-block; margin-top: 4px; padding: 6px 10px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; font-size: 15px; letter-spacing: 1px; }
.twofa-steps { padding-left: 20px; line-height: 1.7; }
.twofa-steps li { margin-bottom: 18px; }
.action-tile-static { cursor: default; }
#aiTipText { transition: opacity .25s ease; min-height: 3em; }

/* Asset detail tabs + specifications */
.asset-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 4px 0 18px; flex-wrap: wrap; }
.asset-tab { background: none; border: 0; padding: 10px 16px; font: inherit; color: var(--text-mute); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; border-radius: 6px 6px 0 0; }
.asset-tab:hover { color: var(--text); background: var(--bg-alt); }
.asset-tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }
.asset-panel { display: none; }
.asset-panel.active { display: block; }
.spec-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 28px; }
.spec-row { display: flex; justify-content: space-between; gap: 16px; padding: 9px 0; border-bottom: 1px solid var(--border); }
.spec-label { color: var(--text-mute); }
.spec-value { font-weight: 500; text-align: right; word-break: break-word; }
.disk { margin: 12px 0; }
.disk-head { display: flex; justify-content: space-between; gap: 12px; margin-bottom: 5px; font-size: 14px; }
.disk-bar { height: 10px; background: var(--bg-alt); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.disk-fill { height: 100%; background: var(--accent); }
.disk-fill.warn { background: #d98324; }
.disk-fill.crit { background: var(--red); }
.sw-list { max-height: 460px; overflow-y: auto; }
@media (max-width: 640px) { .spec-grid { grid-template-columns: 1fr; } }
@media (max-width: 480px) { .recovery-grid { grid-template-columns: 1fr; } }
.brand {
    display: flex; align-items: center; gap: 10px;
    font-weight: 700; font-size: 17px; color: var(--text);
}
.brand:hover { text-decoration: none; }
.brand-mark {
    width: 34px; height: 34px; border-radius: 8px;
    background: #fff; object-fit: contain; padding: 2px;
    display: block; flex-shrink: 0;
    box-shadow: 0 1px 2px rgba(15, 23, 42, .12);
    border: 1px solid var(--border);
}
.topnav-menu { display: flex; align-items: center; gap: 18px; flex: 1; min-width: 0; }
.topnav nav { display: flex; gap: 4px; flex: 1; min-width: 0; flex-wrap: nowrap; }
.topnav nav a {
    padding: 8px 12px; border-radius: 8px; white-space: nowrap;
    color: var(--text-dim); font-weight: 500;
}
.topnav nav a:hover, .topnav nav a.active {
    color: var(--accent); background: var(--accent-soft); text-decoration: none;
}
.topnav-actions { display: flex; align-items: center; gap: 12px; }
.phone-link { color: var(--text-dim); font-weight: 500; }
.phone-link strong { color: var(--accent); }

/* Mobile menu toggle */
.menu-toggle {
    display: none; background: none; border: 0; cursor: pointer;
    padding: 8px; color: var(--text); border-radius: 6px;
}
.menu-toggle:hover { background: var(--bg-alt); }

.theme-toggle {
    background: var(--bg-alt); border: 1px solid var(--border);
    width: 36px; height: 36px; border-radius: 8px; cursor: pointer;
    display: grid; place-items: center; color: var(--text); font-size: 14px;
}
.theme-toggle:hover { background: var(--accent-soft); border-color: var(--accent-ring); }

@media (max-width: 1024px) {
    .topnav-menu { display: none; }
    .menu-toggle { display: grid; }
    .topnav.nav-open .topnav-menu {
        display: flex; flex-direction: column; align-items: stretch; gap: 4px;
        position: fixed; top: var(--nav-h); left: 0; height: calc(100vh - var(--nav-h));
        width: min(82vw, 320px); background: var(--bg-card); overflow-y: auto;
        padding: 16px 18px; border-right: 1px solid var(--border); box-shadow: var(--shadow-lg);
        animation: slideIn .15s ease-out;
    }
    .topnav.nav-open nav { display: flex; flex-direction: column; gap: 4px; }
    .topnav.nav-open nav a { padding: 12px 12px; }
    .topnav.nav-open .topnav-actions {
        display: flex; flex-direction: column; align-items: stretch; gap: 12px;
        border-top: 1px solid var(--border); margin-top: 12px; padding-top: 16px;
    }
    .topnav.nav-open .topnav-actions .phone-link { padding: 4px 2px; font-size: 15px; }
    .topnav.nav-open .topnav-actions .theme-toggle { align-self: flex-start; }
    .topnav.nav-open .topnav-actions .btn { width: 100%; text-align: center; }
    .scrim {
        position: fixed; top: var(--nav-h); left: 0; right: 0; bottom: 0;
        background: rgba(15, 23, 42, .35); z-index: 40;
    }
}
@keyframes slideIn { from { transform: translateX(-20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --------------------------- Hero --------------------------- */
.hero {
    background: linear-gradient(135deg, #3C7DB3 0%, #336E9E 55%, #2B5C82 100%);
    color: white; padding: 72px 24px 80px;
}
.hero-inner { max-width: 760px; margin: 0 auto; text-align: center; }
.hero h1 { font-size: clamp(28px, 4.2vw, 44px); margin: 0 0 14px; font-weight: 700; }
.hero p { font-size: 17px; opacity: .92; margin: 0 0 28px; }
.hero-search { display: flex; gap: 8px; max-width: 620px; margin: 0 auto; align-items: center;
    background: white; border-radius: 14px; padding: 6px 6px 6px 8px; box-shadow: 0 12px 30px rgba(0,0,0,.18); }
.hero-search input {
    flex: 1; border: 0; padding: 12px 18px; font-size: 16px; outline: none; background: transparent; color: var(--text);
}
.hero-search button {
    background: var(--accent); color: white; border: 0; padding: 12px 22px;
    border-radius: 10px; font-weight: 600; cursor: pointer; font-size: 15px;
}
.hero-search button:hover { background: var(--accent-strong); }

/* Dark mode: mute the hero so it sits calmly against the dark page, and give
   the search bar a dark elevated treatment instead of a glaring white pill. */
[data-theme="dark"] .hero {
    background: linear-gradient(135deg, #27506f 0%, #1d3a54 58%, #15273a 100%);
}
[data-theme="dark"] .hero-search {
    background: #16243d;
    border: 1px solid rgba(255, 255, 255, .10);
    box-shadow: 0 12px 30px rgba(0, 0, 0, .45);
}
[data-theme="dark"] .hero-search input { color: var(--text); }
[data-theme="dark"] .hero-search input::placeholder { color: var(--text-mute); }

/* Inline icon alignment */
.action-tile .icon svg, .kb-cat-card .cat-icon svg { display: block; }
.phone-ico { display: inline-flex; vertical-align: -3px; margin-right: 5px; }
.phone-ico svg { display: block; }

/* Live search suggestions */
.search-host { position: relative; }
.search-suggest {
    position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 60;
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: 12px; box-shadow: var(--shadow-lg);
    max-height: 360px; overflow-y: auto; text-align: left;
}
.search-suggest .ss-item {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 11px 16px; color: var(--text); border-bottom: 1px solid var(--border);
    text-decoration: none;
}
.search-suggest .ss-item:last-child { border-bottom: 0; }
.search-suggest .ss-item:hover,
.search-suggest .ss-item.active { background: var(--accent-soft); text-decoration: none; }
.search-suggest .ss-title { font-weight: 500; font-size: 14px; }
.search-suggest .ss-item:hover .ss-title,
.search-suggest .ss-item.active .ss-title { color: var(--accent); }
.search-suggest .ss-cat { font-size: 12px; color: var(--text-mute); white-space: nowrap; flex-shrink: 0; }
.search-suggest .ss-empty { padding: 13px 16px; color: var(--text-dim); font-size: 14px; }

/* Action tiles */
.action-tiles {
    display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px;
    max-width: 980px; margin: -42px auto 56px; padding: 0 24px;
}
@media (max-width: 720px) { .action-tiles { grid-template-columns: 1fr; } }
.action-tile {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 22px; box-shadow: var(--shadow); display: flex; align-items: center; gap: 16px;
    transition: transform .15s, box-shadow .15s, border-color .15s;
}
.action-tile:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--accent-ring); box-shadow: var(--shadow-lg); }
.action-tile .icon {
    width: 44px; height: 44px; border-radius: 10px;
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center; flex-shrink: 0;
}
.action-tile h3 { margin: 0 0 2px; font-size: 16px; color: var(--text); }
.action-tile p { margin: 0; font-size: 13px; color: var(--text-dim); }

/* --------------------------- KB section --------------------------- */
.kb-section { padding: 0 24px 80px; max-width: var(--container); margin: 0 auto; }
.kb-section h2 {
    font-size: 22px; margin: 28px 0 18px; padding-bottom: 12px;
    border-bottom: 1px solid var(--border); color: var(--text); font-weight: 600;
}
.kb-cat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 18px; }
.kb-cat-card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 22px; box-shadow: var(--shadow-sm);
    transition: border-color .15s, box-shadow .15s, transform .15s;
}
.kb-cat-card:hover { border-color: var(--accent-ring); box-shadow: var(--shadow); transform: translateY(-2px); }
.kb-cat-card .cat-head {
    display: flex; align-items: center; gap: 10px; margin-bottom: 14px;
}
.kb-cat-card .cat-icon {
    width: 36px; height: 36px; border-radius: 8px;
    background: var(--accent-soft); color: var(--accent);
    display: grid; place-items: center; font-size: 15px; flex-shrink: 0;
}
.kb-cat-card h3 { margin: 0; font-size: 16px; color: var(--text); }
.kb-cat-card h3 a { color: var(--text); }
.kb-cat-card h3 a:hover { color: var(--accent); text-decoration: none; }
.kb-cat-card .article-count { color: var(--text-mute); font-size: 13px; }
.kb-cat-card ul { list-style: none; padding: 0; margin: 0 0 14px; }
.kb-cat-card li {
    padding: 7px 0; border-bottom: 1px dashed var(--border);
    font-size: 14px;
}
.kb-cat-card li:last-child { border-bottom: 0; }
.kb-cat-card li a { color: var(--text-dim); }
.kb-cat-card li a:hover { color: var(--accent); }
.kb-cat-card .view-all { font-size: 13px; color: var(--accent); font-weight: 600; }

/* --------------------------- Article --------------------------- */
.article-page { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px; box-shadow: var(--shadow-sm); }
.breadcrumb { font-size: 13px; color: var(--text-mute); margin-bottom: 18px; }
.breadcrumb a { color: var(--text-dim); }
.article-page h1 { margin: 0 0 8px; font-size: 28px; }
.article-meta { color: var(--text-mute); font-size: 13px; margin-bottom: 28px; }
.article-body { font-size: 15.5px; line-height: 1.7; }
.article-body p { margin: 0 0 1em; }
.article-body h2 { margin-top: 1.6em; }
.article-body img { max-width: 100%; height: auto; border-radius: var(--radius-sm); }
.article-body pre {
    background: var(--bg-alt); padding: 14px 16px; border-radius: var(--radius-sm);
    overflow-x: auto; font-size: 13px; border: 1px solid var(--border);
}
.article-body code { background: var(--bg-alt); padding: 1px 6px; border-radius: 4px; font-size: 13px; }
.article-body table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.article-body th, .article-body td { padding: 10px 12px; border: 1px solid var(--border); text-align: left; }

/* --------------------------- Cards & sections --------------------------- */
.section { padding: 32px 24px; max-width: var(--container); margin: 0 auto; }
.section.tight { padding: 16px 24px; }
.card {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow-sm);
}
.card + .card { margin-top: 18px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; gap: 16px; flex-wrap: wrap; }
.card-head h2 { margin: 0; font-size: 18px; }
.card-head .sub { color: var(--text-mute); font-size: 13px; }

/* --------------------------- Forms --------------------------- */
.field { margin-bottom: 16px; }
.field label, label.field-label {
    display: block; margin-bottom: 6px; font-weight: 500;
    font-size: 14px; color: var(--text-dim);
}
.field .hint { font-size: 12px; color: var(--text-mute); margin-top: 4px; }
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="tel"], input[type="url"], select, textarea {
    width: 100%; padding: 10px 12px; font-family: inherit; font-size: 14px;
    background: var(--bg-card); color: var(--text);
    border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
    transition: border-color .12s, box-shadow .12s;
}
input:focus, select:focus, textarea:focus {
    outline: 0; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring);
}
textarea { resize: vertical; min-height: 90px; line-height: 1.5; }
input[type="checkbox"] { accent-color: var(--accent); width: auto; }
.field-row { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); }
.field-row.three { grid-template-columns: repeat(3, 1fr); }
.field-row.four  { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 600px) { .field-row, .field-row.three, .field-row.four { grid-template-columns: 1fr; } }

/* --------------------------- Buttons --------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    padding: 9px 18px; font-size: 14px; font-weight: 600;
    font-family: inherit; line-height: 1.2; white-space: nowrap;
    margin: 0; vertical-align: middle;
    border-radius: var(--radius-sm); cursor: pointer;
    border: 1px solid transparent; background: var(--bg-alt); color: var(--text);
    transition: background .12s, transform .06s, box-shadow .12s, border-color .12s;
    text-decoration: none;
}
.btn:hover  { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-primary {
    background: var(--accent); color: white; border-color: var(--accent);
    box-shadow: 0 1px 2px rgba(30,58,138,.25);
}
.btn-primary:hover { background: var(--accent-strong); border-color: var(--accent-strong); }
.btn-ghost { background: transparent; border: 1px solid var(--border-strong); color: var(--text); }
.btn-ghost:hover { background: var(--accent-soft); border-color: var(--accent-ring); color: var(--accent); }
.btn-danger { background: var(--red); color: white; border-color: var(--red); }
.btn-danger:hover { background: #991b1b; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-xs { padding: 4px 9px; font-size: 12px; }
.btn-block { width: 100%; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
/* Inline action groups (e.g. Edit + Delete), incl. form-wrapped buttons */
.row-actions { display: flex; align-items: center; gap: 8px; }
.row-actions form { margin: 0; display: inline-flex; }

/* --------------------------- Tables --------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--bg-card); }
table.table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.table th, table.table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); }
table.table th { background: var(--bg-alt); font-weight: 600; color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
table.table tbody tr:hover { background: var(--accent-soft); }
table.table tbody tr:last-child td { border-bottom: 0; }

/* --------------------------- Badges --------------------------- */
.badge {
    display: inline-block; padding: 3px 10px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 1.5;
    background: var(--slate-bg); color: var(--slate);
}
.badge.new      { background: var(--indigo-bg); color: var(--indigo); }
.badge.open     { background: var(--amber-bg); color: var(--amber); }
.badge.pending  { background: var(--slate-bg); color: var(--slate); }
.badge.pending_internal { background: var(--slate-bg); color: var(--slate); }
.badge.resolved { background: var(--green-bg); color: var(--green); }
.badge.closed   { background: var(--slate-bg); color: var(--slate); }
.badge.urgent   { background: var(--red-bg); color: var(--red); }
.badge.high     { background: var(--amber-bg); color: var(--amber); }
.badge.normal   { background: var(--accent-soft); color: var(--accent); }
.badge.low      { background: var(--slate-bg); color: var(--slate); }
.badge.public   { background: var(--green-bg); color: var(--green); }
.badge.internal { background: var(--amber-bg); color: var(--amber); }
.badge.client   { background: var(--indigo-bg); color: var(--indigo); }

/* --------------------------- Flashes --------------------------- */
.flash-container { max-width: var(--container); margin: 0 auto; padding: 16px 24px 0; }
.flash {
    padding: 12px 16px; border-radius: var(--radius-sm); margin-bottom: 10px;
    border: 1px solid; font-size: 14px;
}
.flash.success { background: var(--green-bg); color: var(--green); border-color: var(--green); }
.flash.error   { background: var(--red-bg);   color: var(--red);   border-color: var(--red); }
.flash.info    { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-ring); }

/* --------------------------- Auth pages --------------------------- */
.auth-page { display: grid; place-items: center; min-height: calc(100vh - var(--nav-h)); padding: 24px; }
.auth-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 36px; box-shadow: var(--shadow); width: 100%; max-width: 420px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card .sub { color: var(--text-dim); margin-bottom: 24px; font-size: 14px; }
.auth-card .alt { margin-top: 18px; font-size: 14px; color: var(--text-dim); text-align: center; }

/* --------------------------- Admin layout --------------------------- */
.admin-shell { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - var(--nav-h)); }
.admin-sidebar {
    background: var(--bg-card); border-right: 1px solid var(--border); padding: 18px 0;
}
.admin-sidebar a {
    display: flex; align-items: center; gap: 10px; padding: 9px 22px;
    color: var(--text-dim); font-weight: 500; font-size: 14px; border-left: 3px solid transparent;
}
.admin-sidebar a:hover { color: var(--accent); background: var(--accent-soft); text-decoration: none; }
.admin-sidebar a.active { color: var(--accent); background: var(--accent-soft); border-left-color: var(--accent); }
.admin-sidebar .section-label { padding: 14px 22px 4px; font-size: 11px; font-weight: 700; color: var(--text-mute); text-transform: uppercase; letter-spacing: .06em; }
.admin-content { padding: 28px; max-width: 100%; overflow-x: auto; }
.admin-content h1 { margin: 0 0 4px; font-size: 22px; }
.admin-page-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 22px; flex-wrap: wrap; gap: 14px; }

@media (max-width: 860px) {
    .admin-shell { grid-template-columns: 1fr; }
    .admin-sidebar { display: none; }
    .admin-shell.nav-open .admin-sidebar { display: block; position: fixed; top: var(--nav-h); left: 0; height: calc(100vh - var(--nav-h)); width: 240px; z-index: 60; box-shadow: var(--shadow-lg); }
}

/* --------------------------- Tickets --------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; }
.stat-card .label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 26px; font-weight: 700; color: var(--text); margin-top: 4px; }
.stat-card.warn .value { color: var(--red); }

.conversation { display: flex; flex-direction: column; gap: 12px; margin: 16px 0; }
.message {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    padding: 16px 18px;
}
.message.private { background: var(--amber-bg); border-color: var(--amber); }
.message.outbound { border-left: 3px solid var(--accent); }
.message-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-dim); margin-bottom: 8px; flex-wrap: wrap; gap: 8px; }
.message-head strong { color: var(--text); }
.message-body { font-size: 14.5px; line-height: 1.6; }
.message-body p { margin: 0 0 .8em; }
.message-body img { max-width: 100%; }

.filters {
    display: flex; flex-wrap: wrap; gap: 10px; align-items: end;
    margin-bottom: 18px; padding: 14px; background: var(--bg-card);
    border: 1px solid var(--border); border-radius: var(--radius);
}
.filters .field { margin: 0; flex: 1; min-width: 140px; }

.pagination { display: flex; gap: 6px; justify-content: center; margin: 24px 0; }
.pagination a, .pagination span {
    padding: 6px 12px; border-radius: var(--radius-sm); font-size: 13px;
    border: 1px solid var(--border); color: var(--text-dim);
}
.pagination a:hover { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-ring); text-decoration: none; }
.pagination .active { background: var(--accent); color: white; border-color: var(--accent); }

/* --------------------------- Tabs --------------------------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 20px; flex-wrap: wrap; }
.tabs a {
    padding: 10px 16px; color: var(--text-dim); font-size: 14px; font-weight: 500;
    border-bottom: 2px solid transparent;
}
.tabs a:hover { color: var(--accent); text-decoration: none; }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

/* --------------------------- Toast --------------------------- */
#toast {
    position: fixed; top: 80px; right: 24px; z-index: 1000;
    padding: 12px 18px; background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg); font-size: 14px;
    transform: translateX(420px); opacity: 0; transition: transform .25s, opacity .25s;
    max-width: 360px;
}
#toast.show { transform: none; opacity: 1; }
#toast.err  { border-color: var(--red); color: var(--red); }

/* --------------------------- Footer --------------------------- */
.footer {
    background: var(--bg-card); border-top: 1px solid var(--border);
    padding: 28px 24px; margin-top: 60px; text-align: center; color: var(--text-mute); font-size: 13px;
}
.footer a { color: var(--text-dim); }

/* --------------------------- Utility --------------------------- */
.hstack { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.vstack { display: flex; flex-direction: column; gap: 12px; }
.justify-end { justify-content: flex-end; }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex-1 { flex: 1; }
hr { border: 0; border-top: 1px solid var(--border); margin: 18px 0; }
