/* Coupon Book Studio · giao diện chung. Bảng màu "Candy Pop" (chủ dự án chọn thay cho màu trong SPEC mục 10). */

/* Font giao diện (OFL, đóng gói trong assets/fonts). Font nhúng PDF (.ttf) sẽ thêm ở Milestone 4. */
@font-face { font-family: 'Fredoka'; font-weight: 500; font-display: swap; src: url('../fonts/fredoka-latin-500.woff2') format('woff2'); }
@font-face { font-family: 'Fredoka'; font-weight: 600; font-display: swap; src: url('../fonts/fredoka-latin-600.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 400; font-display: swap; src: url('../fonts/inter-latin-400.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 500; font-display: swap; src: url('../fonts/inter-latin-500.woff2') format('woff2'); }
@font-face { font-family: 'Inter'; font-weight: 600; font-display: swap; src: url('../fonts/inter-latin-600.woff2') format('woff2'); }

:root {
  --bg: #FFF6F1;
  --card: #FFFFFF;
  --topbar: #2D1B4E;
  --accent: #D6304B;
  --accent-hover: #B8243D;
  --accent-text: #B8243D;
  --step-active-bg: #FFC93C;
  --focus: #7C3AED;
  --text: #2D1B4E;
  --text-muted: #5E5470;
  --border: #E9DDD8;
  --ok: #1E6B45;
  --ok-bg: #E4F4EA;
  --warn: #7A5300;
  --warn-bg: #FFF3D1;
  --error: #B8243D;
  --error-bg: #FDE6EA;
  --info-bg: #F3EEFA;

  --radius-card: 18px;
  --radius-btn: 11px;
  --tap: 44px;

  --font-title: 'Fredoka', 'Trebuchet MS', system-ui, sans-serif;
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}

h1, h2, h3 { font-family: var(--font-title); line-height: 1.2; margin: 0 0 .4em; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 1em; }
a { color: var(--accent-text); }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

.muted { color: var(--text-muted); }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.icon { flex: none; }
[hidden] { display: none !important; }

/* ---- Thanh trên cùng ---- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  flex-wrap: wrap;
  background: var(--topbar); color: #fff;
  padding: 8px 24px; min-height: 64px;
}
.brand {
  display: inline-flex; align-items: center; gap: 10px;
  color: #fff; text-decoration: none;
  font-family: var(--font-title); font-size: 1.2rem; font-weight: 600;
}
.topbar-nav { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.topbar-nav a { color: #fff; text-decoration: none; padding: 10px 2px; }
.topbar-nav a:hover { text-decoration: underline; }
.topbar-user { color: #D8DAEA; font-size: .9rem; }
.inline-form { display: inline; margin: 0; }

/* ---- Bố cục ---- */
.app-main { max-width: 1180px; margin: 0 auto; padding: 28px 20px 60px; }
.auth-main { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 24px;
  margin-bottom: 24px;
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: 16px;
  flex-wrap: wrap; margin-bottom: 20px;
}
.page-head p { margin: 0; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.two-col .card { margin-bottom: 0; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }

.back-link {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); text-decoration: none; font-weight: 500;
}

/* ---- Nút ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px;
  border-radius: var(--radius-btn); border: 1px solid transparent;
  font: inherit; font-weight: 600; text-decoration: none; cursor: pointer;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:disabled { background: #6B6980; cursor: not-allowed; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { border-color: var(--text-muted); }
.btn-ghost-light { background: transparent; color: #fff; border-color: rgba(255,255,255,.35); }
.btn-ghost-light:hover { border-color: #fff; }
.btn-small { min-height: 36px; padding: 0 12px; font-size: .9rem; }
.btn-block { width: 100%; }
.btn-icon {
  display: inline-grid; place-items: center;
  width: var(--tap); height: var(--tap);
  border: 0; background: transparent; color: var(--text); border-radius: var(--radius-btn); cursor: pointer;
}
.btn-icon:hover { background: var(--bg); }

/* ---- Form ---- */
.form { display: grid; gap: 16px; margin-top: 8px; }
.field { display: grid; gap: 6px; font-weight: 500; }
.field small { font-weight: 400; }
input[type=email], input[type=password], input[type=text], input[type=search], select {
  width: 100%; min-height: var(--tap); padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 10px;
  font: inherit; color: var(--text); background: #fff;
}
input:focus, select:focus { border-color: var(--text-muted); }

/* ---- Thông báo ---- */
.notice { border-radius: 12px; padding: 12px 16px; margin-bottom: 16px; }
.notice-success { background: var(--ok-bg); color: var(--ok); }
.notice-error { background: var(--error-bg); color: var(--error); }
.notice-info { background: var(--info-bg); color: var(--text); }
.notice-warn { background: var(--warn-bg); color: var(--warn); }

/* ---- Trang đăng nhập ---- */
.auth-card { width: 100%; max-width: 440px; padding: 32px; }
.auth-brand {
  display: flex; align-items: center; gap: 10px; margin-bottom: 20px;
  color: var(--accent-text); font-family: var(--font-title); font-weight: 600; font-size: 1.1rem;
}
.auth-links { display: flex; flex-direction: column; gap: 4px; margin-top: 20px; }
.auth-links a { display: inline-flex; align-items: center; min-height: var(--tap); }

.check-table { list-style: none; padding: 0; margin: 0 0 20px; display: grid; gap: 6px; }
.check-table li { display: flex; align-items: center; gap: 8px; }
.check-table .ok { color: var(--ok); }
.check-table .bad { color: var(--error); }

/* ---- Category ---- */
.cat-group { margin-top: 24px; }
.cat-group-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 12px; }
.cat-group-head h3 { margin: 0; }
.cat-grid {
  list-style: none; margin: 0; padding: 0;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 12px;
}
.cat-card {
  display: flex; flex-direction: column; justify-content: center; gap: 4px;
  width: 100%; min-height: 84px; padding: 14px 16px; text-align: left;
  background: #fff; color: var(--text); text-decoration: none;
  border: 1px solid var(--border); border-radius: 16px;
  font: inherit; cursor: pointer;
}
.cat-card:hover { border-color: var(--accent); box-shadow: 0 2px 10px rgba(31,35,64,.08); }
.cat-title { font-family: var(--font-title); font-weight: 600; font-size: 1.05rem; }
.cat-meta { color: var(--text-muted); font-size: .85rem; }
.cat-card.is-locked { background: #FAF9FC; }
.cat-card.is-locked .cat-title { color: var(--text-muted); }
.cat-lock { display: inline-flex; align-items: center; gap: 6px; color: var(--accent-text); font-size: .85rem; font-weight: 500; }
.cat-lock .icon { width: 16px; height: 16px; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 32px; padding: 0 12px; border-radius: 999px;
  font: inherit; font-size: .85rem; font-weight: 600; border: 1px solid transparent;
}
.badge .icon { width: 16px; height: 16px; }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-locked { background: var(--error-bg); color: var(--accent-text); cursor: pointer; min-height: var(--tap); }
.badge-locked:hover { border-color: var(--accent-text); }
.badge-admin { background: var(--step-active-bg); color: var(--text); }

.empty {
  display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px;
  padding: 28px 12px; color: var(--text-muted);
  border: 2px dashed var(--border); border-radius: 14px;
}
.empty .icon { width: 32px; height: 32px; }
.empty p { margin: 0; max-width: 360px; }

/* ---- Thanh bước ---- */
.stepbar { margin-bottom: 20px; }
.stepbar ol {
  list-style: none; margin: 0; padding: 6px;
  display: flex; gap: 6px; overflow-x: auto;
  background: var(--topbar); border-radius: 14px;
}
.stepbar li { flex: 1 0 auto; }
.step {
  position: relative; width: 100%;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 14px;
  background: transparent; color: #fff; border: 0; border-radius: 10px;
  font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.step:hover { background: rgba(255,255,255,.1); }
.step.is-active { background: var(--step-active-bg); color: var(--text); }
.step-num {
  display: inline-grid; place-items: center; width: 24px; height: 24px;
  border-radius: 50%; border: 2px solid currentColor; font-size: .8rem;
}
.step-dot {
  position: absolute; top: 8px; right: 8px;
  width: 8px; height: 8px; border-radius: 50%; background: #FFB020;
}

/* ---- Modal ---- */
.modal {
  width: min(520px, calc(100vw - 32px));
  border: 0; border-radius: var(--radius-card); padding: 24px;
  color: var(--text); box-shadow: 0 20px 60px rgba(31,35,64,.3);
}
.modal::backdrop { background: rgba(31,35,64,.55); }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.modal-head h2 { margin-top: 8px; }
.modal-sub { margin-top: 16px; }
.check-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.check-list li { display: flex; gap: 10px; align-items: flex-start; }
.check-list .icon { color: var(--ok); margin-top: 2px; }
.modal-actions { margin-top: 24px; display: flex; justify-content: flex-end; }
.owned { display: inline-flex; align-items: center; gap: 8px; color: var(--ok); font-weight: 600; margin: 0; }

/* ---- Admin ---- */
.toolbar { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { flex: 1 1 260px; }
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: .95rem; }
table.data th, table.data td { text-align: left; padding: 12px 10px; border-bottom: 1px solid #E6E3EE; vertical-align: top; }
table.data th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 4px 2px 10px; border-radius: 999px;
  background: var(--info-bg); font-size: .85rem; font-weight: 600;
}
.chip .btn-icon { width: 32px; height: 32px; }
.chip .icon { width: 14px; height: 14px; }
.grant-form { display: flex; gap: 6px; }
.grant-form select { min-width: 150px; min-height: 36px; padding: 4px 8px; }
.pager { display: flex; align-items: center; gap: 12px; margin-top: 16px; }

@media (max-width: 600px) {
  .topbar { padding: 8px 16px; }
  .topbar-user { display: none; }
  .app-main { padding: 20px 14px 40px; }
  .card { padding: 18px; }
  .step-label { display: none; }
  .step.is-active .step-label { display: inline; }
}

/* ================= Milestone 2: My books, Setup, Content ================= */
.small { font-size: .85rem; }
.gap { gap: 10px; }
.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: #7E1530; }
.btn-danger-outline { background: #fff; color: var(--error); border-color: #E3A9B8; }
.btn-danger-outline:hover { border-color: var(--error); }
.btn-small { min-height: 36px; }
.link-button {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 0; min-height: 36px;
  background: none; border: 0; color: var(--accent-text); font: inherit; font-weight: 600;
  text-decoration: underline; cursor: pointer;
}
.link-button .icon { width: 16px; height: 16px; }
.icon-wrap { display: inline-flex; }

.books-table td { vertical-align: middle; }
.book-link { font-weight: 600; text-decoration: none; }
.book-link:hover { text-decoration: underline; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.row-actions form { margin: 0; }
.badge-step { background: var(--info-bg); color: var(--text); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }
.cat-grid form { margin: 0; height: 100%; }
.cat-grid form .cat-card { height: 100%; }

/* Trạng thái lưu */
.save-state { margin: 0; font-size: .9rem; color: var(--text-muted); min-height: 24px; }
.save-state[data-state="failed"], .save-state[data-state="locked"], .save-state[data-state="session"] { color: var(--error); font-weight: 600; }

/* Bố cục 2 cột của editor */
.editor-grid { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 24px; align-items: start; }
.content-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
.editor-grid .card { margin-bottom: 0; }
.stack { display: grid; gap: 24px; }
@media (max-width: 960px) { .editor-grid, .content-grid { grid-template-columns: 1fr; } }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .field-row { grid-template-columns: 1fr; } }
.field-group { border: 0; padding: 0; margin: 0; display: grid; gap: 8px; }
.field-group legend { font-weight: 500; padding: 0; margin-bottom: 8px; }
textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  font: inherit; color: var(--text); background: #fff; resize: vertical;
}
textarea:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }
textarea.mono { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace; font-size: .88rem; line-height: 1.45; }
input[type=number] { min-height: var(--tap); padding: 8px 12px; border: 1px solid var(--border); border-radius: 10px; font: inherit; }
.num-input { width: 110px; }
.form-actions { display: flex; justify-content: flex-end; }
.button-row { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 12px; }

/* Nút chọn dạng viên */
.pills { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pill {
  position: relative; display: inline-flex; align-items: center; gap: 6px;
  min-height: var(--tap); padding: 0 16px; border: 1px solid var(--border); border-radius: 999px;
  background: #fff; color: var(--text); font: inherit; font-weight: 500; cursor: pointer;
}
.pill input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pill:has(input:checked) { background: var(--topbar); border-color: var(--topbar); color: #fff; }
.pill:has(input:focus-visible) { outline: 3px solid var(--focus); outline-offset: 2px; }
.pill.is-disabled { color: #6B6980; background: #F1EFF5; cursor: not-allowed; }
.pill.is-locked { background: var(--error-bg); color: var(--accent-text); border-color: transparent; }
.pill .icon { width: 16px; height: 16px; }

/* Công tắc bật/tắt */
.toggles { display: grid; gap: 10px; }
.toggle { display: inline-flex; align-items: center; gap: 12px; min-height: var(--tap); cursor: pointer; font-weight: 500; }
.toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.toggle-track { position: relative; width: 44px; height: 26px; border-radius: 999px; background: #B9B6C8; flex: none; transition: background .15s; }
.toggle-track::after { content: ''; position: absolute; top: 3px; left: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.toggle input:checked + .toggle-track { background: var(--accent); }
.toggle input:checked + .toggle-track::after { transform: translateX(18px); }
.toggle input:focus-visible + .toggle-track { outline: 3px solid var(--focus); outline-offset: 2px; }

/* Book summary */
.summary { position: sticky; top: 16px; }
.summary-list { display: grid; grid-template-columns: auto 1fr; gap: 8px 14px; margin: 0; }
.summary-list dt { color: var(--text-muted); font-size: .9rem; }
.summary-list dd { margin: 0; font-weight: 600; text-align: right; }

/* Content */
.mode-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 12px; margin-bottom: 8px; }
.mode-text { margin: 0; font-weight: 600; color: var(--accent-text); }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; margin-bottom: 12px; }
.list-head h2 { margin: 0; }
.count-chip { font-family: var(--font-body); font-size: .9rem; font-weight: 500; color: var(--text-muted); }
.notice-action { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.notice-action > span { display: inline-flex; align-items: center; gap: 8px; }
.coupon-list { list-style: none; margin: 0 0 16px; padding: 0; display: grid; gap: 8px; }
.coupon-item {
  display: grid; grid-template-columns: auto auto 1fr auto; gap: 4px 8px; align-items: start;
  padding: 10px 8px; border: 1px solid var(--border); border-radius: 14px; background: #fff;
}
.coupon-item.is-flagged { border: 2px solid #E0A800; background: #FFFBEB; }
.coupon-item.is-dragging { opacity: .5; }
.coupon-item.drop-before { box-shadow: 0 -3px 0 var(--accent); }
.coupon-item.drop-after { box-shadow: 0 3px 0 var(--accent); }
.drag-handle { cursor: grab; color: var(--text-muted); }
.coupon-num {
  display: inline-grid; place-items: center; min-width: 28px; height: 28px; margin-top: 8px;
  border-radius: 8px; background: var(--bg); font-size: .85rem; font-weight: 600;
}
.coupon-body { padding-top: 8px; min-width: 0; }
.coupon-body p { margin: 2px 0 4px; }
.coupon-title { font-family: var(--font-title); font-weight: 600; }
.dupe-note { display: flex; align-items: center; gap: 6px; color: var(--warn); font-weight: 600; font-size: .9rem; }
.dupe-note .icon { width: 16px; height: 16px; }
.coupon-actions { display: flex; }
.coupon-edit { grid-column: 1 / -1; display: grid; grid-template-columns: auto 1fr; gap: 10px; }
.coupon-list .empty { list-style: none; }
