:root {
  --bg: #1c1350;
  --bg-2: #2a1d78;
  --panel: rgba(28, 19, 80, 0.72);
  --stroke: rgba(255, 255, 255, 0.14);
  --text: #ffffff;
  --muted: #c9c0e8;
  --gold: #e8c15a;
  --on-gold: #241a5c;
  --error: #ff8a80;
  --ok: #8fd9a8;
  --radius: 16px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  font: 15px/1.5 system-ui, -apple-system, 'Segoe UI', sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 80% -10%, #5a2db5 0%, transparent 60%),
    linear-gradient(180deg, var(--bg-2), var(--bg));
  background-attachment: fixed;
}

[hidden] { display: none !important; }

.wordmark {
  font-family: 'Reem Kufi', serif;
  color: var(--gold);
  letter-spacing: 0.04em;
  font-size: 22px;
  margin: 0;
}
.wordmark span { color: var(--muted); font-family: system-ui, sans-serif; font-size: 14px; font-weight: 500; }

.card {
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--radius);
  padding: 20px;
  backdrop-filter: blur(16px);
}

.login { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { width: min(380px, 100%); display: grid; gap: 14px; }

label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }

input, select, textarea {
  font: inherit;
  color: var(--text);
  background: rgba(0, 0, 0, 0.22);
  border: 1px solid var(--stroke);
  border-radius: 10px;
  padding: 9px 12px;
  min-width: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--gold); outline-offset: 1px; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 999px;
  padding: 7px 14px;
  border: 1px solid var(--stroke);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  white-space: nowrap;
}
button:hover { background: rgba(255, 255, 255, 0.12); }
button:disabled { opacity: 0.5; cursor: default; }
button.primary { background: var(--gold); color: var(--on-gold); border-color: var(--gold); font-weight: 600; }
button.danger { color: var(--error); border-color: rgba(255, 138, 128, 0.4); }
button.ghost { background: none; }

.error { color: var(--error); margin: 0; min-height: 1.2em; font-size: 13px; }

.shell { max-width: 1180px; margin: 0 auto; padding: 0 16px 48px; }

.topbar {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 14px 0;
  background: linear-gradient(180deg, var(--bg-2) 70%, transparent);
}
#tabs { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
#tabs button[aria-current='page'] { background: var(--gold); color: var(--on-gold); border-color: var(--gold); }

.view { display: grid; gap: 16px; }

.toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar input[type='search'] { flex: 1; min-width: 180px; }
.toolbar h2 { margin: 0 auto 0 0; font-size: 20px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat strong { display: block; font-size: 30px; color: var(--gold); font-variant-numeric: tabular-nums; }
.stat span { color: var(--muted); font-size: 13px; }

.list { display: grid; gap: 10px; }
.row {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 14px;
  align-items: center;
}
.row img, .thumb {
  width: 64px; height: 80px; object-fit: cover;
  border-radius: 10px; background: rgba(0, 0, 0, 0.3);
}
.row.plain { grid-template-columns: 1fr auto; }
.thumb { display: grid; place-items: center; font: 600 26px 'Reem Kufi', serif; color: var(--gold); }
.row .main { min-width: 0; }
.row .title { font-weight: 600; overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 13px; overflow-wrap: anywhere; }
.row .actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

.badge {
  display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px;
  border: 1px solid var(--stroke); color: var(--muted); margin-inline-start: 6px; vertical-align: 1px;
}
.badge.gold { color: var(--gold); border-color: rgba(232, 193, 90, 0.5); }
.badge.bad { color: var(--error); border-color: rgba(255, 138, 128, 0.5); }
.badge.ok { color: var(--ok); border-color: rgba(143, 217, 168, 0.5); }

.empty { color: var(--muted); text-align: center; padding: 32px; }

dialog {
  color: var(--text); background: var(--bg-2);
  border: 1px solid var(--stroke); border-radius: var(--radius);
  width: min(440px, calc(100vw - 32px)); padding: 20px;
}
dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
dialog form { display: grid; gap: 12px; }
dialog h3 { margin: 0; }
dialog .buttons { display: flex; gap: 8px; justify-content: flex-end; }

.toast {
  position: fixed; inset-inline: 16px; bottom: 20px; margin: 0 auto; width: fit-content; max-width: calc(100% - 32px);
  background: var(--gold); color: var(--on-gold); font-weight: 600;
  padding: 10px 18px; border-radius: 999px; opacity: 0; transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: none; }
.toast.bad { background: var(--error); }

@media (max-width: 640px) {
  .topbar { position: static; justify-content: space-between; }
  #tabs { order: 3; flex: 1 0 100%; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .row { grid-template-columns: auto 1fr; }
  .row.plain { grid-template-columns: 1fr; }
  .row .actions { grid-column: 1 / -1; justify-content: flex-start; }
}
