:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e3e6eb;
  --text: #1d2330;
  --muted: #6b7385;
  --accent: #2f6fed;
  --accent-hover: #2459c4;
  --warn-bg: #fff7e6;
  --warn-border: #f3c36b;
  --error: #c62828;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171d;
    --surface: #1d2129;
    --border: #2e3440;
    --text: #e6e9ef;
    --muted: #9aa3b5;
    --accent: #5b8ef5;
    --accent-hover: #7aa4f7;
    --warn-bg: #3a2f16;
    --warn-border: #8a6a24;
    --error: #ef6a6a;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

.topbar {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  padding: 16px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 20px; }
.model { color: var(--muted); font-size: 13px; }

.layout {
  display: grid;
  grid-template-columns: minmax(280px, 380px) 1fr;
  gap: 20px;
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px 16px 48px;
}
@media (max-width: 820px) {
  .layout { grid-template-columns: 1fr; }
}

.panel h2 { font-size: 15px; margin: 0 0 12px; color: var(--muted); font-weight: 600; }
.upload-panel { position: sticky; top: 16px; align-self: start; }
@media (max-width: 820px) { .upload-panel { position: static; } }

.dropzone {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 280px;
  max-height: 520px;
  overflow: hidden;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
  transition: border-color 0.15s;
}
.dropzone:hover, .dropzone.dragover { border-color: var(--accent); }
.dropzone-empty { display: flex; flex-direction: column; gap: 6px; text-align: center; padding: 24px; color: var(--muted); }
.dropzone-empty strong { color: var(--text); }
.dropzone img { max-width: 100%; max-height: 520px; object-fit: contain; }

.file-name { margin: 8px 0 12px; color: var(--muted); font-size: 13px; word-break: break-all; min-height: 1em; }

button { font: inherit; cursor: pointer; border-radius: 8px; }
button.primary {
  width: 100%;
  padding: 12px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 16px;
}
button.primary:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
button.ghost {
  padding: 4px 10px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 13px;
}

.error { color: var(--error); margin: 12px 0 0; white-space: pre-wrap; }

.placeholder, .loading {
  padding: 48px 24px;
  text-align: center;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  margin-right: 8px;
  vertical-align: -3px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 16px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  margin-bottom: 16px;
}
.cards .card { margin-bottom: 0; }
.cards { margin-bottom: 16px; }
.card h3 { margin: 0 0 12px; font-size: 15px; }

dl { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; margin: 0; }
dt { color: var(--muted); }
dd { margin: 0; word-break: break-word; }
.null { color: var(--muted); opacity: 0.6; }

.totals dd { text-align: right; font-variant-numeric: tabular-nums; }
.totals .grand { font-weight: 700; font-size: 17px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: left; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }

.warnings {
  background: var(--warn-bg);
  border: 1px solid var(--warn-border);
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
}
.warnings ul { margin: 4px 0 0; padding-left: 20px; }

.usage-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.metric { padding: 12px; border: 1px solid var(--border); border-radius: 8px; }
.metric .label { color: var(--muted); font-size: 12px; }
.metric .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.metric .sub { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.hint { color: var(--muted); font-size: 12px; margin: 12px 0 0; }

.raw summary { cursor: pointer; font-weight: 600; }
.raw[open] summary { margin-bottom: 8px; }
.raw pre {
  margin: 8px 0 0;
  padding: 12px;
  max-height: 420px;
  overflow: auto;
  background: var(--bg);
  border-radius: 8px;
  font-size: 12.5px;
}
