:root {
  --bg: #f7f6f1;
  --surface: #ffffff;
  --surface-raised: #fbfbf8;
  --surface-muted: #f0f3ed;
  --ink: #171d18;
  --ink-soft: #384038;
  --muted: #737b73;
  --line: #e2e5dd;
  --line-strong: #cfd6cc;
  --green: #1f6f3b;
  --green-dark: #102017;
  --green-soft: #e8f3ea;
  --orange: #e45b18;
  --orange-dark: #bd4311;
  --orange-soft: #fff0e7;
  --red: #c73832;
  --red-soft: #fdebea;
  --blue: #2457c5;
  --blue-soft: #e9eefb;
  --shadow-sm: 0 1px 2px rgba(15, 23, 18, 0.06);
  --shadow-md: 0 16px 40px rgba(15, 23, 18, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
button, input, select, textarea { font: inherit; }
button {
  border: 0;
  cursor: pointer;
}
button:disabled {
  cursor: progress;
  opacity: 0.68;
}
.hidden { display: none !important; }
.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(360px, 1fr) minmax(380px, 520px);
  background:
    linear-gradient(90deg, rgba(16, 32, 23, 0.94), rgba(16, 32, 23, 0.9)),
    url("/assets/images/logo.png") left 9vw center / 280px no-repeat,
    var(--green-dark);
}
.login-hero {
  min-width: 0;
  min-height: 100vh;
  padding: min(8vw, 92px);
  color: #fff;
  display: flex;
  flex-direction: column;
  justify-content: center;
}
.login-hero h1 {
  max-width: 740px;
  margin: 12px 0 18px;
  font-size: clamp(48px, 7vw, 88px);
  line-height: 0.95;
  letter-spacing: 0;
  overflow-wrap: break-word;
}
.login-hero p:not(.eyebrow) {
  max-width: 560px;
  margin: 0;
  color: rgba(255, 255, 255, 0.78);
  font-size: 20px;
  line-height: 1.48;
}
.brand-mark {
  width: 64px;
  height: 64px;
  border-radius: var(--radius);
  display: grid;
  place-items: center;
  background: #fff;
  color: var(--green);
  font-weight: 900;
  font-size: 23px;
  box-shadow: 0 18px 42px rgba(0, 0, 0, 0.18);
}
.brand-mark.small {
  width: 42px;
  height: 42px;
  font-size: 15px;
  box-shadow: none;
}
.login-card {
  align-self: center;
  justify-self: start;
  width: min(430px, calc(100vw - 36px));
  margin-right: min(6vw, 72px);
  padding: 28px;
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.97);
  box-shadow: 0 24px 70px rgba(7, 14, 9, 0.2);
}
.login-card h2 {
  margin: 0 0 22px;
  font-size: 28px;
  line-height: 1.1;
  letter-spacing: 0;
}

.segmented {
  width: 100%;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  border-radius: var(--radius);
  background: var(--surface-muted);
  margin-bottom: 18px;
}
.segment {
  min-height: 40px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}
.segment.active {
  color: #fff;
  background: var(--green-dark);
  box-shadow: var(--shadow-sm);
}
.field {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
}
.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}
input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 13px;
  color: var(--ink);
  background: #fff;
  outline: none;
  transition: border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
textarea { min-height: 92px; resize: vertical; }
input:hover, select:hover, textarea:hover { border-color: var(--line-strong); }
input:focus, select:focus, textarea:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 4px rgba(31, 111, 59, 0.1);
}
.form-message {
  min-height: 20px;
  margin: 12px 0 0;
  color: var(--red);
  font-weight: 750;
}

.portal {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
}
.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px;
  background: var(--green-dark);
  color: #fff;
  display: flex;
  flex-direction: column;
  gap: 24px;
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  padding-bottom: 14px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.09);
}
.sidebar-brand strong {
  display: block;
  font-size: 17px;
  line-height: 1.15;
}
.sidebar-brand span {
  display: block;
  max-width: 174px;
  overflow: hidden;
  color: rgba(255, 255, 255, 0.62);
  font-size: 12px;
  line-height: 1.25;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.nav-list {
  display: grid;
  gap: 5px;
}
.nav-item {
  position: relative;
  min-height: 42px;
  text-align: left;
  padding: 0 12px 0 16px;
  border-radius: var(--radius);
  color: rgba(255, 255, 255, 0.7);
  background: transparent;
  font-weight: 800;
  transition: background 140ms ease, color 140ms ease;
}
.nav-item::before {
  content: "";
  position: absolute;
  left: 6px;
  top: 12px;
  bottom: 12px;
  width: 3px;
  border-radius: 999px;
  background: transparent;
}
.nav-item.active,
.nav-item:hover {
  color: #fff;
  background: rgba(255, 255, 255, 0.1);
}
.nav-item.active::before { background: var(--orange); }
.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 10px;
}
#userBadge {
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.07);
  color: rgba(255, 255, 255, 0.82);
  font-weight: 800;
  line-height: 1.35;
}
.main-panel {
  min-width: 0;
  padding: 24px;
}
.topbar {
  min-height: 78px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 18px;
  margin-bottom: 18px;
  padding-bottom: 18px;
  border-bottom: 1px solid var(--line);
}
.topbar h2 {
  margin: 0;
  font-size: 31px;
  line-height: 1.1;
  letter-spacing: 0;
}
.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
  min-height: 40px;
  border-radius: var(--radius);
  padding: 0 15px;
  font-weight: 850;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  white-space: nowrap;
  transition: transform 120ms ease, box-shadow 120ms ease, background 120ms ease;
}
.primary-btn {
  color: #fff;
  background: var(--orange);
  box-shadow: 0 10px 22px rgba(228, 91, 24, 0.22);
}
.primary-btn:hover {
  background: var(--orange-dark);
  transform: translateY(-1px);
}
.secondary-btn {
  color: var(--green-dark);
  background: var(--green-soft);
  border: 1px solid rgba(31, 111, 59, 0.12);
}
.secondary-btn:hover { background: #deedde; }
.ghost-btn {
  color: inherit;
  background: rgba(255, 255, 255, 0.1);
}
.danger-btn {
  color: var(--red);
  background: var(--red-soft);
  border: 1px solid rgba(199, 56, 50, 0.12);
}
.icon-btn {
  min-width: 38px;
  min-height: 34px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 10px;
  color: var(--green-dark);
  background: var(--green-soft);
  font-weight: 800;
  font-size: 12px;
}
.view-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card.pad { padding: 18px; }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-6 { grid-column: span 6; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }
.metric {
  min-height: 126px;
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.metric .label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0;
}
.metric strong {
  display: block;
  margin-top: 10px;
  color: var(--ink);
  font-size: 28px;
  line-height: 1;
  letter-spacing: 0;
}
.metric small {
  display: block;
  margin-top: 8px;
  color: var(--muted);
  font-weight: 700;
}
.metric.green { border-top: 3px solid var(--green); }
.metric.red { border-top: 3px solid var(--red); }
.metric.orange { border-top: 3px solid var(--orange); }
.metric.green strong { color: var(--green); }
.metric.red strong { color: var(--red); }
.metric.orange strong { color: var(--orange); }

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}
.toolbar-left, .toolbar-right {
  display: flex;
  align-items: center;
  gap: 9px;
  flex-wrap: wrap;
}
.search {
  min-width: min(360px, 100%);
}
.table-card {
  overflow: hidden;
}
table {
  width: 100%;
  border-collapse: collapse;
}
th, td {
  padding: 13px 14px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  font-size: 14px;
}
th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
  background: var(--surface-raised);
}
tbody tr { transition: background 120ms ease; }
tr:hover td { background: #fafaf6; }
tr:last-child td { border-bottom: 0; }
.amount-pos { color: var(--green); font-weight: 900; }
.amount-neg { color: var(--red); font-weight: 900; }
.muted { color: var(--muted); }
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  background: var(--surface-muted);
  color: var(--muted);
}
.pill.green { color: var(--green); background: var(--green-soft); }
.pill.red { color: var(--red); background: var(--red-soft); }
.pill.orange { color: var(--orange); background: var(--orange-soft); }
.progress-track {
  height: 7px;
  border-radius: 999px;
  background: var(--surface-muted);
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--green);
}
.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.section-title h3 {
  margin: 0;
  font-size: 17px;
  letter-spacing: 0;
}
.quick-filters {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.chip {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  font-weight: 850;
}
.chip:hover { border-color: var(--line-strong); }
.chip.active {
  color: #fff;
  background: var(--green-dark);
  border-color: var(--green-dark);
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}
.form-grid .wide { grid-column: 1 / -1; }
.import-help {
  display: flex;
  align-items: center;
}
.summary-box {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-raised);
}
.summary-box span {
  color: var(--muted);
  font-weight: 750;
}
.error-text {
  margin: 0;
  color: var(--red);
  font-size: 12px;
  line-height: 1.45;
}
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(8, 14, 10, 0.56);
}
.modal {
  width: min(780px, 100%);
  max-height: min(90vh, 920px);
  overflow: auto;
  border: 1px solid rgba(255, 255, 255, 0.44);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-md);
}
.modal-header {
  position: sticky;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
}
.modal-header h3 {
  margin: 0;
  font-size: 21px;
}
.modal-body { padding: 18px; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 18px;
  border-top: 1px solid var(--line);
}
.empty {
  padding: 30px;
  text-align: center;
  color: var(--muted);
  font-weight: 800;
}
.toast-root {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  display: grid;
  gap: 10px;
}
.toast {
  min-width: 260px;
  padding: 13px 14px;
  border-radius: var(--radius);
  color: #fff;
  background: var(--green-dark);
  box-shadow: var(--shadow-md);
  font-weight: 800;
}
.toast.error { background: var(--red); }
.mobile-menu-btn { display: none; }

@media print {
  .sidebar, .topbar, .toolbar, .nav-list, .modal-backdrop, .toast-root { display: none !important; }
  .portal { display: block; }
  .main-panel { padding: 0; }
  body { background: #fff; }
  .card { box-shadow: none; break-inside: avoid; }
}

@media (max-width: 1120px) {
  .portal { grid-template-columns: 88px minmax(0, 1fr); }
  .sidebar {
    padding: 14px 10px;
    align-items: center;
  }
  .sidebar-brand {
    justify-content: center;
    width: 100%;
  }
  .sidebar-brand div:not(.brand-mark), .sidebar-footer span { display: none; }
  .nav-item {
    width: 54px;
    height: 46px;
    padding: 0;
    text-align: center;
    font-size: 0;
  }
  .nav-item::first-letter { font-size: 16px; }
  .nav-item::before { left: 50%; right: auto; top: auto; bottom: 6px; width: 18px; height: 3px; transform: translateX(-50%); }
  .ghost-btn {
    width: 54px;
    padding: 0;
    font-size: 0;
  }
  .span-3, .span-4 { grid-column: span 6; }
  .span-5, .span-6, .span-7, .span-8 { grid-column: span 12; }
}

@media (max-width: 760px) {
  .login-screen {
    grid-template-columns: 1fr;
    padding: 16px;
    background: var(--green-dark);
  }
  .login-hero {
    min-height: auto;
    padding: 34px 2px 18px;
  }
  .login-hero h1 { font-size: 46px; }
  .login-hero p:not(.eyebrow) { font-size: 16px; }
  .login-card {
    justify-self: center;
    margin: 0 auto 20px;
    padding: 22px;
  }
  .portal { display: block; }
  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    height: auto;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px 12px;
  }
  .sidebar-brand {
    width: auto;
    min-width: 42px;
    padding: 0 10px 0 0;
    border-bottom: 0;
    border-right: 1px solid rgba(255, 255, 255, 0.12);
  }
  .sidebar-brand div:not(.brand-mark), .sidebar-footer { display: none; }
  .nav-list {
    display: flex;
    gap: 6px;
  }
  .nav-item {
    min-width: 50px;
    height: 42px;
  }
  .main-panel { padding: 16px; }
  .topbar {
    min-height: auto;
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }
  .topbar h2 { font-size: 27px; }
  .topbar-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
  }
  .topbar-actions button { width: 100%; }
  .view-grid { grid-template-columns: 1fr; }
  .span-3, .span-4, .span-5, .span-6, .span-7, .span-8, .span-12 { grid-column: span 1; }
  .toolbar {
    align-items: stretch;
    flex-direction: column;
  }
  .toolbar-left, .toolbar-right {
    align-items: stretch;
  }
  .toolbar-right {
    display: grid;
    grid-template-columns: 1fr;
  }
  .form-grid { grid-template-columns: 1fr; }
  .metric { min-height: 116px; }
  table { min-width: 780px; }
  .table-card { overflow-x: auto; }
  .toast-root {
    right: 14px;
    left: 14px;
    bottom: 14px;
  }
  .toast { min-width: 0; }
}
