:root {
  --bg: #f6f6f4;
  --surface: #fff;
  --text: #1c1d1f;
  --muted: #6a6d72;
  --line: #dcdcd8;
  --accent: #1f4e79;
  --accent-soft: #e6eef6;
  --danger: #a12a2a;
  --ok: #2c6e49;
  --radius: 4px;
}

* { box-sizing: border-box; }

html { scroll-padding-top: 72px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[hidden] { display: none !important; }

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

/* ---- controls ---- */

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

button, .button {
  display: inline-block;
  padding: 7px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
button:hover, .button:hover { border-color: #b9b9b4; }

.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.primary:hover { background: #183d5f; border-color: #183d5f; }
.quiet { border-color: transparent; background: none; color: var(--muted); }
.quiet:hover { border-color: transparent; color: var(--text); }
.danger:hover { color: var(--danger); }

input, select, textarea {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}
textarea { resize: vertical; }

:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
input.invalid { border-color: var(--danger); }

/* ---- header ---- */

.top {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 600; color: inherit; text-decoration: none; }
.top nav { display: flex; gap: 8px; align-items: center; }

/* ---- list ---- */

main.list { max-width: 1200px; margin: 0 auto; padding: 24px; }

.toolbar { display: flex; align-items: center; gap: 16px; margin-bottom: 12px; }
.toolbar input { max-width: 320px; }

.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }

table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 14px; text-align: left; white-space: nowrap; }
th { font-size: 13px; font-weight: 600; color: var(--muted); border-bottom: 1px solid var(--line); }
td { border-bottom: 1px solid #ececea; }
td:nth-child(4) { white-space: normal; }
tr:last-child td { border-bottom: 0; }
tbody tr { cursor: pointer; }
tbody tr:hover, tbody tr:focus-visible { background: var(--accent-soft); outline: none; }
tr.empty { cursor: default; }
tr.empty:hover { background: none; }
tr.empty td { padding: 40px; text-align: center; color: var(--muted); }
td.id { font-weight: 600; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---- record form ---- */

main.form {
  display: grid;
  grid-template-columns: 180px minmax(0, 860px);
  gap: 32px;
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 24px 96px;
}

aside { position: sticky; top: 76px; align-self: start; font-size: 14px; }
aside ol { list-style: none; margin: 0 0 16px; padding: 0; }
aside a { display: block; padding: 4px 0; color: var(--text); text-decoration: none; }
aside a:hover { color: var(--accent); }

.record-head { display: flex; align-items: end; gap: 24px; margin-bottom: 8px; }
.record-head .field { width: 200px; flex: none; }
.record-head input { font-weight: 600; }
.hint { margin: 0 0 6px; font-size: 13px; }

section {
  margin-top: 16px;
  padding: 20px 24px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

h2 {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin: 0 0 16px;
  font-size: 16px;
  font-weight: 600;
}
h2 span { font-size: 13px; font-weight: 400; font-variant-numeric: tabular-nums; }

.grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px 24px; }
.field.wide { grid-column: 1 / -1; }

label { display: block; margin-bottom: 5px; font-size: 13px; color: var(--muted); }

.choices { display: flex; flex-wrap: wrap; }
.choices button { border-radius: 0; margin: 0 -1px -1px 0; padding: 7px 12px; }
.choices button:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.choices button:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.choices.multi { gap: 6px; }
.choices.multi button { margin: 0; border-radius: var(--radius); }
.choices button[aria-pressed="true"] {
  position: relative;
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.number { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.number input { width: 110px; font-variant-numeric: tabular-nums; }
.unit { color: var(--muted); font-size: 13px; }
.warn { color: #8a5a00; font-size: 13px; }

.savebar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 24px;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.status { flex: 1; min-width: 0; margin-right: 8px; text-align: right; font-size: 14px; color: var(--muted); }
.status.ok { color: var(--ok); }
.status.error, .error { color: var(--danger); }

.fatal { padding: 48px; text-align: center; color: var(--danger); }

/* ---- login ---- */

body.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-box {
  width: 100%;
  max-width: 320px;
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}
.login-box h1 { margin: 0 0 20px; font-size: 18px; font-weight: 600; }
.login-box button { width: 100%; margin-top: 16px; }
.login-box .error { margin: 10px 0 0; font-size: 14px; }

/* ---- small screens ---- */

@media (max-width: 800px) {
  main.form { grid-template-columns: minmax(0, 1fr); padding: 16px 16px 96px; }
  aside { display: none; }
  .grid { grid-template-columns: minmax(0, 1fr); }
  .record-head { flex-direction: column; align-items: stretch; gap: 8px; }
  section { padding: 16px; }
  main.list { padding: 16px; }
  .top, .savebar { padding: 10px 16px; }
}
