[x-cloak] { display: none !important; }
body { align-items: flex-start; padding: 0; background: var(--brand-page); }

  .shell { display: flex; min-height: 100vh; width: 100%; }

  /* ── Sidebar ── */
  .sidebar {
    width: 220px;
    flex-shrink: 0;
    background: white;
    border-right: 1px solid var(--brand-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }
  .sidebar-brand {
    padding: 1.25rem 1rem 1rem;
    border-bottom: 1px solid var(--brand-border);
  }
  .sidebar-brand h2 { font-size: 1rem; font-weight: 700; color: var(--brand-navy); margin-bottom: 2px; }
  .sidebar-brand p  { font-size: 0.75rem; color: var(--brand-slate); }

  .nav-section { padding: 0.75rem 0 0.25rem; }
  .nav-label {
    padding: 0 1rem 0.4rem;
    font-size: 0.7rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--brand-slate);
  }
  .nav-item {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    padding: 0.55rem 1rem;
    cursor: pointer;
    font-size: 0.875rem;
    color: var(--brand-slate);
    border-left: 3px solid transparent;
    transition: background 0.12s, color 0.12s;
  }
  .nav-item:hover  { background: var(--brand-page); color: var(--brand-navy); }
.nav-item.active { background: var(--brand-page); color: var(--brand-navy); border-left-color: var(--brand-navy); font-weight: 600; }
  .nav-item .ni { font-size: 0.95rem; width: 18px; text-align: center; }
  .nav-badge {
    margin-left: auto;
    background: #dc3545;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
  }

  .sidebar-footer {
    margin-top: auto;
    padding: 1rem;
    border-top: 1px solid var(--brand-border);
    font-size: 0.8rem;
  }
  .sidebar-footer .sf-name { font-weight: 600; color: var(--brand-navy); }
  .sidebar-footer .sf-role {
    display: inline-block;
    margin-top: 3px;
    background: #dc3545;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 1px 7px;
    border-radius: 3px;
    letter-spacing: 0.05em;
    text-transform: uppercase;
  }
  .sidebar-footer a { display: block; margin-top: 0.6rem; color: var(--brand-slate); font-size: 0.78rem; text-decoration: none; }
.sidebar-footer a:hover { color: var(--brand-navy); }

  /* ── Main ── */
  .main-wrap { flex: 1; min-width: 0; display: flex; flex-direction: column; }

  .topbar {
    background: white;
    border-bottom: 1px solid var(--brand-border);
    padding: 0.85rem 1.5rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    position: sticky;
    top: 0;
    z-index: 50;
  }
  .topbar h1 { font-size: 1.1rem; font-weight: 700; color: var(--brand-navy); }
  .topbar-right { display: flex; align-items: center; gap: 0.75rem; }

  .content { padding: 1.5rem; flex: 1; }

  /* ── Stat cards ── */
  .stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
  }
  .stat-card {
    background: white;
    border: 1px solid var(--brand-border);
    border-radius: 8px;
    padding: 1rem;
  }
.stat-num       { font-size: 2rem; font-weight: 700; color: var(--brand-navy); line-height: 1; margin-bottom: 4px; }
  .stat-num.red   { color: #dc3545; }
.stat-num.green { color: #1e7e34; }
  .stat-num.amber { color: #fd7e14; }
  .stat-num.grey  { color: #6c757d; }
  .stat-lbl       { font-size: 0.75rem; color: var(--brand-slate); font-weight: 500; }

  /* ── Panels ── */
  .panel { background: white; border: 1px solid var(--brand-border); border-radius: 8px; overflow: hidden; margin-bottom: 1.25rem; }
  .panel-header {
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--brand-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 0.5rem;
    background: var(--brand-page);
  }
  .panel-title { font-size: 0.9rem; font-weight: 600; color: var(--brand-navy); }
  .panel-body  { padding: 1rem; }

  /* ── Tables ── */
  .tbl { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
  .tbl th {
    padding: 0.6rem 0.75rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--brand-navy);
    border-bottom: 1px solid var(--brand-border);
    background: var(--brand-page);
    white-space: nowrap;
  }
  .tbl td { padding: 0.65rem 0.75rem; border-bottom: 1px solid var(--brand-border); vertical-align: middle; }
  .tbl tr:last-child td { border-bottom: none; }
  .tbl tbody tr:hover td { background: var(--brand-page); }

  /* ── Extra button colours ── */
  .btn-red   { background: #dc3545; color: white; }
  .btn-red:hover   { background: #b02a37; }
.btn-green { background: #155724; color: white; }
.btn-green:hover { background: #0f401b; }
.btn-green:disabled { background: #e5e7eb; color: var(--brand-navy); opacity: 1; }
.btn-amber { background: #a84300; color: white; }
.btn-amber:hover { background: #873600; }
  .btn-outline {
    background: transparent;
    border: 1px solid var(--brand-border);
    color: var(--brand-slate);
  }
  .btn-outline:hover { background: var(--brand-page); border-color: #999; color: var(--brand-navy); }

  /* ── Tags ── */
  .tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
  }
  .tag-red    { background: #fde8ea; color: #c0392b; }
  .tag-green  { background: #d4edda; color: #155724; }
  .tag-blue   { background: #d1ecf1; color: #0c5460; }
  .tag-amber  { background: #fff3cd; color: #856404; }
  .tag-grey   { background: #e9ecef; color: var(--brand-slate); }

  /* ── Config rows ── */
  .cfg-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 0;
    border-bottom: 1px solid var(--brand-border);
    gap: 1rem;
    flex-wrap: wrap;
  }
  .cfg-row:last-child { border-bottom: none; }
  .cfg-label { font-size: 0.875rem; font-weight: 600; color: var(--brand-navy); }
  .cfg-desc  { font-size: 0.75rem; color: var(--brand-slate); margin-top: 2px; }
  .cfg-ctrl  { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
  .cfg-ctrl input[type="number"] {
    width: 80px;
    padding: 0.35rem 0.5rem;
    border: 1px solid var(--brand-border);
    border-radius: 4px;
    font-size: 0.875rem;
    text-align: right;
  }
  .cfg-ctrl input:focus { outline: none; border-color: var(--brand-navy); }
  .cfg-unit { font-size: 0.75rem; color: var(--brand-slate); }

  /* ── SQL editor ── */
  .sql-editor {
    width: 100%;
    min-height: 100px;
    padding: 0.75rem;
    background: var(--brand-page);
    border: 1px solid var(--brand-border);
    border-radius: 4px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.85rem;
    color: var(--brand-navy);
    resize: vertical;
    line-height: 1.5;
  }
  .sql-editor:focus { outline: none; border-color: var(--brand-navy); }
  .result-wrap { overflow: auto; max-height: 380px; }

  /* ── Announcement bar ── */
  .ann-bar {
    padding: 0.65rem 1.5rem;
    font-size: 0.85rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.6rem;
  }
  .ann-info    { background: #d1ecf1; color: #0c5460; border-bottom: 1px solid #bee5eb; }
  .ann-warning { background: #fff3cd; color: #856404; border-bottom: 1px solid #ffc107; }
  .ann-danger  { background: #f8d7da; color: #721c24; border-bottom: 1px solid #f5c6cb; }

  /* ── Toast ── */
  .toast-wrap {
    position: fixed; top: 1rem; right: 1rem;
    z-index: 9999;
    display: flex; flex-direction: column; gap: 0.5rem;
  }
  .toast {
    padding: 0.65rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    max-width: 320px;
    box-shadow: 0 2px 8px rgba(0,0,0,.12);
    animation: tin .2s ease;
  }
  @keyframes tin { from { opacity:0; transform:translateX(12px); } to { opacity:1; transform:none; } }
  .toast-ok     { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }
  .toast-danger { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }
  .toast-warn   { background: #fff3cd; color: #856404; border: 1px solid #ffc107; }

  /* ── Confirm dialog ── */
  .confirm-overlay {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    display: flex; align-items: center; justify-content: center;
    z-index: 2000;
  }
  .confirm-box {
    background: white;
    border-radius: 8px;
    padding: 1.5rem;
    width: 90%; max-width: 420px;
    box-shadow: 0 8px 30px rgba(0,0,0,.15);
  }
  .confirm-box h3 { font-size: 1rem; font-weight: 700; margin-bottom: 0.5rem; color: var(--brand-navy); }
  .confirm-box p  { font-size: 0.875rem; color: var(--brand-slate); margin-bottom: 1.25rem; line-height: 1.5; }
  .confirm-actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

  /* ── Spinner ── */
  .spin {
    display: inline-block;
    width: 14px; height: 14px;
    border: 2px solid var(--brand-border);
    border-top-color: var(--brand-navy);
    border-radius: 50%;
    animation: sp .7s linear infinite;
    vertical-align: middle;
  }
  @keyframes sp { to { transform: rotate(360deg); } }

  .empty { padding: 2rem; text-align: center; color: var(--brand-slate); font-size: 0.875rem; }

  /* ── DB table cards ── */
  .table-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
  }
  .tbl-card { background: white; border: 1px solid var(--brand-border); border-radius: 8px; overflow: hidden; }
  .tbl-card-head {
    padding: 0.65rem 0.85rem;
    background: var(--brand-page);
    border-bottom: 1px solid var(--brand-border);
    display: flex; align-items: center; justify-content: space-between;
  }
  .tbl-card-name { font-weight: 600; font-size: 0.875rem; font-family: monospace; color: var(--brand-navy); }
  .tbl-card-body { padding: 0.65rem 0.85rem; }
  .col-pill {
    display: inline-block;
    margin: 2px;
    padding: 2px 7px;
    background: var(--brand-page);
    border-radius: 3px;
    font-size: 0.7rem;
    font-family: monospace;
    color: var(--brand-navy);
  }

  /* ── Quick action cards ── */
  .qa-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.75rem;
  }
  .qa-btn {
    padding: 0.85rem 1rem;
    background: white;
    border: 1px solid var(--brand-border);
    border-radius: 8px;
    cursor: pointer;
    text-align: left;
    transition: box-shadow .15s, border-color .15s;
    font-family: inherit;
  }
  .qa-btn:hover { border-color: var(--brand-navy); box-shadow: 0 2px 8px rgba(0,123,255,.1); }
  .qa-btn.qa-danger:hover { border-color: #dc3545; box-shadow: 0 2px 8px rgba(220,53,69,.1); }
  .qa-icon  { font-size: 1.3rem; margin-bottom: 0.4rem; display: block; }
  .qa-label { font-size: 0.8rem; font-weight: 600; color: var(--brand-navy); }
  .qa-sub   { font-size: 0.7rem; color: var(--brand-slate); margin-top: 1px; }

  @media (max-width: 768px) {
    .sidebar { display: none; }
    .content { padding: 1rem; }
    .topbar  { padding: 0.75rem 1rem; }
  }
/* Panel overrides follow shared styles so the shell owns its layout. */
body { display: block; padding: 0; }
.nav-item { width: 100%; border: 0; border-left: 3px solid transparent; background: transparent; text-align: left; font: inherit; font-size: .875rem; border-radius: 0; min-height: 44px; }
button, select, input, textarea, a { touch-action: manipulation; }
:where(button, select, input, textarea, a, summary):focus-visible { outline: 3px solid #2563eb; outline-offset: 3px; }
.mobile-section { display: none; }
.content { min-width: 0; }
.panel-body, .panel-header, .topbar-right { min-width: 0; }
.topbar { gap: 1rem; flex-wrap: wrap; }
.topbar-right { flex-wrap: wrap; }
.btn { min-height: 40px; }
.confirm-overlay { padding: 1rem; overflow-y: auto; }
.confirm-box { max-height: calc(100dvh - 2rem); overflow-y: auto; }
.confirm-actions { flex-wrap: wrap; }
.toast-wrap { max-width: calc(100vw - 2rem); }
.toast { overflow-wrap: anywhere; }
.cfg-ctrl { max-width: 100%; flex-wrap: wrap; }
.sql-editor { min-width: 0; }
@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar { position: static; align-items: flex-start; }
  .mobile-section { display: grid; gap: .25rem; width: 100%; }
  .mobile-section label { font-size: .75rem; font-weight: 600; color: #475569; }
  .mobile-section select { width: 100%; min-width: 0; min-height: 44px; padding: .65rem; border: 1px solid #cbd5e1; border-radius: 6px; background: white; font: inherit; }
  .topbar-right { width: 100%; gap: .5rem; }
  .stat-grid, .qa-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
  .table-grid { grid-template-columns: minmax(0, 1fr); }
  .stat-card, .qa-btn { min-width: 0; padding: .85rem; overflow-wrap: anywhere; }
  .panel-header > div { flex-wrap: wrap; }
  .tbl td { overflow-wrap: anywhere; }
  .ann-bar { flex-wrap: wrap; padding: .75rem 1rem; overflow-wrap: anywhere; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

.role-actions { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; margin-top: .5rem; }
.role-change { flex-basis: 100%; font-size: .8rem; color: #475569; }
.user-admin-actions { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.action-error { color: #9f1239; font-size: .85rem; margin-top: .5rem; overflow-wrap: anywhere; }

.list-filters { display: flex; flex-wrap: wrap; gap: .75rem; padding: 1rem 1rem .5rem; align-items: end; }
.list-filters label { display: grid; gap: .3rem; min-width: 0; flex: 1 1 160px; font-size: .8rem; font-weight: 600; color: #475569; }
.list-filters input, .list-filters select { width: 100%; min-width: 0; min-height: 44px; border: 1px solid #cbd5e1; border-radius: 6px; padding: .5rem .65rem; background: white; font: inherit; }
.list-count { padding: .25rem 1rem .75rem; font-size: .8rem; color: #475569; }
@media (max-width: 480px) { .list-filters label { flex-basis: 100%; } }

@media (max-width: 768px) {
  .locked-accounts-table, .locked-accounts-table tbody { display: block; width: 100%; min-width: 0; }
  .locked-accounts-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .locked-accounts-table tr { display: block; padding: .5rem .75rem; border: 1px solid #dce3ec; border-radius: 8px; background: #fff; margin-bottom: .75rem; }
  .locked-accounts-table td { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: .75rem; align-items: center; padding: .35rem 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .locked-accounts-table td::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: #475569; }
  .locked-accounts-table td[data-label="Select"] input[type="checkbox"] { width: 20px; height: 20px; }
  .locked-accounts-table td[data-label="Action"] .btn { min-height: 44px; }

  .organizations-table, .organizations-table tbody { display: block; width: 100%; min-width: 0; }
  .organizations-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .organizations-table tr { display: block; padding: .5rem .75rem; border: 1px solid #dce3ec; border-radius: 8px; background: #fff; margin-bottom: .75rem; }
  .organizations-table td { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: .75rem; padding: .35rem 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .organizations-table td::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: #475569; }

  .sessions-table, .sessions-table tbody { display: block; width: 100%; min-width: 0; }
  .sessions-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .sessions-table tr { display: block; padding: .5rem .75rem; border: 1px solid #dce3ec; border-radius: 8px; background: #fff; margin-bottom: .75rem; }
  .sessions-table td { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: .75rem; padding: .35rem 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .sessions-table td::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: #475569; }

  .users-table, .users-table tbody { display: block; width: 100%; min-width: 0; }
  .users-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .users-table tr { display: block; padding: .5rem .75rem; border: 1px solid #dce3ec; border-radius: 8px; background: #fff; margin-bottom: .75rem; }
  .users-table td { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: .75rem; padding: .35rem 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .users-table td::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: #475569; }
  .users-table td[data-label="Role"] select { width: 100%; min-height: 40px; }
  .user-admin-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
}

@media (max-width: 768px) {
  .audit-table, .audit-table tbody { display: block; width: 100%; min-width: 0; }
  .audit-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); }
  .audit-table tr { display: block; padding: .5rem .75rem; border: 1px solid #dce3ec; border-radius: 8px; background: #fff; margin-bottom: .75rem; }
  .audit-table td { display: grid; grid-template-columns: 6rem minmax(0, 1fr); gap: .75rem; padding: .35rem 0; border: 0; white-space: normal; overflow-wrap: anywhere; }
  .audit-table td::before { content: attr(data-label); font-size: .75rem; font-weight: 600; color: #475569; }
  .audit-table td[data-label="Details"] details { min-width: 0; }
  .audit-table td[data-label="Details"] summary { display: flex; align-items: center; min-height: 44px; cursor: pointer; }
}

.audit-pagination { display: flex; gap: .75rem; align-items: center; flex-wrap: wrap; padding: .75rem 1rem; }
.audit-pagination span { font-size: .85rem; }
.audit-error { padding: 1rem; color: #9f1239; overflow-wrap: anywhere; }
.audit-filters input[type="date"] { max-width: 100%; box-sizing: border-box; }
@media (max-width: 768px) {
  .audit-filters input[type="date"] { min-height: 48px; font-size: 16px; }
}

.action-feedback { padding: .5rem 1rem; font-size: .85rem; }
.cfg-ctrl .action-error { flex-basis: 100%; }
.sidebar-brand-link {
    display: inline-flex;
    align-items: center;
    gap: .5rem;
    min-height: 36px;
    color: var(--brand-navy);
    font-size: 1rem;
    font-weight: 700;
    text-decoration: none;
}
.sidebar-brand-link img { width: 28px; height: 28px; }
.sidebar-brand-link:hover { text-decoration: underline; text-decoration-color: var(--brand-amber); text-underline-offset: 3px; }
.sidebar-brand-link:focus-visible { outline: 3px solid var(--brand-focus); outline-offset: 3px; border-radius: 3px; }
