:root {
  color-scheme: light;
  --bg: #e8e1d9;
  --surface: #ede9e3;
  --surface-input: #f3f0ec;
  --ink: #2e2d2c;
  --muted: #655b52;
  --subtle: #8d8176;
  --line: rgba(109, 91, 81, 0.14);
  --line-strong: #cec4b8;
  --accent: #e43c2f;
  --accent-dark: #b92d22;
  --accent-soft: #fbe7e3;
  --table-head: #e5e0d9;
  --good: #24724b;
  --bad: #b92d22;
  --shadow: 0 1px 3px rgba(46, 45, 44, 0.06), 0 4px 16px rgba(46, 45, 44, 0.07);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-feature-settings: "cv02", "cv03", "cv04", "cv11";
}

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 24px;
  background: var(--bg);
}

.login-screen.hidden { display: none; }

.login-panel {
  width: min(420px, 100%);
  display: grid;
  gap: 18px;
  padding: 32px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.login-logo {
  width: 160px;
  height: 40px;
  object-fit: contain;
  object-position: left center;
}

.login-panel h1 {
  font-size: 26px;
}

.login-panel input,
.login-panel button {
  width: 100%;
}

.login-status {
  min-height: 18px;
  color: var(--bad);
  font-size: 13px;
  font-weight: 700;
}

/* ── Shared card surface ─────────────────────────── */
.dashboard-shell,
.dashboard-table-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
}

.dashboard-drop-header {
  border-radius: 0 0 20px 20px;
  border-top: 0;
  border-right: 0;
  border-left: 0;
}

/* ── Header ──────────────────────────────────────── */
.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 16px clamp(16px, 4vw, 48px);
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 240px;
}

.brand-logo {
  display: block;
  width: clamp(132px, 14vw, 168px);
  height: 40px;
  object-fit: contain;
  object-position: left center;
}

h1, h2, p { margin: 0; }

h1 {
  color: var(--ink);
  font-size: clamp(22px, 2.2vw, 32px);
  font-weight: 760;
  line-height: 1.1;
}

h2 {
  color: var(--ink);
  font-size: 18px;
  font-weight: 760;
}

main {
  width: min(1680px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 48px) 48px;
}

/* ── Toolbar ─────────────────────────────────────── */
.toolbar,
.panel-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.toolbar {
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: flex-end;
}

label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
}

/* ── Inputs ──────────────────────────────────────── */
input, button {
  min-height: 46px;
  border-radius: 12px;
  font: inherit;
}

input {
  width: 216px;
  border: 1px solid var(--line-strong);
  background: var(--surface-input);
  color: var(--ink);
  padding: 0 14px;
  box-shadow: none;
  outline: none;
  font-size: 14px;
  font-weight: 700;
}

input:focus {
  border-color: var(--muted);
  box-shadow: 0 0 0 2px rgba(46, 45, 44, 0.10);
}

input::placeholder { color: var(--subtle); }

/* ── Month picker ────────────────────────────────── */
.month-picker {
  display: flex;
  gap: 6px;
}

.month-picker .custom-select:first-child { width: 92px; }
.month-picker .custom-select:last-child  { width: 90px; }

/* ── Button ──────────────────────────────────────── */
button {
  border: 0;
  background: var(--accent);
  color: #fff;
  padding: 0 18px;
  font-weight: 800;
  cursor: pointer;
  box-shadow: none;
  transition: background 160ms ease, transform 160ms ease;
  font-size: 14px;
  min-width: 110px;
}

button:hover {
  background: var(--accent-dark);
  transform: translateY(-1px);
}

button.secondary-button {
  border: 1px solid var(--line-strong);
  background: var(--surface-input);
  color: var(--ink);
  box-shadow: none;
}

button.secondary-button:hover {
  border-color: var(--muted);
  background: var(--surface);
  color: var(--ink);
}

button:disabled {
  cursor: wait;
  opacity: 0.7;
  transform: none;
}

/* ── Tab Navigation ──────────────────────────────── */
.tab-nav {
  display: flex;
  gap: 4px;
  padding: 6px;
  border-radius: 16px;
  margin-bottom: 0;
}

.tab-btn {
  padding: 10px 28px;
  border-radius: 10px;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 160ms ease;
  min-width: 0;
}

.tab-btn:hover { background: rgba(46, 45, 44, 0.07); color: var(--ink); transform: none; box-shadow: none; }
.tab-btn.active { background: var(--accent); color: #fff; box-shadow: none; }
.tab-panel { display: block; }
.tab-panel.hidden { display: none; }

/* ── Charts ──────────────────────────────────────── */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-card { padding: 24px; }

.chart-head { margin-bottom: 20px; }
.chart-head h3 { font-size: 15px; font-weight: 800; color: var(--ink); margin: 0 0 4px; }
.chart-head p  { font-size: 12px; color: var(--subtle); margin: 0; }
.chart-wrap { position: relative; height: 260px; }

/* ── Stage Badge ─────────────────────────────────── */
.stage-badge { display: inline-block; font-size: 12px; font-weight: 700; color: var(--ink); }

/* ── Metric Cards ────────────────────────────────── */
.metrics {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metrics article {
  min-width: 0;
  padding: 20px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.metrics span {
  display: block;
  color: var(--subtle);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.metrics strong {
  display: block;
  margin-top: 10px;
  overflow-wrap: anywhere;
  color: var(--ink);
  font-size: clamp(22px, 3vw, 31px);
  font-weight: 780;
  line-height: 1.08;
}

/* ── Panels ──────────────────────────────────────── */
.panel { display: flow-root; }
.panel + .panel { margin-top: 18px; }

.panel-head {
  justify-content: space-between;
  padding: 18px 20px;
  border-bottom: 1px solid var(--line);
}

.panel-head p {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
}

/* ── CRM Filters ─────────────────────────────────── */
#searchInput { width: min(380px, 100%); }

.crm-filters {
  display: flex;
  gap: 10px;
  align-items: center;
  flex: 1;
  justify-content: flex-end;
}

.crm-filters button {
  min-width: 124px;
}

#crmSearchInput {
  flex: 1;
  max-width: 520px;
  min-width: 200px;
  width: auto;
}

/* ── Custom Select ───────────────────────────────── */
.custom-select { position: relative; }

.cs-trigger {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 46px;
  padding: 0 14px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface-input);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  box-shadow: none;
  transition: border-color 160ms;
  min-width: 0;
  width: 100%;
  white-space: nowrap;
}

.cs-trigger:hover { background: var(--surface); transform: none; }

.cs-trigger.cs-open {
  border-color: var(--muted);
  box-shadow: 0 0 0 2px rgba(46, 45, 44, 0.10);
}

.cs-chevron {
  display: flex;
  align-items: center;
  color: var(--subtle);
  flex-shrink: 0;
  transition: transform 160ms;
}

.cs-trigger.cs-open .cs-chevron { transform: rotate(180deg); }

.cs-panel {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 100;
  overflow: hidden;
  padding: 6px;
}

.cs-panel.cs-open { display: block; }

.cs-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 14px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  transition: background 120ms, color 120ms;
  box-shadow: none;
  min-width: 0;
  min-height: 0;
}

.cs-item:hover { background: rgba(46, 45, 44, 0.07); color: var(--ink); transform: none; }
.cs-item.cs-active { background: var(--ink); color: #fff; font-weight: 700; }
.cs-item.cs-active:hover { background: var(--muted); }

/* ── Status ──────────────────────────────────────── */
.status {
  display: none;
  margin: 18px;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 760;
}

.status.visible { display: block; }

.status.error {
  border-color: rgba(185, 45, 34, 0.3);
  background: #fff0ed;
  color: var(--bad);
}

/* ── Table ───────────────────────────────────────── */
.table-wrap { overflow-y: auto; max-height: 600px; }

table {
  width: 100%;
  min-width: 980px;
  border-collapse: separate;
  border-spacing: 0;
}

th, td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  z-index: 5;
  background: var(--table-head);
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

td { color: var(--muted); font-size: 14px; }

tbody tr { transition: background 160ms ease; }
tbody tr:hover { background: rgba(46, 45, 44, 0.03); }
tbody tr:last-child td { border-bottom: 0; }

.number { text-align: right; white-space: nowrap; }
.project-name { color: var(--ink); font-weight: 800; }
.doc-list { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.empty { padding: 38px 18px; color: var(--subtle); text-align: center; }
.positive { color: var(--good); font-weight: 800; }
.negative { color: var(--bad); font-weight: 800; }
.center { text-align: center; }
.doc-sub { color: var(--subtle); font-size: 11px; margin-top: 2px; }

/* ── Modal ───────────────────────────────────────── */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal.hidden { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.45); }
.modal-content { position: relative; z-index: 1; background: var(--surface); border-radius: 14px; width: min(94vw, 780px); max-height: 88vh; overflow: hidden; box-shadow: 0 8px 40px rgba(0,0,0,0.18); display: flex; flex-direction: column; }

.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: flex-start; flex-shrink: 0; gap: 12px; }
.modal-title-block { flex: 1; min-width: 0; }
.modal-header h2 { margin: 0; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-meta { margin: 3px 0 0; font-size: 12px; color: var(--muted); }
.modal-close { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--muted); padding: 0; width: 28px; height: 28px; display: flex; align-items: center; justify-content: center; border-radius: 6px; flex-shrink: 0; }
.modal-close:hover { background: rgba(46,45,44,0.1); }

.modal-body { padding: 20px 24px; overflow-y: auto; flex: 1; }

.modal-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.modal-col { min-width: 0; }
.modal-col-head { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 8px; border-bottom: 2px solid var(--line); margin-bottom: 4px; font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--muted); }
.modal-col-total { font-size: 12px; color: var(--ink); font-weight: 700; }

.modal-doc-row { display: flex; justify-content: space-between; align-items: center; padding: 7px 0; border-bottom: 1px solid var(--line); font-size: 13px; gap: 8px; }
.modal-doc-row:last-child { border-bottom: 0; }
.modal-doc-num { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.modal-doc-amt { flex-shrink: 0; font-weight: 600; color: var(--ink); white-space: nowrap; }
.modal-empty { padding: 16px 0; font-size: 13px; color: var(--subtle); }

/* ── Responsive ──────────────────────────────────── */
@media (max-width: 980px) {
  .app-header { align-items: flex-start; flex-direction: column; }
  .toolbar { justify-content: flex-start; width: 100%; align-items: stretch; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .panel-head { align-items: stretch; flex-direction: column; }
  .charts-row { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .brand-block { align-items: flex-start; flex-direction: column; gap: 10px; }
  .toolbar label, .toolbar button, #searchInput { width: 100%; }
  .crm-filters { flex-direction: column; width: 100%; }
  .crm-filters button,
  .crm-filters .custom-select {
    width: 100%;
  }
  #crmSearchInput { width: 100%; }
  input, button { min-height: 44px; }
  input { width: 100%; }
  .metrics { grid-template-columns: 1fr; }
}
