/* =========================================================
   Design tokens
   ========================================================= */
:root {
  /* layout */
  --container-max: 1440px;
  --space-1: 6px;
  --space-2: 10px;
  --space-3: 14px;
  --space-4: 18px;
  --space-5: 24px;
  --radius-sm: 8px;
  --radius-lg: 14px;

  /* colors (light theme by default) */
  --bg: #f7f8fb;
  --surface: #ffffff;
  --text: #0f172a;
  --text-dim: #475569;
  --brand: #2563eb;
  --brand-ink: #1e40af;
  --border: #e5e7eb;
  --danger: #dc2626;

  /* shadows */
  --shadow-1: 0 1px 2px rgba(0,0,0,.05), 0 0 0 1px rgba(15,23,42,.04);
  --shadow-2: 0 10px 25px rgba(2,6,23,.10), 0 2px 6px rgba(2,6,23,.06);

  /* grid/card sizing */
  --grid-gap: 14px;
  --card-media-ratio: 3 / 4;     /* portrait window on cards */
  --card-media-height: auto;     /* let aspect-ratio drive height */
  --card-media-fit: contain;     /* show full photo; change to 'cover' for full-bleed */
}

/* Dark theme tokens */
:root[data-theme="dark"] {
  --bg: #0b1220;
  --surface: #121a2a;
  --text: #e5e7eb;
  --text-dim: #93a3b8;
  --brand: #60a5fa;
  --brand-ink: #93c5fd;
  --border: #1f2a3a;
  --danger: #f87171;
  --shadow-1: 0 1px 2px rgba(0,0,0,.4), 0 0 0 1px rgba(255,255,255,.04);
  --shadow-2: 0 12px 28px rgba(0,0,0,.35), 0 2px 6px rgba(0,0,0,.25);
}

/* =========================================================
   Base layout
   ========================================================= */
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font: 16px/1.45 system-ui, -apple-system, Segoe UI, Roboto, Inter, "Helvetica Neue", Arial, "Apple Color Emoji","Segoe UI Emoji";
  color: var(--text);
  background: var(--bg);
  transition: background .2s ease, color .2s ease, border-color .2s ease;
}

/* container */
.container {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: 20px;
}

/* nav/header */
.nav {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 700; }
.nav-link { color: var(--text); text-decoration: none; padding: 6px 10px; border-radius: 8px; }
.nav-link[aria-current="page"] { background: #eef2ff22; }
.flex-1 { flex: 1; }
.theme-toggle { border: 1px solid var(--border); background: var(--surface); padding: 6px 10px; border-radius: 10px; cursor: pointer; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace; }

/* buttons / inputs (shared) */
.button {
  border: 1px solid var(--border);
  background: var(--brand);
  color: #fff;
  padding: 8px 14px;
  border-radius: 10px;
  cursor: pointer;
  box-shadow: var(--shadow-1);
}
.button.secondary {
  background: var(--surface);
  color: var(--text);
}
.button.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.button.icon { padding: 6px 8px; }
.input, input[type="text"], input[type="password"], select, textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  background: var(--surface);
  color: var(--text);
}
label { display: block; margin-top: 10px; }
.form .row { display: flex; gap: 10px; align-items: center; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-5); }
.meta { color: var(--text-dim); font-size: .92rem; }

/* admin sections / cards */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 16px;
  box-shadow: var(--shadow-1);
}
.section + .section { margin-top: 18px; }
.section__header { display:flex; align-items:center; justify-content:space-between; margin-bottom:10px; }
.section__title { margin:0; font-size:1.15rem; }

/* forms in a grid (for neat query/search bars) */
.form-grid {
  display: grid;
  grid-template-columns: 2fr 1.2fr auto;
  gap: 12px;
  align-items: end;
}

/* toast */
.toast-wrap { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 10px; z-index: 30; }
.toast {
  display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 10px 12px; box-shadow: var(--shadow-2);
}
.toast.ok { border-color: #10b981; }
.toast.warn { border-color: #f59e0b; }
.toast.err { border-color: #ef4444; }

/* tables (admin) */
.table { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: 12px; overflow: hidden; box-shadow: var(--shadow-1); }
.table th, .table td { padding: 10px 12px; border-bottom: 1px solid var(--border); text-align: left; }
.table-striped tbody tr:nth-child(even) { background: #fafafa11; }

/* search */
.search-bar { margin-bottom: 16px; }
.search-bar input {
  height: 42px;
  padding: 10px 12px;
}

/* =========================================================
   Card grid (1 → 5 columns)
   ========================================================= */
.grid {
  display: grid;
  gap: var(--grid-gap);
  grid-template-columns: 1fr;                       /* 1 col by default */
}

/* Responsive columns */
@media (min-width: 520px)  { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 820px)  { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (min-width: 1080px) { .grid { grid-template-columns: repeat(4, 1fr); } }
@media (min-width: 1320px) { .grid { grid-template-columns: repeat(5, 1fr); } }  /* cap at 5 */

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-1);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  cursor: pointer;
  transition: transform .06s ease, box-shadow .2s ease;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }

/* Card media area: portrait window for profile shots */
.card__media {
  position: relative;
  background: transparent;
  display: block;
  aspect-ratio: var(--card-media-ratio);
  height: var(--card-media-height);
}
.card__media img {
  position: absolute; inset: 0;
  width: 100%; height: 100%;
  object-fit: var(--card-media-fit);
  object-position: center center;
}

/* Card body */
.card__body { padding: 12px; }
.card__title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.3;
  font-weight: 700;
}
.card__meta {
  margin-top: 4px;
  color: var(--text-dim);
  font-size: .9rem;
  display: -webkit-box;
  -webkit-line-clamp: 2; line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden;
}

/* Loading */
.loading { color: var(--text-dim); }

/* =========================================================
   Modal / Subject details (larger + adaptive)
   ========================================================= */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(2,6,23,.6);
  display: grid; place-items: center;
  padding: 24px;
  z-index: 40;
}
.modal {
  width: clamp(1000px, 95vw, 1600px);
  max-height: 94vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-2);
  display: flex; flex-direction: column;
}
.modal--wide { width: min(1000px, 96vw); }
.modal--xl { width: clamp(1100px, 95vw, 1600px); }
.modal__header, .modal__footer { padding: 14px 16px; border-bottom: 1px solid var(--border); background: var(--surface); }
.modal__footer { border-top: 1px solid var(--border); border-bottom: 0; }
.modal__title { margin: 0; font-size: 1.25rem; }
.modal__body {
  padding: 16px;
  overflow: auto;
}

/* Three-column subject layout */
.subject-layout {
  display: grid;
  grid-template-columns: repeat(3, minmax(420px, 1fr));
  gap: 16px;
  align-items: start;
}

/* Left: image pane (sticky) */
.subject-left { position: sticky; top: 16px; }
.subject-left img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: var(--radius-lg);
  background: transparent;
  box-shadow: var(--shadow-1);
}

/* Middle: key/value table */
.kv-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-1);
}
.kv-table th, .kv-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 12px;
  font-size: .95rem;
  vertical-align: top;
}
.kv-table th {
  width: 240px;
  background: #f8fafc11;
  text-align: left;
  font-weight: 600;
}

/* Right: notes + tags (larger) */
.subject-right .comment-box {
  width: 100%;
  min-height: 220px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  font: inherit;
  background: var(--surface);
  color: var(--text);
  white-space: pre-wrap;
}
.tag-chips {
  display: flex; flex-wrap: wrap;
  gap: 8px; margin-top: 10px;
}
.chip {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  box-shadow: var(--shadow-1);
  transition: transform .02s ease-in, background-color .2s, border-color .2s;
}
.chip:hover { transform: translateY(-1px); }
.chip.selected {
  border-color: var(--brand);
  background: var(--brand);
  color: #fff;
}
.subject-actions { display: flex; gap: 8px; margin-top: 10px; }

/* Responsive modal */
@media (max-width: 1280px) {
  .subject-layout {
    grid-template-columns: repeat(3, minmax(340px, 1fr));
  }
}
@media (max-width: 1080px) {
  .subject-layout { grid-template-columns: repeat(2, minmax(320px, 1fr)); }
  .subject-right { grid-column: 1 / -1; }
}
@media (max-width: 780px) {
  .subject-layout { grid-template-columns: 1fr; }
}

/* =========================================================
   Utility lists used in admin modals
   ========================================================= */
.list-grid .list-item {
  display: grid;
  grid-template-columns: 64px 1fr;
  gap: 10px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
}
.list-grid .list-item.clickable { cursor: pointer; }
.list-grid .thumb {
  width: 64px; height: 64px; object-fit: cover; border-radius: 8px; background: transparent;
}
.list-item__title { font-weight: 600; }
.item-meta { color: var(--text-dim); font-size: .9rem; }

/* =========================================================
   Keep your existing "modal-open" body lock behavior
   ========================================================= */
body.modal-open { overflow: hidden; }

/* =========================================================
   Helpers
   ========================================================= */
.pill {
  display:inline-block;
  padding:4px 8px;
  border-radius:999px;
  border:1px solid var(--border);
  background:var(--surface);
  font-size:.85rem;
}
.pill.ok { border-color:#10b981; }
.pill.muted { color: var(--text-dim); }
