:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --text: #1d2330;
  --muted: #6b7280;
  --line: #e3e6eb;
  --accent: #2459d6;
  --accent-soft: #e8eefc;
  --danger: #c83737;
  --danger-soft: #fdecec;
  --ok: #1f8a4c;
  --warn: #b26a00;
  --warn-soft: #fff4e0;
  --side: #1b2233;
  --side-text: #c8cedb;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12151c;
    --panel: #1a1f29;
    --text: #e6e9ef;
    --muted: #949cab;
    --line: #2b3240;
    --accent: #6b93f2;
    --accent-soft: #1f2a44;
    --danger: #ef6b6b;
    --danger-soft: #3a1f22;
    --ok: #4cc27f;
    --warn: #f0a83a;
    --warn-soft: #3a2d17;
    --side: #0d1016;
    --side-text: #aab2c2;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", sans-serif;
}
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }

/* ---- 레이아웃 ---- */
.layout { display: grid; grid-template-columns: 210px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 2px; }
.side .brand { color: #fff; font-weight: 700; font-size: 16px; padding: 4px 10px 16px; }
.side a { color: var(--side-text); padding: 8px 10px; border-radius: 6px; }
.side a:hover { background: rgba(255,255,255,.06); }
.side a.active { background: rgba(255,255,255,.12); color: #fff; }
.side .spacer { flex: 1; }
.side .who { font-size: 12px; padding: 8px 10px; opacity: .8; }
.main { padding: 24px 28px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.menu-btn { display: none; }

@media (max-width: 800px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 230px; z-index: 20; transform: translateX(-100%); transition: transform .2s; }
  .side.open { transform: none; }
  .main { padding: 16px; }
  .menu-btn { display: inline-flex; }
}

/* ---- 공통 요소 ---- */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 16px; grid-template-columns: minmax(0, 1fr); }
.grid > * { min-width: 0; }
.cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.two { grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr)); }
.card .label { color: var(--muted); font-size: 12px; }
.card .value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.card .sub { color: var(--muted); font-size: 12px; }

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

button, .btn {
  font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 12px; border-radius: 6px; cursor: pointer; white-space: nowrap;
}
button:hover { border-color: var(--muted); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
button.small { padding: 3px 8px; font-size: 12px; }
button:disabled { opacity: .5; cursor: default; }

input, select, textarea {
  font: inherit; color: var(--text); background: var(--panel);
  border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea { resize: vertical; min-height: 60px; }

.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
.form .row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.click { cursor: pointer; }
tr.click:hover td { background: var(--accent-soft); }
tr.canceled td { color: var(--muted); text-decoration: line-through; }
.empty { color: var(--muted); text-align: center; padding: 28px 0; }

.badge { white-space: nowrap; display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--accent-soft); color: var(--accent); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.danger { background: var(--danger-soft); color: var(--danger); }
.badge.muted { background: var(--bg); color: var(--muted); }
.plus { color: var(--ok); }
.minus { color: var(--danger); }
.muted { color: var(--muted); }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button.on { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }

/* ---- 막대 그래프 ---- */
.bars { display: flex; align-items: flex-end; gap: 6px; height: 160px; padding-top: 8px; }
.bars .bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; justify-content: flex-end; min-width: 0; }
.bars .fill { width: 100%; max-width: 34px; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bars .tick { font-size: 11px; color: var(--muted); white-space: nowrap; }

/* ---- 로그인 ---- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .panel { width: 100%; max-width: 360px; padding: 28px; }
.login h1 { margin-bottom: 18px; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ---- 모달 / 알림 ---- */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--text); width: min(640px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0,0,0,.4); }
#modal-body { padding: 20px; max-height: calc(100vh - 80px); overflow: auto; }
#modal-body h2 { font-size: 17px; margin-bottom: 16px; }
.items td { padding: 4px; }
.items input, .items select { width: 100%; }
.total { text-align: right; font-size: 16px; font-weight: 700; }

#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 8px; opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 50; }
#toast.show { opacity: 1; }
#toast.err { background: var(--danger); color: #fff; }

/* ---- 좁은 화면 (위 규칙보다 뒤에 있어야 적용된다) ---- */
@media (max-width: 800px) {
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card .value { font-size: 18px; }
  .bars { gap: 3px; }
  .bars .bar:nth-child(even) .tick { visibility: hidden; }
  .form .row { grid-template-columns: 1fr; }
  /* 표는 좁게 찌그러뜨리지 않고 옆으로 밀어서 본다 */
  .table-wrap table { min-width: max-content; }
}

/* ---- 외주 / 기록 ---- */
.badge.ok { background: color-mix(in srgb, var(--ok) 15%, transparent); color: var(--ok); }
.badge.claude { background: #f3e8ff; color: #7c3aed; }
@media (prefers-color-scheme: dark) { .badge.claude { background: #2e1f4a; color: #c4a5ff; } }
.log-detail { white-space: pre-wrap; word-break: break-word; }
.info { display: grid; grid-template-columns: max-content 1fr max-content 1fr; gap: 6px 14px; margin-bottom: 16px; }
.info dt { color: var(--muted); }
.info dd { margin: 0; }
.info .wide { grid-column: 2 / -1; white-space: pre-wrap; }
.alert { border-color: var(--danger); }
.keybox { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 10px; word-break: break-all; user-select: all; }
.section { margin-top: 20px; }
@media (max-width: 800px) {
  .info { grid-template-columns: max-content 1fr; }
  .info .wide { grid-column: 2; }
}
.card.click { cursor: pointer; }
.card.click:hover { border-color: var(--accent); }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

/* ---- 수입 그래프 (외주 입금 + 주문 매출) ---- */
.bars .stack { width: 100%; max-width: 34px; display: flex; flex-direction: column; min-height: 2px; border-radius: 4px 4px 0 0; overflow: hidden; background: var(--line); }
.bars .stack .fill { width: 100%; max-width: none; border-radius: 0; min-height: 0; }
.bars .fill.os, .dot.os { background: var(--ok); }
.bars .fill.ord, .dot.ord { background: var(--accent); }
.bars .amt { font-size: 10px; color: var(--muted); white-space: nowrap; }
.legend { font-size: 12px; color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 2px; margin: 0 3px 0 8px; }
