/* ==========================================================================
   Shared design system for every screen. Tokens first, then base elements,
   then the app shell (sidebar / topbar), then components.
   Page-specific styles stay inline in each page and still win over these.
   ========================================================================== */

:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --border: #e4e8f0;
  --border-strong: #d3d9e6;
  --text: #141a2e;
  --muted: #6a7388;
  --primary: #2475bb;
  --primary-600: #1c5e96;
  --primary-soft: #e6f3fb;
  --danger: #e5484d;
  --success: #16a34a;
  --warn: #b7791f;
  --radius: 12px;
  --radius-sm: 8px;

  --sidebar-w: 252px;
  --sidebar-bg: #0b3560;
  --sidebar-bg-2: #082b50;
  --sidebar-text: #c5d5ee;
  --sidebar-muted: #8aa3cc;
  --accent: #31c5f4;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 8px 24px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: Inter, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(36, 117, 187, 0.18); }

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

:focus-visible { outline: 2px solid rgba(36, 117, 187, 0.55); outline-offset: 2px; }

h1 { font-size: 24px; line-height: 1.2; font-weight: 700; letter-spacing: -0.015em; margin: 0 0 6px; }
h2 { font-size: 17px; font-weight: 650; letter-spacing: -0.01em; }
.subtitle { color: var(--muted); margin-bottom: 24px; font-size: 14px; line-height: 1.55; }

/* ---- Page container ---------------------------------------------------- */

.page {
  max-width: 1240px;
  margin: 0 auto;
  padding: 32px 36px 56px;
}

/* ---- Form controls (:where keeps specificity at 0 so page styles win) --- */

:where(input:not([type=checkbox]):not([type=radio]):not([type=hidden]):not([type=file]):not([type=range]), select, textarea) {
  font: inherit;
  color: var(--text);
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  transition: border-color 0.15s, box-shadow 0.15s;
}
:where(input, select, textarea):focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(36, 117, 187, 0.14);
}
:where(input, select, textarea)::placeholder { color: #a3abbd; }
:where(input:disabled, select:disabled, textarea:disabled) { background: #f4f6fa; color: var(--muted); }
:where(input[type=checkbox], input[type=radio]) { accent-color: var(--primary); }

/* ---- Cards ------------------------------------------------------------- */

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
  overflow-y: hidden;
  box-shadow: var(--shadow-sm);
}
.card-interactive { transition: box-shadow 0.2s ease, border-color 0.2s ease, transform 0.2s ease; }
.card-interactive:hover { box-shadow: var(--shadow-md); border-color: var(--border-strong); transform: translateY(-2px); }

/* ---- Tables ------------------------------------------------------------ */

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 13px 18px; font-size: 14px; }
td { font-variant-numeric: tabular-nums; }
thead th {
  background: #f8f9fc;
  color: var(--muted);
  font-weight: 600;
  font-size: 12.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-top: 1px solid var(--border); transition: background 0.12s; }
tbody tr:first-child { border-top: none; }
tbody tr:hover { background: #f8faff; }

/* ---- Badges ------------------------------------------------------------ */

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; line-height: 1.5;
}
.badge.active    { background: #e8f8ee; color: var(--success); }
.badge.inactive  { background: #fdecec; color: var(--danger); }
.badge.role-admin { background: var(--primary-soft); color: var(--primary); }
.badge.role-staff { background: #eff1f6; color: var(--muted); }
.badge.warn      { background: #fff5e0; color: var(--warn); }

/* ---- Buttons ----------------------------------------------------------- */

button {
  font: inherit;
  font-size: 13px;
  font-weight: 550;
  color: var(--text);
  border: 1px solid var(--border-strong);
  background: var(--card);
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s, box-shadow 0.15s, background 0.15s;
}
button:hover { border-color: var(--primary); color: var(--primary); box-shadow: 0 2px 8px rgba(36, 117, 187, 0.12); }
button:active { box-shadow: none; }
button.danger:hover { border-color: var(--danger); color: var(--danger); box-shadow: 0 2px 8px rgba(229, 72, 77, 0.12); }
button:disabled { opacity: 0.5; cursor: not-allowed; box-shadow: none; }

/* Row-level actions inside tables: quieter than page-level buttons. */
td button { padding: 5px 11px; font-size: 12.5px; font-weight: 500; }
td button + button { margin-left: 4px; }

.btn-primary,
button.btn-primary {
  background: var(--primary); color: #fff; border-color: var(--primary);
  box-shadow: 0 1px 2px rgba(36, 117, 187, 0.3);
}
.btn-primary:hover,
button.btn-primary:hover {
  background: var(--primary-600); border-color: var(--primary-600); color: #fff;
  box-shadow: 0 4px 12px rgba(36, 117, 187, 0.28);
}

/* ---- Toast ------------------------------------------------------------- */

.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  background: var(--text); color: #fff;
  padding: 11px 18px; border-radius: 10px; font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0; transform: translateY(8px);
  transition: opacity 0.25s, transform 0.25s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }

/* ==========================================================================
   App shell: sticky top navigation. Primary screens sit in the bar, the
   secondary areas (Monitor, Admin) and the account menu open as dropdowns.
   Below 1100px it collapses into a hamburger panel.
   ========================================================================== */

.topnav {
  position: sticky; top: 0; z-index: 200;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, var(--sidebar-bg-2) 100%);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  box-shadow: 0 6px 20px rgba(7, 32, 74, 0.18);
  color: var(--sidebar-text);
}
.topnav-inner {
  max-width: 1480px; margin: 0 auto; padding: 0 28px; height: 60px;
  display: flex; align-items: center; gap: 28px;
}

.brand { display: flex; align-items: center; gap: 11px; color: #fff; text-decoration: none; flex-shrink: 0; }
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px;
  background: linear-gradient(135deg, #2475bb 0%, #2fb8eb 100%);
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 1px rgba(49, 197, 244, 0.55), 0 6px 16px rgba(47, 184, 235, 0.35);
}
.brand-mark svg { width: 19px; height: 19px; stroke: #fff; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 15px; font-weight: 700; letter-spacing: -0.01em; }
.brand-text small { font-size: 11.5px; color: var(--sidebar-muted); }

.tn-burger { display: none; }
.tn-nav { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: space-between; }
.tn-links { display: flex; align-items: center; gap: 2px; }

.tn-link,
button.tn-trigger {
  position: relative;
  display: inline-flex; align-items: center; gap: 6px;
  height: 36px; padding: 0 12px;
  border: none; border-radius: 9px; background: transparent; box-shadow: none;
  color: var(--sidebar-text); font: inherit; font-size: 13.5px; font-weight: 500;
  white-space: nowrap; text-decoration: none; cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tn-link:hover,
button.tn-trigger:hover { background: rgba(255, 255, 255, 0.07); color: #fff; text-decoration: none; box-shadow: none; }
.tn-link.active,
.tn-menu.active > button.tn-trigger,
.tn-menu.open > button.tn-trigger { background: rgba(255, 255, 255, 0.1); color: #fff; }
.tn-link.active::after,
.tn-menu.active > button.tn-trigger::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: -12px; height: 2px;
  background: var(--accent); border-radius: 2px 2px 0 0;
}
.tn-chevron { width: 14px; height: 14px; stroke: currentColor; fill: none; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; opacity: 0.7; transition: transform 0.15s; }
.tn-menu.open > .tn-trigger .tn-chevron { transform: rotate(180deg); }

.tn-menu { position: relative; }
.tn-dropdown {
  display: none; position: absolute; top: calc(100% + 12px); left: 0; z-index: 250;
  min-width: 232px; padding: 6px;
  background: #fff; border: 1px solid var(--border); border-radius: 12px;
  box-shadow: var(--shadow-md);
}
.tn-menu.open > .tn-dropdown { display: block; }
.tn-user .tn-dropdown { left: auto; right: 0; min-width: 220px; }

.tn-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 11px; border-radius: 8px;
  color: var(--text); font-size: 13.5px; font-weight: 500; text-decoration: none;
}
.tn-item:hover { background: #f4f6fa; text-decoration: none; }
.tn-item.active { background: var(--primary-soft); color: var(--primary); }
.tn-item svg { width: 17px; height: 17px; flex-shrink: 0; color: var(--muted); }
.tn-item.active svg { color: var(--primary); }
.tn-item.logout:hover { background: #fdecec; color: #b42328; }
.tn-item.logout:hover svg { color: #b42328; }

.tn-user-head { padding: 10px 11px 9px; margin-bottom: 6px; border-bottom: 1px solid var(--border); line-height: 1.3; }
.tn-user-head strong { display: block; font-size: 13.5px; }
.tn-user-head span { font-size: 12px; color: var(--muted); }

button.tn-user-trigger {
  height: 40px; padding: 0 10px 0 5px; gap: 9px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.06); border: 1px solid rgba(255, 255, 255, 0.08); color: #fff;
}
button.tn-user-trigger:hover { background: rgba(255, 255, 255, 0.1); }
.tn-user-name { max-width: 140px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; font-weight: 600; }
.user-avatar {
  width: 30px; height: 30px; flex-shrink: 0; border-radius: 50%;
  background: #2d3a6e; color: #e3e8fc;
  display: flex; align-items: center; justify-content: center;
  font-size: 12.5px; font-weight: 650;
}

@media (max-width: 1180px) {
  .topnav-inner { padding: 0 16px; gap: 12px; }
  button.tn-burger {
    display: flex; margin-left: auto; width: 40px; height: 40px; padding: 0;
    align-items: center; justify-content: center;
    background: transparent; border: 1px solid rgba(255, 255, 255, 0.16); color: #fff; box-shadow: none;
  }
  button.tn-burger:hover { background: rgba(255, 255, 255, 0.08); color: #fff; border-color: rgba(255, 255, 255, 0.26); box-shadow: none; }
  .tn-burger svg { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; }

  .tn-nav {
    display: none; position: absolute; top: 60px; left: 0; right: 0;
    flex-direction: column; align-items: stretch; justify-content: flex-start;
    max-height: calc(100vh - 60px); overflow-y: auto; padding: 10px 14px 18px;
    background: var(--sidebar-bg-2);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: 0 24px 40px rgba(0, 0, 0, 0.35);
  }
  .topnav.open .tn-nav { display: flex; }
  .tn-links { flex-direction: column; align-items: stretch; gap: 2px; }
  .tn-link { height: 42px; }
  .tn-link.active { box-shadow: inset 3px 0 0 var(--accent); }
  .tn-link.active::after, .tn-menu.active > button.tn-trigger::after { display: none; }

  /* Groups become always-open sections with a small heading. */
  .tn-menu { position: static; }
  .tn-links .tn-menu > button.tn-trigger,
  .tn-links .tn-menu.open > button.tn-trigger {
    height: 32px; margin-top: 10px; padding: 0 12px; pointer-events: none;
    background: transparent; color: var(--sidebar-muted); font-size: 12px; font-weight: 600;
  }
  .tn-chevron { display: none; }
  .tn-dropdown,
  .tn-user .tn-dropdown {
    display: block; position: static; min-width: 0; padding: 0;
    background: transparent; border: none; box-shadow: none;
  }
  .tn-item { color: var(--sidebar-text); padding: 11px 12px; }
  .tn-item:hover { background: rgba(255, 255, 255, 0.07); color: #fff; }
  .tn-item.active { background: rgba(255, 255, 255, 0.1); color: #fff; box-shadow: inset 3px 0 0 var(--accent); }
  .tn-item svg, .tn-item.active svg { color: var(--sidebar-text); }
  .tn-item.logout:hover { background: rgba(229, 72, 77, 0.14); color: #ffa3a6; }
  .tn-item.logout:hover svg { color: #ffa3a6; }

  .tn-user { margin-top: 14px; padding-top: 12px; border-top: 1px solid rgba(255, 255, 255, 0.08); }
  button.tn-user-trigger, button.tn-user-trigger:hover {
    height: 44px; width: 100%; pointer-events: none; background: transparent; border: none; padding: 0 12px 0 8px;
  }
  .tn-user-head { display: none; }

  .page { padding: 22px 16px 48px; }
  th, td { padding: 11px 12px; }
}

@media print {
  .topnav { display: none !important; }
  .page { max-width: none; padding: 0; }
}

/* State Life logo in the top bar (public/assets/img/statelife-logo.png|svg) - fixed 36px icon */
.brand-logo { display: block; flex: none; width: 36px; height: 36px; border-radius: 10px; overflow: hidden; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25), 0 6px 16px rgba(47, 184, 235, 0.35); }
.brand-logo img { display: block; width: 36px; height: 36px; max-width: 36px; max-height: 36px; object-fit: contain; }
.brand-mark.tri svg { fill: #fff; stroke: none; width: 22px; height: 22px; }
