:root {
  --bg: #0f1419;
  --surface: #1a222d;
  --surface-2: #232d3b;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f3f4f6;
  --muted: #9ca3af;
  --accent: #2f4f4a;
  --accent-hover: #3d6b63;
  --gold: #c4a574;
  --danger: #ef4444;
  --radius: 12px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); background: var(--bg); color: var(--text); line-height: 1.5; }
button, input, select, textarea { font: inherit; }
a { color: var(--gold); }

.login-screen {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
}
.login-screen.is-hidden,
.login-screen[hidden] {
  display: none !important;
}
.admin-app.is-hidden,
.admin-app[hidden] {
  display: none !important;
}
body.admin-mode .login-screen {
  display: none !important;
}
body.admin-mode .admin-app {
  display: grid !important;
}
.login-card {
  width: min(100%, 400px); background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 32px; display: flex; flex-direction: column; gap: 16px;
}
.login-card h1 { font-size: 24px; }
.login-card p { color: var(--muted); font-size: 14px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.login-card input,
.login-card select {
  padding: 12px 14px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text);
}
.sidebar__role {
  font-size: 12px; color: var(--muted); padding: 0 12px 16px; margin-top: -12px;
}
.error { color: #fca5a5; font-size: 14px; background: rgba(239, 68, 68, 0.12); padding: 10px 12px; border-radius: 8px; border: 1px solid rgba(239, 68, 68, 0.35); }
.error code { color: #fecaca; }
.error a { color: #fde68a; }
#login-form[data-loading="1"] { opacity: 0.85; pointer-events: none; }
.btn:disabled { opacity: 0.6; cursor: wait; }

.admin-app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 20px 12px;
}
.sidebar__brand { font-weight: 700; font-size: 18px; padding: 8px 12px 24px; color: var(--gold); }
.sidebar__nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  text-align: left; padding: 10px 14px; border: none; border-radius: 8px;
  background: none; color: var(--muted); cursor: pointer; font-weight: 500;
}
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active { background: var(--accent); color: #fff; }
.sidebar__footer { display: flex; flex-direction: column; gap: 10px; padding: 12px; }
.link-muted { color: var(--muted); font-size: 13px; text-decoration: none; }
.link-muted:hover { color: var(--text); }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 28px; border-bottom: 1px solid var(--border); background: var(--surface);
  position: sticky; top: 0; z-index: 10;
}
.topbar h2 { font-size: 20px; font-weight: 600; }
.topbar__actions { display: flex; align-items: center; gap: 12px; }
.save-status { font-size: 13px; color: var(--muted); }

.tab-panel { display: none; padding: 24px 28px 48px; overflow: auto; }
.tab-panel.is-active { display: block; }

.panel-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 16px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px;
}
.card h3 { font-size: 15px; margin-bottom: 16px; color: var(--gold); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12px; color: var(--muted); font-weight: 500; }
.field input, .field textarea, .field select {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); width: 100%;
}
.field textarea { min-height: 80px; resize: vertical; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface-2); color: var(--text); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background 0.2s;
}
.btn:hover { background: #2d3748; }
.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; }
.btn--danger { background: rgba(239, 68, 68, 0.15); border-color: var(--danger); color: #fca5a5; }
.btn--sm { padding: 6px 12px; font-size: 12px; }

.table-wrap { overflow: auto; border: 1px solid var(--border); border-radius: var(--radius); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); color: var(--muted); font-size: 12px; font-weight: 600; }
tr:hover td { background: rgba(255,255,255,0.02); }
.thumb { width: 48px; height: 36px; object-fit: contain; background: var(--surface-2); border-radius: 6px; }

.toolbar { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; align-items: center; }
.toolbar input[type="search"] {
  flex: 1; min-width: 200px; padding: 10px 14px; border-radius: 999px;
  border: 1px solid var(--border); background: var(--surface-2); color: var(--text);
}

.banner-item {
  display: grid; grid-template-columns: 200px 1fr auto; gap: 16px; align-items: start;
  padding: 16px; border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 12px;
}
.banner-item img { width: 200px; aspect-ratio: 1140/380; object-fit: cover; border-radius: 8px; background: var(--surface-2); }

.upload-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.upload-preview { max-width: 120px; max-height: 80px; border-radius: 8px; }

.price-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 16px; }
.hint { font-size: 13px; color: var(--muted); margin-top: 8px; line-height: 1.6; }

.modal[hidden] { display: none; }
.modal {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
}
.modal__backdrop { position: absolute; inset: 0; background: rgba(0,0,0,0.6); }
.modal__dialog {
  position: relative; width: min(100%, 640px); max-height: 90vh; overflow: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 24px;
}
.modal__close {
  position: absolute; top: 12px; right: 12px; width: 32px; height: 32px;
  border: none; border-radius: 50%; background: var(--surface-2); color: var(--text); cursor: pointer;
}

.toast {
  position: fixed; bottom: 24px; right: 24px; background: var(--accent); color: #fff;
  padding: 12px 18px; border-radius: 999px; font-size: 14px; opacity: 0; transform: translateY(20px);
  transition: all 0.3s; z-index: 200; pointer-events: none;
}
.toast.is-visible { opacity: 1; transform: translateY(0); }

.tier-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }

.badge {
  display: inline-block; font-size: 12px; padding: 2px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted);
}
.badge--ok { background: rgba(34, 197, 94, 0.15); color: #22c55e; }
.badge--err { background: rgba(239, 68, 68, 0.15); color: #ef4444; }

@media (max-width: 900px) {
  .admin-app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; flex-wrap: wrap; }
  .sidebar__nav { flex-direction: row; flex-wrap: wrap; flex: none; }
  .banner-item { grid-template-columns: 1fr; }
}