:root {
  --bg: #f6f7f4;
  --surface: #ffffff;
  --surface-2: #f0f4ef;
  --soft-bg: #fbfcfa;
  --field-bg: #ffffff;
  --table-bg: #ffffff;
  --line: #d9ded4;
  --line-strong: #b7c1b0;
  --text: #1f2920;
  --muted: #657163;
  --accent: #2f7d4f;
  --accent-dark: #205c3a;
  --accent-soft: #e7f4ea;
  --green: #2f7d4f;
  --green-dark: #205c3a;
  --amber: #a36a00;
  --red: #b13c37;
  --blue: #356a88;
  --body-bg: var(--bg);
  --sidebar-bg: #1f2920;
  --brand-bg: var(--accent);
  --brand-muted: #b8c5b5;
  --nav-text: #e9efe6;
  --nav-active-bg: rgba(255, 255, 255, 0.1);
  --leaf-opacity: 0;
  --shadow: 0 18px 40px rgba(31, 41, 32, 0.08);
}

:root[data-theme="canada"] {
  --bg: #fff7ef;
  --surface: #ffffff;
  --surface-2: #fff1e3;
  --soft-bg: #fffaf5;
  --field-bg: #ffffff;
  --table-bg: #ffffff;
  --line: #ead8ca;
  --line-strong: #d8ad96;
  --text: #2f201a;
  --muted: #786457;
  --accent: #c94c1f;
  --accent-dark: #8f2e18;
  --accent-soft: #fff0e6;
  --amber: #b45f06;
  --body-bg:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180' viewBox='0 0 180 180'%3E%3Cg fill='none' stroke='%23e17845' stroke-opacity='.14' stroke-width='2'%3E%3Cpath d='M87 25 97 58 122 40 111 70 145 71 115 89 137 112 105 105 107 139 90 111 73 139 75 105 43 112 65 89 35 71 69 70 58 40 83 58Z'/%3E%3Cpath d='M90 111v39'/%3E%3C/g%3E%3C/svg%3E"),
    linear-gradient(135deg, #fff9f2 0%, #fff2e8 52%, #f8faf4 100%);
  --sidebar-bg: linear-gradient(180deg, #4b1f17 0%, #7a2f17 58%, #362016 100%);
  --brand-bg: linear-gradient(135deg, #f07a2a, #b32620);
  --brand-muted: #ffd9c0;
  --nav-active-bg: rgba(255, 236, 220, 0.16);
  --shadow: 0 18px 40px rgba(86, 38, 20, 0.09);
}

:root[data-theme="dark"] {
  --bg: #0f1115;
  --surface: #181c22;
  --surface-2: #232933;
  --soft-bg: #15191f;
  --field-bg: #10141a;
  --table-bg: #15191f;
  --line: #303845;
  --line-strong: #4a5565;
  --text: #eef2f6;
  --muted: #a9b2bf;
  --accent: #d7a64a;
  --accent-dark: #f0c76d;
  --accent-soft: #2a2112;
  --green: #50b978;
  --green-dark: #82d69d;
  --amber: #f0b853;
  --red: #f06b61;
  --blue: #80bde8;
  --body-bg: radial-gradient(circle at top right, rgba(215, 166, 74, 0.12), transparent 34%), #0f1115;
  --sidebar-bg: linear-gradient(180deg, #080a0d 0%, #161a21 56%, #0b0d11 100%);
  --brand-bg: linear-gradient(135deg, #d7a64a, #75551e);
  --brand-muted: #b8c0ca;
  --nav-text: #eef2f6;
  --nav-active-bg: rgba(215, 166, 74, 0.16);
  --shadow: 0 18px 40px rgba(0, 0, 0, 0.28);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--body-bg);
  color: var(--text);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.45;
}

a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

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

button {
  border: 0;
  cursor: pointer;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 248px;
  padding: 18px;
  background: var(--sidebar-bg);
  color: white;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: white;
  text-decoration: none;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: var(--brand-muted);
  text-transform: uppercase;
  font-size: 11px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: var(--brand-bg);
  color: white;
  font-weight: 800;
}

.brand-mark.large {
  width: 54px;
  height: 54px;
  font-size: 24px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.nav-group-toggle,
.logout button {
  width: 100%;
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--nav-text);
  background: transparent;
  text-align: left;
  text-decoration: none;
}

.nav-group-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
}

.nav-group-panel {
  display: grid;
  gap: 4px;
  max-height: 0;
  overflow: hidden;
  opacity: 0;
  transition: max-height 180ms ease, opacity 160ms ease, margin-top 160ms ease;
}

.nav-group-panel.open {
  max-height: 220px;
  opacity: 1;
  margin-top: 4px;
}

.nav-group-panel a {
  padding-left: 22px;
  min-height: 36px;
  display: flex;
  align-items: center;
}

.nav-chevron {
  transition: transform 160ms ease;
}

.nav-group-toggle[aria-expanded="true"] .nav-chevron {
  transform: rotate(180deg);
}

.nav a:hover,
.nav a.active,
.nav-group-toggle:hover,
.nav-group-toggle[aria-expanded="true"],
.logout button:hover {
  background: var(--nav-active-bg);
}

.theme-switcher {
  display: grid;
  gap: 6px;
  color: var(--brand-muted);
  font-size: 12px;
  font-weight: 700;
}

.theme-switcher select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
  color: white;
  min-height: 34px;
  padding: 7px 9px;
}

.theme-switcher select option {
  color: var(--text);
  background: var(--surface);
}

.logout { margin-top: auto; }

.main {
  margin-left: 248px;
  padding: 26px;
}

.auth-main {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.page-header h1,
.panel h2,
.panel h3,
.login-panel h1,
.empty-state h1 {
  margin: 0;
}

.page-header h1 {
  font-size: 26px;
}

.page-header p,
.login-panel p {
  margin: 4px 0 0;
  color: var(--muted);
}

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

.metric-grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}

.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

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

.grid {
  display: grid;
  gap: 14px;
  margin-bottom: 14px;
}

.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.compact { margin-bottom: 0; gap: 10px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  min-width: 0;
}

.panel + .panel,
.grid + .panel,
.panel + .grid {
  margin-top: 14px;
}

.panel-head,
.line-head,
.inline-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.month-filter {
  justify-content: flex-end;
}

.month-filter input[type="month"] {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  min-height: 38px;
  width: 162px;
  padding: 7px 10px;
}

.month-filter .tiny-btn {
  min-height: 38px;
  padding-inline: 14px;
}

.panel h2 {
  font-size: 16px;
}

.panel h3 {
  font-size: 13px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--muted);
  font-size: 12px;
}

.pill.danger { color: var(--red); border-color: #edc1bd; background: #fff1ef; }
.pill.warning { color: var(--amber); border-color: #efd69d; background: #fff8e6; }
.pill.info { color: var(--blue); border-color: #b7d0dc; background: #eef8fb; }

:root[data-theme="dark"] .pill.danger,
:root[data-theme="dark"] .danger-btn,
:root[data-theme="dark"] .delete-btn,
:root[data-theme="dark"] .flash.error,
:root[data-theme="dark"] .toast.error,
:root[data-theme="dark"] .status.belum_bayar,
:root[data-theme="dark"] .status.dibatalkan,
:root[data-theme="dark"] .status.rusak {
  background: #351917;
  border-color: #6f2c27;
}

:root[data-theme="dark"] .pill.warning,
:root[data-theme="dark"] .status.sebagian,
:root[data-theme="dark"] .status.dikirim,
:root[data-theme="dark"] .status.dijadwalkan {
  background: #352711;
  border-color: #72501c;
}

:root[data-theme="dark"] .pill.info,
:root[data-theme="dark"] .flash,
:root[data-theme="dark"] .toast {
  background: #132838;
  border-color: #315875;
}

.form {
  display: grid;
  gap: 12px;
}

.form label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.form input,
.form select,
.form textarea,
.inline-controls input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  padding: 9px 10px;
  min-height: 38px;
}

.form textarea {
  min-height: 76px;
  resize: vertical;
}

.compact-form {
  align-self: start;
  gap: 9px;
  padding: 14px;
}

.compact-form h2 {
  font-size: 15px;
  margin-bottom: 2px;
}

.compact-form label {
  gap: 4px;
  font-size: 11px;
}

.compact-form input,
.compact-form select,
.compact-form textarea {
  min-height: 34px;
  padding: 7px 9px;
}

.compact-form textarea {
  min-height: 58px;
}

.compact-form .split {
  gap: 8px;
}

.compact-form .primary {
  justify-self: center;
  width: auto;
  min-width: 160px;
  min-height: 34px;
  padding: 8px 18px;
}

.check {
  display: flex !important;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px !important;
}

.check input { width: auto; min-height: auto; }

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

.line-stack {
  display: grid;
  gap: 8px;
}

.line {
  display: grid;
  grid-template-columns: 1fr 120px 120px 34px;
  gap: 8px;
  align-items: end;
}

.line.shipment {
  grid-template-columns: 1fr 110px 120px 34px;
}

.primary,
.ghost-btn,
.tiny-btn,
.link-btn {
  border-radius: 8px;
  padding: 10px 13px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

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

.primary:hover { background: var(--accent-dark); }

.ghost-btn,
.tiny-btn {
  background: var(--surface);
  border: 1px solid var(--line-strong);
  color: var(--text);
}

.tiny-btn {
  padding: 7px 10px;
  min-height: 32px;
  font-size: 12px;
}

.danger-btn {
  background: #fff1ef;
  color: var(--red);
  border: 1px solid #edc1bd;
}

.delete-btn {
  border-radius: 7px;
  padding: 6px 9px;
  min-height: 30px;
  background: #fff1ef;
  color: var(--red);
  border: 1px solid #edc1bd;
  font-weight: 700;
}

.table-wrap {
  overflow: auto;
  margin-top: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
}

.table-page-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.table-page-actions label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.table-page-actions select {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field-bg);
  color: var(--text);
  min-height: 32px;
  padding: 5px 8px;
}

.table-page-actions button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
  background: var(--table-bg);
}

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

th {
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

tr:last-child td { border-bottom: 0; }

.status {
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
}

.status-edit select {
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  min-height: 30px;
  padding: 4px 28px 4px 10px;
  background: var(--field-bg);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 800;
}

.status-edit select:focus {
  outline: 2px solid rgba(201, 76, 31, 0.22);
  outline-offset: 2px;
}

.status.lunas,
.status.selesai,
.status.diterima,
.status.layak_jual { color: var(--green-dark); background: #e7f4ea; }
.status.belum_bayar,
.status.dibatalkan,
.status.rusak { color: var(--red); background: #fff1ef; }
.status.sebagian,
.status.dikirim,
.status.dijadwalkan { color: var(--amber); background: #fff8e6; }

.list {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.list-item {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px;
  background: var(--soft-bg);
}

.list-item strong {
  display: block;
}

.list-item span {
  color: var(--muted);
  font-size: 12px;
}

.bars {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.chart-panel {
  overflow: hidden;
}

.chart-canvas {
  min-height: 240px;
  margin-top: 12px;
}

.chart-svg {
  width: 100%;
  height: 240px;
  display: block;
}

.chart-grid {
  stroke: #e5ebe1;
  stroke-width: 1;
}

.chart-axis-label {
  fill: var(--muted);
  font-size: 11px;
}

.chart-line {
  fill: none;
  stroke: var(--accent);
  stroke-width: 3;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.chart-area {
  fill: rgba(201, 76, 31, 0.12);
}

.chart-dot {
  fill: var(--surface);
  stroke: var(--accent);
  stroke-width: 3;
}

.chart-empty {
  min-height: 220px;
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--soft-bg);
}

.alpha-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 12px;
}

.alpha-btn {
  min-width: 32px;
  min-height: 32px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--field-bg);
  color: var(--text);
  font-weight: 700;
  font-size: 12px;
}

.alpha-btn.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

.region-board {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.region-column {
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--soft-bg);
}

.region-column h3 {
  margin: 0;
  padding: 10px 12px;
  background: linear-gradient(135deg, var(--accent), #e37a25);
  color: white;
  font-size: 14px;
}

.region-row {
  display: grid;
  grid-template-columns: 126px 1fr;
  gap: 10px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
}

.region-row strong {
  color: var(--accent-dark);
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.store-tag {
  border: 1px solid var(--line);
  background: var(--field-bg);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 12px;
}

.bar-row {
  display: grid;
  grid-template-columns: 130px 1fr 120px;
  gap: 10px;
  align-items: center;
}

.bar-row strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar progress {
  width: 100%;
  height: 12px;
  border: 0;
  border-radius: 999px;
  overflow: hidden;
  appearance: none;
}

.bar progress::-webkit-progress-bar {
  background: var(--surface-2);
  border-radius: 999px;
}

.bar progress::-webkit-progress-value {
  background: linear-gradient(90deg, var(--accent), #e7832a);
  border-radius: 999px;
}

.bar progress::-moz-progress-bar {
  background: var(--accent);
  border-radius: 999px;
}

.flash-stack {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
}

.flash,
.toast {
  border-radius: 8px;
  padding: 10px 12px;
  background: #eef8fb;
  color: var(--blue);
  border: 1px solid #b7d0dc;
}

.flash.error,
.toast.error {
  background: #fff1ef;
  color: var(--red);
  border-color: #edc1bd;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  box-shadow: var(--shadow);
}

.login-shell {
  width: min(100%, 440px);
}

.login-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.login-help {
  margin-top: 14px;
  color: var(--muted);
  font-size: 12px;
}

.empty-state {
  min-height: 60vh;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 10px;
  text-align: center;
}

.print-body {
  background: #e8e8e8;
  padding: 24px;
}

.print-sheet {
  max-width: 860px;
  margin: 0 auto;
  background: white;
  padding: 32px;
}

.print-head,
.print-meta {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  border-bottom: 1px solid #ddd;
  padding-bottom: 14px;
  margin-bottom: 14px;
}

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

.print-meta dt {
  color: #666;
  font-size: 12px;
}

.print-meta dd {
  margin: 0;
  font-weight: 700;
}

.print-table {
  min-width: 0;
}

@media (max-width: 980px) {
  .sidebar {
    position: static;
    width: auto;
  }

  .main {
    margin-left: 0;
    padding: 16px;
  }

  .metric-grid,
  .grid.two,
  .grid.three {
    grid-template-columns: 1fr;
  }

  .page-header,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }

  .table-pagination {
    align-items: stretch;
    flex-direction: column;
  }

  .line,
  .line.shipment,
  .split,
  .region-board,
  .region-row {
    grid-template-columns: 1fr;
  }
}

@media print {
  .print-body {
    background: white;
    padding: 0;
  }

  .print-sheet {
    max-width: none;
    box-shadow: none;
  }
}
