:root {
  --bg: #0f1115;
  --panel: #181b22;
  --panel-2: #20242e;
  --border: #2b303b;
  --text: #e7e9ee;
  --muted: #9aa3b2;
  --accent: #4f8cff;
  --accent-hover: #3f7bef;
  --danger: #ff5c5c;
  --ok: #48c78e;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

/* The `hidden` attribute must win over any explicit `display` rule below
   (e.g. .modal-backdrop { display: grid }) — otherwise a hidden overlay stays
   laid out and swallows every click. */
[hidden] { display: none !important; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

.muted { color: var(--muted); }
.req { color: var(--accent); font-size: 0.85em; }

/* ---- login ---- */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
}
.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: min(360px, 90vw);
}
.login-card h1 { margin: 0 0 0.25rem; font-size: 1.4rem; }
.login-card form { display: grid; gap: 0.9rem; margin-top: 1.25rem; }
.login-card label { display: grid; gap: 0.35rem; font-size: 0.9rem; }

input, textarea, select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.6rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
  width: 100%;
}
input:focus, textarea:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
textarea { resize: vertical; }
select { cursor: pointer; }

button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1rem;
  font-size: 0.95rem;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent-hover); }
button:disabled { opacity: 0.45; cursor: not-allowed; }

.link-btn {
  background: none;
  color: var(--accent);
  padding: 0;
  font-size: inherit;
}
.link-btn:hover { background: none; text-decoration: underline; }

button.secondary {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}
button.secondary:hover:not(:disabled) { background: var(--border); }

.error { color: var(--danger); font-size: 0.88rem; margin: 0; }

/* ---- app shell ---- */
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.9rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}
.brand { font-weight: 600; }
.user { display: flex; align-items: center; gap: 0.9rem; }

.app {
  max-width: 720px;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: grid;
  gap: 1.25rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
}
.panel h2 { margin: 0 0 0.85rem; font-size: 1.05rem; }

/* ---- dropzone ---- */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 1.5rem;
  text-align: center;
  transition: border-color 0.15s, background 0.15s;
}
.dropzone.dragover { border-color: var(--accent); background: var(--panel-2); }

/* ---- fields ---- */
.field { display: grid; gap: 0.35rem; margin-top: 1rem; }
.key-preview { font-family: var(--mono); font-size: 0.82rem; word-break: break-all; }

.controls { display: flex; gap: 0.6rem; margin-top: 1.1rem; }

/* ---- progress ---- */
#progress-section { margin-top: 1.25rem; }
.progress-outer {
  background: var(--panel-2);
  border-radius: 999px;
  height: 12px;
  overflow: hidden;
}
.progress-inner {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s;
}
.progress-stats {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
  margin-top: 0.5rem;
}

.banner {
  margin-top: 1rem;
  padding: 0.7rem 0.9rem;
  border-radius: 8px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  font-size: 0.88rem;
}
.banner.warn { border-color: #7a5c1a; background: #2a230f; }
.banner.ok { border-color: #1f5c42; background: #10241c; }

/* ---- pending list ---- */
.pending-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.5rem; }
.pending-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
}
.pending-item .meta { display: grid; gap: 0.1rem; cursor: pointer; flex: 1; }
.pending-item .id { font-weight: 600; }
.pending-item .sub { font-size: 0.8rem; color: var(--muted); }
.discard-btn {
  background: none;
  color: var(--danger);
  border: 1px solid var(--border);
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}
.discard-btn:hover { background: var(--danger); color: #fff; }

/* ---- log ---- */
.log {
  font-family: var(--mono);
  font-size: 0.8rem;
  background: #0b0d11;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.8rem;
  margin: 0;
  max-height: 260px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ---- modal ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: grid;
  place-items: center;
  z-index: 10;
}
.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.5rem;
  width: min(440px, 90vw);
}
.modal h3 { margin: 0 0 0.6rem; }
.modal p { margin: 0 0 1.25rem; color: var(--muted); }
.modal-actions { display: flex; gap: 0.6rem; justify-content: flex-end; flex-wrap: wrap; }
.modal-actions .secondary {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--text);
}
.modal-actions .secondary:hover { background: var(--border); }
.modal-actions .danger { background: var(--danger); }
.modal-actions .danger:hover { background: #e04a4a; }
