:root {
  --ink: #17202a;
  --muted: #66727f;
  --line: #dbe2e8;
  --paper: #ffffff;
  --canvas: #f4f6f7;
  --navy: #14324a;
  --blue: #2d6cdf;
  --orange: #f28b30;
  --green: #1f8a70;
  --shadow: 0 18px 45px rgba(20, 50, 74, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input, select { font: inherit; }

.topbar {
  min-height: 86px;
  padding: 18px clamp(22px, 4vw, 64px);
  display: flex;
  align-items: center;
  gap: 14px;
  color: white;
  background: linear-gradient(112deg, #102c42, #174b68 72%, #176b79);
  box-shadow: 0 8px 30px rgba(15, 41, 60, 0.22);
}

.topbar h1 { margin: 2px 0 0; font-size: clamp(20px, 2.2vw, 29px); font-weight: 680; letter-spacing: -0.02em; }
.topbar .eyebrow { color: #a8c7d8; }
.brand-mark {
  width: 116px; height: 50px; padding: 5px 8px; display: grid; place-items: center;
  flex: 0 0 auto; overflow: hidden; border-radius: 11px; background: white;
  box-shadow: 0 5px 16px rgba(5, 24, 37, .2);
}
.brand-mark img { display: block; width: 100%; height: 100%; object-fit: contain; }
.eyebrow { margin: 0; color: var(--muted); text-transform: uppercase; letter-spacing: .12em; font-size: 11px; font-weight: 750; }
.status { margin-left: auto; display: flex; align-items: center; gap: 8px; padding: 9px 13px; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; color: #d4e3eb; font-size: 13px; }
.theme-toggle { margin-left: auto; min-height: 39px; padding: 0 13px; display: flex; align-items: center; gap: 8px; border: 1px solid rgba(255,255,255,.2); color: #edf6fa; background: rgba(255,255,255,.08); }
.theme-toggle:hover { background: rgba(255,255,255,.15); }
.theme-toggle + .status { margin-left: 0; }
.status span { width: 8px; height: 8px; border-radius: 50%; background: #f4ba68; box-shadow: 0 0 0 4px rgba(244,186,104,.12); }
.status.ready span { background: #68d5aa; box-shadow: 0 0 0 4px rgba(104,213,170,.12); }

main { width: min(1440px, calc(100% - 40px)); margin: 28px auto 60px; }
.filter-panel, .report-card, .metrics article { background: var(--paper); border: 1px solid var(--line); box-shadow: var(--shadow); }
.filter-panel { padding: 24px; border-radius: 16px; }
.section-heading, .card-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
h2 { margin: 5px 0 0; font-size: 20px; letter-spacing: -.02em; }
.helper { margin: 7px 0 0; color: var(--muted); font-size: 14px; }
.filters { display: grid; grid-template-columns: minmax(220px, 1.4fr) minmax(240px, 1.4fr) minmax(145px, .75fr) minmax(145px, .75fr) auto; gap: 14px; align-items: start; margin-top: 22px; }
.filters > .primary { margin-top: 19px; }
label span { display: block; margin: 0 0 7px; color: #43505d; font-size: 12px; font-weight: 700; }
select, input[type="date"], #entity-search, #contract-search { width: 100%; height: 45px; padding: 0 12px; border: 1px solid #cfd8df; border-radius: 9px; color: var(--ink); background: white; outline: none; }
select:focus, input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(45,108,223,.12); }
button { border: 0; border-radius: 9px; cursor: pointer; font-weight: 700; }
button:disabled { cursor: not-allowed; opacity: .52; box-shadow: none; }
.primary { min-height: 45px; padding: 0 18px; color: white; background: var(--blue); box-shadow: 0 8px 18px rgba(45,108,223,.18); }
.secondary { min-height: 43px; padding: 0 18px; color: var(--navy); background: #edf2f5; }
.full { width: 100%; margin-top: 14px; }
.text-button { color: var(--blue); background: transparent; }
.text-button.compact { padding: 4px 0 0; text-align: left; font-size: 12px; }
.contract-field { position: relative; display: flex; min-width: 0; flex-direction: column; }
.contract-field > span { margin: 0 0 7px; color: #43505d; font-size: 12px; font-weight: 700; }
.select-trigger { width: 100%; height: 45px; padding: 0 12px; overflow: hidden; border: 1px solid #cfd8df; color: var(--ink); background: white; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.contract-field small { min-height: 18px; margin-top: 5px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.contract-picker { position: absolute; z-index: 20; top: 70px; width: min(520px, 92vw); padding: 10px; border: 1px solid #cfd8df; border-radius: 12px; background: white; box-shadow: 0 18px 45px rgba(20, 50, 74, .18); }
.contract-options { max-height: 280px; margin-top: 8px; overflow-y: auto; }
.contract-option { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 9px 7px; border-bottom: 1px solid #edf0f2; }
.contract-option label { display: flex; min-width: 0; align-items: center; gap: 8px; font-size: 13px; }
.contract-option label span { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contract-option input { accent-color: var(--blue); }
.master-choice { color: var(--muted); font-size: 11px !important; }
.empty-option { padding: 8px; color: var(--muted); font-size: 13px; }
.contract-picker-footer { display: flex; justify-content: flex-end; padding-top: 10px; }
.contract-picker-footer .primary { min-height: 38px; }
.option-group { display: flex; gap: 24px; padding: 12px; border: 1px solid #dbe2e8; border-radius: 10px; }
.option-group legend { padding: 0 5px; color: #43505d; font-size: 12px; font-weight: 700; }
.option-group label { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.muted-field { opacity: .55; }

.metrics { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin: 16px 0; }
.metrics article { position: relative; overflow: hidden; min-height: 132px; padding: 20px; border-radius: 14px; }
.metrics article::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 4px; background: var(--blue); }
.metrics article:nth-child(2)::before { background: var(--green); }
.metrics article:nth-child(3)::before { background: var(--orange); }
.metrics article.accent { color: white; border-color: var(--navy); background: var(--navy); }
.metrics article.accent::before { background: #f6a64e; }
.metrics p { margin: 0 0 11px; color: var(--muted); font-size: 13px; font-weight: 650; }
.metrics .accent p, .metrics .accent span { color: #c7d5de; }
.metrics strong { display: block; font-size: 30px; letter-spacing: -.04em; }
.metrics span { display: block; margin-top: 9px; color: var(--muted); font-size: 12px; }

.workspace-grid { display: grid; grid-template-columns: minmax(0, 2.15fr) minmax(280px, .85fr); gap: 16px; }
.report-card { padding: 22px; border-radius: 16px; }
.legend { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.legend span { width: 9px; height: 9px; border-radius: 3px; }
.legend .blue { background: var(--blue); }
.legend .orange { margin-left: 8px; background: var(--orange); }
.chart { position: relative; height: 260px; margin-top: 20px; padding-left: 34px; display: grid; grid-template-columns: 28px 1fr; grid-template-rows: repeat(4, 1fr); }
.y-label { color: #929ca5; font-size: 11px; transform: translateY(-7px); }
.grid-line { border-top: 1px dashed #dce3e8; }
.bars { position: absolute; inset: 0 10px 0 60px; display: grid; grid-template-columns: repeat(12, 1fr); gap: clamp(5px, 1vw, 16px); align-items: end; }
.bars div { height: calc(100% - 16px); display: flex; align-items: end; justify-content: center; gap: 7px; position: relative; }
.bars i, .bars b { width: clamp(7px, 1.05vw, 16px); height: var(--h); border-radius: 5px 5px 1px 1px; }
.bars i { background: var(--blue); }
.bars b { background: var(--orange); }
.bars span { position: absolute; bottom: -23px; color: var(--muted); font-size: 10px; white-space: nowrap; }
.actions h2 { margin-bottom: 20px; }
.export-progress { margin-top: 12px; }
.export-progress-track { height: 8px; overflow: hidden; border-radius: 999px; background: #dfe6eb; }
.export-progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .45s ease; }
.export-progress small { display: block; margin-top: 7px; color: var(--muted); font-size: 11px; }
.export-progress.failed .export-progress-track span { background: #b93f3f; }
.action-hint { margin: 9px 2px 0; color: var(--muted); font-size: 12px; line-height: 1.45; }
.action-hint.ready { color: var(--green); }
.check { display: flex; align-items: center; gap: 10px; padding: 11px 0; border-bottom: 1px solid #edf0f2; color: #3e4c58; font-size: 14px; }
.check input { accent-color: var(--blue); width: 17px; height: 17px; }
.table-card { margin-top: 16px; }
.table-wrap { overflow-x: auto; margin-top: 17px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th { color: var(--muted); text-align: left; font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
th, td { padding: 13px 12px; border-bottom: 1px solid #e8edf0; }
progress { width: 110px; height: 8px; margin-right: 9px; accent-color: var(--blue); }
.logo-manager {
  margin-top: 16px; padding: 20px 22px; display: flex; align-items: center;
  justify-content: space-between; gap: 24px; border: 1px solid #cfe0e8;
  border-radius: 16px; background: linear-gradient(110deg, #f7fafb, #eaf3f5);
}
.logo-manager h2 { margin-top: 4px; }
.logo-manager .helper { margin-bottom: 0; }
.logo-manager button { min-width: 150px; }
.feedback { min-height: 20px; margin: 14px 4px 0; color: var(--green); font-size: 13px; }
.feedback.error { color: #b93f3f; }
dialog { width: min(760px, calc(100% - 28px)); padding: 0; border: 0; border-radius: 17px; box-shadow: 0 30px 90px rgba(9, 28, 43, .34); }
dialog::backdrop { background: rgba(11, 31, 46, .54); backdrop-filter: blur(3px); }
dialog form { padding: 25px; }
.close { width: 36px; height: 36px; color: var(--muted); background: #edf1f3; font-size: 24px; }
.settings-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 15px; margin-top: 22px; }
.settings-grid input, .settings-grid textarea { width: 100%; padding: 11px 12px; border: 1px solid #cfd8df; border-radius: 9px; }
.settings-grid input[type="checkbox"], .settings-grid input[type="radio"] { width: auto; padding: 0; }
.settings-grid input[type="file"] { height: auto; background: #f8fafb; }
.settings-grid textarea { resize: vertical; }
.logo-preview {
  min-height: 118px; padding: 16px; display: flex; align-items: center; gap: 20px;
  border: 1px dashed #b7c9d3; border-radius: 12px; background: #f8fafb;
}
.logo-preview img { width: 180px; height: 76px; object-fit: contain; background: white; border-radius: 8px; }
.logo-preview p { margin: 0; color: var(--muted); font-size: 13px; }
.span-2 { grid-column: span 2; }
.settings-grid > .check { justify-content: flex-start; gap: 8px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }
.dialog-actions button { padding-inline: 20px; }

:root[data-theme="dark"] {
  --ink: #f1f1f1;
  --muted: #a6a6a6;
  --line: #333333;
  --paper: #111111;
  --canvas: #050505;
  --navy: #181818;
  --shadow: 0 18px 45px rgba(0, 0, 0, .28);
}
:root[data-theme="dark"] body { color-scheme: dark; }
:root[data-theme="dark"] .topbar { background: linear-gradient(112deg, #050505, #111111 72%, #191919); }
:root[data-theme="dark"] .filter-panel,
:root[data-theme="dark"] .report-card,
:root[data-theme="dark"] .metrics article { background: var(--paper); }
:root[data-theme="dark"] select,
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .select-trigger,
:root[data-theme="dark"] .contract-picker { color: var(--ink); border-color: var(--line); background: #0d0d0d; }
:root[data-theme="dark"] label span,
:root[data-theme="dark"] .contract-field > span,
:root[data-theme="dark"] .option-group legend { color: #c5d0d8; }
:root[data-theme="dark"] .contract-option,
:root[data-theme="dark"] th,
:root[data-theme="dark"] td,
:root[data-theme="dark"] .check { border-color: #2b2b2b; }
:root[data-theme="dark"] .secondary,
:root[data-theme="dark"] .close { color: var(--ink); background: #292929; }
:root[data-theme="dark"] .logo-manager { border-color: #333333; background: linear-gradient(110deg, #101010, #181818); }
:root[data-theme="dark"] .logo-preview { border-color: #444444; background: #0d0d0d; }
:root[data-theme="dark"] .grid-line { border-color: #333333; }
:root[data-theme="dark"] .export-progress-track { background: #303030; }

@media (max-width: 1050px) {
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filters > button { grid-column: span 2; }
  .metrics { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .topbar { padding: 16px 18px; }
  .status { display: none; }
  .theme-toggle { margin-left: auto; }
  .theme-toggle #theme-label { display: none; }
  main { width: min(100% - 24px, 720px); margin-top: 16px; }
  .section-heading { display: block; }
  .filters, .metrics, .workspace-grid { grid-template-columns: 1fr; }
  .filters > button { grid-column: auto; }
  .metrics { gap: 10px; }
  .workspace-grid { gap: 12px; }
  .settings-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .logo-manager { align-items: stretch; flex-direction: column; }
  .logo-manager button { width: 100%; }
  .logo-preview { align-items: flex-start; flex-direction: column; }
  .chart { height: 220px; }
  .legend { display: none; }
}
