:root {
  --workspace-navy: #0b2d55;
  --workspace-blue: #1768ac;
  --workspace-ice: #edf5fb;
  --workspace-green: #18794e;
  --workspace-amber: #a15c00;
  --workspace-red: #b42318;
}

.workspace-body { background: #f4f7fb; color: #15253d; }
.workspace-topbar { position: sticky; top: 0; z-index: 20; }
.version-link { text-decoration:none; transition:transform .16s ease, box-shadow .16s ease; }
.version-link:hover { transform:translateY(-1px); box-shadow:0 4px 14px rgba(11,43,82,.12); }
.version-link:focus-visible { outline:3px solid rgba(31,111,178,.28); outline-offset:2px; }
.workspace-shell { padding-bottom: 64px; }
.text-link { color: var(--workspace-navy); font-weight: 750; text-decoration: none; }
.button.small { padding: 9px 14px; min-height: 0; }
.workspace-tabs { display:flex; gap:8px; margin:0 0 20px; padding:6px; border:1px solid #dce6f1; border-radius:14px; background:#fff; width:max-content; max-width:100%; overflow:auto; }
.workspace-tab { display:inline-flex; align-items:center; border:0; border-radius:9px; padding:10px 18px; background:transparent; color:#5c6d82; font-weight:800; text-decoration:none; white-space:nowrap; cursor:pointer; }
.workspace-tab.active { color:#fff; background:var(--workspace-navy); }
.workspace-tab-content { display:grid; gap:20px; }
.workspace-tab-content > .workspace-panel { margin:0; }

.workspace-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 28px;
  margin: 28px 0 20px;
  padding: 34px;
  border-radius: 24px;
  color: white;
  background: linear-gradient(130deg, #0a294e 0%, #0e4d80 65%, #137c8b 120%);
  box-shadow: 0 18px 42px rgba(11, 45, 85, .18);
}
.workspace-hero h1 { margin: 6px 0 10px; color: white; font-size: clamp(30px, 4vw, 48px); }
.workspace-hero p { margin: 0; max-width: 760px; color: rgba(255,255,255,.82); }
.workspace-hero .eyebrow { color: #9dd7ff; }
.entity-chip { min-width: 220px; padding: 18px 20px; border: 1px solid rgba(255,255,255,.25); border-radius: 16px; background: rgba(255,255,255,.1); }
.entity-chip small, .entity-chip strong { display: block; }
.entity-chip small { color: rgba(255,255,255,.7); margin-bottom: 6px; }
.entity-chip strong { color: white; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, .8fr); gap: 20px; align-items: start; }
.workspace-side { display: grid; gap: 20px; }
.workspace-panel { border: 1px solid #dce6f1; box-shadow: 0 8px 24px rgba(29, 51, 79, .06); }
.panel-subtitle { color: #66758a; margin: 6px 0 0; }

.upload-stage { display: grid; gap: 16px; }
.upload-dropzone {
  display: grid;
  place-items: center;
  min-height: 176px;
  padding: 24px;
  border: 2px dashed #a9bfd7;
  border-radius: 18px;
  text-align: center;
  cursor: pointer;
  background: #f8fbff;
  transition: .18s ease;
}
.upload-dropzone:hover { border-color: var(--workspace-blue); background: #f0f7ff; transform: translateY(-1px); }
.upload-dropzone input { position: absolute; opacity: 0; pointer-events: none; }
.upload-icon { display: grid; place-items: center; width: 52px; height: 52px; margin-bottom: 12px; border-radius: 15px; color: white; background: var(--workspace-blue); font-size: 28px; }
.upload-dropzone strong, .upload-dropzone small { display: block; }
.upload-dropzone small { margin-top: 8px; color: #748399; }

.preview-card { padding: 18px; border: 1px solid #bdd9c9; border-radius: 16px; background: #f2faf5; }
.preview-head { display: flex; justify-content: space-between; gap: 14px; align-items: start; }
.preview-head h3 { margin: 0 0 5px; }
.preview-meta { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; margin: 16px 0; }
.preview-meta div { padding: 11px; border-radius: 10px; background: white; }
.preview-meta small, .preview-meta strong { display: block; }
.preview-meta small { color: #6d7c8d; margin-bottom: 3px; }
.route-list { display: grid; gap: 8px; max-height: 360px; overflow: auto; }
.preview-selection-head { display: flex; justify-content: space-between; gap: 12px; align-items: end; margin: 16px 0 10px; }
.preview-selection-head strong, .preview-selection-head small { display: block; }
.preview-selection-head small { margin-top: 3px; color: #68798e; }
.preview-selection-head > div:last-child, .preview-actions > div { display: flex; flex-wrap: wrap; gap: 8px; }
.route-list-head, .route-row { display: grid; grid-template-columns: 24px minmax(180px, 1.25fr) minmax(115px, .7fr) minmax(115px, .7fr) minmax(125px, .72fr) minmax(220px, 1.15fr); gap: 12px; align-items: center; }
.route-list-head { position: sticky; top: 0; z-index: 2; padding: 8px 12px; color: #66788d; background: #f2faf5; font-size: 12px; }
.route-row { padding: 12px; border: 1px solid transparent; border-radius: 10px; background: white; font-size: 13px; }
.route-row.selectable { cursor: pointer; }
.route-row.selectable:has(input:checked) { border-color: #86bd9e; box-shadow: 0 0 0 1px rgba(24,121,78,.08); }
.route-row.route-selected { border-color: #86bd9e; box-shadow: 0 0 0 1px rgba(24,121,78,.08); }
.route-row.route-needs-decision { border-color: #e6bb63; background: #fffdf7; }
.route-row.route-decision-clear { border-color: #e9a69d; background: #fff9f8; }
.route-row.route-decision-keep { border-color: #b8cadc; background: #fbfdff; }
.route-row input { width: 18px; min-height: 18px; margin: 0; accent-color: var(--workspace-green); }
.route-row .badge { white-space: nowrap; }
.route-name strong, .route-name small, .route-values strong, .route-values small, .route-decision small { display: block; }
.route-name small, .route-values small, .route-decision small { margin-top: 4px; color: #718096; line-height: 1.35; }
.route-decision .badge { display: inline-flex; }
.route-difference-zero { color: #60748b; }
.route-difference-nonzero { color: var(--workspace-red); }
.route-decision-marker { display: grid; place-items: center; width: 20px; height: 20px; border: 2px solid #d5a13d; border-radius: 50%; color: #976000; font-size: 11px; font-weight: 850; }
.route-decision-actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 7px; }
.route-choice { min-height: 31px; padding: 5px 9px; border: 1px solid #c6d4e2; border-radius: 8px; color: var(--workspace-navy); background: white; font-size: 11px; font-weight: 750; cursor: pointer; }
.route-choice.active { border-color: #7895b2; background: #eaf2fa; }
.route-choice.clear.active { border-color: #dd877d; color: var(--workspace-red); background: #fff0ee; }
.route-mode-blank { border-color: #e9b4a9; background: #fff8f6; }
.route-mode-zero { background: #fffdf3; }
.route-mode-missing { background: #f7f9fc; }
.route-empty { color: #8996a7; }
.route-disabled { opacity: .55; cursor: not-allowed !important; }
.preview-actions { display: flex; justify-content: space-between; gap: 14px; align-items: center; margin-top: 15px; }
.selection-count { color: #52657c; font-weight: 750; }

.workspace-metrics { grid-template-columns: repeat(4, minmax(0, 1fr)); margin: 0 0 20px; }
.workspace-metrics .metric { min-height: 112px; }
.workspace-metrics .metric span, .workspace-metrics .metric small { display: block; }
.workspace-metrics .metric span { margin-top: 5px; }
.workspace-metrics .metric small { margin-top: 4px; color: #718096; }

#casesPanel .panel-heading { align-items: stretch; flex-direction: column; }
.workspace-filters { display: grid; width: 100%; }
.case-filter-main { display: grid; align-items: end; gap: 10px; width: 100%; }
.case-filter-main.admin { grid-template-columns: minmax(360px, 2.1fr) repeat(5, minmax(145px, 1fr)); }
.case-filter-main.entity { grid-template-columns: minmax(360px, 2.1fr) repeat(4, minmax(145px, 1fr)); }
.case-filter-field, .case-filter-action { display: grid; gap: 6px; }
.case-filter-field > span, .case-filter-action > span { color: #68798e; font-size: 12px; font-weight: 750; }
.case-company-filter { min-width: 0; }
.case-filter-field select { min-width: 0; width: 100%; }
.case-filter-main select, .case-filter-main input { box-sizing: border-box; height: 40px; min-height: 40px; max-height: 40px; }
.case-search-group { display: grid; grid-template-columns: minmax(0, 1fr); width: 100%; }
.case-search-group input { min-width: 0; width: 100%; border-radius: 10px; }
.case-search-group select:focus, .case-search-group input:focus { position: relative; z-index: 1; }
.case-difference-toggle { display: flex; align-items: center; gap: 7px; min-height: 40px; padding: 8px 10px; border: 1px solid #ccdcec; border-radius: 9px; color: var(--workspace-blue); background: #edf5ff; font-weight: 750; white-space: nowrap; }
.case-difference-toggle input { width: 17px; min-height: 17px; margin: 0; accent-color: var(--workspace-navy); }
.case-reset-filters { min-height: 40px; padding: 8px 4px; border: 0; color: var(--workspace-blue); background: transparent; font-weight: 750; white-space: nowrap; }
.case-filter-footer { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #e3ebf3; }
.case-filter-footer-actions { display: flex; align-items: center; gap: 12px; }
.case-filter-count { color: #718096; font-size: 12px; font-weight: 750; text-align: left; }
.case-table th { white-space: nowrap; }
.case-table td { vertical-align: middle; }
.case-party strong, .case-party small { display: block; }
.case-party small { color: #718096; }
.case-scope strong, .case-scope small { display: block; }
.case-scope small { margin-top: 4px; color: #718096; }
.amount { font-variant-numeric: tabular-nums; white-space: nowrap; }
.difference-positive { color: var(--workspace-red); font-weight: 800; }
.difference-zero { color: var(--workspace-green); font-weight: 800; }
.case-owner { white-space: nowrap; }
.badge.waiting { background: #fff4db; color: var(--workspace-amber); }
.badge.closed { background: #eef1f5; color: #58677a; }
.badge.ready { background: #e5f6ed; color: var(--workspace-green); }
.badge.superseded { background: #f5f0ff; color: #6b4ab1; }
.badge.source { background: #f3efff; color: #6544a9; }

.invite-form { display: grid; gap: 12px; }
.invite-form label span { display: block; margin-bottom: 7px; font-weight: 750; }
.invite-form input { width: 100%; }
.invite-list, .batch-list { display: grid; gap: 10px; margin-top: 16px; }
.invite-item, .batch-item { padding: 13px; border: 1px solid #dce6f1; border-radius: 12px; background: #fbfdff; }
.invite-item strong, .invite-item small, .batch-item strong, .batch-item small { display: block; }
.invite-item small, .batch-item small { color: #718096; margin-top: 4px; }
.invite-actions, .batch-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.button.link-button { padding: 7px 10px; font-size: 12px; }
.tab-panel-heading { display:flex; align-items:end; justify-content:space-between; gap:18px; margin-bottom:16px; }
.tab-panel-heading h2 { margin:3px 0 5px; }
.tab-panel-actions { display:flex; flex-wrap:wrap; align-items:center; justify-content:flex-end; gap:10px; }
.tab-search { width:min(360px,100%); }
.link-table td,.link-table th,.history-table td,.history-table th { vertical-align:middle; }
.link-table .company-cell strong,.link-table .company-cell small,.history-table .company-cell strong,.history-table .company-cell small { display:block; }
.link-table .company-cell small,.history-table .company-cell small { color:#718096; margin-top:3px; }
.link-table .link-status { white-space:nowrap; }
.history-table .file-cell { min-width:240px; max-width:420px; overflow-wrap:anywhere; }
.history-table .time-cell { white-space:nowrap; }

.auth-card { max-width: 470px; margin: 70px auto; }
.auth-card h1 { margin-bottom: 8px; }
.auth-card form { display: grid; gap: 15px; margin-top: 24px; }
.auth-card label span { display: block; margin-bottom: 7px; font-weight: 750; }
.auth-card input { width: 100%; }
.access-error { max-width: 640px; margin: 80px auto; text-align: center; }

.case-dialog { width: min(1180px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 22px; }
.case-dialog::backdrop { background: rgba(8, 25, 47, .62); backdrop-filter: blur(3px); }
.case-dialog .dialog-heading { position: sticky; top: 0; z-index: 3; padding: 22px 26px; background: white; border-bottom: 1px solid #e2e9f1; }
.case-dialog .dialog-heading h2 { margin: 3px 0 0; }
.icon-button { border: 0; background: transparent; color: #617188; font-size: 38px; line-height: 1; cursor: pointer; }
#caseDialogBody { padding: 24px 26px 30px; }
.case-summary { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 20px; }
.case-summary div { padding: 14px; border-radius: 12px; background: #f3f7fb; }
.case-summary small, .case-summary strong { display: block; }
.case-summary small { color: #68798e; margin-bottom: 5px; }
.case-toolbar { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 12px; align-items: end; margin: 18px 0; }
.reconciliation-launch { display:flex; align-items:center; justify-content:space-between; gap:18px; margin:18px 0; padding:18px; border:1px solid #b9d8ef; border-radius:16px; background:#eef7fd; }
.reconciliation-launch > div { display:grid; gap:4px; }
.reconciliation-launch strong { color:var(--workspace-navy); }
.reconciliation-launch small { color:var(--workspace-muted); }
.reconciliation-launch.no-data { border-color:#ead7a5; background:#fff8e8; }
.reconciliation-launch button:disabled { cursor:not-allowed; opacity:.5; }
.owner-edit { display: flex; gap: 8px; align-items: end; }
.owner-edit label span { display: block; margin-bottom: 5px; font-size: 12px; font-weight: 750; }
.records-note { color: #6f7d90; font-size: 13px; }
.records-table td, .records-table th { font-size: 12px; white-space: nowrap; }
.records-table .product-cell { max-width: 250px; white-space: normal; }
.activity-mini { display: grid; gap: 7px; margin-top: 18px; }
.activity-mini div { padding: 9px 11px; border-radius: 9px; background: #f7f9fc; font-size: 13px; }

.workspace-toast { position: fixed; right: 24px; bottom: 24px; z-index: 60; max-width: 440px; padding: 14px 18px; border-radius: 12px; color: white; background: #17365d; box-shadow: 0 14px 34px rgba(0,0,0,.2); }
.workspace-toast.error { background: #9f231b; }
.workspace-toast.success { background: #176b46; }
.busy { opacity: .58; pointer-events: none; }

@media (max-width: 980px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .workspace-metrics { grid-template-columns: repeat(2, 1fr); }
  .preview-meta, .case-summary { grid-template-columns: repeat(2, 1fr); }
  .case-filter-main.admin, .case-filter-main.entity { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .case-company-filter { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .workspace-hero { grid-template-columns: 1fr; padding: 26px 22px; }
  .entity-chip { min-width: 0; }
  .workspace-metrics { grid-template-columns: 1fr; }
  .preview-meta, .case-summary { grid-template-columns: 1fr; }
  .preview-selection-head, .preview-actions { align-items: stretch; flex-direction: column; }
  .reconciliation-launch { align-items:stretch; flex-direction:column; }
  .route-list-head { display: none; }
  .route-row { grid-template-columns: auto minmax(0, 1fr); }
  .route-row > .route-values, .route-row > .route-decision { grid-column: 2; }
  .route-row .badge { justify-self: start; }
  .workspace-topbar { align-items: flex-start; }
  .top-actions { flex-wrap: wrap; justify-content: flex-end; }
  .workspace-tabs { width:100%; }
  .tab-panel-heading { align-items:stretch; flex-direction:column; }
  .case-filter-main.admin, .case-filter-main.entity { grid-template-columns: 1fr; }
  .case-company-filter { grid-column: auto; width: 100%; }
  .case-search-group { grid-template-columns: 1fr; }
  .case-search-group select, .case-search-group input { width: 100%; border: 1px solid #ccd8e5; border-radius: 10px; }
  .case-filter-footer { align-items: stretch; flex-direction: column; }
  .case-filter-footer-actions { justify-content: space-between; }
  .case-filter-count { text-align: left; }
}
