/* ── Reset ─────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ── Tokens ────────────────────────────────────────────────── */
:root {
  --bg:       #f4f5f9;
  --surface:  #ffffff;
  --border:   #e2e5ed;
  --text:     #1a1d23;
  --muted:    #6b7280;
  --accent:   #4f6ef7;
  --accent-h: #3a57e8;
  --danger:   #ef4444;
  --danger-h: #dc2626;
  --r:        6px;
  --shadow:   0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
}

[hidden] { display: none !important; }
.error   { color: var(--danger); font-size: 13px; min-height: 18px; }

/* ── Login ─────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 40px 36px;
  width: 360px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card h1 { font-size: 22px; font-weight: 700; }

/* ── Fields ────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; }

.field label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
}

.hint { font-size: 11px; color: var(--muted); font-weight: 400; }

input[type="email"],
input[type="password"],
input[type="text"],
input[type="url"],
input[type="datetime-local"],
textarea,
select {
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 8px 10px;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface);
  outline: none;
  width: 100%;
  transition: border-color .15s, box-shadow .15s;
}

input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,110,247,.12);
}

textarea { resize: vertical; min-height: 100px; }

/* ── Buttons ───────────────────────────────────────────────── */
button {
  cursor: pointer;
  border: none;
  background: none;
  font-family: inherit;
  font-size: 14px;
  border-radius: var(--r);
  transition: background .15s, color .15s, border-color .15s;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  padding: 9px 18px;
  font-weight: 500;
}
.btn-primary:hover    { background: var(--accent-h); }
.btn-primary:disabled { opacity: .55; cursor: not-allowed; }

.btn-sm {
  padding: 5px 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
}
.btn-sm:hover { background: var(--bg); }

.btn-sm.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.btn-sm.btn-primary:hover { background: var(--accent-h); border-color: var(--accent-h); }

.btn-sm.btn-danger  { border-color: var(--danger); color: var(--danger); }
.btn-sm.btn-danger:hover { background: var(--danger); color: #fff; }

/* ── App shell ─────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

.app-header {
  height: 52px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  flex-shrink: 0;
}

.logo { font-size: 16px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }
.user-email { font-size: 13px; color: var(--muted); }

.main-layout { display: flex; flex: 1; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: 180px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--r);
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
  text-align: left;
  width: 100%;
}
.nav-item:hover  { background: var(--bg); color: var(--text); }
.nav-item.active { background: rgba(79,110,247,.1); color: var(--accent); }

/* ── Content / view ────────────────────────────────────────── */
.content { flex: 1; overflow: hidden; display: flex; }

.view { flex: 1; overflow-y: auto; padding: 28px 32px; }

/* ── List view ─────────────────────────────────────────────── */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.view-title { font-size: 22px; font-weight: 700; }

.entity-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: 8px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.entity-table th {
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  padding: 10px 16px;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
}

.entity-table th.sortable { cursor: pointer; user-select: none; }
.entity-table th.sortable:hover { color: var(--text); }
.entity-table th.sort-active { color: var(--accent); }
.sort-icon { font-size: 10px; margin-left: 3px; }

.entity-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.entity-table tr:last-child td { border-bottom: none; }
.entity-table tbody tr        { cursor: pointer; }
.entity-table tbody tr:hover td { background: #fafbff; }

.row-actions { display: flex; gap: 6px; }

.drag-handle { cursor: grab; color: var(--muted); font-size: 18px; user-select: none; text-align: center; padding: 12px 8px; }
.drag-handle:active { cursor: grabbing; }
.entity-table tbody tr.dragging { opacity: 0.4; }
.entity-table tbody tr.drag-over td { border-top: 2px solid var(--accent); }

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

.view-loading {
  color: var(--muted);
  padding: 40px 0;
}

/* ── Form view ─────────────────────────────────────────────── */
.form-back {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 20px;
  background: none;
  border: none;
  padding: 0;
}
.form-back:hover { text-decoration: underline; }

.form-title { font-size: 22px; font-weight: 700; margin-bottom: 28px; }

.form-nav { display: flex; flex-direction: column; gap: 2px; }
.form-nav .form-back  { margin-bottom: 0; }
.form-nav .form-title { margin-bottom: 0; }

.form-body {
  max-width: 580px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.form-actions {
  display: flex;
  gap: 10px;
  padding-top: 4px;
}

/* ── Multi-select checkboxes ───────────────────────────────── */
.ms-label {
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
}

.ms-list {
  border: 1px solid var(--border);
  border-radius: var(--r);
  max-height: 220px;
  overflow-y: auto;
  background: var(--surface);
}

.ms-empty {
  padding: 12px 16px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

.cb-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  cursor: pointer;
  transition: background .1s;
}
.cb-item:hover { background: var(--bg); }
.cb-item + .cb-item { border-top: 1px solid var(--border); }

.cb-item input[type="checkbox"] {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

.cb-item label {
  cursor: pointer;
  flex: 1;
  line-height: 1.3;
}

.cb-sub {
  display: block;
  font-size: 12px;
  color: var(--muted);
}

/* ── Author order list ────────────────────────────────────── */
.author-order-list {
  border: 1px solid var(--border);
  border-radius: var(--r);
  background: var(--surface);
  min-height: 44px;
  margin-bottom: 16px;
}

.author-order-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-bottom: 1px solid var(--border);
}
.author-order-item:last-child { border-bottom: none; }
.author-order-item .drag-handle { padding: 0; font-size: 16px; }
.author-order-item.dragging { opacity: 0.4; }
.author-order-item.drag-over { border-top: 2px solid var(--accent); }

.author-order-empty {
  padding: 12px 16px;
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
}

/* ── Homepage read view ────────────────────────────────────── */
.hp-view { display: flex; flex-direction: column; gap: 24px; }

.hp-hero { padding-bottom: 20px; border-bottom: 1px solid var(--border); }
.hp-title { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.hp-subtitle { font-size: 15px; color: var(--muted); }

.hp-banner {
  width: 100%;
  max-height: 180px;
  object-fit: cover;
  border-radius: var(--r);
  border: 1px solid var(--border);
}

.hp-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px 32px;
}

.hp-field { display: flex; flex-direction: column; gap: 4px; }

.hp-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.hp-text {
  font-size: 14px;
  color: var(--text);
  line-height: 1.7;
  white-space: pre-wrap;
}
.hp-text.none { color: var(--muted); font-style: italic; }

.gt-image-preview {
  width: 100%;
  max-height: 200px;
  object-fit: cover;
  border-radius: var(--r);
  border: 1px solid var(--border);
  margin-top: 6px;
}

/* ── Info tabs ─────────────────────────────────────────────── */
.info-tabs {
  display: flex;
  border-bottom: 2px solid var(--border);
  margin-bottom: 24px;
}

.info-tab {
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  cursor: pointer;
  transition: color .15s, border-color .15s;
  border-radius: 0;
}

.info-tab:hover  { color: var(--text); }
.info-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Settings ──────────────────────────────────────────────── */
.settings-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 20px;
  max-width: 580px;
  box-shadow: var(--shadow);
}

.settings-card-title {
  font-size: 15px;
  font-weight: 600;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}

.settings-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-bottom: 14px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
}
.settings-card-header .settings-card-title {
  padding-bottom: 0;
  margin-bottom: 0;
  border-bottom: none;
}

/* Toggle switch */
.toggle-wrap {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 20px;
}

.toggle { display: inline-flex; cursor: pointer; flex-shrink: 0; }
.toggle input { position: absolute; opacity: 0; width: 0; height: 0; }

.toggle-track {
  width: 46px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  position: relative;
  transition: background .2s;
}

.toggle input:checked + .toggle-track { background: var(--accent); }

.toggle-thumb {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: #fff;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s;
}

.toggle input:checked + .toggle-track .toggle-thumb { transform: translateX(20px); }

.toggle-label { font-size: 14px; }
.toggle-label strong { font-weight: 600; }

/* ── Detail modal ──────────────────────────────────────────── */
#detail-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.detail-card {
  background: var(--surface);
  border-radius: 10px;
  width: 460px;
  max-width: 92vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 12px 48px rgba(0,0,0,.18);
  overflow: hidden;
}

.detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.detail-header h2 { font-size: 17px; font-weight: 700; }

#detail-close {
  color: var(--muted);
  font-size: 15px;
  padding: 4px 6px;
  line-height: 1;
  border-radius: var(--r);
}
#detail-close:hover { background: var(--bg); color: var(--text); }

#detail-body {
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.detail-row { display: flex; flex-direction: column; gap: 4px; }

.detail-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

.detail-value { font-size: 14px; color: var(--text); line-height: 1.5; }
.detail-value.none { color: var(--muted); font-style: italic; }

.detail-photo {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid var(--border);
}

.detail-tags { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 2px; }

.detail-tag {
  background: rgba(79,110,247,.1);
  color: var(--accent);
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 13px;
  font-weight: 500;
}
