/* =====================================================================
   Core design tokens, reset and application shell.
   Dashboard components live in dashboard.css, breakpoints in responsive.css.
   ===================================================================== */

:root {
  --bg: #070b18;
  --bg-2: #0a1122;
  --panel: #0e1526;
  --panel-2: #131c30;
  --panel-3: #182338;
  --border: #223049;
  --border-strong: #2f4368;
  --blue: #2563eb;
  --blue-light: #3b82f6;
  --cyan: #22d3ee;
  --purple: #8b5cf6;
  --text: #eef2fb;
  --text-dim: #c2cbdd;
  --muted: #8492ad;
  --green: #22d38a;
  --red: #ff5470;
  --amber: #f5a524;
  --shadow: 0 14px 38px rgba(2, 6, 18, .55);
  --glow: 0 0 0 1px rgba(59, 130, 246, .18), 0 8px 30px rgba(37, 99, 235, .18);
  --radius: 14px;
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 68px;
  --topbar-h: 68px;
  --tap: 44px;
  --gap: clamp(12px, 1.3vw, 18px);
  --content-max: 1800px;
  --font: "Inter", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background:
    radial-gradient(1200px 600px at 12% -8%, rgba(37, 99, 235, .18), transparent 60%),
    radial-gradient(1000px 520px at 100% 0%, rgba(139, 92, 246, .14), transparent 55%),
    var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-text-size-adjust: 100%;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
a:hover { text-decoration: underline; }

button, input, select, textarea { font: inherit; color: inherit; }
img, svg, canvas { max-width: 100%; }

:focus-visible {
  outline: 2px solid var(--blue-light);
  outline-offset: 2px;
  border-radius: 4px;
}

.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;
}

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 200;
  background: var(--blue); padding: 10px 16px; border-radius: 6px;
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

.ico { width: 18px; height: 18px; flex: 0 0 auto; }

/* ------------------------------------------------------------------ shell */

.app-shell { display: flex; min-height: 100vh; min-height: 100dvh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: linear-gradient(180deg, #0a1122 0%, #070c18 100%);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  z-index: 60;
  transition: width .18s ease, flex-basis .18s ease;
}

.sidebar .logo {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 14px 18px;
  border-bottom: 1px solid var(--border);
  min-height: var(--topbar-h);
}

.logo-mark, .brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 11px;
  background: linear-gradient(135deg, var(--blue) 0%, var(--purple) 100%);
  box-shadow: 0 6px 18px rgba(37, 99, 235, .4);
  display: grid; place-items: center;
  font-weight: 800; letter-spacing: .5px;
}

.logo-text { min-width: 0; }
.logo-text b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo-text small { color: var(--muted); font-size: 11px; }

.drawer-close { display: none; margin-left: auto; }

.side-nav {
  display: grid; gap: 3px; padding: 12px 10px;
  overflow-y: auto; overflow-x: hidden; flex: 1 1 auto;
  align-content: start;
  scrollbar-width: thin;
}

.side-nav a, .side-foot a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 11px; min-height: var(--tap);
  border-radius: 7px;
  color: #aab1bf;
  white-space: nowrap;
  overflow: hidden;
}
.side-nav a:hover, .side-nav a.active { background: #1b2130; color: #fff; text-decoration: none; }
.side-nav a.active { background: linear-gradient(135deg, var(--blue) 0%, var(--blue-light) 100%); color: #fff; box-shadow: 0 8px 20px rgba(37, 99, 235, .35); }
.side-nav a span, .side-foot a span { overflow: hidden; text-overflow: ellipsis; }

.side-foot {
  padding: 10px; border-top: 1px solid var(--border);
  display: grid; gap: 3px;
}
.side-foot a:hover { background: #1b2130; text-decoration: none; }

/* Decorative tagline pinned above the footer links, echoing the brand gradient. */
.side-tag {
  margin-top: auto; padding: 16px 16px 10px;
  display: grid; gap: 2px;
  font-weight: 800; font-size: 15px; letter-spacing: .2px;
  background: linear-gradient(90deg, var(--blue-light), var(--cyan));
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.sidebar.collapsed .side-tag { display: none; }

/* Collapsed rail (desktop only) */
.sidebar.collapsed { width: var(--sidebar-w-collapsed); flex-basis: var(--sidebar-w-collapsed); }
.sidebar.collapsed .logo-text,
.sidebar.collapsed .side-nav a span,
.sidebar.collapsed .side-foot a span { display: none; }
.sidebar.collapsed .logo { justify-content: center; padding-inline: 8px; }
.sidebar.collapsed .side-nav a, .sidebar.collapsed .side-foot a { justify-content: center; padding-inline: 0; }

.nav-overlay {
  position: fixed; inset: 0; z-index: 55;
  background: rgba(6, 8, 12, .62);
  backdrop-filter: blur(2px);
}

/* ------------------------------------------------------------------- main */

.main {
  flex: 1 1 auto;
  min-width: 0;
  padding: var(--gap);
  width: 100%;
  max-width: var(--content-max);
  margin-inline: auto;
}

.topbar {
  position: sticky; top: 0; z-index: 40;
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; flex-wrap: wrap;
  padding: 10px 0 12px;
  margin-bottom: 14px;
  background: linear-gradient(180deg, var(--bg) 72%, rgba(15, 17, 21, 0));
}

.topbar-left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.title-block { min-width: 0; }
.topbar h1 { margin: 0; font-size: clamp(16px, 2.2vw, 21px); line-height: 1.25; }
.topbar #subtitle, .topbar p.muted { margin: 2px 0 0; font-size: 12px; color: var(--muted); }

.top-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.drawer-open { display: none; }

/* ------------------------------------------------------------ controls */

.icon-btn, .btn, select.input, input.input, .input {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 9px 11px;
  min-height: var(--tap);
  cursor: pointer;
  transition: border-color .12s ease, background .12s ease;
}

.input, select.input, input.input { cursor: auto; max-width: 100%; }
.input:hover, select.input:hover, input.input:hover { border-color: var(--border-strong); }
.input:focus, select.input:focus, input.input:focus { border-color: var(--blue-light); outline: none; }
.input.compact { padding: 9px 8px; }

.icon-btn { display: inline-grid; place-items: center; width: var(--tap); padding: 0; }
.icon-btn:hover { border-color: var(--border-strong); background: var(--panel-2); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; }
.btn:hover { border-color: var(--border-strong); background: var(--panel-2); text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: linear-gradient(135deg, var(--blue) 0%, var(--blue-light) 100%); border-color: var(--blue-light); color: #fff; box-shadow: 0 8px 20px rgba(37, 99, 235, .32); }
.btn.primary:hover { background: #23399e; }
.btn.full { width: 100%; }
.btn.small { padding: 6px 9px; min-height: 32px; font-size: 12px; }
.btn.danger-outline { border-color: #6b2a32; color: #ff8891; }
.btn.danger-outline:hover { background: #2a171b; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.user-chip {
  display: flex; align-items: center; gap: 9px;
  background: var(--panel); border: 1px solid var(--border);
  padding: 6px 11px 6px 6px; border-radius: 999px;
  max-width: 240px;
}
.user-chip .avatar {
  width: 30px; height: 30px; flex: 0 0 30px;
  border-radius: 50%; background: var(--blue);
  display: grid; place-items: center; font-weight: 700; font-size: 13px;
}
.user-chip .user-meta { min-width: 0; display: grid; line-height: 1.2; }
.user-chip b { font-size: 12.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip small { font-size: 11px; color: var(--muted); }

/* ------------------------------------------------------------------ forms */

.field { display: grid; gap: 6px; min-width: 0; }
.field > span { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .4px; }
.field input, .field select, .field .input { width: 100%; }
.field-inline { display: flex; align-items: center; gap: 8px; }

.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 10px; align-items: end; }
.form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; }
.form-grid .full-row { grid-column: 1 / -1; }

.checkbox-grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 6px; max-height: 220px; overflow: auto;
  padding: 10px; border: 1px solid var(--border); border-radius: 6px; background: var(--panel-2);
}
.checkbox-grid label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--text-dim); cursor: pointer; }
.checkbox-grid input { width: 16px; height: 16px; flex: 0 0 16px; accent-color: var(--blue-light); }
/* The "Select all" box heads each group: it spans the full width, stays pinned while the
   list scrolls beneath it, and is dimmed by JS when the group has nothing to select. */
.checkbox-grid .select-all {
  grid-column: 1 / -1; position: sticky; top: -10px; z-index: 1;
  display: flex; align-items: center; gap: 8px; margin: 0 0 4px; padding: 2px 0 6px;
  font-size: 12.5px; font-weight: 600; color: var(--text); cursor: pointer;
  background: var(--panel-2); border-bottom: 1px solid var(--border);
}
.checkbox-grid .select-all input { width: 16px; height: 16px; flex: 0 0 16px; accent-color: var(--blue-light); }
.checkbox-grid .select-all:has(input:disabled) { color: var(--muted); cursor: default; opacity: .6; }

/* -------------------------------------------------------------- feedback */

.muted { color: var(--muted); }
.small { font-size: 12px; }
.hint { color: var(--muted); font-size: 12.5px; }
.positive { color: var(--green) !important; }
.negative { color: var(--red) !important; }

.alert { padding: 11px 13px; border-radius: 6px; margin-bottom: 12px; border: 1px solid transparent; font-size: 13px; }
.alert.success { background: #123322; color: #72e6a2; border-color: #1d5236; }
.alert.danger, .alert.error { background: #38171c; color: #ff8b94; border-color: #5e2830; }
.alert.warn { background: #362a12; color: #ffce85; border-color: #5c461d; }
.alert.info { background: #16233d; color: #9dbcff; border-color: #24365c; }
.alert a { text-decoration: underline; }

.empty { padding: 22px 12px; text-align: center; color: var(--muted); font-size: 13px; }

/* The app toggles the hidden attribute on table rows, the nav overlay, the
   notification panel and the custom date fields; nothing may display over it. */
[hidden] { display: none !important; }
.js-filter-empty td { font-style: italic; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
caption { text-align: left; color: var(--muted); font-size: 12px; padding-bottom: 8px; caption-side: top; }
th, td { text-align: left; padding: 10px 11px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { color: var(--muted); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; position: sticky; top: 0; background: var(--panel); z-index: 1; }
tbody tr:hover { background: #1b1f27; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.wrap { white-space: normal; min-width: 180px; }
.mono, code { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.txn-id { color: var(--text-dim); }
.row-actions { display: flex; gap: 6px; }
.inline { display: inline; }

.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; border: 1px solid var(--border-strong); color: var(--text-dim); }
.tag.active { color: var(--green); border-color: #1d5236; background: rgba(53, 208, 127, .1); }
.tag.disabled { color: var(--muted); }
.tag.error { color: var(--red); border-color: #5e2830; background: rgba(255, 92, 105, .1); }

/* ------------------------------------------------------------- pagination */

.pager { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.pager .pages { display: flex; gap: 6px; flex-wrap: wrap; }
.pager a, .pager span.current {
  padding: 7px 11px; border: 1px solid var(--border); border-radius: 6px; font-size: 12.5px; min-height: 36px;
  display: inline-flex; align-items: center;
}
.pager a:hover { background: var(--panel-2); text-decoration: none; }
.pager span.current { background: var(--blue); border-color: var(--blue-light); }

/* -------------------------------------------------------------- login page */

.login-page { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login-card {
  width: min(430px, 100%);
  background: var(--panel); border: 1px solid var(--border);
  padding: clamp(22px, 5vw, 34px); border-radius: 10px; box-shadow: var(--shadow);
}
.login-card.wide { max-width: 640px; width: min(640px, 100%); }
.login-card .brand-mark { width: 46px; height: 46px; font-size: 16px; }
.login-card h1 { margin: 14px 0 4px; font-size: 21px; }
.login-card form { display: grid; gap: 12px; margin-top: 20px; }
.login-card label { display: grid; gap: 6px; color: var(--muted); font-size: 12.5px; }

/* ------------------------------------------------------------- install page */

.check-list { margin: 16px 0; }
.check { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.check span { font-weight: 800; color: var(--green); }
.check.fail span { color: var(--red); }
.login-card form + .hint { margin-top: 10px; }
.login-card a.btn { margin-top: 14px; text-decoration: none; }

/* Secondary form inside the install card, e.g. the bootstrap password reset. */
.login-card .form-panel {
  margin-top: 22px; padding: 16px; border: 1px solid var(--border);
  border-radius: 8px; background: var(--panel-2);
}
.login-card .form-panel h2 { margin: 0 0 6px; font-size: 15px; }
.login-card .form-panel .hint { margin: 0 0 4px; }

/* Reduced motion: honoured across charts, drawers and hovers. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
