/* Admin UI — layered on the design tokens defined in style.css */

/* Tokens shared with the public pages come from style.css */
:root {
  --radius-md: 10px;
  --hover: #fbfbfa;
  --zebra: #faf9f7;
}

body { background: var(--bg); }

/* ── Top bar ─────────────────────────────────────────────── */
.admin-bar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(1.4) blur(8px);
  border-bottom: 1px solid var(--border);
}
.admin-bar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 20px;
  min-height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.admin-brand { font-size: .95rem; font-weight: 650; letter-spacing: -.01em; white-space: nowrap; }
.admin-brand em { font-style: normal; color: var(--text-muted); font-weight: 500; }
.admin-bar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: .84rem;
  color: var(--text-muted);
}
.admin-bar-right a { color: var(--text-muted); }
.admin-bar-right a:hover { color: var(--text); text-decoration: none; }
.bar-sep { width: 1px; height: 16px; background: var(--border); }

/* ── Layout ──────────────────────────────────────────────── */
.admin-main { max-width: 1120px; margin: 0 auto; padding: 26px 20px 72px; }

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head h1 { margin: 0; font-size: 1.35rem; letter-spacing: -.02em; }
.page-head p { margin: 5px 0 0; color: var(--text-muted); font-size: .86rem; max-width: 62ch; }
.page-head .spacer { margin-left: auto; }

/* ── Controls ────────────────────────────────────────────── */
.controls { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }

.tabs { display: inline-flex; background: var(--sunken); padding: 3px; border-radius: 9px; }
.tabs a {
  padding: 6px 14px;
  border-radius: 7px;
  font-size: .85rem;
  font-weight: 550;
  color: var(--text-muted);
  white-space: nowrap;
}
.tabs a:hover { color: var(--text); text-decoration: none; }
.tabs a.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }

.search { position: relative; margin-left: auto; }
.search .search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  display: flex;
}
.search input {
  width: 250px;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface);
  font-size: .87rem;
  color: var(--text);
}
.search input:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }

/* ── List ────────────────────────────────────────────────── */
.list {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.list-head,
.row {
  display: grid;
  grid-template-columns: 34px 60px minmax(0, 1fr) 122px 118px 96px 96px;
  align-items: center;
  gap: 14px;
  padding: 11px 16px;
}

.list-head {
  border-bottom: 1px solid var(--border);
  font-size: .69rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: 600;
}

.row { border-bottom: 1px solid var(--border); }
.list-body .row:nth-child(even) { background: var(--zebra); }
.row:hover { background: var(--hover); }
.list-body .row:last-child { border-bottom: none; border-radius: 0 0 var(--radius-lg) var(--radius-lg); }

.c-num { color: var(--text-muted); font-size: .8rem; font-variant-numeric: tabular-nums; }
.c-facts { display: contents; }

.c-cover img {
  width: 60px;
  height: 90px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--border);
  box-shadow: var(--shadow-sm);
  display: block;
}

.c-title { font-weight: 600; font-size: .9rem; line-height: 1.35; letter-spacing: -.01em; }
.c-genre { margin-top: 3px; font-size: .8rem; color: var(--text-muted); }
.c-asin {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: .76rem;
  color: var(--text-muted);
}
.c-synced { font-size: .78rem; color: var(--text-muted); }
.c-synced .err { color: var(--price); font-weight: 600; }

/* .pill / .pill-free / .pill-paid / .pill-unknown / .pill-warn live in style.css */
.pill-warn { margin-left: 6px; }

.c-actions { display: flex; align-items: center; gap: 6px; justify-content: flex-end; }

.empty { padding: 60px 20px; text-align: center; color: var(--text-muted); font-size: .9rem; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: .84rem;
  font-weight: 550;
  line-height: 1.2;
  cursor: pointer;
  background: var(--brand);
  color: #fff;
  text-decoration: none;
  transition: background .12s ease, border-color .12s ease, box-shadow .12s ease;
}
.btn:hover { background: var(--brand-dark); text-decoration: none; color: #fff; }
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn.secondary {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}
.btn.secondary:hover { background: #f4f4f2; border-color: #d8d8d3; color: var(--text); }
.btn.small { padding: 6px 11px; font-size: .79rem; }
.btn.danger { background: var(--price); color: #fff; }
.btn.danger:hover { background: #8f1e17; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: background .12s ease, color .12s ease;
}
.icon-btn:hover { background: var(--sunken); color: var(--text); }
.icon-btn:focus-visible { outline: none; box-shadow: var(--ring); }

/* ── Row action menu ─────────────────────────────────────── */
.menu { position: relative; }
.menu-pop {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  min-width: 210px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
  padding: 5px;
  z-index: 40;
}
.menu-pop.flip-up { top: auto; bottom: calc(100% + 6px); }
.menu-item {
  display: flex;
  align-items: center;
  gap: 9px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: none;
  border-radius: 7px;
  font-size: .84rem;
  font-family: inherit;
  color: var(--text);
  text-align: left;
  cursor: pointer;
}
.menu-item:hover { background: #f4f4f2; }
.menu-item.danger { color: var(--price); }
.menu-item.danger:hover { background: #fdecea; }
.menu-sep { height: 1px; background: var(--border); margin: 5px 2px; }

/* ── Flash ───────────────────────────────────────────────── */
.flash {
  display: flex;
  align-items: center;
  gap: 9px;
  background: #eaf6ee;
  border: 1px solid #bfe3cb;
  color: #14532d;
  padding: 11px 14px;
  border-radius: var(--radius-md);
  margin-bottom: 18px;
  font-size: .87rem;
}

/* ── Background-refresh status ───────────────────────────── */
/* Quiet by default: the healthy state is a thin line of text, since it's
   true 99% of the time. Only the broken state asks for attention. */
.cron-status {
  display: flex;
  align-items: center;
  gap: 9px;
  margin-bottom: 18px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: var(--radius-md);
  color: var(--text-muted);
  font-size: .8rem;
}
.cron-status strong { color: var(--text); font-weight: 600; }
.cron-dot {
  flex: none;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--free);
  box-shadow: 0 0 0 3px rgba(26, 127, 55, .13);
}
.cron-due {
  margin-left: auto;
  flex: none;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--sunken);
  font-variant-numeric: tabular-nums;
  font-size: .76rem;
}
.cron-status.is-stale {
  background: #fdf4e7;
  border-color: #f0d9b0;
  color: #7a4a06;
}
.cron-status.is-stale strong { color: #6b3f05; }
.cron-status.is-stale .cron-dot {
  background: #c77700;
  box-shadow: 0 0 0 3px rgba(199, 119, 0, .16);
}
.cron-status.is-stale .cron-due { background: rgba(199, 119, 0, .12); }

@media (max-width: 640px) {
  .cron-status { align-items: flex-start; flex-wrap: wrap; }
  .cron-due { margin-left: 0; }
}

/* ── Forms (modal + full-page fallback) ──────────────────── */
.admin-form .field { margin-bottom: 16px; }
.admin-form label { display: block; font-size: .8rem; font-weight: 600; margin-bottom: 6px; }
.admin-form input[type=text] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .9rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
.admin-form input[type=text]:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.admin-form .hint { margin: 6px 0 0; font-size: .78rem; color: var(--text-muted); }
.admin-form .store-row { display: flex; gap: 8px; margin-bottom: 8px; align-items: center; }
.admin-form .store-row .store-label { flex: 0 0 116px; }
.admin-form .store-row .store-url { flex: 1; min-width: 0; }
.admin-form .checkline {
  display: flex;
  gap: 9px;
  align-items: flex-start;
  font-size: .87rem;
  font-weight: 500;
  margin: 0;
}
.admin-form .checkline input { margin-top: 2px; }
.admin-form .form-actions {
  display: flex;
  gap: 8px;
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Modal ───────────────────────────────────────────────── */
dialog#book-modal {
  border: none;
  padding: 0;
  border-radius: var(--radius-lg);
  width: min(540px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow-md);
  color: var(--text);
}
dialog#book-modal::backdrop { background: rgba(16, 24, 40, .45); }
.modal-head {
  position: sticky;
  top: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 15px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 1;
}
.modal-head h2 { margin: 0; font-size: 1rem; letter-spacing: -.01em; }
.modal-body { padding: 18px; }

/* ── Login ───────────────────────────────────────────────── */
.login-wrap { max-width: 380px; margin: 9vh auto 0; padding: 0 20px; }
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 28px;
}
.login-card h1 { margin: 0 0 6px; font-size: 1.1rem; letter-spacing: -.01em; }
.login-card .sub { margin: 0 0 18px; font-size: .86rem; color: var(--text-muted); }
.login-card input[type=password] {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .95rem;
  font-family: inherit;
}
.login-card input[type=password]:focus { outline: none; border-color: var(--brand); box-shadow: var(--ring); }
.login-card .btn { width: 100%; padding: 10px; }
.login-err {
  background: #fdecea;
  border: 1px solid #f3c2bd;
  color: #a3261e;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: .84rem;
  margin-bottom: 12px;
}

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 760px) {
  .admin-main { padding: 18px 14px 56px; }
  .list-head { display: none; }

  .row {
    grid-template-columns: 60px minmax(0, 1fr);
    grid-template-areas:
      "cover main"
      "cover facts"
      "actions actions";
    align-items: start;
    gap: 2px 14px;
    padding: 14px;
  }
  .c-num { display: none; }
  .c-cover { grid-area: cover; }
  .c-main { grid-area: main; }
  .c-facts {
    grid-area: facts;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 7px;
  }
  .c-actions { grid-area: actions; justify-content: flex-start; margin-top: 13px; }
  /* Actions sit at the left edge on mobile, so a right-anchored popup would
     run off the left of the screen. */
  .menu-pop { right: auto; left: 0; }

  .search { margin-left: 0; width: 100%; }
  .search input { width: 100%; }
  .page-head { flex-direction: column; align-items: stretch; gap: 14px; }
  .page-head .spacer { margin-left: 0; }
  .page-head .btn { width: 100%; }

  dialog#book-modal {
    width: 100vw;
    max-width: 100vw;
    height: 100%;
    max-height: 100%;
    margin: 0;
    border-radius: 0;
  }
}
