:root {
  color-scheme: light;
  --surface-1: #fcfcfb;
  --page: #f9f9f7;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);
  --series-1: #2a78d6;   /* 유류비 */
  --series-2: #eb6834;   /* 정비비 */
  --series-3: #1baf7a;   /* 기타비용 */
  --good: #0ca30c;
  --warning: #fab219;
  --critical: #d03b3b;
  --accent: #2a78d6;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;
    --surface-1: #1a1a19;
    --page: #0d0d0d;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.10);
    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --accent: #3987e5;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", "Malgun Gothic", sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

header {
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  padding: 14px 20px;
  display: flex;
  align-items: baseline;
  gap: 14px;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 10;
}
header h1 { font-size: 17px; margin: 0; font-weight: 650; letter-spacing: -0.01em; }
header .sub { color: var(--muted); font-size: 12.5px; }

nav {
  display: flex;
  gap: 2px;
  padding: 0 14px;
  background: var(--surface-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  position: sticky;
  top: 53px;
  z-index: 9;
}
nav button {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 10px 14px;
  font: inherit;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
}
nav button:hover { color: var(--text-primary); }
nav button.on { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

main { padding: 20px; max-width: 1280px; margin: 0 auto; }
.page { display: none; }
.page.on { display: block; }

.card {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  margin-bottom: 16px;
}
.card > h2 {
  font-size: 14px;
  margin: 0 0 12px;
  font-weight: 650;
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: space-between;
}
.card > h2 .hint { font-weight: 400; color: var(--muted); font-size: 12px; }

/* KPI 타일 */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.tile .label { color: var(--text-secondary); font-size: 12.5px; }
.tile .value { font-size: 26px; font-weight: 640; letter-spacing: -0.02em; margin-top: 4px; }
.tile .value small { font-size: 14px; font-weight: 500; color: var(--text-secondary); margin-left: 2px; }
.tile .note { font-size: 12px; color: var(--muted); margin-top: 2px; }
.tile.danger .value { color: var(--critical); }
.tile.warn .value { color: #b8820f; }

/* 표 */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--axis);
  white-space: nowrap;
}
td { padding: 8px; border-bottom: 1px solid var(--grid); vertical-align: middle; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody tr:hover { background: rgba(127, 127, 127, 0.06); }
.table-wrap { overflow-x: auto; }
.empty { color: var(--muted); padding: 18px 4px; font-size: 13px; }

/* 배지 */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11.5px; font-weight: 600;
  padding: 2px 7px; border-radius: 999px;
  border: 1px solid var(--border);
  white-space: nowrap;
}
.badge.danger { color: var(--critical); background: rgba(208, 59, 59, 0.10); border-color: rgba(208, 59, 59, 0.3); }
.badge.warn { color: #9a6c05; background: rgba(250, 178, 25, 0.14); border-color: rgba(250, 178, 25, 0.4); }
.badge.ok { color: var(--good); background: rgba(12, 163, 12, 0.10); border-color: rgba(12, 163, 12, 0.3); }
.badge.mute { color: var(--muted); }

/* 폼 */
.form-row { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 3px; }
.field label { font-size: 11.5px; color: var(--text-secondary); }
input, select, textarea {
  font: inherit; font-size: 13px;
  padding: 6px 8px;
  border: 1px solid var(--axis);
  border-radius: 6px;
  background: var(--surface-1);
  color: var(--text-primary);
  min-width: 110px;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }

button.btn {
  font: inherit; font-size: 13px; font-weight: 600;
  padding: 7px 14px; border-radius: 6px; cursor: pointer;
  border: 1px solid var(--accent); background: var(--accent); color: #fff;
}
button.btn.ghost { background: transparent; color: var(--text-secondary); border-color: var(--axis); font-weight: 500; }
button.btn.small { padding: 3px 9px; font-size: 12px; }
button.btn.danger { background: transparent; color: var(--critical); border-color: rgba(208,59,59,0.4); }
button.btn:hover { filter: brightness(1.06); }

.toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.spacer { flex: 1; }

/* 범례 */
.legend { display: flex; gap: 16px; flex-wrap: wrap; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 8px; }
.legend span.key { display: inline-flex; align-items: center; gap: 6px; }
.legend i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }

/* 차트 */
.chart-wrap { position: relative; }
svg.chart { width: 100%; height: 260px; display: block; overflow: visible; }
.tooltip {
  position: absolute; pointer-events: none; opacity: 0;
  background: var(--surface-1); color: var(--text-primary);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 10px; font-size: 12.5px; min-width: 130px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.14);
  transition: opacity .1s; z-index: 5;
}
.tooltip .tt-title { font-weight: 650; margin-bottom: 4px; }
.tooltip .tt-row { display: flex; justify-content: space-between; gap: 12px; }
.tooltip .tt-row .k { display: inline-flex; align-items: center; gap: 5px; color: var(--text-secondary); }
.tooltip .tt-row i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
.tooltip .tt-total { border-top: 1px solid var(--grid); margin-top: 5px; padding-top: 4px; font-weight: 600; }

.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.kv { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid var(--grid); font-size: 13px; }
.kv .k { color: var(--text-secondary); }

/* 입력 창 */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .45);
  display: none; place-items: center; z-index: 50; padding: 20px;
}
.modal-back.on { display: grid; }
.modal {
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px; width: 100%; max-width: 340px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, .25);
}
.modal h3 { margin: 0 0 16px; font-size: 15px; font-weight: 650; }
.modal .f { margin-bottom: 12px; }
.modal label { display: block; font-size: 12.5px; color: var(--text-secondary); margin-bottom: 5px; }
.modal input { width: 100%; padding: 9px 10px; }
.modal-err { color: var(--critical); font-size: 12.5px; min-height: 18px; }
.modal-btns { display: flex; gap: 8px; justify-content: flex-end; margin-top: 6px; }

@media (max-width: 640px) {
  main { padding: 12px; }
  nav { top: 49px; }
  .tile .value { font-size: 22px; }
}

/* 프로그램 바꾸기 — 배송·미수·매출과 같은 줄 (휴대폰 맨 위) */
.appsw { display: none; }
.applinks { display: flex; gap: 4px; }
.applinks a { font-size: 12.5px; font-weight: 600; color: var(--text-secondary); text-decoration: none;
  padding: 5px 9px; border-radius: 7px; white-space: nowrap; }
.applinks a:hover { background: var(--grid); color: var(--text-primary); }
@media (max-width: 760px) {
  .appsw { display: flex; gap: 4px; padding: 7px 10px; background: #0F1F17; overflow-x: auto; scrollbar-width: none;
    padding-top: calc(7px + env(safe-area-inset-top)); }
  .appsw::-webkit-scrollbar { display: none; }
  .appsw a { flex: 1; text-align: center; white-space: nowrap; padding: 6px 8px; border-radius: 999px;
    font-size: 12.5px; font-weight: 700; color: #A6C9B6; text-decoration: none; }
  .appsw a.on { background: #fff; color: #0B3D26; }
  .applinks { display: none; }
}
