:root {
  --ink: #161310;
  --paper: #f3ece3;
  --card: #fffaf4;
  --line: #d9cfc3;
  --muted: #6f675e;
  --rust: #b84328;
  --rust-d: #8f321c;
  --sage: #2f5a45;
  --good: #2f5a45;
  --warn: #9a6b12;
  --bad: #a33b28;
  --shadow: 0 18px 40px rgba(22, 19, 16, 0.08);
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

h1, .brand {
  font-family: Georgia, "Iowan Old Style", "Palatino Linotype", serif;
  font-weight: 600;
  letter-spacing: -0.03em;
}

[hidden] { display: none !important; }

.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(1200px 500px at 10% -10%, #ead7c4, transparent 50%),
    var(--paper);
}
.login-card {
  width: min(440px, calc(100% - 32px));
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 40px 36px 32px;
  box-shadow: var(--shadow);
}
.eyebrow {
  margin: 0 0 8px;
  font-size: 12px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--rust);
}
.lead, .muted, .hint, .brand-sub { color: var(--muted); }
.lead { margin: 0 0 28px; line-height: 1.45; }
label { display: grid; gap: 8px; font-size: 13px; }
input[type="password"], input, button {
  font: inherit;
}
input[type="password"], #default-count, .ch-count {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 10px;
  padding: 12px 12px;
  color: var(--ink);
}
button {
  border: 0;
  background: var(--rust);
  color: #fff;
  border-radius: 999px;
  padding: 12px 18px;
  cursor: pointer;
}
button:hover { background: var(--rust-d); }
.err { color: var(--bad); font-size: 13px; margin: 10px 0 0; }

#app:not([hidden]) {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}
aside {
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: #efe6db;
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.brand { font-size: 28px; margin: 0; }
.brand-sub { margin: 0; font-size: 13px; }
nav a {
  display: block;
  padding: 8px 0;
  color: var(--ink);
  text-decoration: none;
  border-bottom: 1px solid transparent;
}
nav a.on { border-bottom-color: var(--ink); }
.ghost {
  margin-top: auto;
  background: transparent;
  color: var(--ink);
  border: 1px solid var(--line);
}
.ghost:hover { background: #e4d8c9; color: var(--ink); }

main { padding: 36px 40px 64px; }
.top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}
.top h1 { margin: 0 0 8px; font-size: 34px; }
#refresh { background: var(--ink); }
#refresh:hover { background: #000; }

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 28px;
}
.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 16px 18px;
}
.stat b { display: block; font-size: 28px; font-family: Georgia, serif; }
.stat span { color: var(--muted); font-size: 13px; }

.toolbar {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  margin-bottom: 18px;
}
.label { display: block; font-size: 12px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted); margin-bottom: 8px; }
.step { display: flex; gap: 8px; align-items: center; }
.step button { padding: 8px 14px; }
.step input { width: 72px; text-align: center; padding: 8px; }
.chip { background: var(--sage); }
.chip:hover { background: #244534; }
.hint { max-width: 420px; font-size: 13px; margin: 0; }

.table-wrap {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  overflow: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); font-weight: 600; }
tr:last-child td { border-bottom: 0; }
.title { font-weight: 650; }
.sub { font-size: 13px; color: var(--muted); }
.tag {
  display: inline-block;
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: #e7f0ea;
  color: var(--good);
  margin-left: 8px;
}
.tag.warn { background: #f3ead3; color: var(--warn); }
.tag.bad { background: #f6e4df; color: var(--bad); }

.row-ctrl { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.row-ctrl input { width: 64px; text-align: center; padding: 7px; }
.row-ctrl button { padding: 7px 12px; }
.tiny { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.tiny:hover { background: #efe6db; color: var(--ink); }
.open { background: var(--ink); }
.empty { padding: 28px; margin: 0; }

#toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  max-width: 420px;
  background: var(--ink);
  color: #f3ece3;
  padding: 14px 16px;
  border-radius: 12px;
  white-space: pre-wrap;
  font-size: 13px;
  line-height: 1.4;
}

@media (max-width: 900px) {
  #app:not([hidden]) { grid-template-columns: 1fr; }
  aside { flex-direction: row; align-items: center; }
  .ghost { margin-top: 0; margin-left: auto; }
  .stats, .toolbar { grid-template-columns: 1fr 1fr; display: grid; }
}
