:root {
  --bg: #f6f5f1; --panel: #ffffff; --line: #e2dfd6; --text: #1d2422; --muted: #6a726f;
  --accent: #2f6f5e; --accent-text: #ffffff; --hover: #efede6; --sel: #e1ece8;
  --danger: #b3372f; --warn-bg: #fbeed3; --warn-text: #7a5200;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151918; --panel: #1d2221; --line: #2f3634; --text: #e8ebe9; --muted: #98a19e;
    --accent: #58a892; --accent-text: #0d1513; --hover: #262c2a; --sel: #24352f;
    --danger: #ef7d74; --warn-bg: #3d3117; --warn-text: #f1cf86;
    color-scheme: dark;
  }
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
h1 { font-size: 22px; margin: 8px 0 4px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 13px; margin: 20px 0 6px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); }
p { margin: 6px 0; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--danger); min-height: 1.4em; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

button, input, textarea { font: inherit; color: inherit; }
button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 7px;
  padding: 6px 12px; cursor: pointer; white-space: nowrap;
}
button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; width: auto !important; }
button:disabled { opacity: .6; cursor: default; }
input[type=text], input[type=password], input[type=search], input[type=url], input[type=number], textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px;
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
label { display: block; margin: 12px 0 0; font-size: 12.5px; color: var(--muted); }
label > input, label > textarea { margin-top: 4px; color: var(--text); font-size: 14px; }

/* Gate */
#gate { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.card {
  width: 100%; max-width: 360px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 14px; padding: 28px; text-align: center;
}
.card label { text-align: left; }
.card button { width: 100%; margin-top: 6px; padding: 9px; }

/* App */
#app { height: 100%; display: flex; flex-direction: column; }
header {
  display: flex; gap: 8px; align-items: center; padding: 10px 16px;
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-right: 8px; }
#search { flex: 1; min-width: 80px; max-width: 420px; margin-right: auto; }
.pill { border-radius: 999px; font-size: 12.5px; color: var(--muted); }
.pill.warn { background: var(--warn-bg); color: var(--warn-text); border-color: transparent; }

.panes { flex: 1; display: flex; min-height: 0; }
#list { width: 300px; flex-shrink: 0; overflow-y: auto; border-right: 1px solid var(--line); padding: 8px; }
#list button {
  display: block; width: 100%; text-align: left; border: 0; background: none;
  padding: 8px 10px; border-radius: 8px; overflow: hidden;
}
#list button:hover { background: var(--hover); }
#list button.selected { background: var(--sel); }
#list .t { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
#list .u { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
#list .empty { padding: 16px 10px; color: var(--muted); }

#detail { flex: 1; overflow-y: auto; padding: 24px 28px; min-width: 0; }
#detail .inner { max-width: 560px; }
#detail .placeholder { color: var(--muted); margin-top: 20vh; text-align: center; }
.title-row { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.title-row h2 { flex: 1; margin: 0; overflow-wrap: anywhere; }
.field { padding: 12px 0; border-bottom: 1px solid var(--line); }
.field .k { font-size: 12.5px; color: var(--muted); }
.field .row { display: flex; align-items: center; gap: 8px; }
.field .v { flex: 1; overflow-wrap: anywhere; white-space: pre-wrap; min-width: 0; }
.field a { color: var(--accent); }
.stamp { margin-top: 14px; }

.input-row { display: flex; gap: 6px; margin-top: 4px; }
.input-row input { margin: 0; }
.gen { margin-top: 8px; padding: 10px 12px; border: 1px dashed var(--line); border-radius: 8px; font-size: 12.5px; color: var(--muted);
  display: flex; flex-wrap: wrap; gap: 6px 14px; align-items: center; }
.gen label { margin: 0; display: flex; align-items: center; gap: 5px; }
.gen input[type=number] { width: 64px; padding: 3px 6px; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; }

dialog { max-height: calc(100vh - 32px); overflow-y: auto; }
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(0, 0, 0, .45); }
dialog form button { margin-top: 10px; }
.dialog-actions { display: flex; justify-content: flex-end; margin-top: 20px; }
#sync-info { overflow-wrap: anywhere; }

#toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 999px; font-size: 13px;
}

@media (max-width: 700px) {
  header { flex-wrap: wrap; }
  #search { order: 10; flex-basis: 100%; max-width: none; }
  .brand { margin-right: auto; }
  .panes { flex-direction: column; }
  #list { width: auto; max-height: 38vh; border-right: 0; border-bottom: 1px solid var(--line); }
  #detail { padding: 16px; }
}
