:root {
  --bg: #fafafa;
  --paper: #fffef9;
  --line: #d9d6cf;
  --ink: #202124;
  --muted: #716d66;
  --soft: #f2f0eb;
  --accent: #236953;
  --danger: #9f3535;
  --pane-left: 56%;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button,
input,
select {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
}

button {
  cursor: pointer;
}

button:hover {
  background: var(--soft);
}

.shell {
  display: grid;
  grid-template-rows: 38px 1fr;
  height: 100vh;
  min-height: 520px;
  overflow: hidden;
}

.topSummary {
  display: grid;
  grid-template-columns: auto minmax(90px, 1fr) minmax(110px, 1.2fr) minmax(110px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  min-width: 0;
}

.barButton {
  height: 28px;
  padding: 0 9px;
  font-size: 12px;
  white-space: nowrap;
}

.barMetric {
  display: flex;
  align-items: baseline;
  gap: 6px;
  min-width: 0;
  font-size: 12px;
}

.barMetric span {
  color: var(--muted);
  white-space: nowrap;
}

.barMetric strong {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14px;
}

.barMetric.main strong {
  color: var(--accent);
}

.app {
  display: grid;
  grid-template-columns: minmax(240px, var(--pane-left)) 7px minmax(240px, 1fr);
  min-height: 0;
  overflow: hidden;
}

.app.panelClosed {
  grid-template-columns: 1fr 0 0;
}

.notePane,
.resultPane {
  min-width: 0;
  height: 100%;
}

.notePane {
  display: flex;
  flex-direction: column;
  background: var(--paper);
}

textarea {
  flex: 1;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  padding: 16px 18px;
  color: var(--ink);
  background:
    repeating-linear-gradient(
      to bottom,
      transparent 0,
      transparent 30px,
      rgba(32, 33, 36, 0.08) 31px
    ),
    var(--paper);
  line-height: 31px;
  font-size: 18px;
}

textarea::placeholder {
  color: #9a968c;
}

.noteFooter {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 12px;
  color: var(--muted);
  border-top: 1px solid var(--line);
  font-size: 12px;
}

.resizer {
  background: var(--line);
  cursor: col-resize;
}

.resizer:hover,
.app.resizing .resizer {
  background: #aaa49a;
}

.resultPane {
  overflow: auto;
  border-left: 1px solid var(--line);
  background: #fff;
}

.app.panelClosed .resultPane,
.app.panelClosed .resizer {
  display: none;
}

.tableWrap {
  position: relative;
  min-height: 100%;
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

th,
td {
  padding: 9px 8px;
  border-bottom: 1px solid var(--line);
  text-align: right;
  font-size: 13px;
  vertical-align: top;
}

th:first-child,
td:first-child {
  width: 43%;
  text-align: left;
}

td:first-child {
  overflow-wrap: anywhere;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  color: var(--muted);
  background: #fff;
  font-weight: 600;
}

tfoot th,
tfoot td {
  background: #fffefa;
  font-size: 13px;
}

tfoot th {
  color: var(--muted);
  font-weight: 600;
}

tfoot strong,
tfoot small {
  display: block;
}

tfoot strong {
  font-size: 15px;
}

tfoot small {
  margin-top: 2px;
  color: var(--muted);
  font-size: 11px;
}

#finalTotal,
#barFinalKrw {
  color: var(--accent);
}

.overTarget {
  color: var(--danger);
}

.mutedCell {
  color: var(--muted);
}

.badLine td {
  color: var(--danger);
}

.emptyState {
  margin: 16px;
  color: var(--muted);
  font-size: 13px;
}

.settingsDialog {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 24px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

.settingsDialog::backdrop {
  background: rgba(0, 0, 0, 0.18);
}

.settingsDialog form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.dialogHead,
.sectionTitle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.sectionTitle span {
  color: var(--muted);
  font-size: 12px;
}

.settingRow,
.settingGrid label,
.rateGrid label {
  display: grid;
  gap: 5px;
}

.settingRow label,
.settingGrid span,
.rateGrid span {
  color: var(--muted);
  font-size: 12px;
}

.settingRow input,
.settingGrid input,
.settingGrid select,
.rateGrid input {
  width: 100%;
  height: 36px;
  padding: 0 10px;
}

.settingGrid {
  display: grid;
  grid-template-columns: 1fr 96px;
  gap: 10px;
}

.rateSettings {
  display: grid;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

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

.quickActions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding-top: 10px;
  border-top: 1px solid var(--line);
}

.quickActions button {
  height: 34px;
  padding: 0 10px;
}

.dangerButton {
  color: var(--danger);
}

.srOnly {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 720px) {
  .topSummary {
    grid-template-columns: auto 1fr 1fr auto;
    gap: 8px;
    padding: 4px 8px;
  }

  .barMetric:first-of-type {
    display: none;
  }

  .barMetric {
    display: grid;
    gap: 0;
  }

  .barMetric strong {
    font-size: 12px;
  }

  .app {
    grid-template-columns: minmax(112px, clamp(112px, var(--pane-left), 48%)) 6px minmax(0, 1fr);
  }

  textarea {
    padding: 14px 12px;
    font-size: 16px;
  }

  th,
  td {
    padding: 8px 5px;
    font-size: 12px;
  }

  .tableWrap {
    overflow-x: hidden;
  }

  table,
  thead,
  tbody,
  tfoot,
  tr,
  th,
  td {
    display: block;
  }

  thead {
    display: none;
  }

  tbody tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    column-gap: 6px;
    row-gap: 2px;
    padding: 8px 6px;
    border-bottom: 1px solid var(--line);
  }

  tbody td {
    width: auto;
    padding: 0;
    border: 0;
    text-align: left;
    font-size: 12px;
    line-height: 1.35;
  }

  th:first-child,
  td:first-child {
    width: auto;
  }

  .itemCell {
    grid-column: 1;
    grid-row: 1;
    min-width: 0;
    font-weight: 500;
  }

  .quantityCell,
  .priceCell {
    grid-column: 1;
    color: var(--muted);
    font-size: 11px;
    white-space: nowrap;
  }

  .quantityCell {
    grid-row: 2;
  }

  .priceCell {
    grid-row: 3;
  }

  .quantityCell::before {
    content: "수량 ";
  }

  .priceCell::before {
    content: "가격 ";
  }

  .totalCell {
    grid-column: 2;
    grid-row: 1 / span 3;
    align-self: start;
    text-align: right;
    white-space: nowrap;
    font-weight: 650;
  }

  tfoot tr {
    display: grid;
    grid-template-columns: minmax(0, 1fr) max-content;
    gap: 6px;
    padding: 9px 6px;
    border-bottom: 1px solid var(--line);
    background: #fffefa;
  }

  tfoot th,
  tfoot td {
    width: auto;
    padding: 0;
    border: 0;
    background: transparent;
  }

  tfoot th {
    text-align: left;
  }

  tfoot td {
    min-width: 74px;
    text-align: right;
  }

  tfoot strong,
  tfoot small {
    white-space: nowrap;
  }

  tfoot strong {
    font-size: 14px;
  }

  tfoot small {
    font-size: 10px;
  }

  .rateGrid {
    grid-template-columns: 1fr;
  }
}
