:root {
  --bg: #F4F5F6;
  --surface: #FFFFFF;
  --surface-2: #FAFBFB;
  --ink: #1D2733;
  --muted: #5F6E7C;
  --faint: #8C99A5;
  --line: #E1E6EA;
  --line-soft: #EDF0F2;
  --accent: #166B4E;
  --accent-ink: #0E4F39;
  --accent-soft: #E6F2EC;
  --warn: #9A5B06;
  --warn-soft: #FCF1DC;
  --danger: #AE2B22;
  --danger-soft: #FAEBEA;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(29, 39, 51, 0.05), 0 4px 14px rgba(29, 39, 51, 0.06);
  --font-body: "Assistant", "Segoe UI", sans-serif;
  --font-display: "Secular One", "Assistant", sans-serif;
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.6;
}

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

button { cursor: pointer; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

/* Sidebar */
.sidebar {
  width: 232px;
  flex: 0 0 232px;
  background: var(--surface);
  border-inline-start: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 18px;
}

.brand-mark {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent-ink);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-mark svg { width: 20px; height: 20px; }

.brand-name {
  font-family: var(--font-display);
  font-size: 16px;
  line-height: 1.2;
  display: flex;
  flex-direction: column;
}

.brand-name > span {
  font-family: var(--font-body);
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  text-align: start;
  transition: background 150ms ease, color 150ms ease;
}

.nav-item svg { width: 18px; height: 18px; flex: 0 0 auto; }

.nav-item:hover { background: var(--line-soft); color: var(--ink); }

.nav-item.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  font-weight: 600;
}

.sidebar-foot {
  padding-top: 12px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  justify-content: center;
}

/* Main column */
.main {
  flex: 1;
  min-width: 0;
  padding: 0 28px 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 22px 0 18px;
  flex-wrap: wrap;
}

.page-title {
  font-family: var(--font-display);
  font-size: 24px;
  font-weight: 400;
  margin: 0;
}

.searchbox {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  color: var(--faint);
  width: min(320px, 100%);
}

.searchbox svg { width: 16px; height: 16px; flex: 0 0 auto; }

.searchbox input {
  border: 0;
  outline: none;
  background: transparent;
  width: 100%;
  color: var(--ink);
}

.searchbox input::placeholder { color: var(--faint); }
.searchbox:focus-within { border-color: var(--accent); color: var(--accent); }

/* Cards and layout blocks */
.band {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.band-title {
  font-size: 16px;
  font-weight: 700;
  margin: 0 0 12px;
}

.band-sub {
  color: var(--muted);
  font-size: 13px;
  margin: -8px 0 12px;
}

.stats-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 16px;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.stat .num {
  font-family: var(--font-display);
  font-size: 30px;
  line-height: 1.2;
}

.stat .lbl { color: var(--muted); font-size: 13px; }

.stat.is-warn .num { color: var(--warn); }
.stat.is-danger .num { color: var(--danger); }
.stat.is-accent .num { color: var(--accent-ink); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 8px 15px;
  font-weight: 600;
  font-size: 14px;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.btn svg { width: 16px; height: 16px; }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-ink); }

.btn-outline { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-outline:hover { border-color: var(--accent); color: var(--accent-ink); }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--line-soft); color: var(--ink); }

.btn-danger-ghost { background: transparent; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }

.btn-sm { padding: 5px 10px; font-size: 13px; font-weight: 500; }

.icon-btn {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--muted);
  flex: 0 0 auto;
}

.icon-btn svg { width: 16px; height: 16px; }
.icon-btn:hover { background: var(--line-soft); color: var(--ink); }

.head-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

/* Table */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th {
  text-align: start;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--muted);
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

td {
  padding: 11px 16px;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

tr:last-child td { border-bottom: 0; }
tbody tr { transition: background 120ms ease; }
tbody tr:hover { background: var(--surface-2); }
tr.row-link { cursor: pointer; }

td .cell-main { font-weight: 600; }
td .cell-sub { font-size: 13px; color: var(--muted); }

/* Chips */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border-radius: 999px;
  padding: 3px 10px;
  font-size: 12.5px;
  font-weight: 600;
  white-space: nowrap;
}

.chip svg { width: 12px; height: 12px; }

.chip-neutral { background: var(--line-soft); color: var(--muted); }
.chip-accent { background: var(--accent-soft); color: var(--accent-ink); }
.chip-warn { background: var(--warn-soft); color: var(--warn); }
.chip-danger { background: var(--danger-soft); color: var(--danger); }

/* Empty state */
.empty {
  text-align: center;
  padding: 42px 20px;
  color: var(--muted);
}

.empty .empty-title { font-weight: 700; color: var(--ink); margin-bottom: 4px; }
.empty .btn { margin-top: 14px; }

/* Task rows */
.task-row {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line-soft);
}

.task-row:last-child { border-bottom: 0; }

.task-check {
  width: 20px;
  height: 20px;
  margin-top: 2px;
  flex: 0 0 auto;
  border: 1.6px solid var(--faint);
  border-radius: 6px;
  background: var(--surface);
  display: grid;
  place-items: center;
  padding: 0;
  color: transparent;
  transition: background 150ms ease, border-color 150ms ease, color 150ms ease;
}

.task-check svg { width: 12px; height: 12px; }

.task-check:hover { border-color: var(--accent); }

.task-check.done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.task-body { flex: 1; min-width: 0; }
.task-title { font-weight: 600; }
.task-row.is-done .task-title { color: var(--faint); text-decoration: line-through; }
.task-meta { font-size: 13px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
.task-meta svg { width: 14px; height: 14px; }

/* Forms */
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; }

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  background: var(--surface);
  outline: none;
  transition: border-color 150ms ease;
}

.field textarea { min-height: 110px; resize: vertical; line-height: 1.7; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 12.5px; color: var(--faint); margin-top: 4px; }

/* Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(29, 39, 51, 0.4);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 50;
}

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: min(560px, 100%);
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.modal-head h2 { margin: 0; font-family: var(--font-display); font-weight: 400; font-size: 19px; }
.modal-body { padding: 18px 20px; overflow-y: auto; }
.modal-foot { padding: 12px 20px 16px; display: flex; justify-content: flex-start; gap: 10px; border-top: 1px solid var(--line-soft); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  background: var(--ink);
  color: #fff;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  font-weight: 500;
  box-shadow: var(--shadow);
  z-index: 60;
}

/* Assistant */
.assistant-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.tool-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.tool-card h3 { margin: 0; font-size: 15px; }
.tool-card p { margin: 0; color: var(--muted); font-size: 13.5px; flex: 1; }
.tool-card .btn { align-self: flex-start; }
.assistant-note {
  background: var(--accent-soft);
  border: 1px solid #CFE5DA;
  border-radius: var(--radius);
  padding: 12px 16px;
  color: var(--accent-ink);
  font-size: 13.5px;
  margin-bottom: 16px;
}
.doc-output { margin-top: 16px; }
.doc-output textarea { min-height: 240px; }

/* Deals */
.field-row3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.checkline { display: flex; align-items: center; gap: 8px; font-weight: 600; margin: 4px 0 8px; }
.checkline input { width: 16px; height: 16px; accent-color: var(--accent); }

.party-head, .party-row {
  display: grid;
  grid-template-columns: 24px 1.3fr 1fr 0.7fr 1fr 1.4fr 0.7fr;
  gap: 8px;
  align-items: center;
}

.party-head {
  font-size: 11.5px;
  color: var(--muted);
  font-weight: 600;
  padding: 0 4px 4px;
}

.party-row { margin-bottom: 8px; }
.party-idx { color: var(--faint); font-size: 12px; text-align: center; }

.party-row input, .party-row select {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 6px 8px;
  font-size: 13px;
  width: 100%;
  min-width: 0;
  background: var(--surface);
}

.party-row input:focus, .party-row select:focus { border-color: var(--accent); outline: none; }

.upload-zone {
  border: 1.6px dashed var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 8px 14px;
  align-items: center;
  color: var(--muted);
  background: var(--surface-2);
}

.upload-zone svg { grid-row: span 2; width: 26px; height: 26px; align-self: center; }
.upload-zone strong { color: var(--ink); }
.file-list { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 6px; }
.file-item { background: var(--accent-soft); color: var(--accent-ink); border-radius: 999px; padding: 2px 10px; font-size: 12.5px; font-weight: 600; }

.bundle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
}

.doc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border-bottom: 1px solid var(--line-soft);
  padding: 8px 2px;
  font-size: 13.5px;
}

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

/* Alert cards */
.alert-card {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 11px 4px;
  border-bottom: 1px solid var(--line-soft);
}
.alert-card:last-child { border-bottom: 0; }
.alert-ico {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  display: grid; place-items: center;
  flex: 0 0 auto;
}
.alert-ico svg { width: 15px; height: 15px; }
.alert-ico.is-danger { background: var(--danger-soft); color: var(--danger); }
.alert-ico.is-warn { background: var(--warn-soft); color: var(--warn); }
.alert-ico.is-accent { background: var(--accent-soft); color: var(--accent-ink); }
.alert-title { font-weight: 600; }
.alert-sub { font-size: 13px; color: var(--muted); }

/* Case detail */
.detail-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; align-items: start; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 16px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; font-weight: 600; }

/* Search results */
.result-group { margin-bottom: 18px; }
.result-group h3 { font-size: 13px; color: var(--muted); margin: 0 0 6px; font-weight: 600; }

/* Responsive */
@media (max-width: 900px) {
  .shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex: none;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    border-inline-start: 0;
    border-bottom: 1px solid var(--line);
  }
  .brand { padding: 0; }
  .brand-name > span { display: none; }
  .nav { flex-direction: row; overflow-x: auto; flex: 1; }
  .nav-item { white-space: nowrap; padding: 8px 10px; font-size: 0; }
  .sidebar-foot { border-top: 0; padding: 0; }
  .main { padding: 0 16px 32px; }
  .stats-row, .assistant-grid, .detail-grid, .field-row3 { grid-template-columns: 1fr; }
  .field-row { grid-template-columns: 1fr; }
  .party-head { display: none; }
  .party-row { grid-template-columns: 1fr 1fr; }
  .party-idx { display: none; }
  .upload-zone { grid-template-columns: 1fr; }
  .upload-zone svg { grid-row: auto; }
  .searchbox { width: 100%; }
  .table-wrap { overflow-x: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
