/* ─────────────────────────────────────────────────────────────────────────
   mem — "The Ledger"
   A warm-ink instrument for an archive: espresso ground, film grain, cream
   text, one molten-amber accent. Fraunces carries the voice; IBM Plex Mono
   carries the data. Everything ships in the binary — no external calls.
   ───────────────────────────────────────────────────────────────────────── */

@font-face {
  font-family: "Fraunces";
  src: url(/fonts/fraunces-var.woff2) format("woff2");
  font-weight: 300 700;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url(/fonts/plexmono-400.woff2) format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url(/fonts/plexmono-500.woff2) format("woff2");
  font-weight: 500;
  font-display: swap;
}
@font-face {
  font-family: "Plex Mono";
  src: url(/fonts/plexmono-600.woff2) format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  --ink:       #171310;
  --ink-2:     #1e1915;
  --ink-3:     #272019;
  --line:      #2f2820;
  --line-2:    #423828;
  --cream:     #f0e8d9;
  --cream-dim: #b5a992;
  --faint:     #7d7260;
  --gold:      #e6a13c;
  --gold-hot:  #f5b855;
  --gold-dim:  rgba(230, 161, 60, 0.13);
  --sage:      #a8c489;
  --sage-dim:  rgba(168, 196, 137, 0.12);
  --clay:      #df7550;
  --clay-dim:  rgba(223, 117, 80, 0.12);
  --serif: "Fraunces", "Iowan Old Style", Georgia, serif;
  --mono: "Plex Mono", ui-monospace, "SF Mono", Menlo, monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html { height: 100%; }
body {
  height: 100%;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--mono);
  font-size: 13.5px;
  line-height: 1.55;
  font-feature-settings: "tnum" 1;
  -webkit-font-smoothing: antialiased;
}

/* Film grain over everything — the texture that makes the ink feel like paper. */
body::after {
  content: "";
  position: fixed;
  inset: -50%;
  pointer-events: none;
  z-index: 999;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='240' height='240'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

::selection { background: var(--gold); color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 5px; border: 2px solid var(--ink); }
::-webkit-scrollbar-track { background: transparent; }

.hidden { display: none !important; }
.muted { color: var(--faint); }
a { color: var(--gold); text-decoration: none; border-bottom: 1px solid rgba(230,161,60,.35); }
a:hover { color: var(--gold-hot); border-bottom-color: var(--gold-hot); }
code {
  font-family: var(--mono);
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 12px;
  color: var(--cream-dim);
  word-break: break-all;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}

/* ───────────────────────────── login ───────────────────────────── */

.login {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background:
    radial-gradient(ellipse 720px 480px at 50% 30%, rgba(230, 161, 60, 0.09), transparent 65%),
    radial-gradient(ellipse 900px 700px at 50% 110%, rgba(223, 117, 80, 0.05), transparent 60%),
    var(--ink);
}
.login-card {
  width: min(400px, calc(100vw - 48px));
  padding: 44px 40px 36px;
  background: linear-gradient(180deg, var(--ink-2), var(--ink));
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.8), 0 0 0 1px rgba(0,0,0,.4);
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.login-card h1 {
  font-family: var(--serif);
  font-weight: 420;
  font-size: 58px;
  letter-spacing: -0.02em;
  line-height: 1;
  font-variation-settings: "opsz" 100;
}
.login-card h1::after { content: "."; color: var(--gold); }
.login-card > .muted {
  margin: 8px 0 30px;
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.login-card label {
  display: block;
  margin: 16px 0 6px;
  font-size: 10.5px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}
.login-card input { width: 100%; }
.login-card button#login-btn {
  width: 100%;
  margin-top: 24px;
  padding: 12px;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--ink);
  background: linear-gradient(180deg, var(--gold-hot), var(--gold));
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: filter 0.15s, transform 0.15s;
}
.login-card button#login-btn:hover { filter: brightness(1.08); transform: translateY(-1px); }
.login-card button#login-btn:active { transform: none; }
.err { color: var(--clay); margin-top: 12px; font-size: 12.5px; min-height: 1em; }

/* ───────────────────────── inputs (global) ───────────────────────── */

input, select, textarea {
  font-family: var(--mono);
  font-size: 13px;
  color: var(--cream);
  background: var(--ink);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input::placeholder { color: var(--faint); opacity: 0.7; }
input:focus, select:focus, textarea:focus {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px var(--gold-dim);
}
input[type="file"] { padding: 8px; }
input[type="file"]::file-selector-button {
  font-family: var(--mono);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--cream-dim);
  background: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 10px;
  margin-right: 10px;
  cursor: pointer;
}
select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%237d7260' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 30px;
  cursor: pointer;
}

/* ───────────────────────────── shell ───────────────────────────── */

.app {
  display: grid;
  grid-template-columns: 236px 1fr;
  height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 26px 18px 18px;
  background: linear-gradient(180deg, var(--ink-2), var(--ink) 70%);
  border-right: 1px solid var(--line);
}
.brand {
  font-family: var(--serif);
  font-weight: 420;
  font-size: 34px;
  letter-spacing: -0.02em;
  margin: 0 6px 26px;
  font-variation-settings: "opsz" 60;
}
.brand::after { content: "."; color: var(--gold); }
.sidebar > label {
  margin: 0 6px 6px;
  font-size: 10px;
  letter-spacing: 0.2em;
  text-transform: uppercase;
}
.sidebar select { width: 100%; }

#tabs {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 26px;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}
#tabs button {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  text-align: left;
  font-family: var(--mono);
  font-size: 12px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--faint);
  background: none;
  border: none;
  border-radius: 7px;
  padding: 9px 12px;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}
#tabs button:hover { color: var(--cream); background: var(--ink-3); }
#tabs button.active { color: var(--gold); background: var(--gold-dim); }
#tabs button.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 8px;
  bottom: 8px;
  width: 2px;
  border-radius: 2px;
  background: var(--gold);
}

.badge {
  margin-left: auto;
  font-size: 10px;
  font-weight: 600;
  color: var(--ink);
  background: var(--gold);
  border-radius: 99px;
  padding: 1px 7px;
}

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-size: 11px;
  overflow: hidden;
}
.sidebar-foot .muted { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
button.link {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--gold);
  background: none;
  border: none;
  border-bottom: 1px solid rgba(230,161,60,.35);
  cursor: pointer;
  padding: 0;
  white-space: nowrap;
}
button.link:hover { color: var(--gold-hot); }

.main { overflow-y: auto; }
#view {
  max-width: 880px;
  padding: 44px 48px 80px;
  animation: rise 0.35s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}

/* ─────────────────────────── typography ─────────────────────────── */

#view h2 {
  font-family: var(--serif);
  font-weight: 440;
  font-size: 34px;
  letter-spacing: -0.015em;
  font-variation-settings: "opsz" 80;
  margin-bottom: 4px;
}
#view h3 {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--gold);
  margin: 30px 0 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--line);
}
.sub { color: var(--faint); font-size: 12.5px; margin-bottom: 18px; }
.sub b { color: var(--cream-dim); font-weight: 500; }

/* ───────────────────────────── cards ───────────────────────────── */

.card {
  position: relative;
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-left: 2px solid var(--line);
  border-radius: 10px;
  padding: 16px 18px;
  margin-bottom: 10px;
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
  animation: rise 0.4s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.card:nth-child(2)  { animation-delay: 0.03s; }
.card:nth-child(3)  { animation-delay: 0.06s; }
.card:nth-child(4)  { animation-delay: 0.09s; }
.card:nth-child(5)  { animation-delay: 0.12s; }
.card:nth-child(6)  { animation-delay: 0.15s; }
.card:nth-child(n+7){ animation-delay: 0.18s; }
.card:hover {
  border-left-color: var(--gold);
  background: var(--ink-3);
  transform: translateX(2px);
}
.content { font-size: 13.5px; line-height: 1.6; overflow-wrap: anywhere; }

.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.row.spread { justify-content: space-between; align-items: flex-start; flex-wrap: nowrap; }

.meta {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-size: 11px;
  color: var(--faint);
}

.tag { color: var(--gold); opacity: 0.85; font-size: 11px; }
.tag::before { content: "["; opacity: 0.5; }
.tag::after  { content: "]"; opacity: 0.5; }

.pill {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--cream-dim);
  background: var(--ink-3);
  border: 1px solid var(--line-2);
  border-radius: 99px;
  padding: 2px 9px;
  white-space: nowrap;
}
.pill.flag { color: var(--clay); background: var(--clay-dim); border-color: rgba(223,117,80,.3); }

/* confidence meter (rendered by app.js inside .meta) */
.conf { display: inline-flex; align-items: center; gap: 7px; }
.conf i {
  display: inline-block;
  width: 44px;
  height: 3px;
  border-radius: 2px;
  background: var(--line-2);
  position: relative;
  overflow: hidden;
}
.conf i::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--w, 0%);
  background: linear-gradient(90deg, var(--gold), var(--gold-hot));
  border-radius: 2px;
}

/* ─────────────────────────── buttons ─────────────────────────── */

.btn {
  font-family: var(--mono);
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--cream-dim);
  background: var(--ink-3);
  border: 1px solid var(--line-2);
  border-radius: 8px;
  padding: 9px 16px;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s, background 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { color: var(--cream); border-color: var(--faint); }
.btn:active { transform: translateY(1px); }
.btn.sm { padding: 6px 12px; font-size: 10.5px; }
.btn.primary {
  color: var(--ink);
  font-weight: 600;
  background: linear-gradient(180deg, var(--gold-hot), var(--gold));
  border-color: transparent;
}
.btn.primary:hover { filter: brightness(1.08); color: var(--ink); }
.btn.danger { color: var(--clay); border-color: rgba(223,117,80,.35); background: transparent; }
.btn.danger:hover { background: var(--clay-dim); border-color: var(--clay); color: var(--clay); }
.btn.good { color: var(--sage); border-color: rgba(168,196,137,.35); background: transparent; }
.btn.good:hover { background: var(--sage-dim); border-color: var(--sage); color: var(--sage); }

/* ─────────────────────────── add bar ─────────────────────────── */

.addbar {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.addbar .fact { flex: 2 1 260px; }
.addbar .tags { flex: 1 1 120px; }
.addbar select { flex: 1 1 200px; }
.addbar input[type="file"] { flex: 2 1 240px; }

/* ─────────────────────────── stats (health) ─────────────────────────── */

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-top: 8px;
}
.stat {
  background: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 20px 18px 16px;
  animation: rise 0.45s cubic-bezier(0.2, 0.7, 0.2, 1) both;
}
.stat:nth-child(2) { animation-delay: 0.05s; }
.stat:nth-child(3) { animation-delay: 0.10s; }
.stat:nth-child(4) { animation-delay: 0.15s; }
.stat:nth-child(5) { animation-delay: 0.20s; }
.stat .n {
  font-family: var(--serif);
  font-weight: 400;
  font-size: 42px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--gold);
  font-variation-settings: "opsz" 90;
}
.stat .l {
  margin-top: 8px;
  font-size: 10px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--faint);
}

/* ─────────────────────────── map ─────────────────────────── */

#map-svg {
  width: 100%;
  background:
    radial-gradient(ellipse 500px 300px at 50% 0%, rgba(230,161,60,.05), transparent 70%),
    var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  margin-top: 6px;
}
.legend {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
  margin: 10px 0 12px;
  font-size: 11px;
  color: var(--cream-dim);
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }

/* ─────────────────────────── misc ─────────────────────────── */

.empty {
  border: 1px dashed var(--line-2);
  border-radius: 12px;
  padding: 44px 20px;
  text-align: center;
  color: var(--faint);
  font-size: 12.5px;
}
.empty p { margin-bottom: 16px; }

.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink-3);
  border: 1px solid var(--gold);
  color: var(--cream);
  font-size: 12.5px;
  border-radius: 10px;
  padding: 11px 20px;
  z-index: 1000;
  box-shadow: 0 16px 50px rgba(0,0,0,.6);
  animation: rise 0.25s ease both;
}
.toast.good { border-color: var(--sage); }
.toast.err  { border-color: var(--clay); }

.small { font-size: 11px; }

@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; height: auto; min-height: 100vh; }
  .sidebar { flex-direction: row; flex-wrap: wrap; align-items: center; gap: 10px; border-right: none; border-bottom: 1px solid var(--line); }
  .brand { margin: 0; font-size: 26px; }
  #tabs { flex-direction: row; flex-wrap: wrap; border-top: none; margin-top: 0; padding-top: 0; }
  .sidebar-foot { margin-top: 0; border-top: none; padding-top: 0; margin-left: auto; }
  #view { padding: 26px 20px 60px; }
}
