:root {
  color-scheme: light;
  --navy: #14283f;
  --navy-2: #1d3b58;
  --ink: #1d3348;
  --muted: #6d8194;
  --teal: #138593;
  --teal-dark: #0d6f7c;
  --line: #dfe7ef;
  --paper: #ffffff;
  --canvas: #f1f5f9;
  --soft-blue: #eaf2f8;
  --shadow: 0 12px 34px rgba(23, 48, 72, .08);
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    radial-gradient(ellipse at 88% -10%, rgba(91, 185, 177, .12), transparent 34rem),
    var(--canvas);
}

button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px 22px calc(22px + env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 24px 26px;
  color: #fff;
  background: linear-gradient(118deg, #14283f 0%, #1c4260 62%, #176677 100%);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 24px;
  box-shadow: 0 18px 42px rgba(20, 40, 63, .18);
}

.brand-row { display: flex; align-items: center; gap: 16px; min-width: 0; }
.brand-mark {
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 4px;
  flex: 0 0 50px;
  height: 50px;
  padding: 10px;
  background: rgba(255, 255, 255, .1);
  border: 1px solid rgba(255, 255, 255, .17);
  border-radius: 16px;
}
.brand-mark span { width: 6px; border-radius: 6px; background: #6bd5c3; }
.brand-mark span:nth-child(1) { height: 15px; opacity: .8; }
.brand-mark span:nth-child(2) { height: 25px; }
.brand-mark span:nth-child(3) { height: 19px; opacity: .9; }
.brand-copy { min-width: 0; }
.eyebrow, .section-kicker { color: #58bdaF; font-size: 10px; font-weight: 800; letter-spacing: .14em; }
.brand-copy h1 { margin: 5px 0 4px; font-size: clamp(20px, 3vw, 27px); letter-spacing: -.04em; }
.brand-copy p { margin: 0; color: #c5d5e2; font-size: 12px; }

.header-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.button {
  min-height: 38px;
  padding: 9px 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-size: 12px;
  font-weight: 700;
  transition: transform .15s ease, background-color .15s ease, box-shadow .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:focus-visible, .medium-button:focus-visible, .series-button:focus-visible { outline: 3px solid #63c9bc; outline-offset: 2px; }
.button-ghost { color: #f7fbff; background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .18); }
.button-ghost:hover { background: rgba(255, 255, 255, .17); }
.button-soft { color: #236173; background: #e8f3f5; border-color: #d1e8e9; white-space: nowrap; }
.button-soft:hover { background: #d9ebed; }

main { display: grid; gap: 15px; margin-top: 16px; }
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 19px;
  box-shadow: var(--shadow);
}
.settings-card { padding: 17px 19px; }
.section-title-row, .section-heading, .card-heading { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-title-row h2, .section-heading h2, .card-heading h2 { margin: 3px 0 0; color: var(--ink); font-size: 17px; letter-spacing: -.025em; }
.section-kicker { color: #388f96; font-size: 9px; }
.local-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 7px 10px;
  color: #32786c;
  background: #edf8f4;
  border: 1px solid #d7eee6;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  white-space: nowrap;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: #42ad8f; box-shadow: 0 0 0 3px rgba(66, 173, 143, .13); }
.settings-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; margin-top: 13px; }
.field-label { display: grid; gap: 6px; color: #64798d; font-size: 11px; font-weight: 700; }
.field-control {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fbfdff;
  border: 1px solid #dce5ed;
  border-radius: 10px;
  outline: none;
  font-size: 13px;
}
.field-control:focus { border-color: #54aab0; box-shadow: 0 0 0 3px rgba(19, 133, 147, .12); }

.medium-section { padding: 1px 2px 0; }
.section-heading { align-items: end; margin: 0 1px 9px; }
.section-heading p { margin: 0 2px 2px 0; color: var(--muted); font-size: 11px; }
.medium-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.medium-button {
  min-height: 47px;
  padding: 10px 12px;
  color: #4c6378;
  background: #fff;
  border: 1px solid #dce5ed;
  border-radius: 13px;
  box-shadow: 0 3px 10px rgba(24, 51, 74, .04);
  font-size: 13px;
  font-weight: 800;
  transition: .16s ease;
}
.medium-button:hover { border-color: #89bec2; background: #f6fbfb; }
.medium-button[aria-selected="true"] { color: #fff; background: linear-gradient(135deg, #158593, #176b7d); border-color: transparent; box-shadow: 0 8px 18px rgba(19, 133, 147, .2); }

.chart-card, .data-card, .results-card { padding: 17px 19px; }
.card-heading { align-items: center; margin-bottom: 12px; }
.card-heading h2 { font-size: 17px; }
.helper-text { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.chart-frame { overflow: hidden; background: #fff; border: 1px solid #edf1f5; border-radius: 13px; }
#chartCanvas { display: block; width: 100%; height: 320px; touch-action: manipulation; }
.chart-legend { display: flex; flex-wrap: wrap; gap: 7px; padding-top: 11px; }
.legend-item, .legend-button {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 30px;
  padding: 5px 9px;
  color: #4e6377;
  background: #f7f9fb;
  border: 1px solid #e7edf2;
  border-radius: 999px;
  font-size: var(--legend-font, 10px);
  font-weight: 700;
}
.legend-button { cursor: pointer; }
.legend-button:hover { background: #eef5f7; border-color: #bedbde; }
.legend-button[aria-pressed="true"] { color: #116773; background: #e5f4f3; border-color: #a9d6d4; }
.legend-swatch { width: 18px; height: 0; border-top: 3px solid var(--swatch); border-radius: 3px; }
.legend-swatch.dashed { border-top-style: dashed; }
.legend-swatch.dotted { border-top-style: dotted; }

.series-picker { display: flex; gap: 7px; overflow-x: auto; padding: 2px 1px 9px; scrollbar-width: thin; }
.series-button {
  flex: 0 0 auto;
  min-height: 36px;
  padding: 8px 12px;
  color: #597085;
  background: #f5f8fa;
  border: 1px solid #e2e9ef;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
}
.series-button[aria-selected="true"] { color: #fff; background: #254965; border-color: #254965; }
.lot-field { margin: 4px 0 10px; }
.table-scroll { width: 100%; overflow-x: auto; border: 1px solid #e6edf2; border-radius: 12px; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; }
.data-table th { padding: 10px 7px; color: #62788c; background: #f2f6f9; border-bottom: 1px solid #e3ebf1; font-size: 10px; text-align: center; }
.data-table th:first-child { width: 22%; }
.data-table td { padding: 6px; border-bottom: 1px solid #eef2f5; text-align: center; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table td:first-child { color: #425b71; background: #fbfcfd; font-size: 11px; font-weight: 700; }
.cell-input {
  width: 100%;
  min-width: 0;
  min-height: 38px;
  padding: 7px 5px;
  color: #1e3449;
  background: #fff;
  border: 1px solid #e0e8ef;
  border-radius: 8px;
  font-size: 13px;
  text-align: center;
  outline: none;
  -moz-appearance: textfield;
}
.cell-input::-webkit-outer-spin-button, .cell-input::-webkit-inner-spin-button { margin: 0; -webkit-appearance: none; }
.cell-input:focus { border-color: #48a1a8; box-shadow: 0 0 0 2px rgba(19, 133, 147, .1); }
.table-note { margin: 9px 2px 0; color: #8292a1; font-size: 10px; }

.results-list { display: grid; gap: 9px; }
.result-card {
  padding: 14px;
  background: #fbfdff;
  border: 1px solid #e3eaf0;
  border-left: 4px solid var(--result-color, #71859a);
  border-radius: 13px;
}
.result-top { display: flex; align-items: center; justify-content: space-between; gap: 9px; }
.result-name { color: #29445d; font-size: 13px; font-weight: 800; }
.result-badge { padding: 5px 9px; color: var(--result-color); background: var(--result-bg); border-radius: 999px; font-size: 10px; font-weight: 800; white-space: nowrap; }
.result-f2 { margin-top: 8px; color: #466077; font-size: 12px; font-weight: 700; }
.result-reason { margin: 7px 0 0; color: #63788b; font-size: 11px; line-height: 1.65; white-space: pre-line; }
.result-reason strong { color: #3d556a; }
.empty-results { padding: 16px; color: #73879a; background: #f6f9fb; border-radius: 12px; font-size: 12px; }

.app-footer { display: flex; justify-content: space-between; gap: 14px; padding: 5px 3px 0; color: #8191a0; font-size: 10px; }
.toast {
  position: fixed;
  z-index: 10;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  max-width: min(360px, calc(100vw - 32px));
  padding: 11px 14px;
  color: #fff;
  background: #183650;
  border-radius: 12px;
  box-shadow: 0 10px 28px rgba(15, 38, 58, .22);
  font-size: 12px;
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: .2s ease;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

@media (min-width: 780px) {
  .app-shell { padding-top: 24px; }
  .results-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .data-table th:first-child { width: 18%; }
}

@media (max-width: 700px) {
  .app-shell { padding: 10px 11px calc(15px + env(safe-area-inset-bottom)); }
  .app-header { display: block; padding: 19px 16px 14px; border-radius: 18px; }
  .brand-row { gap: 11px; }
  .brand-mark { flex-basis: 42px; height: 42px; padding: 8px; border-radius: 13px; }
  .brand-copy h1 { font-size: 20px; }
  .brand-copy p { max-width: 260px; font-size: 10px; line-height: 1.5; }
  .eyebrow { font-size: 8px; }
  .header-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px; margin-top: 14px; }
  .header-actions .button { min-height: 36px; padding: 8px 7px; font-size: 10px; }
  main { gap: 11px; margin-top: 11px; }
  .card, .settings-card { padding: 14px 13px; border-radius: 16px; }
  .settings-card { padding: 13px; }
  .section-title-row h2, .section-heading h2, .card-heading h2 { font-size: 15px; }
  .local-badge { padding: 6px 8px; font-size: 9px; }
  .settings-grid { grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
  .settings-grid .field-label:last-child { grid-column: 1 / -1; }
  .field-control { min-height: 40px; font-size: 12px; }
  .section-heading { align-items: start; flex-direction: column; gap: 4px; margin-bottom: 8px; }
  .section-heading p { font-size: 10px; }
  .medium-picker { gap: 6px; }
  .medium-button { min-height: 42px; padding: 8px 4px; border-radius: 11px; font-size: 11px; }
  .card-heading { align-items: flex-start; gap: 8px; }
  .card-heading .button { min-height: 34px; padding: 7px 9px; font-size: 10px; }
  .helper-text { max-width: 100%; font-size: 10px; }
  #chartCanvas { height: 285px; }
  .chart-legend { gap: 5px; padding-top: 8px; }
  .legend-item, .legend-button { min-height: 27px; padding: 4px 7px; font-size: 9px; }
  .series-picker { margin-right: -3px; }
  .lot-field { margin-top: 1px; }
  .data-table th { padding: 8px 4px; font-size: 9px; }
  .data-table th:first-child { width: 22%; }
  .data-table td { padding: 5px 4px; }
  .cell-input { min-height: 36px; padding: 6px 2px; font-size: 12px; }
  .result-card { padding: 12px; }
  .app-footer { flex-direction: column; gap: 3px; font-size: 9px; }
}

@media (max-width: 380px) {
  .brand-mark { display: none; }
  .settings-grid { grid-template-columns: 1fr 1fr; }
  .table-scroll { border-radius: 10px; }
  .data-table th:first-child { width: 21%; }
  .cell-input { font-size: 11px; }
  #chartCanvas { height: 265px; }
}
