:root {
  --bg: #eef1f8;
  --bg-glow-1: rgba(99, 102, 241, 0.16);
  --bg-glow-2: rgba(45, 212, 191, 0.14);

  --sidebar-1: #131a2e;
  --sidebar-2: #1c2541;
  --sidebar-glow: rgba(99, 102, 241, 0.32);

  --surface: #ffffff;
  --surface-soft: #f6f8fc;
  --surface-tint: #eff3fb;

  --ink: #131a2e;
  --ink-soft: #344056;
  --muted: #6b7689;
  --line: #e3e8f2;
  --line-soft: #edf1f8;

  --brand: #4f46e5;
  --brand-strong: #4338ca;
  --brand-soft: #eef0ff;
  --brand-ink: #3730a3;
  --grad-brand: linear-gradient(135deg, #6366f1 0%, #4f46e5 55%, #4338ca 100%);
  --grad-brand-hover: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%);

  --blue: #2563eb;
  --cyan: #0891b2;
  --accent: #db5a16;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warning: #b45309;
  --ok: #16a34a;

  --shadow-sm: 0 1px 2px rgba(19, 26, 46, 0.06);
  --shadow: 0 14px 40px -18px rgba(19, 26, 46, 0.28);
  --shadow-lg: 0 30px 60px -28px rgba(19, 26, 46, 0.4);
  --shadow-brand: 0 14px 30px -10px rgba(79, 70, 229, 0.5);

  --radius: 16px;
  --radius-sm: 11px;
  --radius-pill: 999px;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--bg);
  background-image:
    radial-gradient(1100px 540px at 12% -8%, var(--bg-glow-1), transparent 60%),
    radial-gradient(900px 520px at 105% 0%, var(--bg-glow-2), transparent 55%);
  background-attachment: fixed;
  color: var(--ink);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", "Helvetica Neue", Arial,
    sans-serif;
  font-size: 14px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body.auth-loading .app-shell,
body.authenticated .login-screen,
body.unauthenticated .app-shell,
.login-screen.hidden {
  display: none;
}

body.unauthenticated .login-screen {
  display: grid;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

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

h1,
h2,
h3,
p {
  margin: 0;
}

::selection {
  background: rgba(99, 102, 241, 0.22);
}

/* ---------- Login ---------- */

.login-screen {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
  overflow: hidden;
}

.login-screen::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    radial-gradient(620px 420px at 22% 18%, rgba(99, 102, 241, 0.22), transparent 60%),
    radial-gradient(560px 420px at 84% 82%, rgba(45, 212, 191, 0.2), transparent 60%);
  pointer-events: none;
}

.login-card {
  position: relative;
  display: grid;
  gap: 20px;
  width: min(424px, 100%);
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 22px;
  background: rgba(255, 255, 255, 0.86);
  backdrop-filter: blur(22px);
  padding: 32px 30px;
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.5s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 22px;
  padding: 1px;
  background: linear-gradient(140deg, rgba(99, 102, 241, 0.5), transparent 45%);
  -webkit-mask:
    linear-gradient(#000 0 0) content-box,
    linear-gradient(#000 0 0);
  -webkit-mask-composite: xor;
  mask-composite: exclude;
  pointer-events: none;
}

.brand.compact {
  padding: 0;
  color: var(--ink);
}

.brand.compact span,
.login-copy,
.login-hint {
  color: var(--muted);
}

.login-card .eyebrow {
  margin-bottom: 4px;
}

.login-card h1 {
  font-size: 27px;
  letter-spacing: -0.4px;
}

.login-copy {
  margin-top: 6px;
}

.login-hint {
  min-height: 20px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.login-card .primary-btn {
  margin-top: 4px;
  min-height: 46px;
  font-size: 15px;
}

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

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100vh;
  background:
    radial-gradient(420px 240px at 18% -4%, var(--sidebar-glow), transparent 60%),
    linear-gradient(180deg, var(--sidebar-2) 0%, var(--sidebar-1) 100%);
  color: #f8fafc;
  box-shadow: 18px 0 60px -40px rgba(11, 17, 33, 0.9);
}

.brand {
  display: flex;
  align-items: center;
  gap: 13px;
  padding: 24px 22px 20px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 13px;
  background: var(--grad-brand);
  color: #fff;
  font-weight: 800;
  letter-spacing: 0.5px;
  box-shadow: var(--shadow-brand);
}

.brand strong {
  display: block;
  font-size: 16px;
  line-height: 1.25;
  letter-spacing: -0.2px;
}

.brand span {
  display: block;
  margin-top: 2px;
  color: #9aa6c4;
  font-size: 11.5px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
}

.side-nav {
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 10px 14px;
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  min-height: 44px;
  border-radius: 11px;
  background: transparent;
  color: #aeb8d4;
  padding: 0 13px;
  text-align: left;
  font-weight: 650;
  letter-spacing: 0.1px;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}

.nav-item::before {
  content: "";
  width: 19px;
  height: 19px;
  flex: 0 0 auto;
  background: currentColor;
  opacity: 0.85;
  -webkit-mask: var(--nav-icon) center / contain no-repeat;
  mask: var(--nav-icon) center / contain no-repeat;
}

.nav-item[data-view="overview"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='3' width='7' height='9'/%3E%3Crect x='14' y='3' width='7' height='5'/%3E%3Crect x='14' y='12' width='7' height='9'/%3E%3Crect x='3' y='16' width='7' height='5'/%3E%3C/svg%3E");
}
.nav-item[data-view="tasks"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M2 12s3.5-7 10-7 10 7 10 7-3.5 7-10 7-10-7-10-7z'/%3E%3C/svg%3E");
}
.nav-item[data-view="records"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z'/%3E%3Cpath d='M14 2v6h6'/%3E%3Cpath d='M8 13h8M8 17h6'/%3E%3C/svg%3E");
}
.nav-item[data-view="archive"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Crect x='3' y='4' width='18' height='4' rx='1'/%3E%3Cpath d='M5 8v11a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V8'/%3E%3Cpath d='M10 12h4'/%3E%3C/svg%3E");
}
.nav-item[data-view="admin"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2'/%3E%3Ccircle cx='9' cy='7' r='4'/%3E%3Cpath d='M22 21v-2a4 4 0 0 0-3-3.87M16 3.13a4 4 0 0 1 0 7.75'/%3E%3C/svg%3E");
}
.nav-item[data-view="settings"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='3'/%3E%3Cpath d='M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 1 1-2.83 2.83l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-4 0v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 1 1-2.83-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1 0-4h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 1 1 2.83-2.83l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 4 0v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 1 1 2.83 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 0 4h-.09a1.65 1.65 0 0 0-1.51 1z'/%3E%3C/svg%3E");
}
.nav-item[data-view="logs"] {
  --nav-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23fff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M12 8v4l3 2'/%3E%3Ccircle cx='12' cy='12' r='9'/%3E%3C/svg%3E");
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.07);
  color: #ffffff;
}

.nav-item.active {
  background: linear-gradient(135deg, rgba(99, 102, 241, 0.95), rgba(79, 70, 229, 0.92));
  color: #ffffff;
  box-shadow: var(--shadow-brand);
}

.nav-item.active::after {
  content: "";
  position: absolute;
  left: -14px;
  top: 50%;
  transform: translateY(-50%);
  width: 4px;
  height: 22px;
  border-radius: 0 4px 4px 0;
  background: #c7d2fe;
}

.sidebar-status {
  display: flex;
  align-items: center;
  gap: 9px;
  min-height: 56px;
  margin: 14px;
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 13px;
  background: rgba(255, 255, 255, 0.05);
  padding: 0 14px;
  color: #c2cbe4;
  font-size: 13px;
  font-weight: 650;
}

.status-dot {
  position: relative;
  width: 9px;
  height: 9px;
  border-radius: 999px;
  background: var(--warning);
  box-shadow: 0 0 0 4px rgba(180, 83, 9, 0.18);
}

.status-dot.ready {
  background: #22c55e;
  box-shadow: 0 0 0 4px rgba(34, 197, 94, 0.2);
}

.status-dot.ready::after {
  content: "";
  position: absolute;
  inset: -4px;
  border-radius: 999px;
  border: 1px solid rgba(34, 197, 94, 0.55);
  animation: ping 1.8s cubic-bezier(0, 0, 0.2, 1) infinite;
}

.status-dot.error {
  background: #ef4444;
  box-shadow: 0 0 0 4px rgba(239, 68, 68, 0.2);
}

/* ---------- Topbar ---------- */

.app-main {
  min-width: 0;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  gap: 18px;
  align-items: center;
  min-height: 80px;
  padding: 16px clamp(18px, 4vw, 38px);
  border-bottom: 1px solid var(--line);
  background: rgba(246, 248, 252, 0.82);
  backdrop-filter: blur(18px) saturate(1.4);
}

.eyebrow {
  color: var(--brand);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 1px;
  text-transform: uppercase;
}

h1 {
  margin-top: 2px;
  font-size: 24px;
  font-weight: 750;
  letter-spacing: -0.5px;
}

.topbar p:last-child,
.section-head span,
.settings-subhead p {
  color: var(--muted);
  font-size: 13px;
}

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

.user-chip {
  display: grid;
  gap: 1px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  padding: 6px 14px;
  box-shadow: var(--shadow-sm);
}

.user-chip span {
  color: var(--ink);
  font-size: 13px;
  font-weight: 720;
}

.user-chip strong {
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.icon-btn {
  display: inline-grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 18px;
  box-shadow: var(--shadow-sm);
  transition: background 0.16s ease, color 0.16s ease, transform 0.16s ease, border-color 0.16s ease;
}

.icon-btn:hover {
  background: var(--brand-soft);
  border-color: rgba(79, 70, 229, 0.3);
  color: var(--brand);
}

#refreshBtn:active {
  transform: rotate(120deg);
}

/* ---------- Content ---------- */

.content {
  display: grid;
  gap: 20px;
  width: min(1320px, 100%);
  margin: 0 auto;
  padding: 24px clamp(14px, 3vw, 36px) 48px;
}

.site-filing {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  width: min(1320px, 100%);
  margin: -24px auto 28px;
  padding: 0 clamp(14px, 3vw, 36px);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
  text-align: center;
}

.site-filing a {
  color: inherit;
  text-decoration: none;
}

.site-filing a:hover {
  color: var(--brand);
  text-decoration: underline;
}

.view {
  display: none;
  gap: 20px;
}

.view.active {
  display: grid;
  animation: fade-up 0.4s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
}

.metric,
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.metric {
  position: relative;
  display: grid;
  gap: 6px;
  align-content: center;
  min-height: 112px;
  padding: 20px 22px;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
}

.metric::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--grad-brand);
  opacity: 0.9;
}

.metric::after {
  content: "";
  position: absolute;
  right: -30px;
  top: -30px;
  width: 110px;
  height: 110px;
  border-radius: 999px;
  background: radial-gradient(circle, rgba(99, 102, 241, 0.12), transparent 70%);
}

.metric:hover {
  transform: translateY(-3px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(79, 70, 229, 0.28);
}

.metric span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.metric strong {
  color: var(--ink);
  font-size: 32px;
  font-weight: 780;
  line-height: 1.05;
  letter-spacing: -0.5px;
  font-variant-numeric: tabular-nums;
}

.panel {
  overflow: hidden;
}

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 66px;
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-soft), var(--surface));
}

.section-head > div:first-child {
  display: grid;
  gap: 2px;
}

h2 {
  font-size: 16.5px;
  font-weight: 740;
  letter-spacing: -0.2px;
}

h3 {
  color: var(--ink);
  font-size: 14px;
  font-weight: 740;
}

/* ---------- Forms ---------- */

.task-form,
.filters,
.user-form {
  display: grid;
  align-items: end;
  gap: 14px;
  padding: 22px;
}

.task-form {
  grid-template-columns: minmax(300px, 2fr) minmax(180px, 1fr) 150px auto;
}

.filters {
  grid-template-columns: 150px minmax(180px, 1fr) 130px 130px 140px auto;
}

.user-form {
  grid-template-columns: minmax(180px, 1fr) minmax(180px, 1fr) 150px auto;
}

.settings-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 22px;
  padding: 22px;
}

.settings-group {
  position: relative;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: var(--radius-sm);
  background: var(--surface-soft);
  padding: 18px;
}

.settings-group.wide,
.settings-actions {
  grid-column: 1 / -1;
}

.settings-subhead,
.full-span {
  grid-column: 1 / -1;
}

.settings-subhead {
  display: grid;
  gap: 3px;
  margin-bottom: 2px;
  padding-left: 12px;
  border-left: 3px solid var(--brand);
}

label {
  display: grid;
  gap: 7px;
  min-width: 0;
  color: var(--ink-soft);
  font-size: 12px;
  font-weight: 680;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--ink);
  padding: 0 12px;
  outline: none;
  transition: border-color 0.16s ease, box-shadow 0.16s ease, background 0.16s ease;
}

input::placeholder {
  color: #9aa3b5;
}

input:hover,
select:hover {
  border-color: #c5cdde;
}

input:focus,
select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.14);
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%236b7689' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 34px;
}

.inline-input {
  width: min(130px, 100%);
  min-height: 36px;
  padding-inline: 10px;
}

.masked-secret-input {
  -webkit-text-security: disc;
}

.masked-secret-input::placeholder {
  -webkit-text-security: none;
}

.credential-reset {
  width: 122px;
}

.check-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  color: var(--ink);
}

.check-label input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand);
}

.settings-actions {
  display: flex;
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

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

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn,
.tiny-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 42px;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  white-space: nowrap;
  font-weight: 700;
  letter-spacing: 0.1px;
  transition: transform 0.14s ease, box-shadow 0.16s ease, background 0.16s ease,
    border-color 0.16s ease, color 0.16s ease;
}

.primary-btn:active,
.secondary-btn:active,
.ghost-btn:active,
.danger-btn:active,
.tiny-btn:active {
  transform: translateY(1px);
}

.primary-btn {
  background: var(--grad-brand);
  color: #ffffff;
  box-shadow: var(--shadow-brand);
}

.primary-btn:hover {
  background: var(--grad-brand-hover);
  box-shadow: 0 16px 34px -10px rgba(79, 70, 229, 0.62);
  transform: translateY(-1px);
}

.secondary-btn {
  background: linear-gradient(135deg, #38bdf8, #2563eb);
  color: #ffffff;
  box-shadow: 0 12px 26px -12px rgba(37, 99, 235, 0.6);
}

.secondary-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 16px 30px -12px rgba(37, 99, 235, 0.7);
}

.ghost-btn,
.tiny-btn {
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink-soft);
  box-shadow: var(--shadow-sm);
}

.ghost-btn:hover,
.tiny-btn:hover {
  background: var(--brand-soft);
  border-color: rgba(79, 70, 229, 0.32);
  color: var(--brand);
}

.tiny-btn {
  min-height: 34px;
  border-radius: 9px;
  padding: 0 12px;
  font-size: 12.5px;
}

.danger-btn {
  min-height: 34px;
  border-radius: 9px;
  padding: 0 12px;
  border: 1px solid rgba(220, 38, 38, 0.24);
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 12.5px;
}

.danger-btn:hover {
  background: var(--danger);
  border-color: var(--danger);
  color: #ffffff;
}

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

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
}

th,
td {
  padding: 14px 22px;
  border-bottom: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  position: sticky;
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

td {
  color: var(--ink-soft);
}

tbody tr {
  transition: background 0.14s ease;
}

tbody tr:hover {
  background: var(--surface-tint);
}

tbody tr:last-child td {
  border-bottom: 0;
}

td strong {
  color: var(--ink);
  font-weight: 700;
}

.actions-col {
  width: 246px;
}

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

.link-cell {
  max-width: 260px;
  overflow: hidden;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 25px;
  border-radius: var(--radius-pill);
  padding: 0 11px;
  font-size: 12px;
  font-weight: 750;
  border: 1px solid transparent;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: currentColor;
}

.badge.monitoring {
  background: var(--brand-soft);
  color: var(--brand-ink);
  border-color: rgba(79, 70, 229, 0.18);
}

.badge.recording {
  background: #fff1e6;
  color: var(--accent);
  border-color: rgba(219, 90, 22, 0.2);
}

.badge.recording::before {
  animation: blink 1.1s steps(2, start) infinite;
}

.badge.stopping,
.badge.transcribing {
  background: #fef6e2;
  color: var(--warning);
  border-color: rgba(180, 83, 9, 0.18);
}

.badge.done {
  background: #e7f7ee;
  color: var(--ok);
  border-color: rgba(22, 163, 74, 0.2);
}

.badge.paused {
  background: #eef1f7;
  color: var(--muted);
  border-color: var(--line);
}

.badge.failed,
.badge.error {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(220, 38, 38, 0.18);
}

.muted {
  color: var(--muted);
}

.error-text {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  color: var(--danger);
  text-overflow: ellipsis;
  vertical-align: middle;
  white-space: nowrap;
}

.file-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.file-state {
  flex-basis: 100%;
  color: var(--muted);
  font-size: 12px;
}

.failed-text-actions {
  display: grid;
  gap: 8px;
  justify-items: start;
}

.empty {
  padding: 40px 22px;
  color: var(--muted);
  text-align: center;
  font-weight: 600;
}

/* ---------- Archive ---------- */

.archive-panel {
  min-height: 520px;
}

.archive-head {
  align-items: center;
}

.archive-toolbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
}

.archive-toolbar select {
  width: 120px;
  min-height: 38px;
}

.archive-selection-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 13px;
}

.archive-selection-bar strong {
  color: var(--brand);
  font-weight: 780;
}

.archive-groups {
  display: grid;
  gap: 16px;
  padding: 22px;
}

.archive-room {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s ease, border-color 0.18s ease;
}

.archive-room:hover {
  box-shadow: var(--shadow);
  border-color: rgba(79, 70, 229, 0.22);
}

.archive-room-head,
.archive-date-head,
.archive-record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.archive-room-head {
  min-height: 60px;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-soft), #ffffff);
}

.archive-room-head h3 {
  font-size: 15px;
}

.archive-room-head span,
.archive-date-head small,
.archive-record-main small {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

.archive-date-group + .archive-date-group {
  border-top: 1px solid var(--line-soft);
}

.archive-date-head {
  justify-content: flex-start;
  min-height: 52px;
  padding: 10px 18px;
  color: var(--ink);
  cursor: pointer;
  transition: background 0.14s ease;
}

.archive-date-head:hover {
  background: var(--surface-soft);
}

.archive-date-head input,
.archive-record-main input {
  flex: 0 0 auto;
  width: 18px;
  min-height: 18px;
  accent-color: var(--brand);
}

.archive-record-list {
  display: grid;
  border-top: 1px solid var(--line-soft);
  background: #ffffff;
}

.archive-record {
  min-height: 54px;
  padding: 10px 18px 10px 44px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 0.14s ease;
}

.archive-record:hover {
  background: var(--surface-tint);
}

.archive-record:last-child {
  border-bottom: 0;
}

.archive-record-main {
  display: flex;
  align-items: center;
  gap: 11px;
  min-width: 0;
  color: var(--ink);
  cursor: pointer;
}

.archive-record-main span {
  min-width: 0;
}

.archive-record-main strong {
  display: block;
  overflow: hidden;
  color: var(--ink);
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---------- Health ---------- */

.health-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0;
}

.health-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 62px;
  padding: 0 22px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 0.14s ease;
}

.health-item:hover {
  background: var(--surface-soft);
}

.health-item:nth-last-child(-n + 2) {
  border-bottom: 0;
}

.health-item:nth-child(odd) {
  border-right: 1px solid var(--line-soft);
}

.health-item strong {
  font-size: 13.5px;
}

.health-item span {
  color: var(--muted);
  font-size: 12px;
}

/* ---------- Events ---------- */

.compact-events,
.events {
  display: grid;
}

.events {
  max-height: calc(100vh - 200px);
  overflow: auto;
}

.event {
  display: grid;
  grid-template-columns: 174px 84px 1fr;
  gap: 10px;
  align-items: center;
  padding: 12px 22px;
  border-bottom: 1px solid var(--line-soft);
  transition: background 0.14s ease;
}

.event:hover {
  background: var(--surface-soft);
}

.event:last-child {
  border-bottom: 0;
}

.event-time {
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.event-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 22px;
  padding: 0 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-tint);
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.event-level.error {
  background: var(--danger-soft);
  color: var(--danger);
}

.event-level.warning {
  background: #fef6e2;
  color: var(--warning);
}

.event span:last-child {
  color: var(--ink-soft);
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(420px, calc(100vw - 40px));
  transform: translateY(20px) scale(0.98);
  opacity: 0;
  pointer-events: none;
  border-radius: 13px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(135deg, #1f2540, #131a2e);
  color: #ffffff;
  padding: 13px 18px;
  font-weight: 600;
  box-shadow: 0 22px 50px -18px rgba(11, 17, 33, 0.7);
  transition: opacity 0.2s ease, transform 0.2s cubic-bezier(0.22, 1, 0.36, 1);
}

.toast::before {
  content: "";
  width: 7px;
  height: 7px;
  border-radius: 999px;
  background: #34d399;
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.25);
}

.toast.show {
  transform: translateY(0) scale(1);
  opacity: 1;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  background: rgba(13, 18, 33, 0.5);
  backdrop-filter: blur(4px);
  padding: 22px;
  animation: fade-in 0.18s ease both;
}

.modal-backdrop.hidden {
  display: none;
}

.modal-panel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: min(920px, 100%);
  max-height: min(760px, calc(100vh - 44px));
  overflow: hidden;
  border-radius: 20px;
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  animation: pop-in 0.26s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 22px;
}

.modal-head {
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, var(--surface-soft), var(--surface));
}

.modal-head h2 {
  margin-top: 2px;
}

.modal-actions {
  border-top: 1px solid var(--line);
}

.modal-actions span {
  color: var(--muted);
  font-size: 13px;
}

.preview-text {
  min-height: 360px;
  margin: 0;
  overflow: auto;
  background: var(--surface-soft);
  color: var(--ink);
  padding: 22px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 13px;
  line-height: 1.8;
  white-space: pre-wrap;
}

/* ---------- Animations ---------- */

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pop-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes ping {
  75%,
  100% {
    transform: scale(1.9);
    opacity: 0;
  }
}

@keyframes blink {
  50% {
    opacity: 0.25;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Responsive ---------- */

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    z-index: 20;
    height: auto;
    grid-template-rows: auto auto;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  }

  .brand {
    padding-bottom: 12px;
  }

  .side-nav {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 6px 14px 14px;
    scrollbar-width: none;
  }

  .side-nav::-webkit-scrollbar {
    display: none;
  }

  .nav-item {
    flex: 0 0 auto;
    width: auto;
    padding: 0 16px;
    text-align: center;
  }

  .nav-item.active::after {
    display: none;
  }

  .sidebar-status {
    display: none;
  }

  .status-grid,
  .health-list,
  .task-form,
  .filters,
  .user-form,
  .settings-form,
  .settings-group {
    grid-template-columns: 1fr 1fr;
  }

  .task-form button,
  .filters button,
  .user-form button {
    width: 100%;
  }

  .archive-head,
  .archive-selection-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .archive-toolbar {
    justify-content: flex-start;
    width: 100%;
  }
}

@media (max-width: 720px) {
  .topbar {
    align-items: flex-start;
    min-height: auto;
    padding-block: 14px;
  }

  h1 {
    font-size: 20px;
  }

  .content {
    padding-inline: 12px;
  }

  .site-filing {
    gap: 4px 8px;
    margin-top: -28px;
    padding-inline: 12px;
  }

  .status-grid,
  .health-list,
  .task-form,
  .filters,
  .user-form,
  .settings-form,
  .settings-group {
    grid-template-columns: 1fr;
  }

  .top-actions {
    flex-wrap: wrap;
    justify-content: flex-end;
  }

  .settings-actions {
    justify-content: stretch;
  }

  .settings-actions button {
    width: 100%;
  }

  .health-item,
  .health-item:nth-child(odd) {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .health-item:last-child {
    border-bottom: 0;
  }

  .section-head {
    align-items: flex-start;
    flex-direction: column;
    justify-content: center;
    padding-block: 14px;
  }

  .archive-toolbar,
  .archive-toolbar select,
  .archive-toolbar button {
    width: 100%;
  }

  .archive-record {
    align-items: flex-start;
    flex-direction: column;
    padding-left: 18px;
  }

  .event {
    grid-template-columns: 1fr;
    gap: 4px;
  }

  .modal-backdrop {
    padding: 10px;
  }

  .modal-head,
  .modal-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .modal-actions button {
    width: 100%;
  }
}
