:root {
  color-scheme: light;
  --bg: #f6f7f4;
  --panel: #ffffff;
  --ink: #16201d;
  --muted: #66736c;
  --line: #dfe5df;
  --primary: #0c6b58;
  --primary-strong: #084c40;
  --accent: #c2702c;
  --danger: #b42318;
  --soft: #ecf4f0;
  --gold: #f0b35e;
  --blue: #2f6f9f;
  --shadow: 0 18px 44px rgba(29, 45, 41, 0.09);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #10231f;
  color: #f7fbf9;
  display: flex;
  flex-direction: column;
  padding: 22px;
  gap: 24px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 44px;
  height: 44px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #f0b35e;
  color: #10231f;
  font-weight: 800;
}

.brand strong,
.brand span {
  display: block;
}

.brand span,
.security-note p {
  color: #b7c5c0;
  font-size: 0.9rem;
}

.nav-list {
  display: grid;
  gap: 8px;
}

.nav-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 12px 14px;
  text-align: left;
  background: transparent;
  color: #e8f0ed;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-button:hover,
.nav-button.active {
  background: #1c3932;
  border-color: #34554c;
}

.security-note {
  margin-top: auto;
  border: 1px solid #34554c;
  border-radius: 8px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.04);
}

.main {
  min-width: 0;
  padding: 28px;
}

.topbar,
.section-bar,
.panel-header,
.form-actions,
.doc-total {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.topbar {
  margin-bottom: 24px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
}

h1 {
  font-size: clamp(1.75rem, 3vw, 2.35rem);
}

h2 {
  font-size: 1.12rem;
}

.view {
  display: none;
}

.view.active {
  display: block;
  animation: viewIn 0.26s ease both;
}

@keyframes viewIn {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric-card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  padding: 18px;
  position: relative;
  overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.metric-card::after {
  content: "";
  position: absolute;
  inset: auto 16px 0 16px;
  height: 3px;
  border-radius: 999px 999px 0 0;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  transform: scaleX(0.35);
  transform-origin: left;
  transition: transform 0.22s ease;
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 52px rgba(29, 45, 41, 0.13);
}

.metric-card:hover::after {
  transform: scaleX(1);
}

.accent-card {
  background: linear-gradient(135deg, #0c6b58, #123f37);
  color: #fff;
}

.accent-card span {
  color: #d8eee7;
}

.metric-card span {
  color: var(--muted);
  font-size: 0.9rem;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 1.55rem;
}

.split-layout,
.doc-layout {
  display: grid;
  grid-template-columns: minmax(360px, 0.95fr) minmax(360px, 1.05fr);
  gap: 18px;
}

.doc-layout {
  grid-template-columns: minmax(460px, 1fr) minmax(340px, 0.8fr);
}

.panel {
  padding: 18px;
  min-width: 0;
}

.segmented-control {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.segment {
  border: 0;
  border-radius: 6px;
  min-height: 34px;
  padding: 0 13px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segment.active {
  background: var(--primary);
  color: #fff;
}

.finance-hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 24px;
  margin-bottom: 18px;
  border-radius: 8px;
  padding: 24px;
  background:
    linear-gradient(135deg, rgba(12, 107, 88, 0.96), rgba(16, 35, 31, 0.96)),
    linear-gradient(90deg, var(--gold), transparent);
  color: #fff;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.finance-hero h3 {
  margin: 0 0 6px;
  font-size: clamp(2rem, 5vw, 3.5rem);
}

.finance-hero span {
  color: #d9eee8;
}

.finance-score {
  width: 132px;
  height: 132px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  align-content: center;
  border: 10px solid rgba(240, 179, 94, 0.9);
  background: rgba(255, 255, 255, 0.08);
}

.finance-score span,
.finance-score small {
  display: block;
}

.finance-score span {
  font-size: 1.65rem;
  font-weight: 900;
}

.finance-score small {
  color: #d9eee8;
  font-weight: 800;
}

.analytics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(320px, 0.75fr);
  gap: 18px;
}

.chart-panel {
  min-height: 320px;
}

.chart-panel canvas {
  width: 100%;
  height: 260px;
  display: block;
  margin-top: 10px;
}

.compact-chart canvas {
  height: 290px;
}

.rank-list,
.insight-list {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.rank-item,
.insight-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfb;
}

.rank-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  font-weight: 900;
}

.rank-bar {
  height: 8px;
  margin-top: 10px;
  border-radius: 999px;
  background: #e7eee9;
  overflow: hidden;
}

.rank-bar span {
  display: block;
  height: 100%;
  width: var(--value, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), var(--gold));
  animation: growBar 0.7s ease both;
}

.insight-item strong,
.insight-item span {
  display: block;
}

.insight-item span {
  margin-top: 4px;
  color: var(--muted);
}

@keyframes growBar {
  from {
    width: 0;
  }
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 12px 8px;
  text-align: left;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.quick-actions {
  display: grid;
  gap: 10px;
}

.quick-actions button,
.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfb;
  padding: 13px;
  text-align: left;
}

.quick-actions button:hover,
.list-item:hover {
  border-color: #adc4bb;
  background: var(--soft);
}

.section-bar {
  margin-bottom: 18px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

label,
fieldset {
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  margin-top: 6px;
  border: 1px solid #cfd8d2;
  border-radius: 8px;
  padding: 11px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(12, 107, 88, 0.14);
}

.full {
  grid-column: 1 / -1;
}

.primary-button,
.ghost-button,
.danger-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
}

.primary-button {
  background: var(--primary);
  color: white;
}

.primary-button:hover {
  background: var(--primary-strong);
}

.ghost-button,
.icon-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.danger-button {
  background: #fff1ef;
  color: var(--danger);
  border: 1px solid #fac9c4;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.file-button {
  display: inline-grid;
  place-items: center;
}

#importFile {
  display: none;
}

.search-input {
  max-width: 220px;
}

.list {
  display: grid;
  gap: 10px;
  margin-top: 14px;
  max-height: 590px;
  overflow: auto;
}

.list-item {
  cursor: pointer;
}

.list-item strong,
.list-item span {
  display: block;
}

.list-item span {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.9rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--primary-strong);
  font-size: 0.78rem;
  font-weight: 800;
}

.items-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.item-row {
  display: grid;
  grid-template-columns: 1fr 92px 120px 40px;
  gap: 10px;
  margin-bottom: 10px;
  align-items: end;
}

.doc-total {
  padding: 16px;
  border-radius: 8px;
  background: var(--soft);
}

.doc-total strong {
  font-size: 1.45rem;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 360px;
  border-radius: 8px;
  padding: 13px 15px;
  background: #10231f;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: 0.18s ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
  }

  .nav-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metrics-grid,
  .split-layout,
  .doc-layout,
  .analytics-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .main,
  .sidebar {
    padding: 16px;
  }

  .topbar,
  .section-bar,
  .panel-header,
  .form-actions,
  .finance-hero {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar-actions,
  .form-actions {
    width: 100%;
  }

  .topbar-actions > *,
  .form-actions > * {
    width: 100%;
  }

  .form-grid,
  .item-row {
    grid-template-columns: 1fr;
  }

  .metrics-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .finance-score {
    width: 112px;
    height: 112px;
  }
}

@media print {
  body {
    background: #fff;
  }

  .sidebar,
  .topbar,
  .section-bar,
  .doc-layout > .panel:last-child,
  .form-actions,
  .toast {
    display: none !important;
  }

  .app-shell,
  .main,
  .doc-layout {
    display: block;
    padding: 0;
  }

  .panel {
    border: 0;
    box-shadow: none;
  }
}

/* ADSENSE CONTAINERS */
.ad-container { background: rgba(0,0,0,0.02); border: 1px dashed var(--line); padding: 10px; border-radius: 8px; text-align: center; overflow: hidden; }
.sidebar-ad { background: rgba(255,255,255,0.05); border-color: rgba(255,255,255,0.1); margin-top: auto; margin-bottom: 15px;}
.ad-label { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; margin-bottom: 8px; }