:root {
  --ink: #1b1916;
  --paper: #f4efe6;
  --sheet: #fffcf6;
  --line: #e4dccb;
  --muted: #6f675b;
  --brass: #8a6118;
  --ok: #2f7d4a;
  --warn: #b86a12;
  --bad: #b42318;
  --shadow: 0 10px 28px rgba(40, 28, 12, 0.1);
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  --sans: "Source Serif 4", "Songti SC", "Noto Serif SC", serif;
}

* { box-sizing: border-box; }
html, body, #app { height: 100%; min-height: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--sans);
}

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.btn {
  appearance: none;
  border: 1px solid #2a241c;
  background: linear-gradient(#3a332b, #211c17);
  color: #f6efe2;
  padding: 9px 14px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.04em;
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.18), 0 2px 0 #100e0b, 0 6px 12px rgba(0,0,0,0.12);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: translateY(1px); box-shadow: inset 0 1px 3px rgba(0,0,0,0.35); }
.btn.ghost {
  background: linear-gradient(#fffdf8, #f3ead8);
  color: var(--ink);
  border-color: #c9b894;
  box-shadow: inset 0 1px 0 #fff, 0 2px 0 #d7c7a4, 0 4px 10px rgba(80, 50, 10, 0.08);
}
.btn.danger {
  background: linear-gradient(#d14a3c, #9d2218);
  border-color: #7a160f;
  color: #fff7ee;
}
.btn.wide { width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 11px; }

.gate {
  min-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px 16px;
}
.seal {
  width: min(420px, 100%);
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 36px 32px 28px;
}
.seal h1 {
  margin: 0 0 8px;
  text-align: center;
  font-size: 36px;
  font-weight: 600;
}
.seal .lede {
  text-align: center;
  color: var(--muted);
  margin: 0 0 24px;
  font-size: 15px;
}
.field { display: grid; gap: 8px; margin-bottom: 14px; }
.field label {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--brass);
}
.field input, .field textarea, .field select, .search, .filter {
  width: 100%;
  background: #fff;
  border: 1px solid #d8cfbe;
  border-radius: 8px;
  padding: 11px 12px;
  outline: none;
}
input, textarea, select { outline: none; }
.field input:focus, .field textarea:focus, .field select:focus, .search:focus, .filter:focus,
.cell-input:focus, .pick-btn:focus, .otp-code:focus, .secret-btn:focus {
  border-color: #b0892e;
  box-shadow: 0 0 0 3px rgba(176, 137, 46, 0.18);
}
.err { color: var(--bad); font-size: 14px; min-height: 1.2em; margin: 0 0 10px; }

.app { min-height: 100%; display: flex; flex-direction: column; }
.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px 12px;
  background: var(--sheet);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: baseline; gap: 12px; }
.brand h1 { margin: 0; font-size: 28px; font-weight: 600; }
.brand small { font-family: var(--mono); font-size: 12px; color: var(--muted); }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.main { padding: 16px 20px 40px; }
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
  align-items: center;
}
.search { max-width: 360px; font-family: var(--mono); font-size: 13px; }

.pick { position: relative; display: inline-block; min-width: 96px; }
.pick-btn {
  display: inline-flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-width: 96px;
  background: linear-gradient(#fffdf8, #f3ead8);
  border: 1px solid #c9b894;
  border-radius: 8px;
  padding: 7px 10px;
  font-family: var(--mono);
  font-size: 12px;
  box-shadow: inset 0 1px 0 #fff, 0 2px 0 #d7c7a4;
}
.pick-btn:after { content: "▾"; color: var(--muted); }
.pick.open .pick-btn { border-color: #b0892e; }
.pick-menu {
  display: none;
  position: fixed;
  z-index: 80;
  background: #fffdf8;
  border: 1px solid #c9b894;
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 4px;
  max-height: 240px;
  overflow: auto;
  min-width: 120px;
}
.pick-menu.open { display: block; }
.pick-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 0;
  border-radius: 6px;
  padding: 8px 10px;
  font-family: var(--mono);
  font-size: 12px;
}
.pick-item:hover, .pick-item.on { background: #efe3c4; }

.table-wrap {
  overflow-x: auto;
  overflow-y: visible;
  background: var(--sheet);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.ledger {
  width: 100%;
  border-collapse: collapse;
  min-width: 1280px;
}
.ledger th {
  text-align: left;
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 500;
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  background: #faf6ee;
  white-space: nowrap;
  position: sticky;
  top: 0;
}
.ledger td {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
  white-space: nowrap;
  font-family: var(--mono);
  font-size: 12px;
  overflow: visible;
}
.ledger tr:hover td { background: #fff8ea; }
.copy {
  display: inline-block;
  max-width: 240px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: copy;
}
.copy:hover { background: #efe3c4; }
.copy.empty { color: #b3aa9b; cursor: default; }

.cell-input {
  width: 110px;
  padding: 6px 8px;
  border: 1px solid #d8cfbe;
  border-radius: 6px;
  background: #fff;
  font-family: var(--mono);
  font-size: 12px;
}
.cell-input.slim { width: 72px; }
.cell-input.note { width: 140px; }
.secret-btn {
  position: relative;
  appearance: none;
  border: 1px solid #c9b894;
  background: linear-gradient(#fffdf8, #f3ead8);
  color: var(--ink);
  padding: 6px 10px;
  border-radius: 8px;
  font-family: var(--mono);
  font-size: 11px;
  box-shadow: inset 0 1px 0 #fff, 0 2px 0 #d7c7a4;
}
.secret-btn.empty { opacity: 0.35; }
.secret-tip {
  display: none;
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  min-width: 180px;
  max-width: 320px;
  background: #1b1916;
  color: #f6efe2;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  z-index: 50;
  box-shadow: var(--shadow);
}
.secret-btn:hover .secret-tip { display: block; }
.badge {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 11px;
}
.badge.ok { background: #e5f5ea; color: var(--ok); }
.badge.warn { background: #fff1d6; color: var(--warn); }
.badge.bad { background: #fde4e1; color: var(--bad); }

.otp {
  display: flex;
  align-items: center;
  gap: 8px;
}
.otp-code {
  appearance: none;
  border: 1px solid #d8cfbe;
  background: #fff;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 15px;
  letter-spacing: 0.12em;
  font-weight: 500;
  padding: 6px 10px;
  border-radius: 8px;
  min-width: 88px;
  cursor: copy;
}
.otp-code:hover { background: #efe3c4; }
.otp-code.empty { color: #b3aa9b; letter-spacing: 0; font-size: 12px; cursor: default; }
.otp-timer {
  --p: 1;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: conic-gradient(#8a6118 calc(var(--p) * 360deg), #ece4d4 0);
  position: relative;
  flex: 0 0 30px;
}
.otp-timer:before {
  content: "";
  position: absolute;
  inset: 4px;
  background: var(--sheet);
  border-radius: 50%;
}
.otp-timer b {
  position: relative;
  font-family: var(--mono);
  font-size: 11px;
}
.otp-timer.urgent { background: conic-gradient(#b42318 calc(var(--p) * 360deg), #ece4d4 0); }

.life { min-width: 150px; }
.life .meta { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.bar {
  height: 8px;
  background: #ece4d4;
  border-radius: 99px;
  overflow: hidden;
}
.bar > i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, #3d9a5c, #d4a04a 70%, #c23a2b);
}
.bar.late > i { background: #c23a2b; }
.row-actions { display: flex; gap: 6px; }

.empty { padding: 56px 20px; text-align: center; color: var(--muted); }
.empty h2 { margin: 0 0 8px; color: var(--ink); }

.drawer-bg {
  position: fixed;
  inset: 0;
  background: rgba(28, 23, 18, 0.28);
  z-index: 20;
}
.drawer {
  position: fixed;
  top: 0;
  right: 0;
  height: 100%;
  width: min(520px, 100%);
  background: var(--sheet);
  border-left: 1px solid var(--line);
  z-index: 30;
  overflow: auto;
  padding: 24px 22px 48px;
  box-shadow: -16px 0 40px rgba(70, 48, 20, 0.12);
}
.drawer h2 { margin: 0 0 6px; font-size: 28px; }
.drawer .sub { color: var(--muted); margin: 0 0 18px; }
.preview {
  max-height: 260px;
  overflow: auto;
  border: 1px solid var(--line);
  margin: 12px 0 18px;
  background: #fff;
  border-radius: 8px;
}
.preview table { width: 100%; border-collapse: collapse; }
.preview td, .preview th {
  font-family: var(--mono);
  font-size: 11px;
  padding: 7px 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  white-space: nowrap;
}
.toast {
  position: fixed;
  bottom: 22px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #f6efe2;
  padding: 10px 16px;
  font-family: var(--mono);
  font-size: 12px;
  z-index: 90;
  border-radius: 8px;
}
.toast[hidden] { display: none; }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; }
.paste-zone {
  border: 1.5px dashed #c9b894;
  border-radius: 12px;
  background: #fff8ea;
  padding: 28px 16px;
  text-align: center;
  margin-bottom: 16px;
  outline: none;
}
.paste-zone:focus, .paste-zone:hover {
  border-color: #8a6118;
  background: #fff3d6;
}
.paste-zone strong { display: block; margin-bottom: 6px; }
.paste-zone span { color: var(--muted); font-size: 13px; }

@media (max-width: 860px) {
  .top { padding: 14px 12px; }
  .main { padding: 12px; }
  .brand h1 { font-size: 22px; }
}
