:root {
  font-family: -apple-system, BlinkMacSystemFont, 'Apple SD Gothic Neo', 'Malgun Gothic', sans-serif;
  color-scheme: light;
  color: #182640;
  background: #f2f5fa;
  --ink: #182640;
  --muted: #53637d;
  --quiet: #64748d;
  --line: #dce4ef;
  --line-soft: #e9eef5;
  --blue: #214fc3;
  --blue-deep: #153f9e;
  --blue-wash: #edf3ff;
  --white: #fff;
}

* { box-sizing: border-box; }
body { margin: 0; }
[hidden] { display: none !important; }
button, input, select { font: inherit; }
button {
  min-height: 35px;
  padding: 6px 12px;
  border: 1px solid #d6e0ee;
  border-radius: 7px;
  background: var(--white);
  color: var(--ink);
  font-size: 13px;
  font-weight: 690;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: #a6b8d8; background: #f4f8ff; }
button:disabled { cursor: default; opacity: .45; }
button.primary { border-color: var(--blue); background: var(--blue); color: #fff; }
button.primary:hover:not(:disabled) { border-color: var(--blue-deep); background: var(--blue-deep); }
button.compact { min-height: 30px; padding: 4px 8px; font-size: 12px; }
button.text-button { min-height: 30px; padding: 4px 0; border-color: transparent; background: transparent; color: var(--blue); }
button.text-button:hover:not(:disabled) { border-color: transparent; background: transparent; text-decoration: underline; }
:where(button, input, select, a, [tabindex]):focus-visible { outline: 2px solid #426be3; outline-offset: 2px; }
:where(input:not([type=checkbox]), select) {
  width: 100%;
  min-width: 0;
  min-height: 37px;
  padding: 7px 9px;
  border: 1px solid #ced9eb;
  border-radius: 6px;
  color: var(--ink);
  background: #fff;
  font-size: 13px;
}
select { text-overflow: ellipsis; }
:where(input, select):disabled { background: #f1f4f8; color: var(--muted); }
h1, h2, h3, p { margin: 0; }

.shell { width: min(100% - 48px, 1440px); margin-inline: auto; }
.site-header { border-bottom: 1px solid var(--line); background: #fcfdff; }
.header-inner { min-height: 58px; display: flex; align-items: center; gap: 14px; }
.header-inner .brand-mark { background: #2a53c5; }
.header-inner .brand-period { color: #2a53c5; }
.header-divider { width: 1px; height: 16px; background: var(--line); }
.app-name, .draft-status { font-size: 13px; color: var(--muted); }
.draft-status { margin-left: auto; text-align: right; }

main { padding-block: 32px 56px; }
.heading { display: flex; justify-content: space-between; align-items: flex-end; flex-wrap: wrap; gap: 14px 22px; margin-bottom: 23px; }
h1 { font-size: clamp(1.85rem, 3.25vw, 3rem); line-height: 1.12; letter-spacing: -.075em; font-weight: 800; }
.intro p { margin-top: 8px; font-size: 15px; color: var(--muted); line-height: 1.5; overflow-wrap: anywhere; }
.file-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.file-actions button { white-space: nowrap; }

.workbench { display: grid; grid-template-columns: minmax(190px, 237px) minmax(0, 1fr); gap: 16px; align-items: start; }
.sidebar, .analysis { min-width: 0; display: grid; gap: 14px; }
.panel, .chart-card, .metric {
  min-width: 0;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 1px 2px #203e7110;
}
.panel-heading {
  min-height: 45px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 8px 13px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-heading h2 { display: flex; align-items: center; gap: 6px; font-size: 15px; letter-spacing: -.035em; }
.source-kind {
  min-width: 0;
  max-width: 112px;
  overflow: hidden;
  border-radius: 5px;
  padding: 3px 6px;
  background: #e9f0fe;
  color: #2650a9;
  font-size: 11px;
  font-weight: 730;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.source-body { display: grid; gap: 7px; padding: 12px; }
.source-body > label { color: var(--muted); font-size: 12px; font-weight: 700; }
.column-list, .filter-list { margin: 0; padding: 0; list-style: none; }
.column-list { display: grid; gap: 3px; max-height: 270px; margin-top: 4px; overflow-y: auto; scrollbar-width: thin; }
.column-list li { min-width: 0; display: flex; align-items: center; gap: 7px; min-height: 28px; padding-inline: 1px 4px; font-size: 13px; }
.column-type {
  flex: 0 0 24px;
  min-height: 22px;
  display: grid;
  place-items: center;
  border-radius: 4px;
  background: #edf1f7;
  color: var(--muted);
  font: 700 11px ui-monospace, SFMono-Regular, Consolas, monospace;
}
.column-type[data-type=number] { background: #e9f0fe; color: #2853ae; }
.column-type[data-type=date] { background: #e8f6f5; color: #176b70; }
.column-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.column-type-label { color: var(--quiet); font-size: 11px; white-space: nowrap; }

#filter-count { padding: 2px 5px; min-width: 19px; border-radius: 4px; background: #edf3ff; color: #2953a9; font: 700 11px ui-monospace, monospace; text-align: center; }
.filters-body { padding: 11px; }
.empty-state { padding: 3px 1px; color: var(--muted); font-size: 13px; line-height: 1.5; }
.filter-list { display: grid; gap: 5px; }
.filter-item { min-width: 0; display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 3px; }
.filter-item button { min-width: 0; background: var(--blue-wash); border-color: #dbe7ff; color: var(--blue-deep); }
.filter-item button:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-align: left; }
#clear-filters { margin-top: 4px; }

.overview { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.metric {
  display: grid;
  align-content: start;
  gap: 4px;
  min-height: 110px;
  padding: 13px 15px;
}
.metric:first-child { border-top: 3px solid #3b6aef; padding-top: 11px; }
.metric-label { overflow: hidden; color: #526582; font-size: 13px; font-weight: 720; text-overflow: ellipsis; white-space: nowrap; }
.metric strong {
  overflow: hidden;
  color: #17336e;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(1.5rem, 3.2vw, 2.2rem);
  font-weight: 760;
  letter-spacing: -.055em;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.metric-caption { overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.chart-heading { display: flex; justify-content: space-between; align-items: flex-start; flex-wrap: wrap; gap: 8px; margin: 22px 0 10px; }
.chart-heading h2 { margin-bottom: 4px; font-size: 20px; letter-spacing: -.045em; }
.chart-heading p { color: var(--muted); font-size: 13px; line-height: 1.4; }
.chart-heading button { white-space: nowrap; }
.selection {
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 9px;
  padding: 7px 9px;
  border: 1px solid #c5d7fb;
  border-radius: 7px;
  background: var(--blue-wash);
  color: var(--blue-deep);
  font-size: 13px;
  font-weight: 680;
}
.selection span { min-width: 0; overflow-wrap: anywhere; }
.selection button { flex: none; min-height: 28px; padding: 3px 6px; font-size: 12px; }

.chart-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 11px; }
.chart-card { overflow: hidden; }
.chart-card:first-child { grid-column: 1 / -1; }
.chart-card.is-linked { border-color: #789df6; box-shadow: 0 0 0 1px #789df6; }
.chart-card-header {
  min-width: 0;
  min-height: 55px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--line-soft);
}
.chart-card-header h3 { overflow-wrap: anywhere; font-size: 15px; letter-spacing: -.04em; }
.chart-card-header p { margin-top: 3px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.chart-card-actions { flex: none; display: flex; gap: 4px; }
.chart-area { position: relative; min-width: 0; padding: 0 7px; background: #fff; }
.chart-area canvas { display: block; width: 100%; height: auto; aspect-ratio: 2 / 1; max-height: 260px; cursor: pointer; }
.chart-card:first-child .chart-area canvas { max-height: 285px; }
.chart-footer {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 5px 8px;
  min-height: 42px;
  margin: 0;
  padding: 7px 11px;
  border-top: 1px solid var(--line-soft);
  font-size: 11px;
  color: var(--muted);
}
.chart-footer label { min-width: 0; display: flex; align-items: center; gap: 7px; }
.chart-footer select { width: auto; min-width: 0; max-width: min(100%, 250px); min-height: 27px; padding: 2px 4px; font-size: 12px; }
.chart-footer span { margin-left: auto; }
.chart-error { padding: 0 8px 11px; color: #a6282d; font-size: 12px; }
.empty-charts { grid-column: 1 / -1; padding: 14px; }

.table-heading h2 { margin-bottom: 4px; }
.table-heading p { color: var(--muted); font-size: 12px; }
.table-heading button { flex: none; }
.table-scroll { overflow: auto; }
table { width: 100%; border-collapse: collapse; text-align: left; font-variant-numeric: tabular-nums; }
th, td { max-width: 240px; min-width: 72px; overflow: hidden; padding: 8px 11px; border-bottom: 1px solid #eef2f7; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
th:first-child, td:first-child { min-width: 44px; max-width: 65px; color: var(--muted); }
th { color: #394e72; background: #f6f8fc; }
th button { display: flex; align-items: center; gap: 6px; max-width: 100%; min-height: 25px; padding: 0; border: 0; border-radius: 2px; background: transparent; color: inherit; }
th button span:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
th button span:last-child { color: #546482; font-size: 11px; }
tbody tr:nth-child(even) { background: #fbfcfe; }
td.number { text-align: right; }
td.blank { color: var(--quiet); }
td.table-empty { padding: 24px 11px; text-align: center; }
.pagination { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 11px; color: var(--muted); font-size: 12px; }
.pagination > div { display: flex; gap: 5px; }

dialog {
  width: min(440px, calc(100% - 24px));
  max-height: 90vh;
  padding: 0;
  border: 1px solid #cdd9eb;
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 15px 65px #15273b42;
}
dialog::backdrop { background: #15223b63; }
.dialog-heading, .dialog-actions { display: flex; justify-content: space-between; align-items: center; gap: 9px; padding: 12px 15px; }
.dialog-heading { border-bottom: 1px solid var(--line-soft); }
.dialog-heading h2 { font-size: 18px; letter-spacing: -.045em; }
.form-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; padding: 12px 15px; }
.form-body > label { margin-top: 3px; font-size: 13px; font-weight: 710; }
.form-body .checkbox-label { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.form-body input[type=checkbox] { min-width: 16px; min-height: 16px; margin: 3px 0; accent-color: var(--blue); }
.dialog-actions { justify-content: flex-end; border-top: 1px solid var(--line-soft); }
#chart-delete { color: #a6282d; margin-right: auto; }
.form-error { margin-top: 4px; color: #a6282d; font-size: 13px; }
.notice {
  position: fixed;
  z-index: 2;
  inset: auto 16px 16px auto;
  max-width: min(460px, calc(100vw - 32px));
  padding: 10px 13px;
  border: 1px solid #a9bcdf;
  border-radius: 8px;
  background: #f6f9ff;
  color: #214486;
  box-shadow: 0 7px 22px #15273b29;
  font-size: 13px;
  overflow-wrap: anywhere;
}

@media (max-width: 940px) {
  .shell { width: calc(100% - 24px); }
  main { padding-block: 23px 42px; }
  .heading { margin-bottom: 16px; }
  .workbench { gap: 11px; }
}
@media (max-width: 700px) {
  .workbench { grid-template-columns: minmax(0, 1fr); }
  .sidebar { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .column-list { max-height: 124px; }
  .metric { min-height: 90px; padding: 10px 8px; }
  .metric:first-child { padding-top: 8px; }
  .overview { gap: 6px; }
}
@media (max-width: 500px) {
  .chart-grid { grid-template-columns: minmax(0, 1fr); }
  .chart-card:first-child { grid-column: auto; }
  .header-inner { gap: 8px; }
  .draft-status { font-size: 11px; }
  .panel-heading { padding-inline: 8px; }
  .source-kind { max-width: 54px; }
  .source-body { padding: 8px; }
  .column-list li { gap: 4px; }
  .column-type-label { display: none; }
  .filters-body { padding: 8px; }
  .metric-label { font-size: 11px; }
  .metric-caption { font-size: 10px; }
}
