:root {
  color-scheme: light;
  --crm-ink: #26322b;
  --crm-muted: #65736a;
  --crm-green: #218a44;
  --crm-green-dark: #176f38;
  --crm-pale: #eff8f1;
  --crm-line: #e0e8e2;
  --crm-bg: #f5f8f5;
  --crm-gold: #806e45;
  --crm-danger: #8b625d;
}

html,
body {
  min-width: 320px;
  margin: 0;
  color: var(--crm-ink);
  background: var(--crm-bg);
  font-family: "Microsoft JhengHei", "PingFang HK", system-ui, sans-serif;
}

body { line-height: 1.55; }
.hidden { display: none !important; }
.crm-shell-layout { min-height: 100vh; background: var(--crm-bg); }
.crm-shell-layout .portal-sidebar { background: #fff; border-right-color: var(--crm-line); color: var(--crm-ink); }
.crm-shell-layout .portal-brand-copy strong { color: var(--crm-ink); }
.crm-shell-layout .portal-brand-copy small { color: var(--crm-muted); }
.crm-shell-layout .portal-sidebar-rule,
.crm-shell-layout .portal-sidebar-foot { border-color: var(--crm-line); }
.crm-shell-layout .portal-sidebar-label { color: var(--crm-muted); }
.crm-shell-layout .portal-nav a { color: #53635a; }
.crm-shell-layout .portal-nav a:hover { color: var(--crm-green-dark); background: #f4f8f5; }
.crm-shell-layout .portal-nav a.is-active { border-color: #d8e9dc; color: var(--crm-green-dark); background: var(--crm-pale); }
.crm-shell-layout .portal-nav-icon { border-color: #d9e3dc; color: #748179; }
.crm-shell-layout .portal-nav a.is-active .portal-nav-icon { border-color: #b8d6bf; color: var(--crm-green); background: #e4f2e6; }
.crm-shell-layout .portal-sidebar-foot { color: var(--crm-muted); }
.crm-shell-layout .portal-status-dot { background: var(--crm-green); box-shadow: none; }
.crm-shell-layout .portal-main { background: var(--crm-bg); }
.crm-shell { width: min(100%, 1460px); padding-bottom: 42px; }
.crm-topbar { border-color: var(--crm-line); background: rgb(245 248 245 / 94%); }
.crm-topbar h1 { margin: 0; color: var(--crm-ink); }
.crm-subtitle { margin: 0; color: var(--crm-muted); font-size: 13px; }
.crm-eyebrow { margin: 0 0 6px; color: var(--crm-green); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.crm-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.crm-button,
.crm-text-button { border: 1px solid var(--crm-line); border-radius: 9px; padding: 9px 14px; cursor: pointer; font: inherit; font-weight: 700; }
.crm-button { min-height: 40px; }
.crm-button.primary { color: #fff; border-color: var(--crm-green); background: var(--crm-green); }
.crm-button.primary:hover { border-color: var(--crm-green-dark); background: var(--crm-green-dark); }
.crm-button.secondary { color: #4e6055; background: #fff; }
.crm-button.secondary:hover { border-color: #bfd3c4; background: #f8fbf8; }
.crm-text-button { border-color: transparent; color: var(--crm-green-dark); background: transparent; }
.crm-card { border: 1px solid var(--crm-line); border-radius: 15px; background: #fff; box-shadow: 0 12px 30px rgb(24 54 47 / 5%); }
.crm-login-panel { width: min(100% - 32px, 470px); margin: 60px auto; padding: 30px; }
.crm-login-panel h2 { margin: 0 0 7px; color: var(--crm-ink); font-size: 25px; }
.crm-login-panel form { display: grid; gap: 7px; margin-top: 24px; }
.crm-login-panel label { color: #40564a; font-size: 13px; font-weight: 700; }
.crm-login-panel input,
.crm-form-grid input,
.crm-form-grid select,
.crm-form-grid textarea,
.crm-filters input,
.crm-filters select { width: 100%; box-sizing: border-box; border: 1px solid #cfded4; border-radius: 8px; padding: 9px 10px; color: var(--crm-ink); background: #fff; font: inherit; }
.crm-login-panel input:focus,
.crm-form-grid input:focus,
.crm-form-grid select:focus,
.crm-form-grid textarea:focus,
.crm-filters input:focus,
.crm-filters select:focus { outline: 3px solid rgb(33 138 68 / 13%); border-color: var(--crm-green); }
.crm-error { min-height: 20px; margin: 8px 0 0; color: var(--crm-danger); font-size: 13px; }
.crm-login-panel .crm-error { margin: 3px 0 4px; }
.crm-stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.crm-stats article { display: grid; gap: 5px; min-height: 76px; align-content: center; padding: 14px 18px; border: 1px solid var(--crm-line); border-radius: 13px; background: #fff; box-shadow: 0 8px 20px rgb(24 54 47 / 4%); }
.crm-stats span { color: var(--crm-muted); font-size: 12px; }
.crm-stats strong { color: var(--crm-green-dark); font-size: 27px; line-height: 1; }
.crm-list-panel { padding: clamp(20px, 4vw, 30px); }
.crm-list-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.crm-list-heading h2 { margin: 0 0 4px; color: var(--crm-ink); font-size: 22px; }
.crm-list-search { width: min(320px, 42%); margin: 0; }
.crm-list-search input { width: 100%; max-width: none; }
.crm-muted { color: var(--crm-muted); font-size: 12px; }
.crm-filters { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(190px, .65fr); gap: 12px; margin-bottom: 16px; }
.crm-filters label { display: grid; gap: 5px; color: var(--crm-muted); font-size: 12px; }
.crm-loading { padding: 28px; color: var(--crm-muted); text-align: center; }
.crm-table-wrap { overflow-x: auto; border: 1px solid var(--crm-line); border-radius: 11px; }
.crm-table { width: 100%; min-width: 930px; border-collapse: collapse; font-size: 12px; }
.crm-table th,
.crm-table td { padding: 12px 13px; border-bottom: 1px solid var(--crm-line); text-align: left; vertical-align: middle; }
.crm-table th { color: #53665a; background: #f7faf7; font-size: 11px; font-weight: 800; white-space: nowrap; }
.crm-table tr:last-child td { border-bottom: 0; }
.crm-company { display: grid; gap: 2px; min-width: 220px; }
.crm-company strong { color: var(--crm-ink); font-size: 13px; }
.crm-company small,
.crm-cell-meta { color: var(--crm-muted); font-size: 11px; }
.crm-ubo { min-width: 190px; white-space: nowrap; }
.crm-cell-stack { display: grid; gap: 5px; min-width: 120px; }
.crm-status-pill { display: inline-flex; width: fit-content; align-items: center; border: 1px solid #e1e7e2; border-radius: 999px; padding: 3px 8px; color: #65736a; background: #f7f9f7; font-size: 11px; font-weight: 800; white-space: nowrap; }
.crm-status-pill.case-active { border-color: #cfe4d4; color: #557b60; background: #f1f7f2; }
.crm-status-pill.case-progress { border-color: #e8dfca; color: var(--crm-gold); background: #fbf8f1; }
.crm-status-pill.case-void { border-color: #ead8d5; color: var(--crm-danger); background: #fbf4f3; }
.crm-status-pill.risk-high { border-color: #ead8d5; color: var(--crm-danger); background: #fbf4f3; }
.crm-status-pill.risk-medium { border-color: #e8dfca; color: var(--crm-gold); background: #fbf8f1; }
.crm-status-pill.risk-low { border-color: #cfe4d4; color: #557b60; background: #f1f7f2; }
.crm-row-actions { display: flex; flex-wrap: nowrap; gap: 6px; min-width: 170px; }
.crm-table td:nth-child(2),
.crm-table td:nth-child(3),
.crm-table td:nth-child(5),
.crm-table td:nth-child(6) { white-space: nowrap; }
.crm-row-actions .crm-document-link { display: inline-flex; align-items: center; padding: 6px 8px; border: 1px solid var(--crm-line); border-radius: 7px; color: var(--crm-green-dark); background: #fff; cursor: pointer; font: inherit; font-size: 11px; font-weight: 700; line-height: 1.2; text-decoration: none; white-space: nowrap; }
.crm-row-actions .crm-document-link:hover { border-color: #bfd3c4; background: #f7fbf8; }
.crm-empty { margin: 0; padding: 38px 18px; color: var(--crm-muted); text-align: center; }
.crm-dialog { width: min(620px, calc(100% - 24px)); max-width: 620px; padding: 0; border: 1px solid var(--crm-line); border-radius: 15px; color: var(--crm-ink); background: #fff; box-shadow: 0 24px 70px rgb(24 54 47 / 20%); }
.crm-dialog::backdrop { background: rgb(22 39 29 / 30%); }
.crm-dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; padding: 18px 20px 15px; border-bottom: 1px solid var(--crm-line); background: #f8fbf8; }
.crm-dialog-head h2 { margin: 0; font-size: 20px; }
.crm-dialog-body { padding: 20px; }
.crm-form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 13px; margin-top: 16px; }
.crm-form-grid label { display: grid; gap: 5px; color: #40564a; font-size: 13px; font-weight: 700; }
.crm-form-grid .span-2 { grid-column: span 2; }
.crm-form-grid textarea { resize: vertical; }
.crm-dialog-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 20px 18px; border-top: 1px solid var(--crm-line); }
@media (max-width: 900px) {
  .crm-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crm-list-heading { align-items: flex-start; flex-direction: column; }
  .crm-list-search { width: 100%; }
}
@media (max-width: 760px) {
  .crm-shell-layout .portal-sidebar { position: static; width: auto; border-right: 0; border-bottom: 1px solid var(--crm-line); }
  .crm-shell-layout .portal-main { grid-column: auto; padding: 0 16px 34px; }
  .crm-shell-layout .portal-nav { display: flex; overflow-x: auto; }
  .crm-shell-layout .portal-nav a { flex: 0 0 auto; }
  .crm-topbar { align-items: flex-start; flex-direction: column; }
  .crm-filters { grid-template-columns: 1fr; }
}
@media (max-width: 520px) {
  .crm-stats { gap: 8px; }
  .crm-stats article { padding: 12px; }
  .crm-stats strong { font-size: 22px; }
  .crm-list-panel { padding: 16px; }
  .crm-form-grid { grid-template-columns: 1fr; }
  .crm-form-grid .span-2 { grid-column: auto; }
  .crm-dialog-foot { justify-content: stretch; }
  .crm-dialog-foot .crm-button { flex: 1; }
}
