:root {
  --navy: #071b44;
  --navy-2: #0b2f6b;
  --blue: #155eef;
  --blue-soft: #edf4ff;
  --ink: #14213d;
  --muted: #667085;
  --line: #dbe4f0;
  --surface: #fff;
  --canvas: #f3f6fb;
  --success: #067647;
  --success-soft: #ecfdf3;
  --danger: #b42318;
  --danger-soft: #fef3f2;
  --warning: #b54708;
  --warning-soft: #fffaeb;
  --shadow: 0 18px 46px rgba(7, 27, 68, .09);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-width: 320px; font-family: Inter, Arial, sans-serif; color: var(--ink); background: var(--canvas); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: wait; opacity: .62; }
:focus-visible { outline: 3px solid rgba(21, 94, 239, .28); outline-offset: 2px; }
[hidden] { display: none !important; }

.auth-gate { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 1rem; background: radial-gradient(circle at top left, #edf4ff, #f8fafc 50%, #eef2f7); }
.auth-card { width: min(420px, 100%); padding: 2rem; text-align: center; border: 1px solid var(--line); border-radius: 24px; background: #fff; box-shadow: var(--shadow); }
.auth-logo { width: 190px; max-width: 70%; }
.auth-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: .75rem; margin-top: .25rem; }
.auth-actions[hidden] { display: none; }
.spinner { width: 36px; height: 36px; margin: 1.5rem auto 1rem; border: 3px solid #dbeafe; border-top-color: var(--blue); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 1.35rem; color: #fff; background: linear-gradient(180deg, var(--navy), #07152f); overflow-y: auto; }
.brand { display: block; padding: .75rem; border-radius: 14px; background: #fff; }
.brand img { display: block; width: 165px; max-width: 100%; }
.framework-mark { margin: 1.5rem .4rem 1rem; }
.framework-mark span, .framework-mark small { display: block; color: #b8cdf7; font-size: .73rem; font-weight: 700; letter-spacing: .09em; text-transform: uppercase; }
.framework-mark strong { display: block; margin: .35rem 0; font-size: 1.1rem; }
.nav-list { display: grid; gap: .4rem; margin: 1rem 0; }
.nav-item { width: 100%; padding: .82rem 1rem; border: 0; border-radius: 12px; color: #dbe8ff; background: transparent; text-align: left; font-weight: 700; }
.nav-item:hover, .nav-item.active { color: #fff; background: rgba(255,255,255,.12); }
.boundary-note { margin-top: auto; padding: 1rem; border: 1px solid rgba(255,255,255,.14); border-radius: 16px; background: rgba(255,255,255,.07); }
.boundary-note strong { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; }
.boundary-note p { margin: .55rem 0 0; color: #cbd8ed; font-size: .78rem; line-height: 1.55; }
.sign-out { margin-top: 1rem; padding: .75rem; border: 1px solid rgba(255,255,255,.2); border-radius: 12px; color: #fff; background: transparent; font-weight: 700; }

.main-content { min-width: 0; padding: clamp(1rem, 2.5vw, 2.3rem); }
.topbar { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.7rem; }
.eyebrow { margin: 0 0 .45rem; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: .09em; text-transform: uppercase; }
h1, h2, h3 { margin: 0; color: var(--navy); letter-spacing: -.025em; }
h1 { font-size: clamp(1.75rem, 3vw, 2.6rem); }
h2 { font-size: clamp(1.4rem, 2.2vw, 1.9rem); }
h3 { font-size: 1.08rem; }
.subtitle { margin: .55rem 0 0; color: var(--muted); line-height: 1.55; }
.topbar-actions { display: flex; align-items: center; gap: .7rem; }
.user-chip, .count-chip { display: inline-flex; align-items: center; min-height: 38px; padding: .55rem .85rem; border: 1px solid var(--line); border-radius: 999px; color: var(--navy-2); background: #fff; font-size: .8rem; font-weight: 700; }
.app-message { margin: 0 0 1rem; padding: .85rem 1rem; border: 1px solid #b2ccff; border-radius: 12px; color: var(--navy-2); background: var(--blue-soft); }
.app-message.error { border-color: #fecdca; color: var(--danger); background: var(--danger-soft); }
.section-heading, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.section-heading { margin-bottom: 1rem; }
.last-updated { color: var(--muted); font-size: .8rem; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: .85rem; margin-bottom: 1rem; }
.metric-card { min-height: 126px; padding: 1rem; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); box-shadow: 0 8px 24px rgba(7,27,68,.05); }
.metric-card span { display: block; min-height: 34px; color: var(--muted); font-size: .76rem; font-weight: 700; line-height: 1.35; }
.metric-card strong { display: block; margin-top: .65rem; color: var(--navy); font-size: 1.7rem; }
.metric-card.highlight { border-color: #b2ccff; background: linear-gradient(145deg, #fff, var(--blue-soft)); }

.dashboard-grid { display: grid; grid-template-columns: minmax(0, 1.55fr) minmax(280px, .8fr); gap: 1rem; }
.panel { min-width: 0; padding: 1.15rem; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: 0 8px 28px rgba(7,27,68,.055); }
.panel-heading { margin-bottom: 1rem; }
.text-button { padding: .4rem; border: 0; color: var(--blue); background: transparent; font-weight: 800; }
.case-list, .breakdown-list { display: grid; gap: .65rem; }
.attention-card { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .8rem; align-items: center; padding: .85rem; border: 1px solid #e6ebf2; border-radius: 13px; background: #fbfcfe; }
.attention-card strong, .attention-card span { display: block; }
.attention-card span { margin-top: .25rem; color: var(--muted); font-size: .78rem; }
.breakdown-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .7rem; align-items: center; padding: .7rem 0; border-bottom: 1px solid #eef2f6; }
.breakdown-row:last-child { border: 0; }
.breakdown-row strong { color: var(--navy); }
.breakdown-row span { display: inline-grid; place-items: center; min-width: 32px; height: 32px; border-radius: 10px; color: var(--blue); background: var(--blue-soft); font-weight: 800; }

.button { min-height: 42px; padding: .68rem .95rem; border: 1px solid transparent; border-radius: 11px; font-weight: 800; }
.button.primary { color: #fff; background: var(--blue); box-shadow: 0 8px 18px rgba(21,94,239,.2); }
.button.secondary { color: var(--navy-2); border-color: #b8cff7; background: #f5f8ff; }
.button.success { color: var(--success); border-color: #abefc6; background: var(--success-soft); }
.button.danger { color: var(--danger); border-color: #fecdca; background: var(--danger-soft); }
.button.ghost { color: var(--muted); border-color: var(--line); background: #fff; }
.button.full { width: 100%; }

.filters-panel { margin-bottom: 1rem; }
label span { display: block; margin-bottom: .4rem; color: #344054; font-size: .76rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cdd8e7; border-radius: 10px; color: var(--ink); background: #fff; }
input, select { min-height: 43px; padding: .62rem .72rem; }
textarea { padding: .72rem; resize: vertical; line-height: 1.5; }
.search-field { display: block; margin-bottom: .9rem; }
.filter-grid { display: grid; grid-template-columns: repeat(7, minmax(120px, 1fr)); gap: .65rem; margin-bottom: .85rem; }
.table-panel { padding: 0; overflow: hidden; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .82rem; }
th, td { padding: .8rem .75rem; border-bottom: 1px solid #e9eef5; text-align: left; vertical-align: middle; white-space: nowrap; }
th { color: #475467; background: #f7f9fc; font-size: .7rem; letter-spacing: .04em; text-transform: uppercase; }
td strong { color: var(--navy); }
.status-pill { display: inline-flex; padding: .35rem .55rem; border-radius: 999px; color: var(--navy-2); background: var(--blue-soft); font-size: .7rem; font-weight: 800; text-transform: capitalize; }
.status-pill.ready { color: var(--success); background: var(--success-soft); }
.priority-high { color: var(--danger); font-weight: 800; }
.empty-state { padding: 3rem 1rem; text-align: center; color: var(--muted); }
.empty-state strong { color: var(--navy); }
.empty-state p { margin: .5rem 0 0; }

.queue-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1rem; }
.queue-card { padding: 1.15rem; border: 1px solid var(--line); border-radius: 17px; background: #fff; box-shadow: 0 8px 24px rgba(7,27,68,.05); }
.queue-card-header { display: flex; justify-content: space-between; gap: 1rem; }
.queue-card-header span { color: var(--blue); font-size: 1.35rem; font-weight: 800; }
.queue-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-top: 1rem; }
.queue-stats div { padding: .6rem; border-radius: 10px; background: #f7f9fc; text-align: center; }
.queue-stats strong, .queue-stats small { display: block; }
.queue-stats small { margin-top: .25rem; color: var(--muted); font-size: .64rem; }

.case-dialog { width: min(1360px, calc(100% - 2rem)); max-height: calc(100vh - 2rem); padding: 0; border: 0; border-radius: 22px; background: #fff; box-shadow: 0 30px 90px rgba(7,27,68,.3); }
.case-dialog::backdrop { background: rgba(4, 15, 37, .62); backdrop-filter: blur(3px); }
.dialog-shell { max-height: calc(100vh - 2rem); overflow-y: auto; }
.dialog-header { position: sticky; top: 0; z-index: 2; display: flex; justify-content: space-between; gap: 1rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); background: rgba(255,255,255,.97); }
.icon-button { width: 40px; height: 40px; border: 1px solid var(--line); border-radius: 12px; color: var(--navy); background: #fff; font-size: 1.6rem; }
.case-summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: .65rem; padding: 1rem 1.25rem; background: #f8faff; }
.summary-item { min-width: 0; }
.summary-item span, .summary-item strong { display: block; overflow-wrap: anywhere; }
.summary-item span { color: var(--muted); font-size: .68rem; font-weight: 700; text-transform: uppercase; }
.summary-item strong { margin-top: .3rem; font-size: .82rem; }
.case-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; padding: 1.25rem; }
.tab-list { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .6rem; }
.tab-button { flex: 0 0 auto; padding: .6rem .75rem; border: 1px solid var(--line); border-radius: 10px; color: var(--muted); background: #fff; font-size: .75rem; font-weight: 800; }
.tab-button.active { color: #fff; border-color: var(--blue); background: var(--blue); }
.document-viewer { min-height: 520px; padding: clamp(1rem, 3vw, 2rem); border: 1px solid var(--line); border-radius: 15px; color: #26344f; background: #fff; box-shadow: inset 0 0 0 8px #f7f9fc; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.7; }
.document-viewer h3 { margin-bottom: 1rem; }
.document-empty { display: grid; place-items: center; min-height: 360px; color: var(--muted); text-align: center; }
.action-panel { align-self: start; padding: 1rem; border: 1px solid var(--line); border-radius: 16px; background: #f8faff; }
.action-grid { display: grid; gap: .55rem; margin: 1rem 0; }
.field { display: block; margin: .8rem 0; }
.assignment-box { margin-top: 1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.microcopy { margin: .7rem 0 0; color: var(--muted); font-size: .72rem; line-height: 1.5; }

@media (max-width: 1180px) {
  .metric-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .filter-grid { grid-template-columns: repeat(4, minmax(140px, 1fr)); }
  .case-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; padding: 1rem; }
  .brand { width: 190px; }
  .framework-mark { margin: 1rem 0 .6rem; }
  .nav-list { grid-template-columns: repeat(3, 1fr); }
  .boundary-note { margin-top: .5rem; }
  .dashboard-grid, .case-layout { grid-template-columns: 1fr; }
  .queue-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .action-panel { order: -1; }
}

@media (max-width: 640px) {
  .main-content { padding: .85rem; }
  .topbar, .section-heading { align-items: stretch; flex-direction: column; }
  .topbar-actions { justify-content: space-between; }
  .user-chip { max-width: 62%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .metric-grid, .queue-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .nav-list { grid-template-columns: 1fr; }
  .nav-item { text-align: center; }
  .case-dialog { width: calc(100% - .6rem); max-height: calc(100vh - .6rem); border-radius: 14px; }
  .dialog-shell { max-height: calc(100vh - .6rem); }
  .case-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); padding: .8rem; }
  .case-layout { padding: .8rem; }
  .document-viewer { min-height: 400px; }
}

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