/* ── Xpress Key Admin · refined styles ──────────────────────────────── */
:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #f8fafc;
  --border: #e3e8ef;
  --border-strong: #d1d8e0;
  --ink: #0f172a;
  --ink-2: #475569;
  --ink-3: #94a3b8;
  --primary: #1565C0;
  --primary-2: #0d47a1;
  --primary-soft: #e6f0fb;
  --accent: #22A06B;
  --accent-soft: #e3f5ec;
  --warn: #f59e0b;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.04);
  --shadow:    0 1px 3px rgba(15,23,42,.06), 0 4px 14px rgba(15,23,42,.04);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.08), 0 2px 6px rgba(15,23,42,.04);
  --radius: 14px;
  --radius-sm: 10px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: 'Poppins', system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

button { font-family: inherit; cursor: pointer; transition: all .15s ease; }
button:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder { color: var(--ink-3); }
input:hover:not(:focus) { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(21, 101, 192, .14);
}

label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  margin: 14px 0 6px;
  letter-spacing: .15px;
}

/* ── Brand ──────────────────────────────────────────────────────────── */
.brand {
  font-weight: 800;
  font-size: 19px;
  letter-spacing: -.4px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}
.brand-logo {
  width: 30px;
  height: 30px;
  object-fit: contain;
  flex-shrink: 0;
}
.brand-logo-lg { width: 56px; height: 56px; }
.brand-x { color: var(--ink); }
.brand-key { color: var(--primary); }
.brand small {
  font-weight: 700;
  color: var(--ink-3);
  margin-left: 6px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
}
.auth-brand {
  flex-direction: row;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
  font-size: 22px;
}
.auth-brand > div { line-height: 1.1; }

/* ── Buttons ────────────────────────────────────────────────────────── */
.primary {
  background: linear-gradient(180deg, var(--primary) 0%, #114a98 100%);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: .15px;
  box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, 0 2px 6px rgba(21,101,192,.25);
}
.primary:hover { transform: translateY(-1px); box-shadow: 0 1px 0 rgba(255,255,255,.15) inset, 0 6px 16px rgba(21,101,192,.32); }
.primary:active { transform: translateY(0); }
.primary:disabled { opacity: .55; cursor: not-allowed; transform: none; }

.ghost {
  background: var(--surface);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 14px;
  font-weight: 600;
  font-size: 13px;
}
.ghost:hover { background: var(--surface-2); border-color: var(--border-strong); color: var(--ink); }

.danger {
  background: var(--surface);
  color: var(--danger);
  border: 1px solid #f3c1c4;
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-weight: 600;
  font-size: 12px;
}
.danger:hover { background: var(--danger-soft); border-color: #e7a8ad; }

.icon-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  font-weight: 600;
  font-size: 12px;
  color: var(--ink-2);
}
.icon-btn:hover { background: var(--surface-2); color: var(--ink); }

/* ── Auth page ──────────────────────────────────────────────────────── */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background:
    radial-gradient(ellipse at top left,  rgba(21,101,192,.15), transparent 50%),
    radial-gradient(ellipse at bottom right, rgba(34,160,107,.12), transparent 50%),
    #f5f7fb;
}
.auth-card {
  background: var(--surface);
  border-radius: 20px;
  padding: 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  border: 1px solid rgba(255,255,255,.7);
  animation: fadeUp .35s ease both;
}
.auth-card .brand { margin-bottom: 24px; font-size: 22px; }
.auth-card form button {
  margin-top: 22px;
  width: 100%;
  padding: 13px;
  font-size: 14px;
}
@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: none; }
}

/* ── Top bar ────────────────────────────────────────────────────────── */
.topbar {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: saturate(180%) blur(8px);
}
.topbar-right { display: flex; align-items: center; gap: 12px; }
.dl-apk-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--primary);
  background: var(--primary-soft);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
}
.dl-apk-btn:hover { background: rgba(21,101,192,.18); }
.me {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--ink);
  font-size: 13px;
}
.me-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), #2a83e8);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 13px;
  box-shadow: var(--shadow-sm);
}

/* ── Layout ─────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: calc(100vh - 57px);
  /* `align-items: start` lets `position: sticky` on the sidebar pin to the
     top of its grid cell instead of stretching to the row height. */
  align-items: start;
}
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  /* Static sidebar on desktop — stays visible as the content scrolls. The
     57px offset matches the .topbar height (sticky topbar above). */
  position: sticky;
  top: 57px;
  height: calc(100vh - 57px);
  overflow-y: auto;
}
.navlink {
  background: transparent;
  border: 0;
  text-align: left;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  color: var(--ink-2);
  font-weight: 600;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 10px;
  position: relative;
}
.navlink svg { width: 18px; height: 18px; flex-shrink: 0; }
.navlink:hover { background: var(--surface-2); color: var(--ink); }
.navlink.active {
  background: var(--primary-soft);
  color: var(--primary);
}
.navlink.active::before {
  content: '';
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--primary);
  border-radius: 2px;
}

.content {
  padding: 28px 32px;
  animation: fadeIn .25s ease both;
}
.tab.hidden { display: none; }
.tab { animation: fadeIn .25s ease both; }
.tab-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
}
.tab-head h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  letter-spacing: -.5px;
}
.tab-head .subtle {
  font-size: 12px;
  color: var(--ink-3);
  margin-top: 2px;
}
@keyframes fadeIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

/* ── Cards / lists ──────────────────────────────────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}
.banner-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.banner-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}
.banner-card img {
  width: 100%;
  height: 150px;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}
.banner-card .meta {
  padding: 12px 14px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.banner-card .meta .title {
  font-weight: 700;
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.banner-card .meta .actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.row-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow-sm);
  transition: transform .15s, box-shadow .15s;
}
.row-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
}
.row-card .avatar {
  width: 42px; height: 42px;
  border-radius: 50%;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  flex-shrink: 0;
  background-size: cover;
  background-position: center;
}
.row-card .row-main {
  flex: 1;
  min-width: 0;
}
.row-card .row-title {
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row-card .row-sub {
  font-size: 12px;
  color: var(--ink-2);
  margin-top: 2px;
}
.row-card .row-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
}

/* Small inline status/role badges used on the row-card title. Inline styles
   on the element supply background/color so the same pill can render in any
   accent — see roleBadge() / statusBadge() / keyBadge() in dashboard.js. */
.role-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
  vertical-align: middle;
}

.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px 24px;
  max-width: 580px;
  box-shadow: var(--shadow-sm);
}
.form-card button { margin-top: 22px; }
.status {
  margin-left: 12px;
  font-size: 12px;
  font-weight: 600;
  color: var(--accent);
}

/* ── Image upload widget ────────────────────────────────────────────── */
.image-upload {
  display: grid;
  gap: 10px;
}
.image-upload .thumb {
  width: 100%;
  height: 160px;
  background: var(--surface-3) center/cover no-repeat;
  border-radius: var(--radius-sm);
  border: 1.5px dashed var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--ink-3);
  font-size: 12px;
  font-weight: 600;
  transition: border-color .15s;
}
.image-upload:hover .thumb { border-color: var(--primary); }
.image-upload-controls {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}
.image-upload-controls button { white-space: nowrap; }
.image-upload-controls input[type="url"] {
  flex: 1;
  min-width: 180px;
}
.upload-status {
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
  min-height: 16px;
}

/* Video row: URL input + upload button */
.video-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.video-row input[type="url"] { flex: 1; }
.video-row button { white-space: nowrap; }

/* ── Modal ──────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, .55);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
  animation: fadeIn .2s ease both;
  /* Allow the backdrop itself to scroll if content somehow exceeds viewport.
     The card's own overflow handles most cases, but this is the safety net. */
  overflow-y: auto;
}
.modal-backdrop.hidden { display: none; }
.modal-card {
  background: var(--surface);
  border-radius: 18px;
  padding: 24px 24px 20px;
  width: 100%;
  max-width: 460px;
  /* Tall forms (e.g. Add admin) would clip out the top/bottom of the viewport
     when centered — cap the card height and let its body scroll instead. */
  max-height: calc(100vh - 40px);
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 60px rgba(15,23,42,.25);
  animation: modalUp .25s ease both;
}
/* Only the form body scrolls — the title and Save/Cancel actions stay pinned
   so the user can always see what they're doing and submit without scrolling
   back. */
.modal-card h3 { flex-shrink: 0; }
.modal-card #modalForm {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  margin: 0 -24px;
  padding: 0 24px;
}
.modal-card #modalError { flex-shrink: 0; }
.modal-card .modal-actions { flex-shrink: 0; }
.modal-card h3 {
  margin: 0 0 8px;
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.3px;
}
.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
  margin-top: 22px;
}
@keyframes modalUp {
  from { opacity: 0; transform: translateY(12px) scale(.98); }
  to   { opacity: 1; transform: none; }
}

/* ── Misc ───────────────────────────────────────────────────────────── */
.error {
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  min-height: 18px;
}
.empty {
  padding: 48px 24px;
  text-align: center;
  color: var(--ink-2);
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius);
  background: var(--surface);
}
.empty .empty-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}
.empty .empty-icon svg { width: 26px; height: 26px; }
.empty p {
  margin: 0;
  font-size: 13px;
  color: var(--ink-2);
}
.empty p + p { margin-top: 4px; color: var(--ink-3); font-size: 12px; }

/* ── Responsive ─────────────────────────────────────────────────────── */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  /* Sidebar collapses into a horizontal scroller below the topbar. Sticky so
     it stays visible while the content scrolls, mirroring the static
     desktop sidebar but as a slim chip row. */
  .sidebar {
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--border);
    padding: 8px 12px;
    gap: 4px;
    position: sticky;
    top: 56px;
    height: auto;
    z-index: 5;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .sidebar::-webkit-scrollbar { display: none; }
  .navlink { white-space: nowrap; padding: 8px 12px; }
  .navlink.active::before { display: none; }
  .content { padding: 16px 14px 22px; }

  /* Topbar — tighter on phones; brand name truncates rather than wraps. */
  .topbar { padding: 10px 14px; gap: 8px; }
  .brand small { display: none; }
  .me { font-size: 0; }            /* hide name, keep avatar */
  .me-avatar { font-size: 13px; }
  .ghost.logout-text { display: none; }
  .dl-apk-btn { padding: 7px 10px; font-size: 11.5px; }

  /* Tab heads stack: title + subtitle line above, the "+ Add" button below
     spans full width so it stays comfortably tappable. */
  .tab-head {
    flex-direction: column;
    align-items: stretch;
    gap: 12px;
    margin-bottom: 18px;
  }
  .tab-head h2 { font-size: 20px; }
  .tab-head .primary { width: 100%; padding: 11px 14px; }

  /* Row cards — actions wrap to a second line on narrow screens so the
     title + meta have room. */
  .row-card {
    flex-wrap: wrap;
    gap: 10px;
    padding: 12px 14px;
  }
  .row-card .row-main { flex: 1 1 100%; min-width: 0; order: 1; }
  .row-card .avatar  { order: 0; }
  .row-card .row-actions {
    order: 2;
    flex: 1 1 100%;
    justify-content: flex-end;
  }

  /* Cards-grid (banners) — single column. */
  .card-grid { grid-template-columns: 1fr !important; }

  /* Modal — near-full-width with safer padding so big forms don't overflow. */
  .modal-backdrop { padding: 12px; align-items: flex-start; padding-top: 24px; }
  .modal-card {
    padding: 18px 18px 14px;
    max-width: 100%;
    max-height: calc(100vh - 48px);
    overflow-y: auto;
  }
  .modal-card h3 { font-size: 17px; }
  .modal-actions { flex-direction: column-reverse; gap: 8px; }
  .modal-actions .primary,
  .modal-actions .ghost { width: 100%; padding: 12px; }

  /* Video-form rows wrap on mobile so the "Upload file" button doesn't push
     the URL field off-screen. */
  .video-row { flex-wrap: wrap; gap: 8px; }
  .video-row input[type="url"] { flex: 1 1 100%; }
}
