:root {
  color-scheme: light;
  --bg: #f5f7fa;
  --panel: #ffffff;
  --text: #172033;
  --muted: #687385;
  --line: #d8e0ea;
  --brand: #176b68;
  --brand-dark: #104f4d;
  --danger: #c24135;
  --danger-bg: #fde8e5;
  --ok: #237a43;
  --ok-bg: #e7f5eb;
  --warn: #f8d866;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 22px;
  background: #18314f;
  color: #fff;
  box-shadow: 0 1px 8px rgba(15, 23, 42, 0.18);
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 22px;
  font-weight: 800;
}

.topbar p {
  margin-top: 4px;
  color: #d7e3f1;
  font-size: 13px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.tab,
.icon-button,
.delete-button,
.edit-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 7px;
  min-height: 36px;
  padding: 0 12px;
  font-weight: 700;
  cursor: pointer;
}

.tab {
  border-color: transparent;
  background: transparent;
  color: #eaf2fb;
}

.tab.active {
  background: #fff;
  color: #18314f;
}

main {
  width: min(1120px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.panel,
.metric {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.form-panel {
  max-width: 620px;
  margin: 0 auto;
  padding: 18px;
}

.panel {
  padding: 16px;
}

.panel-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.dashboard-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.dashboard-actions input {
  min-height: 36px;
}

h2 {
  font-size: 18px;
}

.date-row,
.stock-note-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 54px;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.date-row .icon-button {
  padding: 0;
}

.stock-note-row {
  grid-template-columns: minmax(105px, 0.7fr) minmax(130px, 1fr) 78px;
}

.date-row label,
.stock-note-row label {
  margin-bottom: 0;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

label span {
  font-size: 13px;
  color: var(--muted);
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 0 12px;
  background: #fff;
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus,
button:focus-visible {
  outline: 3px solid rgba(23, 107, 104, 0.22);
  border-color: var(--brand);
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin-bottom: 12px;
  padding: 4px;
  background: #e9eef5;
  border-radius: 8px;
}

.segmented input {
  position: absolute;
  opacity: 0;
}

.segmented label {
  display: grid;
  place-items: center;
  margin: 0;
  min-height: 42px;
  border-radius: 6px;
  font-weight: 800;
  cursor: pointer;
}

.segmented input:checked + label {
  background: var(--brand);
  color: #fff;
}

.picker-block {
  margin-bottom: 14px;
}

.picker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.picker-head span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.picker-head strong {
  color: var(--brand-dark);
  font-size: 13px;
}

.button-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.button-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
}

.choice-button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: #000;
  font: inherit;
  font-size: 15px;
  font-weight: 900;
  line-height: 1.15;
  padding: 5px;
  cursor: pointer;
}

.choice-button.active {
  border-color: var(--brand);
  background: #dff5f2;
  color: #000;
}

.choice-button.type-16 {
  border-color: #9bb7df;
  background: #eaf2ff;
  color: #000;
}

.choice-button.type-9 {
  border-color: #94c9a9;
  background: #eaf7ef;
  color: #000;
}

.choice-button.type-16.active {
  border-color: #1f4e79;
  background: #cfe2ff;
  color: #000;
}

.choice-button.type-9.active {
  border-color: #17613a;
  background: #d7f3df;
  color: #000;
}

.auto-sum-toggle {
  min-height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  margin-bottom: 0;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  font-size: 12px;
  font-weight: 900;
  color: #000;
}

.auto-sum-toggle input {
  width: 16px;
  min-height: 16px;
  padding: 0;
}

.session-toggle {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
}

.session-toggle button {
  min-height: 30px;
  border: 0;
  border-radius: 5px;
  background: transparent;
  font-weight: 900;
  cursor: pointer;
}

.session-toggle button.active {
  background: var(--brand);
  color: #fff;
}

.picker-empty {
  grid-column: 1 / -1;
  min-height: 42px;
  display: grid;
  place-items: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.selected-model {
  margin-top: 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.selected-model strong {
  color: var(--brand-dark);
}

.primary {
  width: 100%;
  min-height: 48px;
  border: 0;
  border-radius: 7px;
  background: var(--brand);
  color: #fff;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
}

.primary:hover,
.icon-button:hover {
  filter: brightness(0.96);
}

.message {
  min-height: 22px;
  margin-top: 10px;
  color: var(--brand-dark);
  font-weight: 700;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 14px;
}

.metric {
  padding: 14px;
}

.metric span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 6px;
  font-size: 30px;
}

#latestTime {
  font-size: 20px;
}

.metric.danger strong {
  color: var(--danger);
}

.list {
  display: grid;
  gap: 10px;
}

.record {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
}

.record-main,
.record-numbers {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.record-meta {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.badge {
  flex: 0 0 auto;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.badge.short {
  background: var(--danger-bg);
  color: var(--danger);
}

.badge.ok {
  background: var(--ok-bg);
  color: var(--ok);
}

.record-numbers {
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.delete-button {
  color: var(--danger);
}

.edit-button {
  color: var(--brand-dark);
}

.icon-button.closed {
  border-color: #f3b8b2;
  background: #fff0ef;
  color: var(--danger);
}

.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fbfcfe;
  color: var(--muted);
  text-align: center;
  font-weight: 700;
}

.search {
  max-width: 320px;
}

.settings-panel {
  margin-top: 14px;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcfe;
}

.settings-row.single {
  grid-template-columns: 1fr;
}

.settings-row label {
  margin: 0;
}

.danger-panel {
  border-color: #f3b8b2;
  background: #fffafa;
}

.danger-panel h2 {
  color: var(--danger);
}

.matrix-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.matrix {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: #fff;
}

.matrix th,
.matrix td {
  border: 1px solid var(--line);
  min-width: 92px;
  height: 42px;
  padding: 8px;
  text-align: center;
  vertical-align: middle;
  font-size: 13px;
}

.matrix thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #fff200;
  color: #000;
  font-weight: 900;
}

.matrix tbody th {
  position: sticky;
  left: 0;
  z-index: 1;
  min-width: 112px;
  background: #f8fafc;
  font-weight: 900;
}

.matrix tbody td:nth-child(2) {
  min-width: 132px;
  text-align: left;
  font-weight: 700;
}

.matrix td strong {
  display: block;
  font-size: 15px;
}

.matrix td span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

.matrix .empty-cell {
  background: #fbfdff;
}

.matrix .unused-row th,
.matrix .unused-row td:nth-child(2) {
  color: #e11d48;
}

@media (max-width: 720px) {
  .topbar {
    position: static;
    display: block;
    padding: 16px;
  }

  .tabs {
    margin-top: 14px;
  }

  .tab {
    flex: 1;
    padding: 0 8px;
  }

  main {
    padding: 12px;
  }

  .form-panel,
  .panel {
    padding: 14px;
  }

  .grid.two,
  .summary-grid {
    grid-template-columns: 1fr;
  }

  .button-grid,
  .button-grid.compact {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .choice-button {
    min-height: 36px;
    font-size: 14px;
  }

  .panel-title {
    align-items: stretch;
    flex-direction: column;
  }

  .date-row {
    grid-template-columns: minmax(0, 1fr) 52px;
  }

  .dashboard-actions {
    display: grid;
    grid-template-columns: 1fr 92px 48px 76px 68px;
    width: 100%;
  }

  .dashboard-actions .icon-button {
    padding: 0 6px;
    font-size: 12px;
  }

  .stock-note-row {
    grid-template-columns: 0.75fr 1fr 74px;
  }

  .search {
    max-width: none;
  }

  .settings-row {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 380px) {
  .button-grid.compact {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
