/* memory-web — one stylesheet, no framework, light and dark from one set of variables. */

:root {
  --bg: #fbfbfa;
  --panel: #ffffff;
  --line: #e4e2dd;
  --ink: #1c1b19;
  --ink-soft: #6b6862;
  --ink-faint: #97938c;
  --accent: #3b5bdb;
  --accent-soft: #edf0fd;
  --warn: #b45309;
  --warn-soft: #fdf3e4;
  --bad: #b02a2a;
  --good: #2f7a52;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(0 0 0 / 6%), 0 8px 24px rgb(0 0 0 / 6%);
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --panel: #1d2026;
    --line: #2d323b;
    --ink: #e8e9ec;
    --ink-soft: #a2a8b4;
    --ink-faint: #6f7682;
    --accent: #8aa4ff;
    --accent-soft: #232a42;
    --warn: #e3a008;
    --warn-soft: #332a16;
    --bad: #f08585;
    --good: #6fcf97;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%), 0 8px 24px rgb(0 0 0 / 35%);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.55 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, system-ui, sans-serif;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0; font-weight: 620; letter-spacing: -0.01em; }

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

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

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  gap: 12px 20px;
  align-items: center;
  justify-content: space-between;
  padding: 12px max(16px, env(safe-area-inset-left)) 12px max(16px, env(safe-area-inset-right));
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--line);
}

.brand { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.brand h1 { font-size: 17px; }

.mark {
  align-self: center;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--good) 22%, transparent);
}
.mark.is-readonly { background: var(--warn); box-shadow: 0 0 0 3px color-mix(in srgb, var(--warn) 22%, transparent); }
.mark.is-down { background: var(--bad); box-shadow: 0 0 0 3px color-mix(in srgb, var(--bad) 22%, transparent); }

.corpus {
  font-family: var(--mono);
  font-size: 11.5px;
  color: var(--ink-faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 46vw;
  direction: rtl;
  text-align: left;
}

.tabs { display: flex; gap: 4px; }

.tab {
  position: relative;
  padding: 6px 12px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: none;
  color: var(--ink-soft);
  cursor: pointer;
}
.tab:hover { color: var(--ink); background: var(--panel); }
.tab.is-on { color: var(--ink); background: var(--panel); border-color: var(--line); box-shadow: var(--shadow); }

.pip {
  display: inline-block;
  min-width: 18px;
  padding: 0 5px;
  margin-left: 4px;
  border-radius: 999px;
  background: var(--warn-soft);
  color: var(--warn);
  font-size: 11px;
  font-weight: 650;
  text-align: center;
}

/* --- layout ---------------------------------------------------------------- */

main {
  max-width: 860px;
  margin: 0 auto;
  padding: 20px max(16px, env(safe-area-inset-left)) 96px max(16px, env(safe-area-inset-right));
}

.view { display: none; }
.view.is-on { display: block; }

/* --- search ---------------------------------------------------------------- */

.searchbar { display: flex; gap: 8px; }

.searchbar input[type="search"] {
  flex: 1;
  min-width: 0;
  padding: 11px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  outline: none;
}
.searchbar input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: end;
  margin-top: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
}

.filters label, .form label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 12px;
  font-weight: 560;
  color: var(--ink-soft);
}
.filters label.check { flex-direction: row; align-items: center; gap: 7px; padding-bottom: 8px; }

.filters select, .filters input, .form input, .form select, .form textarea {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--bg);
  color: var(--ink);
  outline: none;
}
.form input:focus, .form select:focus, .form textarea:focus,
.filters select:focus, .filters input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.meta {
  margin: 16px 2px 10px;
  font-size: 12.5px;
  color: var(--ink-faint);
}
.meta .dropped { color: var(--warn); }

/* --- results --------------------------------------------------------------- */

.results { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.card {
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  cursor: pointer;
  transition: border-color 0.12s, transform 0.12s;
}
.card:hover { border-color: color-mix(in srgb, var(--accent) 45%, var(--line)); }
.card:active { transform: translateY(1px); }

.card h3 { font-size: 15px; margin-bottom: 5px; }
.card .snippet { margin: 0 0 9px; font-size: 13.5px; color: var(--ink-soft); }

.badges { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.badge {
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 11px;
  font-weight: 560;
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge.type { background: var(--accent-soft); border-color: transparent; color: var(--accent); }
.badge.stale { background: var(--warn-soft); border-color: transparent; color: var(--warn); }
.badge.inactive { background: transparent; color: var(--ink-faint); text-decoration: line-through; }
.badge.confirmed { color: var(--good); border-color: color-mix(in srgb, var(--good) 35%, var(--line)); }
.badge.src { font-family: var(--mono); font-size: 10.5px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }

.empty {
  padding: 28px 18px;
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  text-align: center;
  color: var(--ink-faint);
  font-size: 13.5px;
}
.empty strong { display: block; color: var(--ink-soft); margin-bottom: 4px; font-weight: 600; }

/* --- forms ----------------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 14px; max-width: 640px; }
.form .row { display: flex; gap: 12px; flex-wrap: wrap; }
.form .row > label { flex: 1; min-width: 180px; }
.form textarea { resize: vertical; font: inherit; }
.req { color: var(--bad); font-weight: 500; }
.hint { color: var(--ink-faint); font-weight: 400; }

.actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

.primary {
  padding: 9px 18px;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.primary:disabled { opacity: 0.5; cursor: not-allowed; }

.ghost {
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
}
.ghost:hover { color: var(--ink); border-color: var(--ink-faint); }
.ghost.danger:hover { color: var(--bad); border-color: var(--bad); }

.form-note { font-size: 12.5px; color: var(--ink-faint); }
.form-note.bad { color: var(--bad); }
.form-note.good { color: var(--good); }

/* --- detail ---------------------------------------------------------------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: rgb(0 0 0 / 35%);
}

.detail {
  position: fixed;
  z-index: 40;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(560px, 100vw);
  overflow-y: auto;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: var(--shadow);
  overscroll-behavior: contain;
}

.detail-inner {
  padding: 20px max(18px, env(safe-area-inset-right)) 60px 18px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail h2 { font-size: 17px; line-height: 1.4; }
.detail .close { position: absolute; top: 12px; right: 14px; }

.fact {
  margin: 0;
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg);
  border: 1px solid var(--line);
  white-space: pre-wrap;
  font-size: 14px;
}

.fields { display: grid; grid-template-columns: auto 1fr; gap: 7px 14px; font-size: 12.5px; align-items: baseline; }
.fields dt { color: var(--ink-faint); font-weight: 560; }
.fields dd { margin: 0; font-family: var(--mono); font-size: 11.5px; word-break: break-word; }

.section-label {
  font-size: 11px;
  font-weight: 660;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-faint);
}

.chain { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }

.chain li {
  position: relative;
  padding: 10px 12px 10px 26px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  background: var(--bg);
}
.chain li::before {
  content: "";
  position: absolute;
  left: 11px;
  top: 15px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ink-faint);
}
.chain li.is-current { border-color: var(--accent); background: var(--accent-soft); }
.chain li.is-current::before { background: var(--accent); }
.chain .when { color: var(--ink-faint); font-size: 11.5px; }

.detail .form { max-width: none; }

details.panel { border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); }
details.panel > summary { padding: 10px 14px; cursor: pointer; font-size: 13px; font-weight: 560; color: var(--ink-soft); }
details.panel > summary:hover { color: var(--ink); }
details.panel[open] > summary { border-bottom: 1px solid var(--line); }
details.panel .form { padding: 14px; }

/* --- toast ----------------------------------------------------------------- */

.toast {
  position: fixed;
  z-index: 60;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 32px));
  padding: 11px 16px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
  font-size: 13.5px;
  box-shadow: var(--shadow);
}
.toast.bad { background: var(--bad); color: #fff; }

@media (max-width: 620px) {
  .detail { width: 100vw; border-left: none; }
  .corpus { display: none; }
  .top { padding-top: max(10px, env(safe-area-inset-top)); }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
