/* ════════════════════════════════════════════════════════════
   LogProxy Dashboard — Material-inspired admin theme
   Fonts: Inter + JetBrains Mono
   ════════════════════════════════════════════════════════════ */

:root {
    /* Brand accent — Signal Teal: links, focus, selected nav/pills (never a button fill) */
    --primary:        #0BA5B7;
    --primary-rgb:    11,165,183;
    --primary-dark:   #0E7C8A;
    --primary-bg:     #CFF2F6;

    /* Buttons — teal-ink contained fill (3c Hybrid v3), distinct from the Signal Teal accent */
    --cta-fill:       #0B5062;
    --cta-fill-hover: #0A4552;

    /* Warm-neutral surfaces (3c Hybrid v3) */
    --bg:             #F7F5F1;
    --surface:        #FFFFFF;
    --surface-alt:    #EEEAE3;
    --appbar:         #FBF9F5;
    --chip-fill:      #F1EDE6;
    --border:         #D9D3C8;   /* borderRow — hairlines, row separators, input borders */
    --border-strong:  #D6C6A8;   /* borderStrong (sand) — card/table frames, neutral chip borders; grey read too dark/heavy */

    /* Text */
    --text:           #282624;   /* ink */
    --text-mid:       #63605A;   /* secondary */
    --text-dim:       #A19A8D;   /* tertiary / muted */

    /* Status */
    --green:          #16A34A;
    --green-rgb:      22,163,74;
    --green-bg:       #E7F6EC;
    --green-text:     #15803D;
    --amber:          #FB923C;
    --amber-rgb:      251,146,60;
    --amber-bg:       #FFF1E6;
    --amber-text:     #9A3412;
    --red:            #EF4444;   /* danger — destructive actions */
    --red-rgb:        239,68,68;
    --red-bg:         #FDEAEA;
    --red-text:       #B91C1C;
    --error:          #FB7185;   /* status/severity error (salmon) */
    --error-rgb:      251,113,133;
    --error-bg:       #FFEDEF;
    --error-text:     #9F1239;
    --purple:         #7C3AED;
    --purple-bg:      #EDE9FE;
    --blue:           #3B82F6;
    --blue-bg:        #EAF2FE;
    --blue-text:      #0369A1;
    /* Typography + shape tokens aligned with the shared 3c Hybrid v3 theme:
       Inter type family, 6/12 control/card radius, dark thin-outline (no card shadows). */
    --font-sans:    'Inter', 'Roboto', 'Helvetica', 'Arial', sans-serif;
    --font-mono:    'JetBrains Mono', 'IBM Plex Mono', monospace;
    --radius:       12px;  /* cards */
    --radius-md:    6px;   /* controls */
    --radius-sm:    4px;   /* small */
    --shadow-sm:    0 6px 16px -12px rgba(63,49,25,.35);  /* soft warm card shadow */
    --shadow:       0 4px 16px rgba(40,38,36,.12), 0 1px 2px rgba(40,38,36,.06);
    --focus-ring:   0 0 0 3px rgba(11, 165, 183, 0.25);
}

/* Button typography matches the shared theme (medium weight, slight tracking). */
.btn-search, .btn-ghost, .btn-action-primary, .btn-danger, .btn-warning, .nav-tab, .btn-sm {
    letter-spacing: .02em;
}

/* Branded focus halo on interactive chrome, matching the shared theme. */
:focus-visible { outline: none; }
button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible,
[tabindex]:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; }

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }

/* ── Loading ─────────────────────────────────────────────── */
.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 16px;
    background: var(--bg);
}

.loader-ring {
    width: 28px;
    height: 28px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.loading-screen p {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-dim);
    letter-spacing: .04em;
}

/* ── Top bar ─────────────────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
    height: 56px;
    background: var(--appbar);
    box-shadow: 0 1px 0 var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 24px;
    height: 24px;
    background: var(--primary);
    border-radius: 6px;
    flex-shrink: 0;
    position: relative;
}

.brand-icon::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(15deg);
    width: 10px;
    height: 10px;
    background: rgba(255,255,255,.85);
    border-radius: 2px;
}

.brand-name {
    font-family: var(--font-sans);
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
    letter-spacing: -.03em;
}

.brand-tag {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    letter-spacing: .04em;
    padding: 2px 10px;
    border-radius: 20px;
    background: var(--green-bg);
    color: var(--green-text);
    border: 1px solid rgba(var(--green-rgb),.25);
}

.brand-tag.error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: rgba(var(--error-rgb),.3);
}

/* ── Top bar nav ─────────────────────────────────────────── */
.topbar-nav {
    display: flex;
    align-items: center;
    gap: 2px;
    flex: 1;
    justify-content: center;
}

.nav-tab {
    background: none;
    border: 1px solid transparent;
    color: var(--text-mid);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    padding: 5px 14px;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.nav-tab:hover { background: var(--surface-alt); color: var(--text); border-color: var(--border); }

.nav-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(var(--primary-rgb), .35);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-label {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-dim);
}

.btn-ghost {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-mid);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    padding: 5px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: all .15s;
}

.btn-ghost:hover { border-color: var(--text-dim); color: var(--text); background: var(--surface-alt); }

/* ── Metrics strip ───────────────────────────────────────── */
.metrics-strip {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    margin: 24px 32px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.metric-card {
    padding: 20px 24px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    position: relative;
    border-right: 1px solid var(--border);
    transition: background .15s;
    overflow: hidden;
}

.metric-card:last-child { border-right: none; }
.metric-card:hover { background: var(--surface-alt); }

.metric-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 2px;
    background: var(--primary);
    transform: scaleX(0);
    transform-origin: left;
    transition: transform .25s ease;
}

.metric-card:hover::after { transform: scaleX(1); }

.metric-label {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .07em;
    display: flex;
    align-items: center;
    gap: 4px;
}

.metric-value {
    font-family: var(--font-mono);
    font-size: 30px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -.04em;
    line-height: 1;
}

/* ── Running badge ───────────────────────────────────────── */
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

.running-badge {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--amber-text);
    letter-spacing: .03em;
    animation: pulse 1.2s ease-in-out infinite;
    margin-left: 4px;
}

/* ── Sections ────────────────────────────────────────────── */
.chart-section,
.table-section {
    margin: 0 32px 24px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
}

.section-header h2 {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    text-transform: uppercase;
    letter-spacing: .07em;
}

.section-header .subtle {
    color: var(--text-dim);
    font-weight: 400;
    margin-left: 6px;
    text-transform: none;
    letter-spacing: 0;
}

/* ── Chart ───────────────────────────────────────────────── */
.chart-container { padding: 20px 24px; }
.chart-container canvas { width: 100% !important; display: block; }

/* ── Search ──────────────────────────────────────────────── */
.search-box input {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    padding: 7px 14px;
    border-radius: 20px;
    width: 280px;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.search-box input::placeholder { color: var(--text-dim); }

.search-box input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
    background: var(--surface);
}

/* ── Search panel ─────────────────────────────────────────── */
.search-panel {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 10px 14px;
}

.field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }

.field label {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-mid);
}

.field input,
.field select {
    font-family: var(--font-mono);
    font-size: 14px;
    height: 32px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    width: 100%;
    box-sizing: border-box;
}
.field input::placeholder { color: var(--text-dim); }
.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}
.field select { cursor: pointer; }

/* App / Host combobox — full list on click, filter as you type. */
.combo { position: relative; width: 100%; }
.combo-input { width: 100%; padding-right: 26px; }
.combo-toggle {
    position: absolute; top: 0; right: 0; height: 100%; width: 24px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 12px; line-height: 1;
}
.combo-toggle:hover { color: var(--text-mid); }
.combo-list {
    position: absolute; z-index: 50; top: calc(100% + 4px); left: 0;
    /* Grow past the field so long names (which often share a prefix) are readable,
       but never past the viewport. */
    min-width: 100%; width: max-content; max-width: min(560px, 92vw);
    max-height: 280px; overflow-y: auto; margin: 0;
    background: var(--surface); border: 1px solid var(--border);
    border-radius: var(--radius-md); box-shadow: var(--shadow);
    padding: 4px; list-style: none;
}
.combo-item {
    padding: 6px 10px; font-size: 15px; color: var(--text); cursor: pointer;
    border-radius: var(--radius-sm);
    /* Wrap rather than truncate, so a long name is shown in full. */
    white-space: normal; overflow-wrap: anywhere; line-height: 1.35;
}
.combo-item:hover, .combo-item.active { background: var(--primary-bg); color: var(--primary-dark); }
.combo-empty { padding: 8px 10px; font-size: 14px; color: var(--text-dim); }

.search-controls {
    display: flex;
    align-items: flex-end;
    gap: 22px;
    flex-wrap: wrap;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
}

.pill-group { display: flex; flex-direction: column; gap: 6px; }

.pill-group-label {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
}

.search-actions { display: flex; gap: 8px; margin-left: auto; align-items: flex-end; }

.btn-search {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    padding: 7px 22px;
    border: none;
    border-radius: var(--radius-sm);
    background: var(--cta-fill);
    color: #fff;
    cursor: pointer;
    transition: background .15s;
}
.btn-search:hover { background: var(--cta-fill-hover); }
.btn-search:disabled { opacity: .5; cursor: progress; }

/* Coloured status / severity pills when active */
.pill-2xx.active { background: var(--green); border-color: var(--green); }
.pill-4xx.active,
.pill-warn.active { background: var(--amber-text); border-color: var(--amber-text); }
.pill-5xx.active,
.pill-error.active { background: var(--error-text); border-color: var(--error-text); }

/* ── Filter bar (legacy, kept for pill/date shared styles) ── */
.filter-bar {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 20px;
    flex-wrap: wrap;
    background: var(--surface-alt);
}

.filter-group { display: flex; align-items: center; gap: 8px; }

.filter-label {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-dim);
    white-space: nowrap;
}

.filter-pills { display: flex; gap: 4px; }

.pill {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-mid);
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    padding: 3px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: all .12s;
    line-height: 1.5;
}

.pill:hover { border-color: var(--text-dim); color: var(--text); }
.pill.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.filter-note {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    margin-left: auto;
}

.filter-date {
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 3px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
}
.filter-date:focus { outline: none; border-color: var(--primary); }

.btn-clear-filters {
    font-family: var(--font-sans);
    font-size: 13px;
    padding: 3px 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--text-dim);
    cursor: pointer;
    transition: all .15s;
}
.btn-clear-filters:hover { border-color: var(--red); color: var(--red-text); }

/* ── Search index health strip ───────────────────────────── */
.index-health {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 7px 20px;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
}
.index-health-label {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
}
.index-health-items { display: flex; gap: 10px; flex-wrap: wrap; }
.idx {
    font-family: var(--font-mono);
    font-size: 12px;
    white-space: nowrap;
}
.idx-ready    { color: var(--green-text); }
.idx-building { color: var(--amber-text); font-weight: 600; }
.idx-pending  { color: var(--text-dim); }

/* ── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 14px;
}

thead th {
    text-align: left;
    padding: 10px 16px;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border-strong);
    white-space: nowrap;
    background: var(--surface);
    position: sticky;
    top: 0;
}

tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:nth-child(even) { background: var(--surface-alt); }
tbody tr:hover { background: var(--primary-bg); }
tbody tr:last-child { border-bottom: none; }

td { padding: 9px 16px; white-space: nowrap; vertical-align: middle; }

.col-time { width: 168px; color: var(--text-mid); font-size: 14px; }
.col-direction { width: 52px; }
.col-dir { width: 48px; }
.col-status { width: 60px; }
.col-method { width: 68px; }
.col-app { white-space: nowrap; color: var(--text-mid); }
.col-path { color: var(--text); max-width: 300px; overflow: hidden; text-overflow: ellipsis; }
.col-trace { width: 128px; color: var(--text-dim); font-size: 14px; }
.col-size { width: 78px; text-align: right; color: var(--text-mid); }
.col-expires { width: 88px; text-align: right; }
.col-actions { width: 56px; text-align: right; }

/* Status badge (HTTP status code, coloured by class; severity adds a ring) */
.status-tag {
    display: inline-block;
    min-width: 36px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 600;
    padding: 2px 7px;
    border-radius: var(--radius-sm);
    line-height: 1.4;
}
.status-2xx  { background: var(--green-bg); color: var(--green-text); }
.status-3xx  { background: var(--blue-bg); color: var(--blue-text); }
.status-4xx  { background: var(--amber-bg); color: var(--amber-text); }
.status-5xx  { background: var(--error-bg); color: var(--error-text); }
.status-warn { background: var(--amber-bg); color: var(--amber-text); }
.status-none { background: transparent; color: var(--text-dim); min-width: 0; }
.status-sev-error { box-shadow: inset 0 0 0 1.5px var(--error); }
.status-sev-warn  { box-shadow: inset 0 0 0 1.5px rgba(var(--amber-rgb),.6); }

/* Direction badge (IN = our service, OUT = external API call) */
.dir-tag {
    display: inline-block;
    min-width: 30px;
    text-align: center;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}
/* Direction is neutral too; IN/OUT is read from the label, not the colour. */
.dir-in   { background: var(--surface-alt); color: var(--text-mid); }
.dir-out  { background: var(--surface-alt); color: var(--text-mid); }
.dir-none { background: transparent; color: var(--text-dim); min-width: 0; }

/* Badges */
.badge {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    padding: 2px 8px;
    border-radius: 20px;
    display: inline-block;
}

.badge-in  { background: var(--blue-bg);  color: var(--blue-text);  }
.badge-out { background: var(--amber-bg); color: var(--amber-text); }

.method-tag {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .02em;
    padding: 2px 8px;
    border-radius: var(--radius-sm);
    display: inline-block;
}

/* Methods are neutral — the label already distinguishes them, so colour is reserved
   for the status code (the meaningful signal). DELETE keeps a faint warning tint. */
.method-get, .method-post, .method-put, .method-patch,
.method-head, .method-options { background: var(--surface-alt); color: var(--text-mid); }
.method-delete  { background: var(--surface-alt); color: var(--red-text); }

td a {
    color: var(--primary);
    text-decoration: none;
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    padding: 2px 9px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(var(--primary-rgb),.25);
    transition: all .12s;
}

td a:hover { background: var(--primary-bg); border-color: var(--primary); }

.table-empty {
    padding: 48px;
    text-align: center;
    font-family: var(--font-sans);
    font-size: 15px;
    color: var(--text-dim);
}

/* ── Content (body) search — admin only ──────────────────── */
.content-search {
    margin: 10px 16px 0;
    padding: 12px 14px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
}

.content-search-row {
    display: flex;
    align-items: flex-end;
    gap: 12px;
    flex-wrap: wrap;
}

.content-search-pattern { flex: 1 1 260px; min-width: 200px; }

.content-search-bytes { flex: 0 0 130px; }
.content-search-bytes input { width: 100%; }

.content-search-regex {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-mid);
    white-space: nowrap;
    padding-bottom: 6px;
}

.content-search-hint {
    margin: 6px 0 0;
    font-size: 13px;
    color: var(--text-dim);
}

.content-search-status {
    margin-top: 8px;
    font-size: 14px;
    color: var(--text-mid);
}

.content-search-results { margin-top: 8px; }

.content-search-row-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.content-search-row-item:last-child { border-bottom: none; }

.content-search-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    font-size: 14px;
}

.content-search-snippet {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-mid);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 6px 8px;
    white-space: pre-wrap;
    word-break: break-word;
}

.content-search-snippet mark {
    background: var(--amber-bg);
    color: var(--text);
    border-radius: 2px;
}

.table-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
}

.table-info {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-dim);
}

.pagination { display: flex; align-items: center; gap: 4px; }

.page-label {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-dim);
    min-width: 64px;
    text-align: center;
    padding: 4px 6px;
}

.btn-page {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-mid);
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.btn-page:hover:not(:disabled) { border-color: var(--primary); color: var(--primary); background: var(--primary-bg); }
.btn-page:disabled { opacity: .3; cursor: not-allowed; }

/* Expiry */
.expiry-ok   { color: var(--text-dim); font-size: 13px; }
.expiry-soon { color: var(--amber-text); font-size: 13px; font-weight: 600; }
.expiry-past { color: var(--error-text); font-size: 13px; font-weight: 600; }
.expiry-none { color: var(--border); }

/* ── Danger zone ─────────────────────────────────────────── */
.danger-zone {
    margin: 0 32px 24px;
    background: var(--surface);
    border: 1px solid rgba(var(--red-rgb),.3);
    border-radius: var(--radius);
    overflow: hidden;
}

.danger-zone-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 18px 24px;
    gap: 24px;
    background: var(--red-bg);
}

.danger-zone-row--border {
    border-top: 1px solid rgba(var(--red-rgb),.18);
}

.danger-zone-row h3 {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    color: var(--red-text);
    text-transform: uppercase;
    letter-spacing: .07em;
    margin-bottom: 4px;
}

.danger-zone-row p {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-mid);
    line-height: 1.4;
}

.btn-action-primary {
    background: var(--cta-fill);
    border: 1px solid var(--cta-fill);
    color: #fff;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.btn-action-primary:hover { background: var(--cta-fill-hover); border-color: var(--cta-fill-hover); color: #fff; }
.btn-action-primary:disabled { opacity: .4; cursor: not-allowed; }

.danger-zone-controls { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

.danger-zone-controls input[type="date"] {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 14px;
    padding: 7px 12px;
    border-radius: var(--radius-sm);
    outline: none;
    transition: border-color .15s;
}

.danger-zone-controls input[type="date"]:focus { border-color: var(--red); }

.btn-danger {
    background: var(--red-bg);
    border: 1px solid rgba(var(--red-rgb),.3);
    color: var(--red-text);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}

.btn-danger:hover { background: var(--red-text); border-color: var(--red-text); color: #fff; }
.btn-danger:disabled { opacity: .4; cursor: not-allowed; }

.btn-warning {
    background: var(--amber-bg);
    border: 1px solid rgba(var(--amber-rgb),.3);
    color: var(--amber-text);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    padding: 7px 16px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.btn-warning:hover { background: var(--amber-text); border-color: var(--amber-text); color: #fff; }
.btn-warning:disabled { opacity: .4; cursor: not-allowed; }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 1100px) { .metrics-strip { grid-template-columns: repeat(3, 1fr); } }

@media (max-width: 700px) {
    .metrics-strip { grid-template-columns: repeat(2, 1fr); margin: 16px; }
    .chart-section, .table-section { margin: 0 16px 16px; }
    .danger-zone, .config-section { margin: 0 16px 16px; }
    .topbar { padding: 0 16px; }
    .search-box input { width: 180px; }
}

/* ── Config section ──────────────────────────────────────── */
.config-section {
    margin: 0 32px 32px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    padding: 20px 24px;
}

.config-title {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--text-dim);
    margin: 0 0 16px;
}

.config-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
}

.config-item {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 18px;
    border-right: 1px solid var(--border);
    border-bottom: 1px solid var(--border);
}

.config-item:nth-child(3n) { border-right: none; }
.config-item:nth-last-child(-n+3) { border-bottom: none; }

.config-key {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: .07em;
}

.config-val { min-height: 22px; }

.cfg-badge {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 500;
    color: var(--primary-dark);
    background: var(--primary-bg);
    border: 1px solid rgba(var(--primary-rgb),.25);
    border-radius: 4px;
    padding: 2px 8px;
    cursor: default;
}

@media (max-width: 900px) {
    .config-grid { grid-template-columns: repeat(2, 1fr); }
    .config-item:nth-child(3n) { border-right: 1px solid var(--border); }
    .config-item:nth-child(2n) { border-right: none; }
    .config-item:nth-last-child(-n+3) { border-bottom: 1px solid var(--border); }
    .config-item:nth-last-child(-n+2) { border-bottom: none; }
}

@media (max-width: 700px) {
    .config-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ── Installations section ───────────────────────────────── */
.installations-section {
    margin: 0 32px 24px;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.inst-detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
    flex-wrap: wrap;
}

.inst-detail-meta {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
    font-family: var(--font-sans);
    font-size: 15px;
}

.inst-detail-name {
    font-weight: 600;
    color: var(--text);
}

.inst-detail-notes {
    color: var(--text-mid);
    font-size: 14px;
}

.inst-key-count {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 20px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    color: var(--text-dim);
}

.inst-key-count--active {
    background: var(--green-bg);
    border-color: rgba(var(--green-rgb),.3);
    color: var(--green-text);
}

.key-status {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    letter-spacing: .03em;
    padding: 2px 8px;
    border-radius: 20px;
}

.key-status--active  { background: var(--green-bg);  color: var(--green); }
.key-status--revoked { background: var(--surface-alt); color: var(--text-dim); border: 1px solid var(--border); }

.btn-sm {
    font-size: 13px !important;
    padding: 3px 10px !important;
}

/* ── Modal ───────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, .45);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    animation: fadeIn .15s ease both;
}

.modal-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 440px;
    display: flex;
    flex-direction: column;
    gap: 0;
    overflow: hidden;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
}

.modal-header h3 {
    font-family: var(--font-sans);
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -.01em;
}

.modal-close {
    background: none;
    border: none;
    font-size: 18px;
    line-height: 1;
    color: var(--text-dim);
    cursor: pointer;
    padding: 0 2px;
    transition: color .12s;
}
.modal-close:hover { color: var(--text); }

.modal-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    padding: 14px 20px;
    border-top: 1px solid var(--border);
    background: var(--surface-alt);
}

.modal-error {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--error-text);
    background: var(--error-bg);
    border: 1px solid rgba(var(--error-rgb),.3);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
}

.modal-warning {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--amber-text);
    background: var(--amber-bg);
    border: 1px solid rgba(var(--amber-rgb),.3);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
}

.field-required { color: var(--red-text); font-weight: 700; }
.field-optional { color: var(--text-dim); font-weight: 400; font-size: 12px; }

.token-display-wrap {
    display: flex;
    align-items: center;
    gap: 10px;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
}

.token-display {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text);
    word-break: break-all;
    flex: 1;
    user-select: all;
}

.copy-confirm {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--green);
    font-weight: 500;
}

@media (max-width: 700px) {
    .installations-section { margin: 0 16px 16px; }
    .modal-box { max-width: calc(100vw - 32px); }
}

/* ── Installations category sub-tabs ────────────────────── */
.inst-category-tabs {
    display: flex;
    align-items: center;
    gap: 2px;
    padding: 10px 20px 0;
    background: var(--surface-alt);
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.inst-cat-tab {
    background: none;
    border: 1px solid transparent;
    border-bottom: none;
    color: var(--text-mid);
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    padding: 6px 14px;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    transition: all .12s;
    white-space: nowrap;
    position: relative;
    bottom: -1px;
}

.inst-cat-tab:hover {
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
    border-bottom-color: transparent;
}

.inst-cat-tab.active {
    background: var(--surface);
    border-color: var(--border);
    border-bottom-color: var(--surface);
    color: var(--primary);
    font-weight: 600;
}

.inst-cat-count {
    display: inline-block;
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    background: var(--primary-bg);
    color: var(--primary-dark);
    border-radius: 10px;
    padding: 0 5px;
    margin-left: 5px;
    line-height: 1.6;
}

.inst-cat-tab.active .inst-cat-count {
    background: var(--primary);
    color: #fff;
}

/* ── Permission select (detail + bulk) ───────────────────── */
.inst-permission-select {
    font-family: var(--font-sans);
    font-size: 14px;
    height: 32px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.inst-permission-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

/* ── Installations search bar ────────────────────────────── */
.inst-search-bar {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border);
    background: var(--surface-alt);
}

/* Checkbox fields: undo the text-input styling (.field input) and the uppercase
   label styling (.field label) so the checkbox renders at its natural size. */
.field--checkbox .checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-sans);
    font-size: 15px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: normal;
    color: var(--text);
    cursor: pointer;
}
.field--checkbox input[type="checkbox"] {
    width: 15px;
    height: 15px;
    padding: 0;
    margin: 0;
    flex: 0 0 auto;
    border: none;
    background: none;
    box-shadow: none;
    accent-color: var(--primary);
    cursor: pointer;
}

.keylookup-help {
    padding: 12px 20px 0;
    margin: 0;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-mid);
    line-height: 1.5;
}

.keylookup-bar {
    display: flex;
    gap: 8px;
    align-items: center;
}
.keylookup-bar #keylookup-search {
    flex: 1;
}

.inst-search-bar input {
    font-family: var(--font-mono);
    font-size: 14px;
    height: 32px;
    padding: 0 12px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text);
    width: 320px;
    max-width: 100%;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
}

.inst-search-bar input::placeholder { color: var(--text-dim); }

.inst-search-bar input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

/* ── Similar-match hint ──────────────────────────────────── */
.inst-similar {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--amber-text);
    background: var(--amber-bg);
    border: 1px solid rgba(var(--amber-rgb),.3);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    line-height: 1.4;
}

.bulk-review {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-mid);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 7px 12px;
    line-height: 1.5;
}
.bulk-review--warn {
    color: var(--amber-text);
    background: var(--amber-bg);
    border-color: rgba(var(--amber-rgb),.3);
}

.inst-group-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--text-mid);
}

/* ── Installation detail header zones (change 6) ─────────── */
.inst-detail-header {
    justify-content: flex-start;
    gap: 0;
    padding: 10px 24px;
}

.inst-detail-zone {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.inst-detail-zone--left {
    flex: 0 0 auto;
    padding-right: 16px;
    border-right: 1px solid var(--border);
    margin-right: 16px;
}

.inst-detail-zone--middle {
    flex: 1 1 auto;
    min-width: 0;
}

.inst-detail-zone--right {
    flex: 0 0 auto;
    padding-left: 16px;
    border-left: 1px solid var(--border);
    margin-left: 16px;
}

/* Visual gap between Generate key and Delete */
.inst-detail-sep {
    display: inline-block;
    width: 8px;
}

@media (max-width: 1000px) {
    .inst-detail-header { flex-direction: column; align-items: flex-start; gap: 10px; }
    .inst-detail-zone--left,
    .inst-detail-zone--right { border: none; margin: 0; padding: 0; }
}

/* ── Activity cap note (change 4) ────────────────────────── */
.activity-cap-note {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-dim);
    padding: 5px 0 3px 18px;
    line-height: 1.4;
}

/* ── Installation activity modal ─────────────────────────── */
.activity-controls {
    display: flex;
    gap: 8px;
    align-items: center;
    padding-bottom: 6px;
}
.activity-controls input[type="text"] {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 14px;
    height: 32px;
    padding: 0 9px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
}
.activity-list {
    max-height: 55vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    font-family: var(--font-mono);
    font-size: 13px;
}
.activity-row {
    border-bottom: 1px solid var(--border);
}
.activity-row:last-child { border-bottom: none; }
.activity-summary {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 5px 0;
    cursor: pointer;
    list-style: none;
}
.activity-summary::-webkit-details-marker { display: none; }
.activity-summary::before {
    content: '▸';
    color: var(--text-dim);
    flex: 0 0 auto;
}
.activity-row[open] .activity-summary::before { content: '▾'; }
.activity-summary:hover { background: var(--surface-alt); }
.activity-time {
    color: var(--text-dim);
    white-space: nowrap;
}
.activity-msg {
    flex: 1;
    min-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.activity-detail {
    padding: 4px 0 10px 18px;
}
.activity-section-title {
    font-family: var(--font-sans);
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--text-dim);
    margin: 8px 0 3px;
}
.activity-pre {
    margin: 0;
    white-space: pre-wrap;
    word-break: break-word;
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}
.activity-pre--exc { color: var(--error-text); }
.activity-props {
    display: grid;
    grid-template-columns: minmax(120px, max-content) 1fr;
    gap: 2px 14px;
}
.activity-prop { display: contents; }
.activity-prop-name { color: var(--text-dim); white-space: nowrap; }
.activity-prop-value { word-break: break-word; }

.activity-stored-row {
    display: flex;
    gap: 8px;
    align-items: baseline;
    padding: 5px 0 5px 18px;
    border-bottom: 1px solid var(--border);
}
.activity-stored-row:last-of-type { border-bottom: none; }
.activity-stored-actions { white-space: nowrap; }

/* Full-page activity view */
.activity-page-controls { padding: 8px 20px 0; }
.activity-page-body { padding: 4px 20px 16px; }
.activity-list--page { max-height: none; }

/* ── Bulk modal wider box ────────────────────────────────── */
.modal-box--wide {
    max-width: 600px;
}

/* ── Bulk textarea (names input) ─────────────────────────── */
.bulk-textarea {
    font-family: var(--font-mono);
    font-size: 14px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    width: 100%;
    resize: vertical;
    outline: none;
    transition: border-color .15s, box-shadow .15s;
    line-height: 1.5;
}

.bulk-textarea::placeholder { color: var(--text-dim); }

.bulk-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-bg);
}

/* ── Bulk results area ───────────────────────────────────── */
.bulk-summary {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    padding: 6px 0 2px;
}

.bulk-errors {
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--error-text);
    background: var(--error-bg);
    border: 1px solid rgba(var(--error-rgb),.3);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
}

.bulk-output-wrap {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.bulk-output {
    font-family: var(--font-mono);
    font-size: 13px;
    padding: 9px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    color: var(--text);
    width: 100%;
    resize: vertical;
    min-height: 100px;
    outline: none;
    user-select: all;
}

.bulk-note {
    font-family: var(--font-sans);
    font-size: 13px;
    color: var(--text-dim);
    line-height: 1.4;
}

/* ══════════════════════════════════════════════════════════
   Mobile pass — field-technician-facing views
   Primary breakpoint : 720 px
   Tightest fixes     : 480 px
   Desktop unchanged — all rules scoped inside @media blocks.
   ══════════════════════════════════════════════════════════ */

@media (max-width: 720px) {

    /* ── 1. Top bar ──────────────────────────────────────── */
    .topbar {
        flex-wrap: wrap;
        height: auto;
        padding: 8px 12px 0;
        gap: 0;
        row-gap: 0;
    }

    .topbar-brand {
        /* first row, left */
        order: 0;
        padding-bottom: 6px;
    }

    .topbar-actions {
        /* first row, right */
        order: 1;
        margin-left: auto;
        padding-bottom: 6px;
        gap: 8px;
    }

    /* Nav scrolls horizontally across the full width below brand row */
    .topbar-nav {
        order: 2;
        flex: 0 0 100%;
        justify-content: flex-start;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        /* hide scrollbar but keep functionality */
        scrollbar-width: none;
        padding-bottom: 4px;
        gap: 2px;
        /* stretch to edge-to-edge under the bar padding */
        margin: 0 -12px;
        padding-left: 12px;
        padding-right: 12px;
    }
    .topbar-nav::-webkit-scrollbar { display: none; }

    .nav-tab {
        flex-shrink: 0;
        font-size: 14px;
        padding: 6px 12px;
        /* ensure reasonable touch target height */
        min-height: 36px;
    }

    /* User label too long on small screens — hide it, keep logout button */
    .user-label { display: none; }

    /* ── 2. Key lookup view ──────────────────────────────── */
    /* .keylookup-bar is already flex with input flex:1 — only needs
       to be allowed to wrap when the button would overflow */
    .keylookup-bar {
        flex-wrap: wrap;
    }
    .keylookup-bar #keylookup-search {
        /* ensure full width before button if it wraps */
        min-width: 0;
    }

    /* Make small action buttons tappable */
    .btn-sm {
        padding: 7px 12px !important;
        font-size: 14px !important;
        min-height: 40px;
        min-width: 40px;
    }

    /* Name column truncates; Code column allowed to shrink */
    #keylookup-table .col-path,
    #keylookup-table td:nth-child(2) {
        max-width: 140px;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    /* ── 3. Activity view ────────────────────────────────── */
    .activity-controls {
        flex-wrap: wrap;
        gap: 6px;
    }

    /* Text input takes its own full row */
    .activity-controls input[type="text"] {
        flex: 1 1 100%;
        min-width: 0;
    }

    /* Selects and buttons share the second row */
    .activity-controls .inst-permission-select,
    .activity-controls .btn-ghost,
    .activity-controls .btn-search {
        flex: 0 0 auto;
    }

    /* Summary rows: allow wrapping so time can drop below message */
    .activity-summary {
        flex-wrap: wrap;
        align-items: flex-start;
    }
    .activity-time {
        flex: 0 0 100%;
        order: -1;
        font-size: 12px;
    }
    .activity-msg {
        min-width: 0;
        flex: 1 1 auto;
    }

    /* Properties grid → single column */
    .activity-props {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .activity-prop-name {
        color: var(--text-dim);
        font-weight: 600;
        margin-top: 6px;
    }
    /* Prevent first prop-name from adding extra top margin */
    .activity-prop:first-child .activity-prop-name { margin-top: 0; }

    /* pre blocks: already pre-wrap/word-break in base — just ensure
       they do not escape the viewport */
    .activity-pre {
        max-width: 100%;
        overflow-x: hidden;
    }

    /* ── 4. Table wrap ───────────────────────────────────── */
    .table-wrap {
        -webkit-overflow-scrolling: touch;
        max-width: 100vw;
    }

    /* ── 5. Modals ───────────────────────────────────────── */
    .modal-box,
    .modal-box--wide {
        width: 94vw;
        max-width: 94vw;
        margin: 0 auto;
    }

    .modal-body { padding: 14px; gap: 10px; }
    .modal-footer { padding: 10px 14px; }
    .modal-header { padding: 12px 14px; }

    /* Bulk output textarea fills width (already width:100% but override max-width) */
    .bulk-output,
    .bulk-textarea {
        max-width: 100%;
    }

    /* ── 6. Installation detail header zones ─────────────── */
    /* Already wraps at 1000px via existing rule; reinforce spacing */
    .inst-detail-zone--left,
    .inst-detail-zone--right {
        border: none;
        margin: 0;
        padding: 0;
    }
    .inst-detail-header {
        gap: 8px;
    }

    /* ── General section margins ─────────────────────────── */
    .installations-section { margin: 0 12px 16px; }
    .section-header { padding: 10px 14px; }

    /* keylookup help text padding */
    .keylookup-help { padding: 10px 14px 0; }
    .activity-page-controls { padding: 8px 14px 0; }
    .activity-page-body { padding: 4px 14px 16px; }
    .inst-search-bar { padding: 8px 14px; }

    /* ── 7. Stacked log rows ─────────────────────────────── */
    .log-row-summary { padding: 8px 32px 7px 12px; }
    .log-row-detail  { padding: 8px 12px 12px 14px; }
    .log-row-path    { max-width: 220px; }
    .log-row-primary { gap: 6px; }
    .log-row-dl      { grid-template-columns: minmax(60px, max-content) 1fr; gap: 3px 8px; }

    /* Stored/compat rows on mobile */
    .log-row-compat { padding: 7px 12px; }
    details.log-row-compat > .activity-summary { padding: 7px 28px 7px 12px; }
}

@media (max-width: 480px) {
    /* Even tighter: reduce font sizes that still read fine */
    .nav-tab { font-size: 13px; padding: 6px 10px; }

    /* Metrics strip single column */
    .metrics-strip { grid-template-columns: repeat(2, 1fr); margin: 12px; }
    .metric-value { font-size: 24px; }

    /* Topbar brand: hide tag on very small screens */
    .brand-tag { display: none; }

    /* Section header wraps when actions overflow */
    .section-header { flex-wrap: wrap; gap: 8px; }
    .section-header-actions { width: 100%; justify-content: flex-start; }
}

/* ══════════════════════════════════════════════════════════
   Stacked log rows (.log-list / .log-row)
   Replaces the 10-column table in the Logs view. Also used
   as the shared language for activity stored rows and events
   via .log-row-compat.
   ══════════════════════════════════════════════════════════ */

/* Container: sits inside .table-wrap */
.log-list {
    display: flex;
    flex-direction: column;
}

/* Each entry is a native <details> — expand/collapse is CSS-only */
.log-row {
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    transition: background .1s;
}
.log-row:last-child { border-bottom: none; }
.log-row:hover { background: var(--surface-alt); }
.log-row[open] { background: var(--primary-bg); }

/* The <summary> holds two stacked lines */
.log-row-summary {
    display: flex;
    flex-direction: column;
    gap: 3px;
    padding: 9px 16px 8px;
    cursor: pointer;
    list-style: none;
    position: relative;
    /* chevron space on the right */
    padding-right: 32px;
}
.log-row-summary::-webkit-details-marker { display: none; }

/* Rotating chevron affordance */
.log-row-summary::after {
    content: '›';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    font-size: 16px;
    color: var(--text-dim);
    transition: transform .2s;
    line-height: 1;
}
.log-row[open] > .log-row-summary::after {
    transform: translateY(-50%) rotate(90deg);
}

/* Primary line: app name left, status chip + timestamp right */
.log-row-primary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    min-width: 0;
}

/* Left of the primary line: direction badge + service name */
.log-row-left {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 0;
}

.log-row-app {
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
    min-width: 0;
}

.log-row-right {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.log-row-time {
    font-family: var(--font-mono);
    font-size: 14px;
    color: var(--text-dim);
    white-space: nowrap;
}

/* Secondary line: method badge · path · elapsed · size */
.log-row-secondary {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-wrap: wrap;
    min-width: 0;
}

.log-row-path {
    font-family: var(--font-mono);
    font-size: 15px;
    color: var(--text-mid);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
    max-width: 480px;
}

.log-row-sep {
    color: var(--text-dim);
    font-size: 13px;
    flex-shrink: 0;
}

.log-row-dur,
.log-row-size {
    font-family: var(--font-mono);
    font-size: 15px;
    color: var(--text-dim);
    white-space: nowrap;
    flex-shrink: 0;
}

/* Message line (used in activity events secondary) */
.log-row-msg {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--text-mid);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
    display: block;
}

/* Expanded detail panel */
.log-row-detail {
    padding: 10px 16px 14px 20px;
    border-top: 1px dashed var(--border);
    background: var(--surface);
}

/* Definition list for detail fields */
.log-row-dl {
    display: grid;
    grid-template-columns: minmax(72px, max-content) 1fr;
    gap: 4px 12px;
    font-family: var(--font-mono);
    font-size: 15px;
    margin-bottom: 10px;
}
.log-row-dl dt {
    color: var(--text-dim);
    font-weight: 400;
    white-space: nowrap;
    align-self: center;
}
.log-row-dl dd {
    margin: 0;
    word-break: break-word;
    align-self: center;
}

/* Trace value: click-to-copy */
.log-row-trace {
    cursor: pointer;
    color: var(--text-mid);
    border-bottom: 1px dashed var(--border);
}
.log-row-trace:hover { color: var(--primary); border-color: var(--primary); }

/* View / Share on the primary line — visible without expanding the row.
   The buttons stop click propagation so they don't toggle the row open. */
.log-row-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
    margin-left: 2px;
}
.log-row-actions .btn-sm { padding: 2px 8px; font-size: 13px; }

/* ── Compatibility class for activity rows using the same language ── */
/* .log-row-compat applies to .activity-stored-row and .activity-row  */
.log-row-compat {
    border-bottom: 1px solid var(--border);
    padding: 8px 16px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    background: var(--surface);
}
.log-row-compat:last-of-type { border-bottom: none; }
.log-row-compat:hover { background: var(--surface-alt); }

/* activity-row is a <details>; override display so flex works on summary */
details.log-row-compat { display: block; padding: 0; }
details.log-row-compat > .activity-summary {
    flex-direction: column;
    gap: 3px;
    padding: 8px 32px 8px 16px;
    position: relative;
}
details.log-row-compat > .activity-summary::before { display: none; }
details.log-row-compat > .activity-summary::after {
    content: '›';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%) rotate(0deg);
    font-size: 16px;
    color: var(--text-dim);
    transition: transform .2s;
    line-height: 1;
}
details.log-row-compat[open] > .activity-summary::after {
    transform: translateY(-50%) rotate(90deg);
}
details.log-row-compat[open] { background: var(--primary-bg); }

/* ── Structured property tree (.prop-tree / .prop-leaf / .prop-key) ── */

/* Wrapper for an object-valued property rendered as a collapsible */
.prop-obj-details {
    display: inline-block;
    max-width: 100%;
}
.prop-obj-summary {
    cursor: pointer;
    list-style: none;
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-dim);
    padding: 1px 4px;
    border-radius: var(--radius-sm);
    background: var(--surface-alt);
    border: 1px solid var(--border);
    display: inline-block;
    transition: background .12s;
}
.prop-obj-summary::-webkit-details-marker { display: none; }
.prop-obj-summary:hover { background: var(--primary-bg); color: var(--primary); border-color: rgba(var(--primary-rgb),.3); }
.prop-obj-details[open] .prop-obj-summary { background: var(--primary-bg); color: var(--primary-dark); }

/* The nested key→value block */
.prop-tree {
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px 0 2px 10px;
    border-left: 2px solid var(--border);
    margin-top: 4px;
}

.prop-leaf {
    display: flex;
    align-items: baseline;
    gap: 6px;
    font-family: var(--font-mono);
    font-size: 15px;
    flex-wrap: wrap;
    min-width: 0;
}

.prop-key {
    color: var(--text-dim);
    font-size: 14px;
    white-space: nowrap;
    flex-shrink: 0;
}
.prop-key::after { content: ':'; }

.prop-leaf--more {
    color: var(--text-dim);
    font-size: 12px;
    font-style: italic;
}

/* ── Harmonised tables: key lookup + installations ───────── */
/* Same row hover/background/chip styling without changing layout. */
#keylookup-table tbody tr,
#installations-table tbody tr {
    /* keep existing zebra + hover, just add a touch more padding comfort */
}
#keylookup-table td,
#installations-table td {
    padding: 10px 16px;
}

/* ── Animations ──────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

.metrics-strip .metric-card:nth-child(1) { animation: fadeIn .35s ease both; animation-delay: .04s; }
.metrics-strip .metric-card:nth-child(2) { animation: fadeIn .35s ease both; animation-delay: .07s; }
.metrics-strip .metric-card:nth-child(3) { animation: fadeIn .35s ease both; animation-delay: .10s; }
.metrics-strip .metric-card:nth-child(4) { animation: fadeIn .35s ease both; animation-delay: .13s; }
.metrics-strip .metric-card:nth-child(5) { animation: fadeIn .35s ease both; animation-delay: .16s; }
.metrics-strip .metric-card:nth-child(6) { animation: fadeIn .35s ease both; animation-delay: .19s; }
.chart-section  { animation: fadeIn .35s ease both; animation-delay: .22s; }
.table-section  { animation: fadeIn .35s ease both; animation-delay: .25s; }

/* ── View containers ─────────────────────────────────────── */
.view-container { padding-bottom: 8px; }

/* ── Section header actions group ───────────────────────── */
.section-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* ── Sync result banner ──────────────────────────────────── */
.sync-result {
    margin: 0 0 0;
    padding: 10px 24px;
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.sync-result--ok {
    background: var(--green-bg);
    color: var(--green-text);
    border-bottom-color: rgba(var(--green-rgb),.3);
}

.sync-result--error {
    background: var(--error-bg);
    color: var(--error-text);
    border-bottom-color: rgba(var(--error-rgb),.3);
}

/* ── Credentials section ─────────────────────────────────── */
.credentials-section {
    margin: 24px 32px 0;
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.credentials-body {
    padding: 20px 24px;
}

.credentials-fields {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px 14px;
    margin-bottom: 16px;
}

.credentials-footer {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.cred-message {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    flex: 1;
}

.cred-message--ok {
    background: var(--green-bg);
    color: var(--green-text);
    border: 1px solid rgba(var(--green-rgb),.3);
}

.cred-message--error {
    background: var(--error-bg);
    color: var(--error-text);
    border: 1px solid rgba(var(--error-rgb),.3);
}

/* danger-zone inside view-system needs its own top margin */
#view-system .danger-zone {
    margin-top: 24px;
}

/* responsive for credentials and new sections */
@media (max-width: 700px) {
    .credentials-section { margin: 16px 16px 0; }
    #view-system .danger-zone { margin: 16px; }
    .topbar-nav { gap: 1px; }
    .nav-tab { padding: 5px 10px; font-size: 13px; }
}

/* ── Mobile: stack the small lookup/inventory tables into cards so the row's
   actions are never cut off (no horizontal scroll needed). ── */
@media (max-width: 600px) {
    #keylookup-table, #keylookup-table tbody, #keylookup-table tr, #keylookup-table td { display: block; width: auto; }
    #keylookup-table thead,
    #installations-table thead { display: none; }
    #installations-table, #installations-table tbody, #installations-table tr, #installations-table td { display: block; width: auto; }
    #keylookup-table tr, #installations-table tr {
        border: 1px solid var(--border);
        border-radius: var(--radius-md);
        padding: 8px 12px;
        margin-bottom: 8px;
        background: var(--surface);
    }
    #keylookup-table td, #installations-table td {
        padding: 2px 0;
        border: none;
    }
    /* The actions cell (always the last one) gets its own row of full-width-ish buttons. */
    #keylookup-table td:last-child, #installations-table td:last-child {
        margin-top: 6px;
        display: flex;
        flex-wrap: wrap;
        gap: 6px;
    }
    #keylookup-table td:last-child .btn-sm,
    #installations-table td:last-child .btn-sm { flex: 1 1 auto; min-height: 38px; }
    /* First cell (the code) reads as the card title. */
    #keylookup-table td:first-child, #installations-table td:first-child {
        font-weight: 600; color: var(--text);
    }
    .table-wrap { overflow-x: visible; }
}

/* ── Mobile: keep log / event rows within the screen. The right group
   (status, time, actions) drops to its own full-width line under the name,
   and long text wraps instead of forcing horizontal scroll. ── */
@media (max-width: 600px) {
    .log-row-primary { flex-wrap: wrap; row-gap: 4px; }
    .log-row-left { flex: 1 1 100%; min-width: 0; }
    /* The name shows in full (wraps) instead of being clipped with an ellipsis. */
    .log-row-app { white-space: normal; overflow: visible; text-overflow: clip; overflow-wrap: anywhere; }
    .log-row-right { flex: 1 1 100%; justify-content: space-between; flex-wrap: wrap; flex-shrink: 1; min-width: 0; }
    .log-row-time { font-size: 13px; }
    .log-row-secondary { width: 100%; }
    .log-row-path { white-space: normal; overflow-wrap: anywhere; max-width: 100%; }
    .activity-msg { min-width: 0; white-space: normal; overflow-wrap: anywhere; }
    /* A touch less right padding so the name has the full width up to the chevron. */
    .log-row-summary { padding-right: 26px; }
}

/* ── Combobox clear button + Logs console controls (live tail, filters) ── */
.combo-input { padding-right: 44px; }
.combo-clear {
    position: absolute; top: 0; right: 22px; height: 100%; width: 22px;
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; cursor: pointer;
    color: var(--text-dim); font-size: 15px; line-height: 1;
}
.combo-clear:hover { color: var(--red-text); }

.activity-text-filter {
    min-width: 150px;
}

/* Live tail toggle */
.btn-live { display: inline-flex; align-items: center; gap: 6px; }
.live-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--text-dim); flex-shrink: 0; transition: background .15s;
}
.btn-live.active {
    border-color: rgba(var(--green-rgb),.4); color: var(--green-text); background: var(--green-bg);
}
.btn-live.active .live-dot { background: var(--green); animation: pulse 1.4s ease-in-out infinite; }

/* Copy-JSON action inside an expanded event */
.activity-detail-actions { margin-top: 10px; display: flex; gap: 6px; }

/* New events appended by the live tail flash briefly so they're easy to spot. */
@keyframes logRowFlash { 0% { background: var(--primary-bg); } 100% { background: transparent; } }
.activity-row.log-row-new { animation: logRowFlash 2.6s ease-out; }
