:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --border: #dde1e6;
  --text: #1a1d21;
  --muted: #667085;
  --primary: #0b6e4f;
  --primary-dark: #095a40;
  --accent: #fdb913;
  --danger: #b3261e;
  --danger-bg: #fdecea;
  --danger-border: #f3c2bd;
  --ok-bg: #eaf6ef;
  --ok-border: #bfe3cc;
  --ok-text: #0b6e4f;
  --info-bg: #eef3fb;
  --info-border: #cddaf0;
  --info-text: #24467a;
  --warn-bg: #fff6d6;
  --warn-border: #f0d77a;
  --warn-text: #6b5200;
  --input-bg: #ffffff;
  --card-bg: #fafbfc;
  --line-soft: #f0f1f3;
  --hover-bg: #eef7f2;
  --track-off: #c7ccd1;
  --track-off-text: #3a3f45;
  --header-bg: #0b6e4f;
  --header-sub: #d6efe3;
  --heading: #095a40;
  --shadow: rgba(0, 0, 0, 0.12);
  --radius: 8px;
  color-scheme: light;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

/* Dark palette: applied by js/theme.js (saved choice, else the system setting). */
:root[data-theme="dark"] {
  --bg: #12161c;
  --panel: #1b222b;
  --border: #2f3946;
  --text: #e6eaf0;
  --muted: #9aa5b4;
  --primary: #2f9e75;
  --primary-dark: #5fd0a3;
  --accent: #fdb913;
  --danger: #ff8a80;
  --danger-bg: #3b1d1b;
  --danger-border: #6d2f2b;
  --ok-bg: #14301f;
  --ok-border: #24573a;
  --ok-text: #7fe0ac;
  --info-bg: #1a2a45;
  --info-border: #2d4672;
  --info-text: #a9c4f2;
  --warn-bg: #3a3116;
  --warn-border: #6b5a1f;
  --warn-text: #f1d77d;
  --input-bg: #121820;
  --card-bg: #161d26;
  --line-soft: #28313d;
  --hover-bg: #223329;
  --track-off: #4a5563;
  --track-off-text: #e6eaf0;
  --header-bg: #0f4a37;
  --header-sub: #bfe5d4;
  --heading: #7fe0ac;
  --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

header {
  background: var(--header-bg);
  color: #fff;
  padding: 20px 24px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.theme-toggle {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid rgba(255, 255, 255, 0.55);
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
}
.theme-toggle:hover { background: rgba(255, 255, 255, 0.24); }
.theme-toggle:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.theme-toggle svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
/* show the icon of the mode a click switches to */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

header h1 {
  margin: 0 0 4px;
  font-size: 22px;
}

header p {
  margin: 0;
  color: var(--header-sub);
  font-size: 14px;
}

main {
  max-width: 960px;
  margin: 24px auto;
  padding: 0 16px 60px;
  display: grid;
  grid-template-columns: minmax(0, 1fr); /* let wide tables scroll inside .table-scroll instead of stretching the page */
  gap: 20px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.panel h2 {
  margin: 0 0 16px;
  font-size: 16px;
  color: var(--heading);
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  align-items: end;
}

.field-grid > div {
  display: flex;
  flex-direction: column;
}

label {
  display: flex;
  align-items: flex-end;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--muted);
  min-height: 2.4em;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid var(--primary);
  outline-offset: 1px;
}

.toggle-row {
  display: flex;
  gap: 20px;
  align-items: center;
}

.toggle-row label.inline {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  color: var(--text);
  margin: 0;
}

.switch-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
  z-index: 1;
}

.switch-track {
  position: absolute;
  inset: 0;
  background: var(--track-off);
  border-radius: 999px;
  transition: background 0.15s ease;
}

.switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 2px rgba(0,0,0,0.3);
  transition: transform 0.15s ease;
}

.switch input:checked ~ .switch-track {
  background: var(--primary);
}

.switch input:checked ~ .switch-track .switch-thumb {
  transform: translateX(20px);
}

.switch input:focus-visible ~ .switch-track {
  outline: 2px solid var(--primary-dark);
  outline-offset: 2px;
}

.switch-caption {
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
}

.switch-state {
  font-size: 12px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--primary);
  color: #fff;
}

.switch-state.off {
  background: var(--track-off);
  color: var(--track-off-text);
}

.item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
  position: relative;
  background: var(--card-bg);
}

.item-card .remove-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 13px;
}

.search-wrap {
  position: relative;
}

.search-results {
  position: absolute;
  z-index: 20;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 6px;
  max-height: 260px;
  overflow-y: auto;
  box-shadow: 0 6px 20px var(--shadow);
  display: none;
}

.search-results.open { display: block; }

.search-result {
  padding: 8px 10px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--line-soft);
}

.search-result:hover { background: var(--hover-bg); }

.search-result .code {
  font-weight: 700;
  color: var(--heading);
  margin-right: 8px;
}

.selected-tariff {
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

/* Quick Lookup / Advanced Lookup mode visibility - toggled by a class on
   <body> (mode-quick or mode-advanced) set from the radio buttons in app.js */
body:not(.mode-advanced) .advanced-only { display: none !important; }
body:not(.mode-quick) .quick-only { display: none !important; }
body:not(.mode-upload) .upload-only { display: none !important; }
body.mode-upload .items-panel { display: none; }

.table-scroll { overflow-x: auto; margin-bottom: 12px; }
.results-table .num { text-align: right; white-space: nowrap; }
.results-table .totals-row td { font-weight: 700; border-top: 2px solid var(--border); }

.user-block { margin-bottom: 26px; }
.user-block h3 { margin: 0 0 8px; font-size: 15px; color: var(--heading); }

.banner-ok, .banner-info, .banner-warn {
  border-radius: 6px; padding: 9px 12px; font-size: 13px; margin: 0 0 10px;
}
.banner-ok { background: var(--ok-bg); border: 1px solid var(--ok-border); color: var(--ok-text); }
.banner-info { background: var(--info-bg); border: 1px solid var(--info-border); color: var(--info-text); }
.banner-warn { background: var(--danger-bg); border: 1px solid var(--danger-border); color: var(--danger); }
.banner-fallback { background: var(--warn-bg); border: 1px solid var(--warn-border); color: var(--warn-text); border-radius: 6px; padding: 9px 12px; font-size: 13px; margin: 0 0 10px; }
.results-table tr.fallback-row td { background: var(--warn-bg); }
.text-danger { color: var(--danger); }
.text-ok { color: var(--ok-text); }

/* Per-user upload results: one column per charge, compact so more fits before scrolling */
.results-table.user-table { font-size: 12.5px; }
.results-table.user-table th, .results-table.user-table td { padding: 6px 7px; }
.results-table .dash { color: var(--muted); }
.results-table tr.fallback-row .pill { margin-left: 4px; }

#uploadFile { margin: 6px 0 12px; }
.upload-note { font-size: 13px; margin: 8px 0; }
.upload-problems { font-size: 13px; color: var(--danger); margin: 0 0 12px; padding-left: 20px; }
.cat-map-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.cat-map-text { font-size: 13px; min-width: 180px; }
.cat-map-row select { max-width: 280px; }

.quick-category-select {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--input-bg);
  color: var(--text);
}

button.primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 11px 18px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

button.primary:hover { filter: brightness(0.92); }

button.secondary {
  background: var(--input-bg);
  color: var(--heading);
  border: 1px solid var(--primary);
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 13px;
  cursor: pointer;
}

.actions-row {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.warning-banner {
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  color: var(--danger);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 14px;
}

.results-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.results-table th, .results-table td {
  text-align: left;
  padding: 6px 8px;
  border-bottom: 1px solid var(--line-soft);
}

.results-table th {
  color: var(--muted);
  font-weight: 600;
}

.item-result {
  margin-bottom: 18px;
  padding-bottom: 12px;
  border-bottom: 1px dashed var(--border);
}

.item-result h3 {
  margin: 0 0 6px;
  font-size: 14px;
}

.grand-total {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding-top: 12px;
  border-top: 2px solid var(--primary);
  margin-top: 8px;
}

.grand-total .amount {
  font-size: 24px;
  font-weight: 700;
  color: var(--heading);
}

.disclaimer {
  font-size: 12px;
  color: var(--muted);
  margin-top: 18px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.pill {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--accent);
  color: #3a2c00;
  margin-left: 8px;
}

.hidden { display: none !important; }
