/*
 * Admin pages. Linked only by the admin layout, but Propshaft's :app bundle
 * can load every stylesheet, so every rule is nested under body.admin.
 */

body.admin {
  --brand: #395775;
  --brand-dark: #2c4560;
  --brand-tint: #e8eef4;
  --page: #f3f5f7;
  --surface: #ffffff;
  --border: #dde2e8;
  --border-strong: #c5ccd5;
  --text: #1d2733;
  --muted: #5d6b7a;
  --danger: #b42318;
  --danger-tint: #fdecea;
  --success: #1e7b45;
  --success-tint: #e6f4ec;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 0.06), 0 1px 3px rgb(16 24 40 / 0.08);

  margin: 0;
  min-height: 100vh;
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;

  *, *::before, *::after { box-sizing: border-box; }

  a { color: var(--brand); }
  :focus-visible { outline: 3px solid #6b9bd1; outline-offset: 2px; border-radius: 4px; }
  h1, h2, h3 { line-height: 1.25; margin: 0; }
  code { font-size: 0.92em; background: var(--brand-tint); padding: 1px 5px; border-radius: 4px; }

  .visually-hidden {
    position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  .muted { color: var(--muted); }
  .small { font-size: 0.875rem; }

  /* Header */
  .admin-header { background: var(--brand); color: #fff; }
  .admin-header__inner {
    max-width: 1180px; margin: 0 auto; padding: 0 24px; min-height: 60px;
    display: flex; align-items: center; gap: 28px; flex-wrap: wrap;
  }
  .admin-brand { color: #fff; font-weight: 750; font-size: 1.1rem; text-decoration: none; letter-spacing: -0.01em; }
  .admin-nav { display: flex; gap: 4px; }
  .admin-nav a {
    color: rgb(255 255 255 / 0.82); text-decoration: none; font-weight: 600;
    padding: 6px 12px; border-radius: 6px;
    &:hover { color: #fff; background: rgb(255 255 255 / 0.1); }
    &.is-active { color: #fff; background: rgb(255 255 255 / 0.16); }
  }
  .admin-user { margin-left: auto; display: flex; align-items: center; gap: 14px; font-size: 0.9rem; }
  .admin-user__name { color: rgb(255 255 255 / 0.85); }
  .admin-user form { margin: 0; }

  .admin-main { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }

  /* Page heading */
  .page-head {
    display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap;
    margin-bottom: 20px;
    h1 { font-size: 1.75rem; font-weight: 750; letter-spacing: -0.02em; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
  }
  .page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; form { margin: 0; } }
  .back-link {
    display: inline-block; margin-bottom: 4px; font-size: 0.9rem; font-weight: 600; text-decoration: none;
    &::before { content: "\2039\00a0"; }
    &:hover { text-decoration: underline; }
  }

  /* Cards */
  .card {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 22px 24px; margin-bottom: 20px;
  }
  .card--flush { padding: 0; overflow: hidden; }
  .card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 14px; }
  .card-title .count {
    display: inline-block; min-width: 1.6em; padding: 0 7px; margin-left: 4px; border-radius: 99px;
    background: var(--brand-tint); color: var(--brand); font-size: 0.85rem; text-align: center;
  }
  .section-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 6px; .card-title { margin: 0; } }
  .section-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
  .empty { text-align: center; padding: 28px 16px; color: var(--muted); h2 { color: var(--text); margin-bottom: 8px; } p { margin: 0 0 16px; } }

  /* Flash */
  .flash {
    border-radius: 8px; padding: 12px 16px; margin-bottom: 20px; border: 1px solid;
    p { margin: 0; }
    ul { margin: 8px 0 0; padding-left: 20px; }
  }
  .flash--notice { background: var(--success-tint); border-color: #b5dcc4; color: #14532d; }
  .flash--alert { background: var(--danger-tint); border-color: #f4c2bd; color: #7a1a12; }
  .flash--info { background: var(--brand-tint); border-color: #c6d4e2; color: var(--brand-dark); }

  /* Buttons */
  .btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    min-height: 40px; padding: 8px 16px; border-radius: 8px;
    border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
    font: inherit; font-weight: 600; font-size: 0.95rem; line-height: 1.2;
    text-decoration: none; cursor: pointer; white-space: nowrap;
    &:hover { background: #f6f8fa; border-color: #aab3be; }
    &:disabled { opacity: 0.55; cursor: progress; }
  }
  .btn--primary {
    background: var(--brand); border-color: var(--brand); color: #fff;
    &:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
  }
  .btn--ghost { background: transparent; border-color: transparent; color: var(--brand); &:hover { background: var(--brand-tint); border-color: transparent; } }
  .btn--danger-ghost { background: transparent; border-color: transparent; color: var(--danger); &:hover { background: var(--danger-tint); border-color: transparent; } }
  .btn--small { min-height: 34px; padding: 5px 12px; font-size: 0.875rem; }
  .btn--large { min-height: 48px; padding: 10px 28px; font-size: 1.05rem; }
  .btn--on-dark {
    background: rgb(255 255 255 / 0.12); border-color: rgb(255 255 255 / 0.35); color: #fff;
    &:hover { background: rgb(255 255 255 / 0.22); border-color: rgb(255 255 255 / 0.5); }
  }
  form.button_to { display: inline-block; margin: 0; }

  /* Badges */
  .badge {
    display: inline-flex; align-items: center; padding: 2px 10px; border-radius: 99px;
    font-size: 0.78rem; font-weight: 700; letter-spacing: 0.02em; line-height: 1.6; vertical-align: middle;
    border: 1px solid transparent;
  }
  .badge--draft { background: #eceff2; color: #4a5562; border-color: #d6dbe1; }
  .badge--scheduled { background: #fef3c7; color: #8a5300; border-color: #f5d98b; }
  .badge--open { background: #dcf3e5; color: #17663a; border-color: #a9dcbc; }
  .badge--closed { background: #e2e8f0; color: #334155; border-color: #c4ced9; }
  .badge--hidden { background: #1d2733; color: #fff; }
  .badge--you { background: var(--brand-tint); color: var(--brand); }

  /* Tables */
  .table-wrap { overflow-x: auto; }
  .table {
    width: 100%; border-collapse: collapse; font-size: 0.95rem;
    th { text-align: left; font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; background: #f8f9fb; }
    th, td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
    tbody tr:last-child td { border-bottom: 0; }
    tbody tr:hover { background: #fafbfc; }
    .num { text-align: right; font-variant-numeric: tabular-nums; }
    .actions { text-align: right; white-space: nowrap; > * + * { margin-left: 6px; } }
  }
  .title-cell { min-width: 14rem; }
  .slug { overflow-wrap: anywhere; }
  .table-title { font-weight: 700; text-decoration: none; color: var(--text); &:hover { color: var(--brand); text-decoration: underline; } }

  /* Forms */
  .form { max-width: 820px; }
  .field { margin-bottom: 18px; &:last-child { margin-bottom: 0; } }
  .field > label, .label-text { display: block; font-weight: 650; margin-bottom: 6px; }
  input[type="text"], input[type="email"], input[type="number"], input[type="datetime-local"], textarea {
    width: 100%; font: inherit; color: var(--text); background: #fff;
    border: 1px solid var(--border-strong); border-radius: 8px; padding: 9px 12px; min-height: 42px;
    &:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgb(57 87 117 / 0.2); }
    &:disabled { background: #f1f3f5; color: var(--muted); }
  }
  textarea { resize: vertical; line-height: 1.45; }
  input[type="number"] { max-width: 10rem; }
  .field--invalid input, .field--invalid textarea { border-color: var(--danger); }
  .field-error { color: var(--danger); font-size: 0.9rem; font-weight: 600; margin: 6px 0 0; }
  .hint { color: var(--muted); font-size: 0.875rem; margin: 6px 0 0; }
  .hint--lead { margin: -8px 0 14px; }
  .lede-admin { margin: 0 0 18px; color: var(--muted); }
  .grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0 24px; }
  .check {
    display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-top: 1px solid var(--border);
    input[type="checkbox"] { width: 20px; height: 20px; margin: 2px 0 0; accent-color: var(--brand); flex: none; }
    label { font-weight: 650; }
    .hint { margin-top: 2px; }
  }
  .grid-2 + .check { margin-top: 8px; }
  .input-prefix {
    display: flex; align-items: stretch; border: 1px solid var(--border-strong); border-radius: 8px; overflow: hidden; background: #fff;
    &:focus-within { border-color: var(--brand); box-shadow: 0 0 0 3px rgb(57 87 117 / 0.2); }
    input { border: 0; border-radius: 0; min-width: 0; &:focus { box-shadow: none; } }
  }
  .input-prefix__text { display: flex; align-items: center; padding: 0 4px 0 12px; color: var(--muted); background: #f6f7f9; white-space: nowrap; font-size: 0.95rem; }
  .form-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-top: 4px; }
  .inline-form { display: flex; gap: 10px; flex-wrap: wrap; max-width: 560px; }
  .inline-form__input { flex: 1 1 240px; }

  /* Color preview */
  .color-row { display: grid; grid-template-columns: minmax(200px, 260px) 1fr; gap: 24px; align-items: start; }
  input[type="color"] { width: 88px; height: 44px; padding: 3px; border: 1px solid var(--border-strong); border-radius: 8px; background: #fff; cursor: pointer; }
  .preview-swatch {
    border-radius: 14px; min-height: 120px; padding: 18px 22px; display: flex; flex-direction: column; justify-content: center;
    box-shadow: inset 0 0 0 1px rgb(0 0 0 / 0.08); transition: background-color 0.15s, color 0.15s;
  }
  .preview-swatch__label { font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.08em; opacity: 0.75; font-weight: 700; }
  .preview-swatch__title { font-size: 1.6rem; font-weight: 800; letter-spacing: -0.02em; line-height: 1.15; overflow-wrap: anywhere; }
  @media (max-width: 640px) { .color-row { grid-template-columns: 1fr; } }

  /* Manage page */
  .status-grid { display: grid; grid-template-columns: 1fr auto; gap: 20px; align-items: start; }
  .status-line { margin: -6px 0 14px; font-size: 1.05rem; }
  .status-actions { text-align: right; max-width: 260px; .hint { text-align: right; } }
  .facts {
    display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 0;
    dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; }
    dd { margin: 2px 0 0; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }
  }
  .share { border-top: 1px solid var(--border); margin-top: 20px; padding-top: 18px; }
  .share__label { display: block; font-weight: 650; margin-bottom: 6px; }
  .share__row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; form { margin: 0; } }
  .share__input { flex: 1 1 280px; max-width: 520px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.9rem !important; background: #f8f9fb !important; }
  .monitor-stats { display: flex; flex-wrap: wrap; gap: 12px 40px; margin: 8px 0 22px; }
  .monitor-stat {
    dt { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); font-weight: 700; }
    dd { margin: 2px 0 0; font-size: 1.25rem; font-weight: 700; font-variant-numeric: tabular-nums; }
  }
  .monitor-cols { display: grid; grid-template-columns: 3fr 2fr; gap: 28px; align-items: start; }
  .monitor-h { font-size: 0.95rem; font-weight: 700; margin-bottom: 2px; }
  .leaderboard { margin-top: 8px; th, td { padding: 8px 12px; } }
  .confidence-message { margin: 10px 0; font-size: 1.05rem; }
  .confidence-list { list-style: none; margin: 0 0 10px; padding: 0; li { display: grid; grid-template-columns: minmax(0, 1fr) 90px 3.2em; gap: 10px; align-items: center; padding: 5px 0; } }
  .confidence-title { overflow-wrap: anywhere; }
  .confidence-bar { height: 8px; border-radius: 99px; background: var(--brand-tint); overflow: hidden; span { display: block; height: 100%; background: var(--brand); } }
  .confidence-pct { text-align: right; font-variant-numeric: tabular-nums; font-weight: 650; }
  @media (max-width: 860px) { .monitor-cols { grid-template-columns: 1fr; } }
  @media (max-width: 720px) {
    .status-grid { grid-template-columns: 1fr; }
    .status-actions { text-align: left; .hint { text-align: left; } }
  }

  .entry-grid {
    list-style: none; margin: 18px 0 0; padding: 0;
    display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 16px;
  }
  .entry-card {
    border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: #fff;
    display: flex; flex-direction: column;
  }
  .entry-card--hidden .entry-card__thumb img { opacity: 0.4; filter: grayscale(0.7); }
  .entry-card__thumb {
    position: relative; aspect-ratio: 4 / 3; background: #eef1f4; display: flex; align-items: center; justify-content: center;
    img { width: 100%; height: 100%; object-fit: cover; display: block; }
    .badge { position: absolute; top: 8px; left: 8px; }
  }
  .entry-card__nophoto { color: var(--danger); font-weight: 650; font-size: 0.9rem; }
  .entry-card__body { padding: 12px 14px 4px; flex: 1; p { margin: 2px 0 0; } }
  .entry-card__title { font-size: 1rem; font-weight: 700; overflow-wrap: anywhere; }
  .entry-card__caption { color: var(--muted); font-size: 0.9rem; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .entry-card__actions { display: flex; gap: 6px; flex-wrap: wrap; padding: 10px 12px 12px; }

  /* Uploads */
  .dropzone {
    position: relative; border: 2px dashed var(--border-strong); border-radius: 12px; background: #fafbfc;
    padding: 28px 20px; text-align: center; transition: border-color 0.15s, background-color 0.15s;
    &:hover, &.is-dragging, &:focus-within { border-color: var(--brand); background: var(--brand-tint); }
    .hint { margin-top: 4px; }
  }
  .dropzone__input {
    /* Covers the whole zone so a click anywhere opens the picker; a plain file input without JS. */
    position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer;
  }
  .dropzone__text { font-size: 1rem; }
  .dropzone__link { color: var(--brand); text-decoration: underline; font-weight: 600; }
  .file-list {
    list-style: none; margin: 12px 0 0; padding: 0; display: grid; gap: 8px;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    &:empty { display: none; }
  }
  .file-item {
    display: grid; grid-template-columns: 56px 1fr auto; gap: 12px; align-items: center;
    border: 1px solid var(--border); border-radius: 10px; padding: 8px; background: #fff;
  }
  .file-item__thumb {
    width: 56px; height: 56px; border-radius: 6px; object-fit: cover; background: #e6eaee;
    display: flex; align-items: center; justify-content: center; font-size: 0.7rem; font-weight: 700; color: var(--muted);
  }
  .file-item__meta { min-width: 0; }
  .file-item__name { font-weight: 600; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .file-item__size { color: var(--muted); font-size: 0.8rem; }
  .file-item__bar { height: 6px; border-radius: 99px; background: #e6eaee; margin-top: 6px; overflow: hidden; }
  .file-item__fill { height: 100%; width: 0; background: var(--brand); transition: width 0.2s; }
  .file-item.is-done .file-item__fill { background: var(--success); }
  .file-item__remove:disabled { visibility: hidden; }
  .file-item__remove {
    border: 0; background: transparent; color: var(--muted); cursor: pointer; font: inherit; font-size: 0.85rem; font-weight: 600;
    padding: 8px; border-radius: 6px;
    &:hover { color: var(--danger); background: var(--danger-tint); }
  }
  .upload-status { color: var(--muted); font-weight: 600; font-variant-numeric: tabular-nums; }

  .photo-picker { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 12px; }
  .photo-picker__item {
    width: 140px; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: #fff;
    img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; display: block; }
    &:has(input:checked) { border-color: var(--danger); img { opacity: 0.35; } }
  }
  .photo-picker__remove {
    display: flex; align-items: center; gap: 8px; padding: 8px 10px; font-size: 0.875rem; font-weight: 600; cursor: pointer;
    input { width: 18px; height: 18px; accent-color: var(--danger); margin: 0; }
  }

  @media (max-width: 640px) {
    .admin-header__inner { padding: 10px 16px; gap: 10px 18px; }
    .admin-user { margin-left: 0; width: 100%; justify-content: space-between; }
    .admin-main { padding: 20px 16px 48px; }
    .card { padding: 18px 16px; }
    .page-head h1 { font-size: 1.45rem; }
  }
}
