/* ================================================================
   Design tokens
   A ledger, not a dashboard: this app's whole job is recording who
   owes what, since when, under whose name. The palette stays quiet
   (ink on paper) so the one place color earns its keep -- status
   pills, the brand accent -- actually stands out. Money and quantity
   figures get a monospace face and tabular numerals throughout: the
   signature move, because scanning a column of amounts is the most
   common thing anyone does in this app.
   ================================================================ */
:root {
  --ink: #16181d;
  --ink-soft: #383c44;
  --muted: #6e7178;
  --faint: #9a9da3;
  --paper: #f7f6f2;
  --surface: #ffffff;
  --line: #e3e1d9;
  --line-strong: #cfccc0;

  --brand: #1e4b4b;
  --brand-ink: #0f2e2e;
  --brand-bg: #e7f0ef;
  --brand-bg-strong: #d3e4e2;

  --good: #1b7a4d;
  --good-bg: #e5f4ec;
  --bad: #b23a2e;
  --bad-bg: #fbeae7;
  --warn: #96631a;
  --warn-bg: #fbf1de;

  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(22, 24, 29, 0.05);
  --shadow-md: 0 8px 24px -8px rgba(22, 24, 29, 0.16), 0 2px 6px rgba(22, 24, 29, 0.06);

  --font-ui: "Pretendard Variable", Pretendard, "Malgun Gothic", "Apple SD Gothic Neo",
    -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --font-mono: "IBM Plex Mono", "SFMono-Regular", ui-monospace, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  /* This app is used in a lit office during business hours; it isn't
     designed for a dark surface, so it opts out rather than half-adapt. */
  :root { color-scheme: light; }
}

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 15px/1.6 var(--font-ui);
  font-feature-settings: "tnum" 1;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); }
a:hover { color: var(--brand-ink); }

:focus-visible {
  outline: 2px solid var(--brand);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
  scroll-margin-top: 4.5rem;
}

.skip-link {
  position: absolute;
  left: 1rem;
  top: -3rem;
  z-index: 100;
  background: var(--brand);
  color: #fff;
  padding: 0.6rem 1rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: top 0.12s ease;
}
.skip-link:focus { top: 1rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------------------------------------------------------
   Header / nav
   --------------------------------------------------------------- */
header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.85rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-sm);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: 0.01em;
  color: var(--ink);
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
}
.brand::before {
  content: "";
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 2px;
  background: var(--brand);
}

header nav { display: flex; gap: 1.25rem; align-items: center; }
header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  transition: color 0.12s ease;
}
header nav a:hover { color: var(--ink); }
header nav .divider { width: 1px; height: 1.1rem; background: var(--line); }
.who { color: var(--muted); font-size: 0.875rem; }
header nav button {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0;
}
header nav button:hover { color: var(--bad); }

/* ---------------------------------------------------------------
   Layout
   --------------------------------------------------------------- */
main { max-width: 1280px; margin: 0 auto; padding: 2rem 1.5rem 4rem; }

h1 {
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  margin: 0 0 1.25rem;
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.muted { color: var(--muted); }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0.25rem 0 1.25rem; line-height: 1.6; }

.flash {
  margin: 0 0 1.25rem;
  padding: 0.7rem 1rem;
  background: var(--good-bg);
  color: var(--good);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}

.error { color: var(--bad); }
p.error {
  margin: 0 0 1rem;
  padding: 0.7rem 1rem;
  background: var(--bad-bg);
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
}
label.bad input, label.bad select { border-color: var(--bad) !important; }
.req-mark { color: var(--bad); margin-left: 0.15rem; }
em.error { display: block; font-size: 0.78rem; font-style: normal; color: var(--bad); margin-top: 0.25rem; }

/* ---------------------------------------------------------------
   Login (the one page shown before anything else -- gets its own
   centered, quieter frame instead of the app-shell layout)
   --------------------------------------------------------------- */
body:has(form.narrow) main {
  max-width: 24rem;
  padding-top: min(18vh, 9rem);
}
form.narrow {
  max-width: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 2rem;
}
body:has(form.narrow) h1 {
  justify-content: center;
  font-size: 1.25rem;
}
body:has(form.narrow) .hint { text-align: center; }

/* ---------------------------------------------------------------
   Fieldsets as cards, legends as eyebrows
   --------------------------------------------------------------- */
fieldset {
  margin: 0 0 1.25rem;
  padding: 1.25rem 1.5rem 1.5rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
legend {
  padding: 0 0.5rem;
  margin-left: -0.5rem;
  font-weight: 700;
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
fieldset[disabled] { opacity: 0.55; }
#contract-identity { margin: 0 0 1.25rem; padding: 0; border: none; border-radius: 0; box-shadow: none; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(15rem, 1fr));
  gap: 1rem 1.25rem;
}

/* ---------------------------------------------------------------
   Forms
   --------------------------------------------------------------- */
label { display: block; }
label > span {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 0.3rem;
}
label.inline { display: flex; gap: 0.4rem; align-items: center; }

input, select, button, textarea {
  font: inherit;
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  transition: border-color 0.12s ease, box-shadow 0.12s ease;
}
input, select { width: 100%; }
input[type="checkbox"] { width: auto; }
input:hover, select:hover { border-color: var(--muted); }
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-bg-strong);
}
input[type="number"] { font-variant-numeric: tabular-nums; }
input::placeholder { color: var(--faint); }
input:disabled, select:disabled { background: var(--paper); color: var(--muted); }

button {
  background: var(--brand);
  border-color: var(--brand);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s ease, box-shadow 0.12s ease, transform 0.05s ease;
}
button:hover { background: var(--brand-ink); }
button:active { transform: translateY(1px); }
button.danger { background: var(--bad); border-color: var(--bad); }
button.danger:hover { background: #8f2e24; }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1.25rem;
}
.filters input, .filters select { width: auto; min-width: 10rem; }

/* ---------------------------------------------------------------
   List toolbar: search on the left, view controls (filter/sort/export)
   on the right -- a Notion-style database view bar. align-items: stretch
   on .search-group makes the input and its button the same height,
   and .view-btn gives every control in the right-hand group (two of
   which are <button>, one a <details><summary>, one an <a>) identical
   box sizing, so nothing looks vertically offset from its neighbors.
   --------------------------------------------------------------- */
.toolbar { display: flex; flex-direction: column; gap: 0.75rem; margin-bottom: 1.25rem; }
.toolbar-row { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.75rem; }
.search-group { display: flex; align-items: stretch; gap: 0.5rem; flex: 1 1 auto; min-width: 16rem; max-width: 30rem; }
.search-group input { width: auto; flex: 1 1 auto; }
.view-controls { display: flex; align-items: center; gap: 0.5rem; flex-wrap: wrap; }

.view-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: var(--surface);
  color: var(--ink-soft);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.85rem;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  list-style: none;
}
.view-btn::-webkit-details-marker { display: none; }
.view-btn:hover { background: var(--paper); border-color: var(--muted); color: var(--ink); }
.view-btn svg {
  width: 1rem; height: 1rem; stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0;
}

/* Contract View / 전체 보기 toggle: adjacent tabs share one border instead of
   each getting an independent border-radius (the same "looks like separate
   chips" mistake flagged above on .actions/.actions-inner) -- only the
   strip's outer corners round, and -1px margin collapses the shared edge. */
.view-tabs { display: flex; }
.view-tab {
  display: inline-flex; align-items: center; padding: 0.5rem 1rem;
  font-size: 0.875rem; font-weight: 600; text-decoration: none;
  color: var(--ink-soft); background: var(--surface);
  border: 1px solid var(--line-strong);
  margin-left: -1px;
}
.view-tab:first-child { margin-left: 0; border-radius: var(--radius-sm) 0 0 var(--radius-sm); }
.view-tab:last-child { border-radius: 0 var(--radius-sm) var(--radius-sm) 0; }
/* Active tab gets the strong brand fill -- previously it got var(--paper),
   the SAME color as the page background, so the "selected" tab was the one
   that visually disappeared while the inactive tab stood out as a solid
   white box. That read backwards; the active tab must be the one that
   pops. */
.view-tab.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 700; z-index: 1; position: relative; }
.view-tab:not(.active):hover { background: var(--paper); color: var(--ink); }

.filter-add-wrap, .sort-wrap { position: relative; }

.sort-panel {
  position: absolute;
  top: calc(100% + 0.35rem);
  right: 0;
  z-index: 6;
  min-width: 21rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}
.sort-panel-label { font-size: 0.78rem; color: var(--muted); margin: 0 0 0.1rem; }
.sort-row { display: flex; align-items: center; gap: 0.6rem; font-size: 0.85rem; }
.sort-row > span:first-child { width: 3rem; flex-shrink: 0; color: var(--muted); font-weight: 600; }
.sort-row select { width: auto; flex: 1 1 auto; }
.sort-row-clear {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.1rem 0.3rem;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
}
.sort-row-clear:hover { color: var(--bad); background: none; }
.sort-apply { align-self: flex-end; }

/* Active filters/sort: only rendered visible once at least one is set
   (server-side on load, filters.js reveals it client-side when a filter
   is freshly added from the menu). Without JS the plain checkboxes above
   still work, so filtering/sorting is never JS-dependent. */
.active-row { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.5rem 0.75rem; justify-content: space-between; }
.active-row[hidden] { display: none; }
.active-row-main { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 0.5rem 0.75rem; flex: 1 1 auto; min-width: 0; }
.filter-bar { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.sort-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
/* Pinned to the far end of the active-row -- only shown while there's
   something to clear (webapp/templates/list.html gates each on
   active_filters/sort independently, since a reset for one shouldn't
   require the other also being active). */
.reset-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }
.reset-btn {
  font-size: 0.8rem; color: var(--muted); text-decoration: none; white-space: nowrap;
  padding: 0.3rem 0.65rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
}
.reset-btn:hover { color: var(--ink); background: var(--paper); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.35rem 0.3rem 0.7rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
}
.chip-sort { background: var(--warn-bg); color: var(--warn); }
.chip-priority {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.15rem;
  height: 1.15rem;
  border-radius: 50%;
  background: var(--warn);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  flex-shrink: 0;
}
.chip-remove {
  background: none;
  border: none;
  padding: 0;
  margin-left: 0.1rem;
  color: inherit;
  opacity: 0.7;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
}
.chip-remove:hover { opacity: 1; }
.filter-field {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.3rem 0.35rem 0.3rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  font-size: 0.85rem;
}
.filter-field[hidden] { display: none; }
.filter-clear, .filter-add-wrap { display: none; }
.js .filter-clear { display: inline; }
.js .filter-add-wrap { display: inline-block; position: relative; }
.filter-clear {
  background: none;
  border: none;
  color: var(--muted);
  padding: 0.1rem 0.3rem;
  font-size: 1rem;
  line-height: 1;
}
.filter-clear:hover { color: var(--bad); background: none; }
.filter-menu {
  position: absolute;
  top: calc(100% + 0.35rem);
  left: 0;
  z-index: 5;
  min-width: 12rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.4rem;
}
.filter-menu[hidden] { display: none; }
.filter-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  color: var(--ink);
  font-weight: 500;
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
}
.filter-menu button:hover { background: var(--paper); }

/* Each filter field is a <details> disclosure so multi-checking values
   (OR within the field) works with zero JS. */
.filter-field summary {
  cursor: pointer;
  color: var(--ink-soft);
  font-weight: 500;
  list-style: none;
}
.filter-field summary::-webkit-details-marker { display: none; }
.filter-field details[open] summary { color: var(--brand); font-weight: 700; }
.filter-field details { position: relative; }
.filter-options {
  position: absolute;
  top: calc(100% + 0.45rem);
  left: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  max-height: 16rem;
  overflow-y: auto;
  min-width: 11rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.45rem;
}
.filter-options label {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.4rem;
  border-radius: var(--radius-sm);
  font-weight: normal;
  color: var(--ink);
  white-space: nowrap;
}
.filter-options label:hover { background: var(--paper); }
.filter-search {
  position: sticky;
  top: -0.45rem;
  margin: -0.45rem -0.45rem 0.3rem;
  width: calc(100% + 0.9rem);
  padding: 0.4rem 0.6rem;
  border: none;
  border-bottom: 1px solid var(--line);
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--surface);
  font-size: 0.85rem;
}
.filter-search:focus { outline: none; box-shadow: inset 0 -2px 0 var(--brand); }

.submit { display: flex; gap: 1.25rem; align-items: center; margin-top: 1.5rem; }
.submit a { color: var(--muted); font-size: 0.9rem; }
.submit a:hover { color: var(--ink); }

/* ---------------------------------------------------------------
   Tables -- the ledger's real surface. Header row reads as a label
   strip, not a heavier version of the data; every numeric column is
   monospace + tabular so a column of amounts lines up like a receipt.
   --------------------------------------------------------------- */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}
th, td { padding: 0.65rem 0.85rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
/* A code/model pair shown as a primary line + a smaller muted line below,
   instead of cramming both onto one line -- used for 계약 코드/#source_row
   and 품목/모델명. */
.stacked { display: flex; flex-direction: column; gap: 0.1rem; line-height: 1.35; }
.stacked .sub { font-size: 0.78rem; color: var(--muted); font-weight: 400; }
.date-col { white-space: nowrap; }

/* Fixed column widths (colgroup in list.html) so a table's shape stays
   constant across filters/searches -- table-layout: auto (the default)
   recomputes each column's width from whatever content the CURRENT result
   set happens to contain, so the whole table visibly resizes on every
   filter/search. Long values are ellipsized instead of reflowing. */
table.fixed-cols { table-layout: fixed; }
.fixed-cols td, .fixed-cols th { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fixed-cols td.actions, .fixed-cols th.num, .fixed-cols td.num { overflow: visible; }
.fixed-cols .stacked, .fixed-cols .stacked > span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Click-to-filter: a table cell's value doubles as a shortcut that reruns
   the list filtered to exactly that value (webapp/templates/list.html's
   filter_link macro). Styled as text with a hover affordance, not a loud
   link, since almost every cell in the table is one. */
.cell-filter { color: inherit; text-decoration: none; border-bottom: 1px dashed var(--line-strong); cursor: pointer; }
.cell-filter:hover { color: var(--brand); border-bottom-color: var(--brand); }
.cell-filter-badge { border-bottom: none; }
.cell-filter-badge:hover .badge { filter: brightness(0.92); }
th {
  background: var(--paper);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  position: sticky;
  top: 0;
  z-index: 1;
  white-space: nowrap;
}
.table-scroll {
  overflow-x: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.table-scroll table { border-radius: 0; box-shadow: none; }
tbody tr { transition: background 0.1s ease; }
tbody tr:hover { background: var(--paper); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }
td.num { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 0.9rem; }

/* display:flex directly on a table cell pulls it out of normal row-height
   stretching in some browsers -- its border then sits at the content's
   height instead of the row's, breaking alignment with sibling cells. The
   flex layout lives on this inner span instead; the td stays a plain cell
   and vertical-align: middle (set globally on th, td) centers the span. */
td.actions { white-space: nowrap; }
.actions-inner { display: flex; gap: 0.3rem; align-items: center; flex-wrap: nowrap; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  width: 2rem;
  height: 2rem;
  min-width: 2rem;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
}
.icon-btn:hover { background: var(--paper); border-color: var(--line); color: var(--ink); }
.icon-btn.danger { color: var(--bad); background: transparent; border-color: transparent; }
.icon-btn.danger:hover { background: var(--bad-bg); border-color: var(--bad-bg); }
.icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.inline-form { display: flex; gap: 0.35rem; }

/* Prev/next + numbered pages, centered as one group. Numbers are the
   first 5 and last 5 pages (page_numbers() in app.py), with a single "..."
   filling the gap -- so a 100-page result doesn't dump 100 links here. */
.pager { display: flex; gap: 0.75rem; align-items: center; justify-content: center; margin-top: 1.25rem; font-size: 0.875rem; }
.pager-btn {
  padding: 0.4rem 0.85rem; border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--ink-soft); text-decoration: none;
}
.pager-btn:hover { background: var(--paper); color: var(--ink); }
.pager-btn.disabled { color: var(--faint); pointer-events: none; }
.pager-pages { display: flex; gap: 0.2rem; align-items: center; }
.pager-page {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.9rem; height: 1.9rem; padding: 0 0.3rem; border-radius: var(--radius-sm);
  color: var(--ink-soft); text-decoration: none; font-variant-numeric: tabular-nums;
}
.pager-page:hover { background: var(--paper); color: var(--ink); }
.pager-page.current { background: var(--brand); color: #fff; font-weight: 700; }
.pager-ellipsis { color: var(--faint); padding: 0 0.15rem; }

/* ---------------------------------------------------------------
   Badges / status pills
   --------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.2rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  background: var(--paper);
  color: var(--muted);
  white-space: nowrap;
}
.badge::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}
.badge.manual { background: var(--brand-bg); color: var(--brand); }

/* Status badges: bucketed by keyword (신규/재계약/유지/기기변경/해지) rather than
   one class per exact contract_status string, so a new status value falls
   back to the neutral look instead of rendering unstyled. */
.status-new { background: var(--good-bg); color: var(--good); }
.status-renew { background: var(--brand-bg); color: var(--brand); }
.status-hold { background: var(--paper); color: var(--muted); }
.status-changed { background: var(--warn-bg); color: var(--warn); }
.status-terminated { background: var(--bad-bg); color: var(--bad); }

/* ---------------------------------------------------------------
   Read-only detail view
   --------------------------------------------------------------- */
.view-field { display: block; margin: 0 0 0.9rem; }
.view-field > span {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 0.2rem;
}
.view-field > strong { font-weight: 500; font-size: 0.95rem; }
.view-field.money > strong { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---------------------------------------------------------------
   Contract-detail timeline (Gantt-style) chart -- one |------| line per
   item (a horizontal span plus two vertical end-caps, not a filled bar),
   positions computed server-side (entries.gantt_data), plain SVG here.
   Lines are colored by contract_status (status_class) -- no separate
   legend, since the item table right below the chart already shows the
   identical status badges.
   --------------------------------------------------------------- */
.gantt { margin-bottom: 1.5rem; }
.gantt h2 { font-size: 0.95rem; margin: 0 0 0.75rem; }
.gantt-scroll { overflow-x: auto; }
.gantt-svg { display: block; font-family: var(--font-ui); }
.gantt-label {
  font-size: 0.78rem; fill: var(--ink-soft); dominant-baseline: middle;
}
/* .gantt-item sets `color`, and gantt-line/-cap pick it up via currentColor
   -- one color per contract_status bucket (status_class), matching the
   badge colors used in the item table below the chart. */
.gantt-line, .gantt-cap { stroke: currentColor; fill: none; }
.gantt-line { stroke-width: 2; stroke-linecap: round; }
.gantt-cap { stroke-width: 2; }
.gantt-item { color: var(--muted); }
.gantt-item.status-new { color: var(--good); }
.gantt-item.status-renew { color: var(--brand); }
.gantt-item.status-hold { color: var(--muted); }
.gantt-item.status-changed { color: var(--warn); }
.gantt-item.status-terminated { color: var(--bad); }
.gantt-axis { stroke: var(--line-strong); stroke-width: 1; }
.gantt-axis-label { font-size: 0.7rem; fill: var(--muted); }
.gantt-unscheduled { margin-top: 0.75rem; font-size: 0.85rem; }
.gantt-unscheduled h3 {
  font-size: 0.72rem; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 0.4rem;
}
.gantt-unscheduled ul { margin: 0; padding-left: 1.1rem; color: var(--ink-soft); }

/* Each item's #N label + line is wrapped in one <a> to /entry/<id>/view --
   plain SVG <a> would otherwise inherit the browser's default link look
   (blue text, underline), which doesn't belong in a chart. */
.gantt-item-link { cursor: pointer; }
.gantt-item-link .gantt-label { fill: var(--ink-soft); text-decoration: none; }
.gantt-item-link:hover .gantt-label { fill: var(--brand); }
.gantt-item-link:hover .gantt-line, .gantt-item-link:hover .gantt-cap { stroke-width: 3; }

/* ---------------------------------------------------------------
   Item edit history (detail.html's 이력 fieldset)
   --------------------------------------------------------------- */
.history-table .badge { margin: 0.1rem 0.2rem 0.1rem 0; }
.prior-values { margin: 0; padding-left: 1.1rem; font-size: 0.85rem; color: var(--ink-soft); }
.prior-values li { margin-bottom: 0.15rem; }

/* ---------------------------------------------------------------
   Small screens
   --------------------------------------------------------------- */
@media (max-width: 640px) {
  header { padding: 0.75rem 1rem; }
  header nav { gap: 0.85rem; }
  main { padding: 1.25rem 1rem 3rem; }
  fieldset { padding: 1rem; }
}
