/* KA Admin — self-contained UI */
:root {
  --bg: #0f0f10;
  --surface: #17181a;
  --surface-2: #1f2023;
  --border: #2a2c30;
  --border-focus: #c9a227;
  --text: #e8e6e1;
  --muted: #9a9a9a;
  --dim: #5c5550;
  --gold: #c9a227;
  --gold-soft: rgba(201, 162, 39, 0.12);
  --ok: #3fb950;
  --danger: #e5534b;
  --radius: 8px;
  --radius-lg: 12px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "JetBrains Mono", Menlo, monospace;
  --bottom-nav-h: 64px;
  --app-bar-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; scrollbar-width: none; }
html::-webkit-scrollbar { display: none; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  min-height: 100%;
}
a { color: inherit; }
p { margin: 0; }

/* ── Utilities ───────────────────────────────────────── */
.muted    { color: var(--muted); }
.dim      { color: var(--dim); }
.ta-right { text-align: right; }
.link     { color: var(--gold); text-decoration: none; font-weight: 500; }
.link:hover { text-decoration: underline; }
.mono     { font-family: var(--font-mono); font-size: 12px; }

/* ════════════════════════════════════════════════════════
   DESKTOP LAYOUT  (≥ 769px)
   ════════════════════════════════════════════════════════ */
.admin {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

/* ── Sidebar (desktop only) ──────────────────────────── */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 24px 12px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow: hidden;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 15px;
  letter-spacing: .02em;
  margin-bottom: 28px;
  padding: 0 8px;
}
.sidebar__logo {
  display: grid;
  place-items: center;
  width: 32px; height: 32px;
  border-radius: 7px;
  background: var(--gold);
  color: #1a1a1a;
  font-weight: 800;
  font-size: 13px;
  flex-shrink: 0;
}
.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.nav-link {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover  { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--gold-soft); color: var(--gold); }
.sidebar__foot {
  margin-top: auto;
  padding: 16px 8px 0;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.sidebar__user {
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Content area (desktop) ──────────────────────────── */
.content {
  padding: 32px 40px;
  min-width: 0;
}

/* ── Page header (desktop) ───────────────────────────── */
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  padding-bottom: 20px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}
.page-head h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}

/* ── Bottom nav (hidden on desktop) ─────────────────── */
.bottom-nav { display: none; }

/* ════════════════════════════════════════════════════════
   SHARED COMPONENTS
   ════════════════════════════════════════════════════════ */

/* ── Stat cards ──────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 28px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px 22px;
  text-decoration: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  transition: border-color .15s;
}
.stat-card:hover { border-color: var(--gold); }
.stat-card__num {
  font-size: 32px;
  font-weight: 700;
  color: var(--gold);
  line-height: 1;
  letter-spacing: -.02em;
}
.stat-card__label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
}

/* ── Panel ───────────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  margin-bottom: 24px;
}
.panel__head {
  padding: 16px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.panel__head h2 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

/* ── Table ───────────────────────────────────────────── */
.table { width: 100%; border-collapse: collapse; }
.table th {
  padding: 10px 20px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--dim);
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 13px 20px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 13.5px;
  vertical-align: middle;
}
.table tbody tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: var(--surface-2); }
.table__empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 20px;
  font-size: 13px;
}

/* ── Badges ──────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge--ok    { background: rgba(63,185,80,.12); color: var(--ok); }
.badge--muted { background: var(--surface-2); color: var(--muted); }

/* ── Buttons ─────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  min-height: 38px;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  line-height: 1;
}
.btn--primary { background: var(--gold); color: #111; border-color: var(--gold); }
.btn--primary:hover { opacity: .88; }
.btn--ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn--ghost:hover { border-color: var(--muted); }
.btn--danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn--danger:hover { background: var(--danger); color: #fff; }
.btn--sm { padding: 6px 12px; font-size: 12.5px; min-height: 32px; }
.btn--block { width: 100%; }

/* ── Form fields ─────────────────────────────────────── */
.field {
  display: flex;
  flex-direction: column;
  gap: 7px;
  margin-bottom: 18px;
}
.field:last-child { margin-bottom: 0; }
.field > span {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}
.field input,
.field select,
.field textarea {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-family: inherit;
  font-size: 14px;
  width: 100%;
  line-height: 1.5;
  min-height: 44px;
  transition: border-color .15s, box-shadow .15s;
  appearance: none;
  -webkit-appearance: none;
}
.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(201,162,39,.1);
}
.field select { cursor: pointer; }
.field textarea { resize: vertical; min-height: 100px; }
.field__hint {
  font-size: 12px;
  color: var(--dim);
  line-height: 1.5;
}
.field__pw-wrap { position: relative; }
.field__pw-wrap input { padding-right: 44px; }
.field__pw-toggle {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: 44px;
  background: none;
  border: none;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color .15s;
}
.field__pw-toggle:hover { color: var(--text); }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; }
.form-grid--full { grid-column: 1 / -1; }
.form-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

/* ── Card ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
}
.card:last-child { margin-bottom: 0; }
.card__title {
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 20px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

/* ── Flash ───────────────────────────────────────────── */
.flash {
  padding: 13px 16px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  font-size: 13.5px;
  line-height: 1.5;
}
.flash--success { background: rgba(63,185,80,.1);  color: var(--ok);     border: 1px solid rgba(63,185,80,.25); }
.flash--error   { background: rgba(229,83,75,.1);  color: var(--danger); border: 1px solid rgba(229,83,75,.25); }
.flash--info    { background: var(--gold-soft);    color: var(--gold);   border: 1px solid rgba(201,162,39,.25); }

/* ── Toolbar ─────────────────────────────────────────── */
.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 20px;
}
.toolbar input[type="search"],
.toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  min-height: 40px;
  transition: border-color .15s;
  appearance: none;
  -webkit-appearance: none;
}
.toolbar input[type="search"]:focus,
.toolbar select:focus { outline: none; border-color: var(--border-focus); }
.toolbar input[type="search"] { min-width: 200px; }

/* ── Pagination ──────────────────────────────────────── */
.pagination {
  display: flex;
  gap: 4px;
  margin-top: 20px;
  flex-wrap: wrap;
  align-items: center;
}
.pagination a,
.pagination span {
  padding: 7px 13px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  text-decoration: none;
  font-size: 13px;
  color: var(--text);
  min-height: 36px;
  display: inline-flex;
  align-items: center;
  transition: border-color .15s;
}
.pagination a:hover { border-color: var(--muted); }
.pagination .is-current { background: var(--gold); color: #111; border-color: var(--gold); font-weight: 600; }
.pagination .is-disabled { opacity: .3; pointer-events: none; }

/* ── Media grid ──────────────────────────────────────── */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 16px;
}
.media-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: border-color .15s;
}
.media-item:hover { border-color: var(--muted); }
.media-item__thumb {
  aspect-ratio: 1;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
}
.media-item__thumb img { width: 100%; height: 100%; object-fit: cover; }
.media-item__meta { padding: 10px 12px; font-size: 11.5px; flex: 1; }
.media-item__name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 500;
  margin-bottom: 2px;
}
.media-item__actions { padding: 0 10px 10px; }

/* ── Categories inline edit ──────────────────────────── */
.inline-edit { display: inline-block; position: relative; }
.inline-edit > summary { list-style: none; cursor: pointer; }
.inline-edit > summary::-webkit-details-marker { display: none; }
.inline-edit[open] > .card {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 20;
  min-width: 280px;
  box-shadow: 0 8px 32px rgba(0,0,0,.5);
}

/* ── Settings tabs ───────────────────────────────────── */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
  overflow-x: auto;
  scrollbar-width: none;
}
.tab-bar::-webkit-scrollbar { display: none; }
.tab-btn {
  flex-shrink: 0;
  padding: 10px 18px;
  border: none;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  margin-bottom: -1px;
  transition: color .15s, border-color .15s;
  white-space: nowrap;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.is-active { color: var(--gold); border-bottom-color: var(--gold); }
.tab-panel { display: none; }
.tab-panel.is-active { display: block; }

/* ── Login ───────────────────────────────────────────── */
.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  width: 100%;
  max-width: 360px;
}
.login-card__brand {
  font-size: 20px;
  font-weight: 800;
  text-align: center;
  color: var(--gold);
  letter-spacing: -.01em;
  margin-bottom: 4px;
}
.login-card__sub {
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 28px;
}
.login-card__back {
  display: block;
  text-align: center;
  margin-top: 18px;
  font-size: 12.5px;
  color: var(--dim);
  text-decoration: none;
  transition: color .15s;
}
.login-card__back:hover { color: var(--muted); }

/* ════════════════════════════════════════════════════════
   MOBILE  (≤ 768px)
   ════════════════════════════════════════════════════════ */
@media (max-width: 768px) {

  /* ── Layout: hide sidebar, single column ─────────── */
  .admin { display: block; }
  .sidebar { display: none; }

  /* ── Content: no outer padding (children handle it) ─ */
  .content {
    padding: 0;
    padding-bottom: calc(var(--bottom-nav-h) + 8px);
  }

  /* ── Flash: inline margin ────────────────────────── */
  .flash { margin: 12px 16px 0; }

  /* ── Page head → sticky app bar ──────────────────── */
  .page-head {
    position: sticky;
    top: 0;
    z-index: 50;
    background: rgba(15,15,16,.96);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--border);
    border-radius: 0;
    padding: 12px 16px;
    margin-bottom: 0;
    gap: 10px;
  }
  .page-head h1 { font-size: 17px; }
  .page-head .btn { padding: 7px 14px; font-size: 13px; min-height: 36px; }
  .page-head .btn--ghost { border-color: transparent; color: var(--gold); padding-left: 0; }

  /* ── Spacing: give content sections a consistent margin */
  .stat-grid,
  .panel,
  .toolbar,
  .tab-bar,
  .pagination,
  .media-grid,
  .form-row:not(.page-head .form-row) {
    margin: 16px 16px 0;
  }
  .content > form { margin: 16px 16px 0; }
  .tab-panel > form { margin: 16px 16px 0; }
  .content > .form-grid { margin: 16px 16px 0; }
  .content > .card { margin: 16px 16px 0; }
  .content > p.muted { margin: 16px; }

  /* ── Stat grid: 2×2 ──────────────────────────────── */
  .stat-grid {
    grid-template-columns: 1fr 1fr;
    gap: 10px;
  }
  .stat-card { padding: 16px; }
  .stat-card__num { font-size: 26px; }

  /* ── Panel: remove border radius on sides ────────── */
  .panel { border-radius: var(--radius); }

  /* ── Table → stacked card rows ───────────────────── */
  .table { display: block; }
  .table thead { display: none; }
  .table tbody { display: flex; flex-direction: column; }
  .table tbody tr {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
  }
  .table tbody tr:last-child { border-bottom: none; }
  .table td {
    display: block;
    padding: 0;
    border: none;
    font-size: 13.5px;
  }
  /* Field labels via data-label on each td */
  .table td[data-label]::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--dim);
    margin-bottom: 3px;
  }
  /* Hide empty action cell label, keep action row aligned */
  .table td.ta-right {
    text-align: left;
    margin-top: 6px;
  }
  .table td.ta-right[data-label]::before { display: none; }
  /* Slug/meta row */
  .table td .mono { font-size: 11px; }
  /* Table empty state */
  .table__empty { padding: 32px 16px; }

  /* ── Cards ───────────────────────────────────────── */
  .card { border-radius: var(--radius); padding: 18px; margin-bottom: 0; }
  .content > form .card,
  .tab-panel > form .card { margin-bottom: 12px; }

  /* ── Form grid: single column ────────────────────── */
  .form-grid { grid-template-columns: 1fr; gap: 0; }
  .form-grid--full { grid-column: auto; }

  /* ── Fields: full-width touch targets ────────────── */
  .field input,
  .field select,
  .field textarea { font-size: 16px; /* prevent iOS zoom */ }

  /* ── Toolbar: scrollable row ─────────────────────── */
  .toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    padding-bottom: 2px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .toolbar::-webkit-scrollbar { display: none; }
  .toolbar input[type="search"] { min-width: 160px; }

  /* ── Media grid: smaller thumbnails ─────────────── */
  .media-grid {
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
  }

  /* ── Categories layout: single column ───────────── */
  .content > .form-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  .content > .form-grid .panel { grid-column: auto; }
  .content > .form-grid .card { grid-column: auto; }

  /* ── Inline edit: full width on mobile ───────────── */
  .inline-edit { display: block; width: 100%; }
  .inline-edit > summary { width: 100%; }
  .inline-edit[open] > .card {
    position: static;
    box-shadow: none;
    margin-top: 8px;
  }

  /* ── Action buttons in table rows ────────────────── */
  .table td > div[style*="display:flex"] {
    gap: 8px;
  }
  .table td .btn--sm {
    padding: 8px 14px;
    min-height: 36px;
    font-size: 13px;
  }

  /* ── Bottom nav ──────────────────────────────────── */
  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--bottom-nav-h);
    background: rgba(23,24,26,.97);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .bottom-nav__item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    text-decoration: none;
    color: var(--dim);
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .04em;
    text-transform: uppercase;
    padding: 8px 4px;
    transition: color .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .bottom-nav__item:hover,
  .bottom-nav__item.is-active { color: var(--gold); }
  .bottom-nav__item svg { flex-shrink: 0; }

  /* ── Login page ──────────────────────────────────── */
  .login-body { padding: 20px; align-items: flex-start; padding-top: 60px; }
  .login-card { padding: 28px 24px; }

} /* end @media mobile */

/* ── Small desktop / tablet sidebar ─────────────────── */
@media (min-width: 769px) and (max-width: 1024px) {
  .admin { grid-template-columns: 200px 1fr; }
  .content { padding: 28px 28px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
}
