[hidden] {
  display: none !important;
}

:root {
  color-scheme: light;
  --paper: #f7f5ef;
  --surface: #fffdf8;
  --surface-strong: #ffffff;
  --ink: #20221f;
  --muted: #686b64;
  --line: #deddd4;
  --line-strong: #c7c5ba;
  --green: #244f3e;
  --green-soft: #dce9df;
  --orange: #dc6a3b;
  --orange-dark: #a74220;
  --shadow: 0 18px 50px rgba(41, 45, 38, 0.08);
  font-family: Pretendard, "Noto Sans KR", "Apple SD Gothic Neo", system-ui, sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-width: 320px;
  background:
    radial-gradient(circle at 8% 0%, rgba(220, 106, 59, 0.09), transparent 28rem),
    var(--paper);
  color: var(--ink);
}

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

.skip-link {
  position: fixed;
  top: 0.5rem;
  left: 0.5rem;
  z-index: 20;
  transform: translateY(-150%);
  padding: 0.7rem 1rem;
  background: var(--ink);
  color: white;
  border-radius: 0.5rem;
}
.skip-link:focus { transform: translateY(0); }

.site-header {
  width: min(1180px, calc(100% - 2rem));
  margin: 0 auto;
  padding: 2rem 0 1.2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
}

.brand { display: flex; align-items: center; gap: 0.85rem; }
.brand-mark {
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  border-radius: 0.9rem;
  background: var(--green);
  color: white;
  font-size: 1.45rem;
  font-weight: 800;
  box-shadow: 0 8px 22px rgba(36, 79, 62, 0.2);
}

.eyebrow {
  margin: 0 0 0.25rem;
  color: var(--orange-dark);
  font-size: 0.75rem;
  font-weight: 800;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(1.35rem, 2.5vw, 1.75rem); letter-spacing: -0.04em; }
h2 { margin-bottom: 0; font-size: 1.45rem; letter-spacing: -0.04em; }

.connection-panel { display: grid; justify-items: end; gap: 0.42rem; }
.connection-actions { display: flex; align-items: center; gap: 0.8rem; }
.connection-note { margin: 0; color: var(--muted); font-size: 0.78rem; line-height: 1.4; }
.connection-status { color: var(--muted); font-size: 0.84rem; }
.connection-status::before {
  content: "";
  display: inline-block;
  width: 0.48rem;
  height: 0.48rem;
  margin-right: 0.4rem;
  border-radius: 999px;
  background: #aaa99f;
  vertical-align: 0.08em;
}
.connection-status[data-state="online"]::before { background: #2d8f62; }
.connection-status[data-state="cached"]::before { background: var(--orange); }

.page-shell { width: min(1180px, calc(100% - 2rem)); margin: 0 auto 4rem; }

.notice {
  margin-bottom: 1rem;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  border: 1px solid #e1c4ad;
  border-radius: 0.9rem;
  background: #fff5e9;
}
.notice p { margin: 0.25rem 0 0; color: #6d533f; font-size: 0.88rem; }
code { padding: 0.1rem 0.28rem; background: rgba(0, 0, 0, 0.06); border-radius: 0.25rem; }
.text-link { color: var(--orange-dark); font-weight: 750; text-underline-offset: 0.2em; }

.summary-grid {
  display: grid;
  grid-template-columns: 1.15fr 1fr 1fr;
  gap: 1rem;
  margin: 0.5rem 0 1.2rem;
}
.summary-card {
  min-height: 9rem;
  padding: 1.2rem 1.3rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  border: 1px solid var(--line);
  border-radius: 1rem;
  background: rgba(255, 253, 248, 0.86);
}
.summary-card-wide { background: var(--green); color: white; border-color: var(--green); }
.summary-card p { margin: 0; color: var(--muted); font-size: 0.85rem; font-weight: 700; }
.summary-card-wide p, .summary-card-wide span { color: rgba(255, 255, 255, 0.72); }
.summary-card strong { font-size: clamp(1.65rem, 4vw, 2.3rem); letter-spacing: -0.055em; }
.summary-card span { color: var(--muted); font-size: 0.75rem; }

.workspace {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 1.15rem;
  background: var(--surface-strong);
  box-shadow: var(--shadow);
}
.workspace-heading {
  padding: 1.35rem 1.45rem 1rem;
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
}
.toolbar { display: flex; align-items: center; gap: 0.55rem; }

.button, .icon-button, .tab, .row-action {
  border: 0;
  cursor: pointer;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}
.button {
  min-height: 2.55rem;
  padding: 0.65rem 0.95rem;
  border-radius: 0.68rem;
  font-weight: 750;
  white-space: nowrap;
}
.button:hover:not(:disabled), .row-action:hover:not(:disabled), .icon-button:hover { transform: translateY(-1px); }
.button:disabled, .row-action:disabled { cursor: not-allowed; opacity: 0.45; }
.button-primary { background: var(--green); color: white; }
.button-accent { background: var(--orange); color: white; }
.button-accent:hover:not(:disabled) { background: #ca592c; }
.button-quiet { border: 1px solid var(--line); background: var(--surface); }

.search-field {
  width: min(19rem, 34vw);
  min-height: 2.55rem;
  padding: 0 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  border: 1px solid var(--line);
  border-radius: 0.68rem;
  background: var(--surface);
}
.search-field:focus-within { border-color: var(--green); outline: 3px solid rgba(36, 79, 62, 0.1); }
.search-field svg { width: 1rem; fill: none; stroke: var(--muted); stroke-width: 1.8; }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; }

.tabs { display: flex; gap: 0.25rem; padding: 0 1.45rem; border-bottom: 1px solid var(--line); }
.tab { padding: 0.8rem 1rem; background: transparent; color: var(--muted); font-weight: 750; border-bottom: 3px solid transparent; }
.tab.is-active { color: var(--green); border-bottom-color: var(--green); }

.table-wrap { overflow-x: auto; }
.records-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.records-table th {
  padding: 0.75rem 0.8rem;
  color: var(--muted);
  background: #faf9f5;
  font-size: 0.72rem;
  letter-spacing: 0.03em;
  text-align: left;
}
.records-table td { padding: 0.9rem 0.8rem; border-top: 1px solid #eeede7; vertical-align: top; }
.records-table tbody tr:hover { background: #fbfaf6; }
.number-cell { text-align: right !important; font-variant-numeric: tabular-nums; }
.actions-cell { width: 6.2rem; text-align: right !important; white-space: nowrap; }
.record-title { display: block; max-width: 25rem; font-weight: 750; }
.record-subtitle { display: block; margin-top: 0.25rem; color: var(--muted); font-size: 0.76rem; }
.status-pill { display: inline-flex; padding: 0.18rem 0.45rem; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 0.7rem; font-weight: 750; }
.row-action { padding: 0.35rem 0.45rem; border-radius: 0.4rem; background: transparent; color: var(--green); font-size: 0.78rem; font-weight: 750; }
.row-action-danger { color: #a33f34; }

.empty-state { padding: 4rem 1rem; display: grid; place-items: center; text-align: center; color: var(--muted); }
.empty-state[hidden] { display: none; }
.empty-state > span { width: 3rem; height: 3rem; display: grid; place-items: center; margin-bottom: 0.8rem; border-radius: 999px; background: var(--green-soft); color: var(--green); font-size: 1.4rem; }
.empty-state strong { color: var(--ink); }
.empty-state p { max-width: 30rem; margin: 0.45rem 0 0; font-size: 0.84rem; }

.memo-list { display: grid; grid-template-columns: 1fr; gap: 0.85rem; padding: 1rem 1.25rem 1.35rem; }
.memo-card { padding: 1rem; border: 1px solid var(--line); border-radius: 0.8rem; background: var(--surface); }
.memo-card h3 { margin: 0 0 0.45rem; font-size: 1rem; }
.memo-card p { margin: 0; color: #51544e; line-height: 1.65; white-space: pre-wrap; }
.memo-card footer { margin-top: 0.9rem; display: flex; justify-content: space-between; align-items: center; gap: 0.6rem; }
.memo-card a { color: var(--orange-dark); font-size: 0.78rem; font-weight: 750; }

.record-dialog {
  width: min(760px, calc(100% - 2rem));
  max-height: calc(100vh - 2rem);
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 1rem;
  background: var(--surface-strong);
  box-shadow: 0 28px 90px rgba(20, 24, 19, 0.25);
}
.record-dialog::backdrop { background: rgba(30, 33, 29, 0.48); backdrop-filter: blur(2px); }
.record-dialog-small { width: min(580px, calc(100% - 2rem)); }
.record-dialog form { padding: 1.35rem; }
.dialog-heading { display: flex; align-items: start; justify-content: space-between; margin-bottom: 1.2rem; }
.icon-button { width: 2.2rem; height: 2.2rem; border-radius: 999px; background: #f0efe9; font-size: 1.35rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.85rem; }
.form-grid-single { grid-template-columns: 1fr; }
.form-grid label { display: grid; gap: 0.35rem; color: #51534e; font-size: 0.78rem; font-weight: 750; }
.form-grid input, .form-grid select, .form-grid textarea {
  width: 100%;
  padding: 0.7rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 0.58rem;
  background: white;
  color: var(--ink);
  outline: none;
}
.form-grid input:focus, .form-grid select:focus, .form-grid textarea:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(36, 79, 62, 0.1); }
.span-2 { grid-column: span 2; }
.calculated-total { padding: 0.8rem 0.9rem; display: flex; align-items: center; justify-content: space-between; border-radius: 0.65rem; background: var(--green-soft); }
.calculated-total span { color: var(--green); font-size: 0.78rem; font-weight: 750; }
.calculated-total strong { color: var(--green); font-size: 1.2rem; }
.form-errors { margin: 0.85rem 0 0; padding: 0.7rem 0.8rem; border-radius: 0.55rem; background: #fff0ec; color: #9a3429; font-size: 0.82rem; white-space: pre-line; }
.dialog-actions { margin-top: 1.1rem; display: flex; justify-content: flex-end; gap: 0.55rem; }

.toast {
  position: fixed;
  right: 1rem;
  bottom: 1rem;
  z-index: 30;
  max-width: min(24rem, calc(100% - 2rem));
  padding: 0.85rem 1rem;
  border-radius: 0.7rem;
  background: #20221f;
  color: white;
  box-shadow: var(--shadow);
  font-size: 0.85rem;
}
.toast[data-kind="error"] { background: #8e352c; }

.sr-only { 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: 820px) {
  .site-header, .workspace-heading { align-items: stretch; flex-direction: column; }
  .connection-panel { justify-items: stretch; }
  .connection-actions { justify-content: space-between; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-card-wide { grid-column: span 2; }
  .toolbar { flex-wrap: wrap; }
  .search-field { width: 100%; }
}

@media (max-width: 620px) {
  .site-header, .page-shell { width: min(100% - 1rem, 1180px); }
  .site-header { padding-top: 1rem; }
  .connection-status { display: none; }
  .connection-actions .button { width: 100%; }
  .connection-note { text-align: left; }
  .notice { align-items: flex-start; flex-direction: column; }
  .notice .text-link { white-space: nowrap; }
  .summary-grid { grid-template-columns: 1fr; gap: 0.55rem; }
  .summary-card-wide { grid-column: auto; }
  .summary-card { min-height: 7.5rem; }
  .workspace-heading { padding: 1.1rem 1rem 0.8rem; }
  .toolbar .button { flex: 1; }
  .tabs { padding: 0 0.8rem; }
  .records-table th:nth-child(3), .records-table td:nth-child(3),
  .records-table th:nth-child(4), .records-table td:nth-child(4),
  .records-table th:nth-child(6), .records-table td:nth-child(6) { display: none; }
  .records-table th, .records-table td { padding: 0.75rem 0.55rem; }
  .record-title { max-width: 12rem; }
  .form-grid { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .record-dialog form { padding: 1rem; }
}
