/* Admin panel — desktop + mobile */
:root {
  --brand: #e31c23;
  --ink: #1c1c1c;
  --muted: #666;
  --line: #e5e5e5;
  --bg: #f3f4f6;
  --side: #1b1b1b;
  --font: "DM Sans", "Segoe UI", sans-serif;
}

*,
*::before,
*::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  line-height: 1.45;
}

a { color: inherit; text-decoration: none; }

img { max-width: 100%; height: auto; }

.admin-shell {
  display: grid;
  grid-template-columns: 240px 1fr;
  min-height: 100vh;
}

.admin-side {
  background: var(--side);
  color: #eee;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
}

.admin-side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 20px;
  padding: 0 4px;
}

.admin-side .logo {
  color: var(--brand);
  font-weight: 700;
  font-size: 1.25rem;
  display: block;
  line-height: 1.2;
  min-width: 0;
}

.admin-side .logo img {
  display: block;
  width: min(168px, 100%);
  height: auto;
  max-height: 34px;
  object-fit: contain;
  object-position: left center;
}

.nav-toggle {
  display: none;
  border: 1px solid #444;
  background: #2a2a2a;
  color: #fff;
  border-radius: 8px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
  flex-shrink: 0;
}

.admin-side nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.admin-side nav a {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: #ccc;
}

.admin-side nav a:hover,
.admin-side nav a.active {
  background: #2b2b2b;
  color: #fff;
}

.admin-main {
  padding: 24px;
  min-width: 0; /* prevent grid blowout */
  overflow-x: hidden;
}

.admin-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.admin-top h1 {
  margin: 0;
  font-size: clamp(1.15rem, 4vw, 1.4rem);
  line-height: 1.25;
}

.admin-top .meta {
  color: #666;
  font-size: 0.9rem;
}

.admin-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.search-bar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  flex: 1 1 220px;
  min-width: 0;
}

.search-bar input {
  flex: 1 1 auto;
  min-width: 0;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 16px; /* iOS: avoid zoom */
  min-height: 42px;
  height: 42px;
}

.search-bar .btn {
  flex: 0 0 auto;
  min-height: 42px;
  height: 42px;
  padding-inline: 16px;
}

.cards {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 22px;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.stat .num {
  font-size: clamp(1.35rem, 4vw, 1.8rem);
  font-weight: 700;
  color: var(--brand);
  word-break: break-word;
}

.split-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr);
  gap: 16px;
  align-items: start;
}

.split-layout.tags {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.6fr);
}

.panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px;
  min-width: 0;
}

.panel-title {
  margin: 0 0 4px;
  font-size: 1.05rem;
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -4px;
  padding: 0 4px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 520px;
}

table.compact {
  min-width: 360px;
}

th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
  font-size: 0.92rem;
}

th { color: var(--muted); font-weight: 600; white-space: nowrap; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 6px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  white-space: nowrap;
}

.btn.secondary {
  background: #fff;
  color: var(--ink);
  border: 1px solid var(--line);
}

.btn.danger { background: #9b1c1c; }

.btn.small {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn.block {
  width: 100%;
}

.flash {
  padding: 12px 14px;
  border-radius: 6px;
  margin-bottom: 14px;
  word-break: break-word;
}

.flash.success { background: #e7f8ed; border: 1px solid #1f7a45; }
.flash.error { background: #fdecec; border: 1px solid #b42318; }

.form-grid {
  display: grid;
  gap: 14px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  font-weight: 600;
  font-size: 0.9rem;
}

.form-grid input[type="text"],
.form-grid input[type="email"],
.form-grid input[type="password"],
.form-grid input[type="number"],
.form-grid input[type="file"],
.form-grid input[type="search"],
.form-grid select,
.form-grid textarea {
  width: 100%;
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
  font-size: 16px; /* iOS: avoid auto-zoom */
}

.form-grid textarea { min-height: 220px; resize: vertical; }
.form-grid textarea.short { min-height: 90px; }
.form-grid textarea.medium { min-height: 120px; }

.thumb-preview {
  margin-top: 8px;
}

.thumb-preview img {
  max-width: min(220px, 100%);
  border-radius: 6px;
  display: block;
}

.checks {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  font-weight: 500;
}

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  font-size: 0.92rem;
}

.checks input {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
}

.muted-line {
  color: #888;
  font-size: 0.8rem;
  word-break: break-all;
}

.login-wrap {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.login-card {
  width: min(400px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 24px 20px;
}

.login-card h1 {
  margin: 0 0 8px;
  color: var(--brand);
  font-size: 1.5rem;
}

.login-brand {
  text-align: left;
}

.login-brand img {
  display: block;
  width: min(220px, 100%);
  height: auto;
  max-height: 48px;
  object-fit: contain;
  object-position: left center;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.actions form {
  display: inline;
  margin: 0;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #eee;
}

.badge.published { background: #dcfce7; color: #166534; }
.badge.draft { background: #fef3c7; color: #92400e; }

.settings-form {
  max-width: 640px;
  width: 100%;
}

/* —— Tablet —— */
@media (max-width: 960px) {
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split-layout,
  .split-layout.tags {
    grid-template-columns: 1fr;
  }
}

/* —— Phone —— */
@media (max-width: 768px) {
  .admin-shell {
    grid-template-columns: 1fr;
  }

  .admin-side {
    position: sticky;
    top: 0;
    z-index: 40;
    height: auto;
    max-height: none;
    padding: 12px;
    border-bottom: 1px solid #333;
  }

  .admin-side-head {
    margin-bottom: 0;
  }

  .nav-toggle {
    display: inline-flex;
    align-items: center;
  }

  .admin-side nav {
    display: none;
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid #333;
  }

  .admin-side nav.is-open {
    display: flex;
  }

  .admin-side nav a {
    padding: 12px;
    font-size: 0.95rem;
  }

  .admin-main {
    padding: 14px 12px 28px;
  }

  .admin-top {
    align-items: flex-start;
    margin-bottom: 14px;
  }

  .admin-toolbar {
    flex-direction: column;
    align-items: stretch;
  }

  .admin-toolbar > .btn {
    width: 100%;
  }

  .search-bar {
    flex: 1 1 auto;
    width: 100%;
    align-items: stretch;
  }

  .search-bar input {
    flex: 1 1 0;
    width: auto;
    min-height: 44px;
    height: 44px;
  }

  .search-bar .btn {
    flex: 0 0 auto;
    width: auto;
    min-width: 4.5rem;
    min-height: 44px;
    height: 44px;
  }

  .cards {
    gap: 10px;
    margin-bottom: 16px;
  }

  .stat {
    padding: 12px;
  }

  .panel {
    padding: 12px;
  }

  .table-wrap {
    margin: 0 -12px;
    padding: 0 12px;
  }

  table {
    min-width: 560px;
  }

  table.compact {
    min-width: 300px;
  }

  th, td {
    padding: 10px 6px;
    font-size: 0.86rem;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions .btn,
  .actions form,
  .actions form .btn {
    width: 100%;
  }

  .btn {
    min-height: 42px;
  }

  .btn.small {
    min-height: 36px;
  }

  .form-grid textarea {
    min-height: 180px;
  }

  .checks {
    flex-direction: column;
    gap: 10px;
  }
}

@media (max-width: 420px) {
  .cards {
    grid-template-columns: 1fr;
  }

  .login-card {
    padding: 20px 16px;
  }
}
