/* ==========================================================================
   Middleware admin theme — light "sidebar dashboard".
   Loaded AFTER bootstrap.min.css, so these rules intentionally override it.
   No external fonts/scripts (keeps the strict Content-Security-Policy happy).
   ========================================================================== */

:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --border: #e6e9ee;
  --text: #1f2733;
  --muted: #5b6675;
  --brand: #2563eb;
  --brand-600: #1d4ed8;
  --brand-50: #eef4ff;
  --ok: #166534;       --ok-bg: #e7f6ec;
  --warn: #b45309;     --warn-bg: #fdf1e0;
  --danger: #c81e1e;   --danger-bg: #fcebec;
  --neutral: #475569;  --neutral-bg: #eef1f5;
  --radius: 11px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 1px 3px rgba(16,24,40,.08);
  --sidebar-w: 250px;
  --topbar-h: 60px;
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

html { font-size: 15px; position: relative; min-height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand-600); }

/* ---------- App shell ---------------------------------------------------- */
.app-sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 1040;
}
.app-main { margin-left: var(--sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }
.app-topbar {
  position: sticky; top: 0; z-index: 1030;
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 12px;
  padding: 0 22px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
}
.app-content { padding: 26px; width: 100%; max-width: 1240px; }

/* ---------- Sidebar ------------------------------------------------------ */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  height: var(--topbar-h);
  padding: 0 20px;
  font-weight: 700; font-size: 1.05rem; letter-spacing: -.01em;
  color: var(--text); text-decoration: none;
  border-bottom: 1px solid var(--border);
}
.logo {
  width: 28px; height: 28px; border-radius: 8px; flex: none;
  background: linear-gradient(135deg, var(--brand), #6366f1);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: .95rem;
}
.sidebar-nav { flex: 1; overflow-y: auto; padding: 14px 12px; }
.nav-section { padding: 14px 12px 6px; font-size: .68rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px; margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: var(--text); text-decoration: none; font-weight: 500; font-size: .92rem;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.active { background: var(--brand-50); color: var(--brand-600); font-weight: 600; }
.nav-link .ico { width: 18px; text-align: center; flex: none; opacity: .85; }
.nav-link.active .ico { opacity: 1; }
.sidebar-foot { border-top: 1px solid var(--border); padding: 12px 16px; font-size: .82rem; color: var(--muted); }

/* ---------- Topbar bits -------------------------------------------------- */
.topbar-toggle { display: none; border: 0; background: none; font-size: 1.3rem; line-height: 1; cursor: pointer; color: var(--text); }
.topbar-title { font-size: 1.02rem; font-weight: 600; margin: 0; }
.topbar-spacer { flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 9px; }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-50); color: var(--brand-600); display: grid; place-items: center; font-weight: 700; font-size: .85rem; }

/* ---------- Page head + toolbar ------------------------------------------ */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 14px; flex-wrap: wrap; margin-bottom: 20px; }
.page-title { font-size: 1.4rem; font-weight: 650; margin: 0; letter-spacing: -.01em; }
.page-sub { color: var(--muted); font-size: .9rem; margin: 4px 0 0; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Stat cards --------------------------------------------------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card::before { content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px; background: var(--brand); }
.stat-card.ok::before { background: var(--ok); }
.stat-card.warn::before { background: var(--warn); }
.stat-card.danger::before { background: var(--danger); }
.stat-card.neutral::before { background: var(--neutral); }
.stat-value { font-size: 1.9rem; font-weight: 700; line-height: 1.05; font-variant-numeric: tabular-nums; }
.stat-label { color: var(--muted); font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; margin-top: 5px; }

/* ---------- Panels ------------------------------------------------------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 22px; overflow: hidden; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); font-weight: 600; }
.panel-head .sub { font-weight: 400; color: var(--muted); font-size: .85rem; }
.panel-body { padding: 18px; }

/* ---------- Data tables -------------------------------------------------- */
.dtable { width: 100%; border-collapse: collapse; font-size: .9rem; }
.dtable th { text-align: left; font-weight: 600; color: var(--muted); font-size: .72rem; text-transform: uppercase; letter-spacing: .04em; padding: 11px 16px; background: var(--surface-2); border-bottom: 1px solid var(--border); white-space: nowrap; }
.dtable td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.dtable tbody tr:last-child td { border-bottom: 0; }
.dtable tbody tr:hover td { background: var(--surface-2); }
.dtable .num { text-align: right; font-variant-numeric: tabular-nums; }
.dtable .actions { text-align: right; white-space: nowrap; }
.dtable code, code.id { background: var(--surface-2); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; font-size: .82em; color: #334155; }

/* key/value detail list */
.kv { width: 100%; border-collapse: collapse; }
.kv th { text-align: left; color: var(--muted); font-weight: 600; font-size: .85rem; padding: 9px 18px 9px 0; white-space: nowrap; width: 1%; vertical-align: top; }
.kv td { padding: 9px 0; border-bottom: 1px solid var(--border); }
.kv tr:last-child td, .kv tr:last-child th { border-bottom: 0; }

/* ---------- Tags / status ------------------------------------------------ */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 999px; font-size: .74rem; font-weight: 600; line-height: 1.5; white-space: nowrap; }
.tag .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag.ok { background: var(--ok-bg); color: var(--ok); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.neutral { background: var(--neutral-bg); color: var(--neutral); }
.tag.info { background: var(--brand-50); color: var(--brand-600); }

/* ---------- Buttons ------------------------------------------------------ */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 7px; padding: 8px 15px; border-radius: var(--radius-sm); border: 1px solid transparent; font-size: .875rem; font-weight: 600; line-height: 1.25; cursor: pointer; text-decoration: none; transition: background .12s, border-color .12s, color .12s; }
.btn:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; box-shadow: none; }
.nav-link:focus-visible, a:focus-visible, .dropdown-item:focus-visible, .topbar-toggle:focus-visible, .form-control:focus-visible, .form-select:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; border-radius: var(--radius-sm); }
.btn-primary { background: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-600); color: #fff; }
.btn-outline { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-outline:hover { background: var(--surface-2); color: var(--text); }
.btn-outline.active { border-color: var(--brand); color: var(--brand-600); background: var(--brand-50); }
.btn-danger { background: var(--surface); border-color: #f1c4c4; color: var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn-warn { background: var(--warn-bg); border-color: #f3d9b0; color: var(--warn); }
.btn-warn:hover { background: #fbe7c8; }
.btn-sm { padding: 4px 11px; font-size: .8rem; border-radius: 7px; }
.btn-link { background: none; border: 0; color: var(--muted); padding: 8px 6px; }
.btn-link:hover { color: var(--text); }

/* ---------- Forms -------------------------------------------------------- */
.form-control, .form-select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 11px; font-size: .9rem; color: var(--text); background: var(--surface); }
.form-select-sm { padding: 4px 9px; font-size: .8rem; border-radius: 7px; }
.form-control:focus, .form-select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37,99,235,.15); outline: none; }
.form-label { font-weight: 600; font-size: .85rem; margin-bottom: 5px; color: var(--text); }
.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar .form-control { min-width: 240px; }
.field { margin-bottom: 16px; }
.field-hint { color: var(--muted); font-size: .8rem; margin-top: 5px; }

/* ---------- Alerts / flash ---------------------------------------------- */
.flash { display: flex; align-items: center; gap: 9px; border: 1px solid var(--border); border-left: 3px solid var(--brand); background: var(--brand-50); color: #1e3a8a; border-radius: var(--radius-sm); padding: 11px 15px; font-size: .9rem; margin-bottom: 18px; }
.flash.danger { border-left-color: var(--danger); background: var(--danger-bg); color: #7f1d1d; }

/* Themed validation errors (the runtime adds .validation-summary-errors / .field-validation-error). */
.text-danger { color: var(--danger); }
.validation-summary-errors { border: 1px solid #f1c4c4; border-left: 3px solid var(--danger); background: var(--danger-bg); color: #7f1d1d; border-radius: var(--radius-sm); padding: 11px 15px; font-size: .88rem; margin-bottom: 14px; }
.validation-summary-errors ul { margin: 0; padding-left: 18px; }
.validation-summary-valid { display: none; }
.panel-body ul { margin: 8px 0 0; padding-left: 20px; line-height: 1.7; }

/* Screen-reader-only utility (visually hidden, still announced). */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* ---------- Empty + code ------------------------------------------------- */
.empty { text-align: center; color: var(--muted); padding: 30px 16px; font-size: .9rem; }
.codeblock { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 13px 15px; font-size: .8rem; line-height: 1.5; overflow: auto; max-height: 360px; white-space: pre-wrap; word-break: break-word; margin: 0; color: #334155; }

/* ---------- Pagination --------------------------------------------------- */
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; font-size: .9rem; }
.pager .page-num { color: var(--muted); }
.btn.disabled, .btn[aria-disabled="true"] { opacity: .4; pointer-events: none; cursor: default; }

/* ---------- Auth (centered, sidebar-less) -------------------------------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 30px; }
.auth-brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.15rem; margin-bottom: 4px; }
.auth-title { font-size: 1.5rem; font-weight: 700; margin: 4px 0 2px; }
.auth-sub { margin-top: 0; margin-bottom: 22px; font-size: .9rem; }
.auth-check { display: flex; align-items: center; }
.auth-check label { display: inline-flex; align-items: center; gap: 8px; margin: 0; font-size: .9rem; color: var(--text); cursor: pointer; }
.auth-check input { width: 15px; height: 15px; margin: 0; accent-color: var(--brand); cursor: pointer; }
.auth-submit { width: 100%; padding: 10px; font-size: .95rem; margin-top: 4px; }
.auth-foot { margin-top: 16px; text-align: center; font-size: .875rem; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 22px; }
.text-muted2 { color: var(--muted); }

/* ---------- Sidebar backdrop (mobile) ------------------------------------ */
.sidebar-backdrop { display: none; }

/* ---------- Responsive --------------------------------------------------- */
@media (max-width: 991px) {
  /* visibility:hidden also removes the off-screen drawer from the tab order for keyboard users */
  .app-sidebar { transform: translateX(-100%); visibility: hidden; transition: transform .22s ease, visibility .22s ease; box-shadow: 0 0 40px rgba(0,0,0,.18); }
  body.sidebar-open .app-sidebar { transform: none; visibility: visible; }
  .app-main { margin-left: 0; }
  .topbar-toggle { display: inline-flex; }
  body.sidebar-open .sidebar-backdrop { display: block; position: fixed; inset: 0; background: rgba(15,23,42,.45); z-index: 1035; }
  .app-content { padding: 18px; }
}

@media (prefers-reduced-motion: reduce) {
  .app-sidebar, .btn { transition: none; }
}
