/* ============================================================
   Admin panel — minimal, quietly aesthetic, theme-aware.
   Self-contained: no icon font, no CSS framework. Icons are
   inline SVG (see ic() in app.js), so they always render.
   ============================================================ */

:root,
html[data-theme="light"] {
  --bg:          #fbfbfa;
  --bg-soft:     #f4f4f2;
  --card:        #ffffff;
  --sidebar:     #f7f7f5;
  --text:        #1c1c1a;
  --text-2:      #5c5c56;
  --muted:       #8f8f88;
  --line:        #e6e6e2;
  --line-strong: #d6d6d1;
  --accent:      #0969da;
  --accent-soft: #e8f1fd;
  --danger:      #c92a2a;
  --danger-soft: #fdecec;
  --success:     #1a7f37;
  --success-soft:#e7f6ec;
  --ring:        rgba(9, 105, 218, .16);
  --shadow-sm:   0 1px 2px rgba(20, 20, 18, .05);
  --shadow-md:   0 4px 16px rgba(20, 20, 18, .07);
}
html[data-theme="dark"] {
  --bg:          #0d1117;
  --bg-soft:     #161b22;
  --card:        #12171f;
  --sidebar:     #0f141b;
  --text:        #e6edf3;
  --text-2:      #9aa4b1;
  --muted:       #6e7681;
  --line:        #262d38;
  --line-strong: #333c48;
  --accent:      #58a6ff;
  --accent-soft: #16273f;
  --danger:      #f87171;
  --danger-soft: #2c1618;
  --success:     #3fb950;
  --success-soft:#12281a;
  --ring:        rgba(88, 166, 255, .18);
  --shadow-sm:   0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md:   0 4px 16px rgba(0, 0, 0, .4);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Source Sans 3", -apple-system, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: .84em;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  padding: .05em .35em;
  border-radius: 5px;
}
.boot { padding: 4rem; text-align: center; color: var(--muted); }

/* ---------- Icons (inline SVG) ---------- */
.ic { width: 16px; height: 16px; flex: 0 0 auto; display: inline-block; vertical-align: -3px; }
.ic-lg { width: 18px; height: 18px; }
.spin { animation: spin 1s linear infinite; transform-origin: 50% 50%; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-size: .875rem; font-weight: 600; line-height: 1;
  padding: .55rem .85rem; border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--card); color: var(--text);
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s;
  box-shadow: var(--shadow-sm);
}
.btn:hover { background: var(--bg-soft); border-color: var(--muted); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn:disabled { opacity: .4; cursor: not-allowed; box-shadow: none; }
.btn:disabled:hover { background: var(--card); border-color: var(--line-strong); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent); border-color: var(--accent); filter: brightness(1.08); }

/* Delete: always clearly visible (never a transparent icon-only button). */
.btn-danger { color: var(--danger); border-color: var(--danger); background: var(--card); }
.btn-danger:hover { background: var(--danger-soft); border-color: var(--danger); color: var(--danger); }

.btn-sm { padding: .38rem .6rem; font-size: .8rem; border-radius: 7px; }
.btn-icon { padding: .38rem; width: 30px; }
.btn-ghost { border-color: transparent; background: transparent; box-shadow: none; }
.btn-ghost:hover { background: var(--bg-soft); border-color: var(--line); }

/* ---------- Auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1.5rem; background: var(--bg-soft); }
.auth-card {
  width: 100%; max-width: 430px; background: var(--card);
  border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow-md); padding: 2rem 1.75rem;
}
.auth-logo { font-size: 1.75rem; line-height: 1; }
.auth-card h1 { font-size: 1.3rem; margin: .6rem 0 .3rem; letter-spacing: -.01em; }
.auth-sub { color: var(--text-2); font-size: .9rem; margin: 0 0 1.4rem; }
#err:not(:empty) {
  color: var(--danger); font-size: .85rem; margin-top: .85rem;
  background: var(--danger-soft); border: 1px solid var(--danger); border-radius: 8px; padding: .5rem .7rem;
}

details.help {
  margin: 1.1rem 0; border: 1px solid var(--line); border-radius: 10px;
  background: var(--bg-soft); padding: .1rem .8rem;
}
details.help summary {
  cursor: pointer; font-weight: 600; font-size: .86rem; padding: .6rem 0;
  display: flex; align-items: center; gap: .45rem; list-style: none;
}
details.help summary::-webkit-details-marker { display: none; }
details.help ol { margin: .2rem 0 .8rem; padding-left: 1.2rem; font-size: .85rem; color: var(--text-2); }
details.help li { margin: .35rem 0; }

.radio-row { display: flex; flex-direction: column; gap: .55rem; }
.radio-row label {
  display: flex; gap: .6rem; align-items: flex-start; font-size: .875rem; cursor: pointer;
  border: 1px solid var(--line); border-radius: 9px; padding: .6rem .7rem;
  transition: border-color .15s, background .15s;
}
.radio-row label:hover { border-color: var(--line-strong); background: var(--bg-soft); }
.radio-row label:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.radio-row input { margin-top: .28rem; accent-color: var(--accent); }
.radio-row small { display: block; color: var(--muted); font-weight: 400; font-size: .78rem; line-height: 1.45; }

/* ---------- Form controls ---------- */
label.lbl {
  display: block; font-weight: 600; font-size: .78rem; letter-spacing: .01em;
  margin-bottom: .35rem; color: var(--text-2);
}
input[type=text], input[type=password], input[type=email], input[type=url],
input[type=date], input[type=number], input[type=file], select, textarea {
  width: 100%; font: inherit; font-size: .9rem;
  padding: .55rem .7rem; border-radius: 8px;
  border: 1px solid var(--line-strong);
  background: var(--card); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring);
}
input[type=file] { padding: .45rem; font-size: .84rem; color: var(--text-2); }
textarea {
  resize: vertical; min-height: 80px; line-height: 1.6;
  font-family: "JetBrains Mono", ui-monospace, monospace; font-size: .82rem;
}
.field { margin-bottom: 1rem; }
.field:last-child { margin-bottom: 0; }
.field-hint { font-size: .78rem; color: var(--muted); margin-top: .3rem; line-height: 1.5; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
@media (max-width: 700px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Shell ---------- */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--sidebar);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 1.15rem 1.15rem .9rem; font-weight: 700; font-size: 1rem;
  letter-spacing: -.01em; display: flex; align-items: center; gap: .5rem;
}
.brand small { display: block; font-weight: 400; font-size: .7rem; color: var(--muted); letter-spacing: 0; }

.nav { flex: 1; overflow-y: auto; padding: .3rem .6rem; }
.nav button {
  display: flex; align-items: center; gap: .65rem; width: 100%;
  padding: .55rem .65rem; margin-bottom: 2px; border: none; border-radius: 8px;
  background: transparent; color: var(--text-2);
  font: inherit; font-size: .885rem; font-weight: 500;
  cursor: pointer; text-align: left;
  transition: background .12s, color .12s;
}
.nav button .ic { color: var(--muted); transition: color .12s; }
.nav button:hover { background: var(--bg-soft); color: var(--text); }
.nav button:hover .ic { color: var(--text-2); }
.nav button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav button.active .ic { color: var(--accent); }

.sidebar-foot { padding: .85rem; border-top: 1px solid var(--line); }
.who { display: flex; align-items: center; gap: .6rem; margin-bottom: .7rem; min-width: 0; }
.who img { width: 30px; height: 30px; border-radius: 50%; flex: 0 0 auto; background: var(--bg-soft); }
.who div { min-width: 0; }
.who b { display: block; font-size: .84rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.who span { color: var(--muted); font-size: .74rem; }
.foot-actions { display: flex; gap: .35rem; }

.content { flex: 1; min-width: 0; padding: 0 2rem 5rem; }

/* ---------- Page header (sticky) ---------- */
.page-head {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem;
  padding: 1.6rem 0 1.1rem; margin-bottom: 1.25rem;
  background: var(--bg); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.page-head h2 { margin: 0; font-size: 1.4rem; letter-spacing: -.015em; }
.page-head p { margin: .3rem 0 0; color: var(--text-2); font-size: .875rem; max-width: 62ch; }
.head-actions { display: flex; gap: .5rem; align-items: center; flex-shrink: 0; }

.pill-dirty {
  font-size: .74rem; font-weight: 600; color: var(--danger);
  background: var(--danger-soft); border: 1px solid var(--danger);
  padding: .25rem .55rem; border-radius: 20px; white-space: nowrap;
}
.pill-dirty[hidden] { display: none; }

/* ---------- Cards & items ---------- */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.2rem; margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}
.card > b { font-size: .95rem; display: flex; align-items: center; gap: .45rem; }

.item {
  background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 1.1rem 1.2rem; margin-bottom: .85rem;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s, box-shadow .15s;
}
.item:hover { border-color: var(--line-strong); box-shadow: var(--shadow-md); }
.item-head {
  display: flex; align-items: center; justify-content: space-between; gap: .75rem;
  padding-bottom: .8rem; margin-bottom: .9rem; border-bottom: 1px solid var(--line);
}
.item-head > b, .item-head > div:first-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.item-head b { font-size: .92rem; }
.grip {
  color: var(--muted); font-size: .74rem; font-weight: 600;
  font-family: "JetBrains Mono", monospace;
  background: var(--bg-soft); border: 1px solid var(--line);
  padding: .1rem .4rem; border-radius: 5px;
}
.item-tools { display: flex; gap: .35rem; align-items: center; flex-shrink: 0; }
.row-inline { display: flex; gap: .6rem; align-items: center; }

.chips { display: flex; flex-wrap: wrap; gap: .45rem; }

.empty {
  text-align: center; padding: 3rem 1rem; color: var(--muted);
  border: 1px dashed var(--line-strong); border-radius: 12px; background: var(--card);
}
.empty .ic { width: 26px; height: 26px; opacity: .5; margin-bottom: .5rem; }
.empty p { margin: .4rem 0 0; font-size: .9rem; }
.loading { padding: 3rem; text-align: center; color: var(--muted); display: flex; align-items: center; justify-content: center; gap: .5rem; }

/* ---------- Dashboard ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: .85rem; margin-bottom: 1rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: .9rem 1rem; box-shadow: var(--shadow-sm); }
.stat .k { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; font-weight: 600; }
.stat .v { font-size: 1.05rem; font-weight: 700; margin-top: .3rem; word-break: break-word; letter-spacing: -.01em; }

.banner {
  display: flex; gap: .6rem; align-items: flex-start;
  border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1.1rem;
  font-size: .865rem; color: var(--text-2);
  border: 1px solid var(--line); background: var(--card);
}
.banner .ic { color: var(--accent); margin-top: .15rem; }

/* ---------- Uploads ---------- */
.upload-box {
  border: 1px dashed var(--line-strong); border-radius: 10px;
  padding: 1.2rem; text-align: center; margin-top: .8rem; background: var(--bg-soft);
}
.upload-box img {
  max-width: 150px; max-height: 150px; border-radius: 10px;
  margin: 0 auto .8rem; display: block; border: 1px solid var(--line);
}
.upload-box input[type=file] { margin-bottom: .7rem; background: var(--card); }

/* ---------- Toast ---------- */
#toast-host { position: fixed; bottom: 1.2rem; right: 1.2rem; display: flex; flex-direction: column; gap: .5rem; z-index: 9999; }
.toast {
  background: var(--card); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: 9px;
  padding: .75rem 1rem; box-shadow: var(--shadow-md); font-size: .865rem;
  max-width: 340px; animation: slidein .22s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
@keyframes slidein { from { transform: translateY(10px); opacity: 0; } }

/* ---------- Mobile ---------- */
.topbar { display: none; }
.menu-btn { display: none; }
.backdrop { display: none; }
@media (max-width: 860px) {
  .sidebar {
    position: fixed; z-index: 60; left: 0; top: 0; height: 100vh; width: 250px;
    transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--shadow-md);
  }
  .sidebar.open { transform: translateX(0); }
  .backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 50; }
  .backdrop.show { display: block; }
  .content { padding: 0 1.1rem 5rem; }
  .topbar {
    display: flex; align-items: center; gap: .6rem;
    padding: .75rem 0; position: sticky; top: 0; z-index: 30;
    background: var(--bg); border-bottom: 1px solid var(--line);
  }
  .menu-btn { display: inline-flex; }
  .page-head { position: static; padding-top: 1.2rem; }
  .head-actions { width: 100%; }
  .item-tools { flex-wrap: wrap; }
}
