:root {
  --bg: #f8f6f2;
  --card: #ffffff;
  --card-2: #fbf9f5;
  --border-gold: rgba(168, 124, 52, 0.28);
  --border-gold-strong: rgba(168, 124, 52, 0.55);
  --gold: #9c7a3c;
  --gold-bright: #b8935a;
  --gold-fill-start: #d8b878;
  --gold-fill-end: #a3813f;
  --text: #1c1c1c;
  --text-dim: #6b6b6b;
  --text-faint: #9a9a9a;
  --green: #1f8a4c;
  --green-soft: rgba(31, 138, 76, 0.1);
  --red: #c33d3d;
  --red-soft: rgba(195, 61, 61, 0.1);
  --amber: #b07a1e;
  --amber-soft: rgba(176, 122, 30, 0.1);
  --radius: 14px;
  --shadow-card: 0 1px 2px rgba(30, 24, 10, 0.04), 0 10px 28px rgba(30, 24, 10, 0.05);
  --border: rgba(28, 28, 28, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-family: 'Playfair Display', Georgia, serif; }

body {
  background:
    radial-gradient(ellipse 900px 500px at 10% 0%, rgba(201,169,110,0.09), transparent 60%),
    radial-gradient(ellipse 900px 600px at 95% 20%, rgba(201,169,110,0.06), transparent 60%),
    var(--bg);
  background-attachment: fixed;
}

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(248, 246, 242, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.header-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 16px 40px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-meta { flex: 1; }
.header-title { font-size: 14px; font-weight: 700; color: var(--text); }
.header-period { font-size: 12px; color: var(--text-dim); margin-top: 2px; }

.header-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 600;
  color: var(--green);
  background: var(--green-soft);
  border: 1px solid rgba(31,138,76,0.25);
  border-radius: 999px;
  padding: 7px 14px;
  white-space: nowrap;
}
.header-badge .dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 3px rgba(31,138,76,0.15);
}

/* ---------- Tab bar ---------- */
.tab-bar { border-top: 1px solid var(--border); }
.tab-bar-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  gap: 4px;
}
.tab-btn {
  border: none;
  background: transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-dim);
  padding: 12px 16px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--gold); border-bottom-color: var(--gold); }

.tab-page { display: none; }
.tab-page.active { display: block; animation: tabFadeIn 0.3s ease; }
@keyframes tabFadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------- Logo lockup ---------- */
.logo-wrap { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.logo-wrap.foot { gap: 9px; }

.logo-icon-wrap {
  height: 36px;
  overflow: hidden;
  display: flex;
  align-items: flex-start;
  flex-shrink: 0;
}
.logo-icon-wrap.foot { height: 22px; }

.logo-icon { height: 60px; width: auto; display: block; }
.logo-icon-wrap.foot .logo-icon { height: 37px; }

.logo-word { display: flex; flex-direction: column; line-height: 1.2; }
.logo-word .l1 { font-size: 14px; font-weight: 700; letter-spacing: 2.6px; color: var(--text); }
.logo-word .l2 { font-size: 8px; font-weight: 600; letter-spacing: 2px; color: var(--text-dim); margin-top: 3px; }
.logo-word.foot .l1 { font-size: 11px; letter-spacing: 2.2px; }
.logo-word.foot .l2 { font-size: 6.5px; letter-spacing: 1.6px; margin-top: 2px; }

/* ---------- Page layout ---------- */
.page {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 40px 60px;
}

.hero { padding: 44px 0 8px; }

.kicker {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 3.5px;
  text-transform: uppercase;
  color: var(--gold);
  margin-bottom: 14px;
}

.title {
  font-size: 38px;
  font-weight: 600;
  letter-spacing: 0.2px;
  color: var(--text);
  line-height: 1.1;
}

.subtitle {
  margin: 10px 0 0;
  font-size: 14.5px;
  font-weight: 400;
  color: var(--text-dim);
}

.panel {
  margin-top: 44px;
  padding-top: 36px;
  border-top: 1px solid var(--border);
}
.panel:first-of-type { border-top: none; padding-top: 0; }

.panel-head { margin-bottom: 22px; }

.section-title {
  font-size: 26px;
  font-weight: 600;
  color: var(--text);
}

.section-subtitle {
  margin: 6px 0 0;
  font-size: 13.5px;
  color: var(--text-dim);
  font-weight: 400;
}

.star { color: var(--gold); }

/* ---------- KPI grid ---------- */
.kpi-grid {
  display: grid;
  gap: 18px;
  margin-bottom: 22px;
}
.kpi-grid.g3 { grid-template-columns: repeat(3, 1fr); }
.kpi-grid.g4 { grid-template-columns: repeat(4, 1fr); }

.card {
  background: var(--card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}

.label {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 1.4px;
  text-transform: uppercase;
  color: var(--text-dim);
}

.value {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 32px;
  font-weight: 600;
  color: var(--text);
  margin-top: 12px;
  line-height: 1.1;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.value.sm { font-size: 24px; }

.sub {
  margin-top: 8px;
  font-size: 12.5px;
  color: var(--text-dim);
  font-weight: 400;
}
.sub.gold { color: var(--gold); }
.value.pos { color: var(--green); }
.value.neg { color: var(--red); }

/* ---------- Chart / table cards ---------- */
.chart-card {
  background: var(--card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  padding: 24px 26px;
  box-shadow: var(--shadow-card);
  margin-bottom: 22px;
}

.chart-panel { height: 320px; position: relative; }
.chart-panel.small { height: 300px; }
.chart-panel canvas { width: 100% !important; height: 100% !important; }

.table-card {
  background: var(--card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  padding: 20px 26px 8px;
  box-shadow: var(--shadow-card);
}

.table-toolbar {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 8px;
}

.segmented {
  display: flex;
  background: var(--card-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px;
  gap: 2px;
}
.seg-btn {
  border: none;
  background: transparent;
  padding: 6px 16px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-dim);
  cursor: pointer;
  font-family: inherit;
}
.seg-btn.active { background: var(--card); color: var(--gold); box-shadow: var(--shadow-card); }

/* ---------- Ranking list ---------- */
.rank-list { padding: 6px 0 10px; }

.rank-row {
  display: grid;
  grid-template-columns: 28px 1.6fr 1.1fr 130px;
  align-items: center;
  gap: 16px;
  padding: 12px 0;
  border-bottom: 1px solid rgba(28,28,28,0.05);
}
.rank-row:last-child { border-bottom: none; }

.rank-num { color: var(--text-faint); font-size: 13px; font-weight: 700; }

.rank-name-wrap { display: flex; align-items: center; gap: 10px; min-width: 0; }
.rank-name { font-size: 14px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.tag {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-dim);
  border: 1px solid rgba(28,28,28,0.14);
  border-radius: 20px;
  padding: 1.5px 8px;
  white-space: nowrap;
  flex-shrink: 0;
}
.tag.owned { color: var(--gold); border-color: var(--border-gold-strong); }

.bar-track {
  height: 20px;
  background: rgba(28,28,28,0.05);
  border-radius: 6px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  border-radius: 6px;
  width: 0%;
  background: linear-gradient(90deg, var(--gold-fill-start), var(--gold-fill-end));
  transition: width 1s cubic-bezier(.22,1,.36,1);
}

.rank-val { text-align: right; white-space: nowrap; }
.rank-val .amt { font-size: 14px; font-weight: 700; color: var(--text); font-family: 'Playfair Display', Georgia, serif; font-variant-numeric: tabular-nums; }
.rank-val .budget { display: block; font-size: 11px; color: var(--text-faint); margin-top: 2px; }
.rank-val .chg { display: block; font-size: 11px; margin-top: 2px; font-weight: 600; }
.rank-val .chg.up { color: var(--green); }
.rank-val .chg.down { color: var(--red); }
.rank-val .chg.mid { color: var(--amber); }

/* ---------- Callouts (summary) ---------- */
.callout-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  margin-bottom: 18px;
}
.callout {
  background: var(--card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-card);
}
.c-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--gold);
}
.c-venue {
  font-family: 'Playfair Display', Georgia, serif;
  font-size: 21px;
  font-weight: 600;
  margin-top: 8px;
}
.c-metric { margin-top: 8px; font-size: 12.5px; color: var(--text-dim); }
.c-metric b { color: var(--text); font-variant-numeric: tabular-nums; }
.callout.warn .c-label { color: var(--red); }

.targets-box {
  background: var(--card-2);
  border: 1px dashed var(--border-gold-strong);
  border-radius: var(--radius);
  padding: 20px 26px;
}
.targets-head {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--gold);
}
.targets-list {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--text);
  font-size: 14px;
  line-height: 1.9;
}
.targets-list li::marker { color: var(--gold); }

/* ---------- Footer ---------- */
.app-footer {
  max-width: 1400px;
  margin: 50px auto 0;
  padding: 24px 40px 0;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
}
.foot-text { font-size: 12px; color: var(--text-faint); }

/* ---------- Responsive ---------- */
@media (max-width: 1150px) {
  .kpi-grid.g3, .kpi-grid.g4 { grid-template-columns: repeat(2, 1fr); }
  .header-inner, .page, .app-footer { padding-left: 22px; padding-right: 22px; }
  .title { font-size: 30px; }
}

@media (max-width: 720px) {
  .header-inner, .page, .app-footer, .tab-bar-inner { padding-left: 16px; padding-right: 16px; }

  /* Header: logo + upload button on one row; the period is repeated in the hero subtitle */
  .header-inner { padding-top: 10px; padding-bottom: 10px; gap: 12px; justify-content: space-between; }
  .header-meta, .header-badge, .ub-extra { display: none; }
  .logo-wrap { gap: 8px; }
  .logo-icon-wrap { height: 28px; }
  .logo-icon { height: 47px; }

  /* Tabs: keep labels on one line, scroll sideways if they don't fit */
  .tab-bar-inner { overflow-x: auto; scrollbar-width: none; }
  .tab-bar-inner::-webkit-scrollbar { display: none; }
  .tab-btn { white-space: nowrap; padding: 11px 12px; flex-shrink: 0; }

  .hero { padding-top: 26px; }
  .title { font-size: 26px; }
  .subtitle { font-size: 13.5px; }
  .panel { margin-top: 32px; padding-top: 28px; }
  .section-title { font-size: 22px; }

  .kpi-grid.g3, .kpi-grid.g4 { grid-template-columns: 1fr; gap: 12px; }
  .card, .callout { padding: 18px 18px; }
  .value { font-size: 28px; }
  .value.sm { font-size: 22px; white-space: normal; }

  .chart-card { padding: 16px 12px; }
  .chart-panel, .chart-panel.small { height: 260px; }

  .table-card { padding: 14px 14px 4px; }
  .table-toolbar { justify-content: stretch; }
  .segmented { width: 100%; }
  .seg-btn { flex: 1; }
  .rank-row { grid-template-columns: 20px minmax(0, 1fr) auto; gap: 10px; }
  .rank-row .bar-track { display: none; }
  .rank-name-wrap { flex-wrap: wrap; row-gap: 4px; }
  .rank-name { white-space: normal; }

  .callout-grid { grid-template-columns: 1fr; gap: 12px; }
  .targets-box { padding: 16px 18px; }
  .targets-list { font-size: 13.5px; line-height: 1.7; }
  .targets-list li { margin-bottom: 6px; }

  .wide-table th, .wide-table td { padding: 8px 10px; }
  .wide-table td.row-label, .wide-table th.row-label { min-width: 110px; max-width: 120px; white-space: normal; }

  .app-footer { flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 36px; }
}

@media (max-width: 380px) {
  .logo-word .l1 { font-size: 11.5px; letter-spacing: 1.5px; }
  .logo-word .l2 { font-size: 7px; letter-spacing: 1.4px; }
  .upload-btn { padding: 7px 12px; font-size: 12px; }
  .value { font-size: 25px; }
}

/* ---------- Wide data tables (Cash Flow / Cash Position) ---------- */
.wide-table-card {
  background: var(--card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}

.wide-table-scroll {
  overflow-x: auto;
  max-height: 560px;
  overflow-y: auto;
}

.wide-table {
  border-collapse: separate;
  border-spacing: 0;
  font-size: 12.5px;
  white-space: nowrap;
}

.wide-table th, .wide-table td {
  padding: 9px 14px;
  text-align: right;
  border-bottom: 1px solid rgba(28,28,28,0.06);
}

.wide-table thead th {
  position: sticky;
  top: 0;
  background: var(--card-2);
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-dim);
  z-index: 2;
  border-bottom: 1px solid var(--border-gold);
}

.wide-table thead tr.group-row th {
  text-align: center;
  color: var(--gold);
  border-bottom: 1px solid rgba(168,124,52,0.2);
}

.wide-table td.row-label, .wide-table th.row-label {
  position: sticky;
  left: 0;
  z-index: 3;
  text-align: left;
  background: var(--card);
  font-weight: 600;
  color: var(--text);
  border-right: 1px solid var(--border-gold);
}
.wide-table thead th.row-label { z-index: 4; background: var(--card-2); }

.wide-table tbody tr:hover td { background: var(--card-2); }
.wide-table tbody tr:hover td.row-label { background: var(--card-2); }

.wide-table tr.row-total td, .wide-table tr.row-balance td {
  font-weight: 700;
  border-top: 2px solid var(--border-gold-strong);
  background: var(--card-2);
}
.wide-table tr.row-revenue td { background: rgba(31,138,76,0.05); }
.wide-table tr.row-total td.row-label,
.wide-table tr.row-balance td.row-label,
.wide-table tr.row-revenue td.row-label,
.wide-table tr.row-summary td.row-label { background: var(--card-2); }
.wide-table tr.row-summary td {
  font-weight: 700;
  border-top: 2px solid var(--border-gold-strong);
  background: var(--card-2);
}

.cell-dash { color: var(--text-faint); }
.cell-err { color: var(--red); font-weight: 600; cursor: help; }
.err-inline { color: var(--red); font-weight: 700; }

.table-footnote {
  margin-top: 12px;
  font-size: 12px;
  color: var(--text-faint);
}
.table-footnote code {
  background: var(--card-2);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 11px;
}

.comparison-pending {
  grid-column: 1 / -1;
  background: var(--card-2);
  border: 1px dashed var(--border-gold-strong);
  border-radius: var(--radius);
  padding: 20px 24px;
  font-size: 13.5px;
  color: var(--text-dim);
}
.comparison-pending b { color: var(--text); }

/* ---------- Upload your data ---------- */
.upload-btn, .btn {
  font-family: inherit;
  font-size: 12.5px;
  font-weight: 600;
  border-radius: 999px;
  padding: 8px 16px;
  cursor: pointer;
  white-space: nowrap;
}
.upload-btn, .btn.primary {
  color: #fff;
  background: var(--gold);
  border: 1px solid var(--gold);
}
.upload-btn:hover, .btn.primary:hover { background: var(--gold-fill-end); }
.btn.primary:disabled { opacity: 0.4; cursor: not-allowed; }
.btn.ghost { color: var(--gold); background: var(--card); border: 1px solid var(--border-gold-strong); }
.btn.ghost:hover { background: var(--card-2); }
.btn.sm { padding: 5px 12px; font-size: 12px; }

.header-badge.user { color: var(--gold); background: rgba(156,122,60,0.08); border-color: var(--border-gold-strong); }
.header-badge.user .dot { background: var(--gold); box-shadow: 0 0 0 3px rgba(156,122,60,0.15); }

.data-banner { background: rgba(156,122,60,0.08); border-top: 1px solid var(--border-gold); }
.banner-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 40px;
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 12.5px;
  color: var(--text-dim);
}
.banner-text { flex: 1; line-height: 1.5; }
.banner-text b { color: var(--gold); }
.banner-warn { display: block; color: var(--amber); font-weight: 600; }
.banner-actions { display: flex; gap: 8px; flex-shrink: 0; }

.source-tag {
  display: inline-block;
  margin-top: 10px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 3px 10px;
}
.source-tag.mine { color: var(--gold); background: rgba(156,122,60,0.1); border: 1px solid var(--border-gold-strong); }
.source-tag.demo { color: var(--text-dim); background: rgba(28,28,28,0.04); border: 1px solid var(--border); }
#sec-overview > .source-tag { margin: 0 0 14px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(28,24,16,0.35);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 16px;
  overflow-y: auto;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  width: 100%;
  max-width: 620px;
  background: var(--card);
  border: 1px solid var(--border-gold);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(30,24,10,0.18);
  padding: 26px 28px 22px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head .section-title { font-size: 22px; }
.modal-close { border: none; background: none; font-size: 26px; line-height: 1; color: var(--text-faint); cursor: pointer; padding: 0 4px; }
.modal-close:hover { color: var(--text); }

.privacy-note {
  margin: 14px 0 18px;
  padding: 12px 14px;
  background: var(--green-soft);
  border: 1px solid rgba(31,138,76,0.25);
  border-radius: 10px;
  font-size: 13px;
  color: var(--text-dim);
  line-height: 1.5;
}
.privacy-note b { color: var(--green); }

.dropzone {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 30px 16px;
  border: 1.5px dashed var(--border-gold-strong);
  border-radius: var(--radius);
  background: var(--card-2);
  cursor: pointer;
  text-align: center;
  transition: background 0.15s, border-color 0.15s;
}
.dropzone:hover, .dropzone.over { background: rgba(156,122,60,0.08); border-color: var(--gold); }
.dz-main { font-size: 14px; font-weight: 600; color: var(--text); }
.dz-main u { color: var(--gold); }
.dz-sub { font-size: 12px; color: var(--text-faint); }

.upload-results { margin-top: 14px; display: flex; flex-direction: column; gap: 6px; }
.ur-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr);
  column-gap: 8px;
  font-size: 12.5px;
  padding: 8px 10px;
  border-radius: 8px;
  background: var(--card-2);
  border: 1px solid var(--border);
}
.ur-icon { font-weight: 700; }
.ur-file { font-weight: 600; color: var(--text); overflow-wrap: anywhere; }
.ur-msg { grid-column: 2; color: var(--text-dim); }
.ur-row.ok .ur-icon { color: var(--green); }
.ur-row.ignored .ur-icon { color: var(--text-faint); }
.ur-row.error { background: var(--red-soft); border-color: rgba(195,61,61,0.2); }
.ur-row.error .ur-icon, .ur-row.error .ur-msg { color: var(--red); }
.ur-row.busy { display: block; color: var(--text-dim); }

.supported { margin-top: 16px; font-size: 12.5px; color: var(--text-dim); }
.supported summary { cursor: pointer; font-weight: 600; color: var(--gold); }
.supported ul { margin: 10px 0 0; padding-left: 18px; line-height: 1.7; }
.supported b { color: var(--text); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

@media (max-width: 1150px) {
  .banner-inner { padding-left: 22px; padding-right: 22px; }
}
@media (max-width: 720px) {
  .banner-inner { flex-direction: column; align-items: flex-start; padding-left: 16px; padding-right: 16px; }
  .modal { padding: 20px 18px 18px; }
  .modal-backdrop { padding: 24px 12px; }
}
