/* Vilo Fence brand (pulled from vilofence.com): burgundy / deep teal-green / tan */
:root {
  --red: #691d20;
  --red-dark: #4f1518;
  --red-darker: #700004;
  --tan-warm: #c18774;
  --beige: #f1e8df;
  --beige-dark: #e6dbcc;
  --green: #253938;
  --green-dark: #16221F;
  --ink: #1a1a1a;
  --muted: #6b6b6b;
  --line: #d8cdbd;
  --white: #ffffff;
  --danger: #b3261e;
  --ok: #2e7d32;
  /* legacy aliases so older selectors keep working */
  --salmon: var(--red);
  --salmon-dark: var(--red-dark);
  --radius: 10px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.06), 0 1px 1px rgba(0,0,0,.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg: 0 16px 40px rgba(0,0,0,.12), 0 4px 8px rgba(0,0,0,.06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--beige);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--green); text-decoration: none; }
a:hover { color: var(--salmon); }

button, .btn {
  font: inherit;
  cursor: pointer;
  border: none;
  background: var(--green);
  color: var(--white);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-weight: 600;
  letter-spacing: 0.2px;
  transition: background 120ms, transform 80ms, box-shadow 120ms;
  box-shadow: var(--shadow-sm);
  display: inline-flex; align-items: center; gap: 8px;
}
button:hover, .btn:hover { background: var(--green-dark); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: var(--white); color: var(--green); border: 1px solid var(--line); }
.btn-secondary:hover { background: var(--beige-dark); color: var(--green-dark); }
.btn-salmon { background: var(--salmon); }
.btn-salmon:hover { background: var(--salmon-dark); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: transparent; color: var(--ink); box-shadow: none; }
.btn-ghost:hover { background: var(--beige-dark); }
.btn-sm { padding: 6px 12px; font-size: 13px; }

input, textarea, select {
  font: inherit;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  padding: 10px 12px;
  border-radius: var(--radius);
  width: 100%;
  outline: none;
  transition: border-color 120ms, box-shadow 120ms;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(44,95,45,0.15);
}

label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }

.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 24px;
}

.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 12px; align-items: center; }
.row.gap-lg { gap: 24px; }
.spread { display: flex; justify-content: space-between; align-items: center; }
.grid { display: grid; gap: 16px; }
.grid-3 { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.hidden { display: none !important; }

/* App shell */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  background: var(--green);
  color: var(--white);
  padding: 14px 24px;
  display: flex; justify-content: space-between; align-items: center;
  box-shadow: var(--shadow-md);
  position: sticky; top: 0; z-index: 50;
}
.topbar .brand { display: flex; align-items: center; gap: 12px; font-weight: 700; letter-spacing: 0.5px; }
.topbar .brand-mark {
  background: var(--salmon); color: var(--white);
  width: 32px; height: 32px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800;
}
.topbar nav { display: flex; gap: 4px; }
.topbar nav a {
  color: rgba(255,255,255,0.85); padding: 8px 14px; border-radius: 8px; font-weight: 500; font-size: 14px;
}
.topbar nav a:hover, .topbar nav a.active { background: rgba(255,255,255,0.12); color: var(--white); }
.topbar .me { font-size: 13px; opacity: 0.9; }
.topbar .logout { background: rgba(255,255,255,0.12); color: var(--white); padding: 6px 12px; font-size: 13px; box-shadow: none; }
.topbar .logout:hover { background: rgba(255,255,255,0.22); }

.main { flex: 1; padding: 24px; max-width: 1200px; width: 100%; margin: 0 auto; }
h1.page-title { margin: 0 0 16px; color: var(--green-dark); font-size: 28px; }
h2.section-title { margin: 24px 0 12px; color: var(--green-dark); font-size: 20px; }

/* Auth pages */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: linear-gradient(135deg, var(--beige), var(--beige-dark));
}
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand-row {
  display: flex; align-items: center; gap: 12px; margin-bottom: 18px;
}
.auth-card .brand-mark {
  background: var(--salmon); color: var(--white);
  width: 44px; height: 44px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 800; font-size: 18px;
}
.auth-card h1 { margin: 0; font-size: 22px; color: var(--green-dark); }
.auth-card p.lede { color: var(--muted); margin: 4px 0 24px; }
.field { margin-bottom: 14px; }
.error { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }
.ok-msg { color: var(--ok); font-size: 13px; margin-top: 8px; }

/* Handbook cards on user dashboard */
.hb-card { display: flex; flex-direction: column; min-height: 220px; padding: 0; overflow: hidden; cursor: pointer; transition: transform 120ms, box-shadow 120ms; }
.hb-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.hb-card .cover { padding: 22px 22px 16px; color: var(--white); }
.hb-card .cover h3 { margin: 0 0 6px; font-size: 18px; }
.hb-card .cover p { margin: 0; font-size: 13px; opacity: 0.92; }
.hb-card .body { padding: 16px 22px 22px; flex: 1; display: flex; flex-direction: column; justify-content: space-between; gap: 14px; }
.hb-card .progress-bar { background: var(--beige-dark); height: 8px; border-radius: 99px; overflow: hidden; }
.hb-card .progress-bar > div { background: var(--salmon); height: 100%; transition: width 180ms; }
.hb-card .meta { font-size: 12px; color: var(--muted); display: flex; justify-content: space-between; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 99px; font-size: 11px; font-weight: 700; letter-spacing: 0.3px; }
.badge-ok { background: rgba(46,125,50,0.12); color: var(--ok); }
.badge-fail { background: rgba(179,38,30,0.10); color: var(--danger); }
.badge-pending { background: var(--beige-dark); color: var(--muted); }

/* Reader */
.reader-wrap { max-width: 820px; margin: 0 auto; padding: 24px; }
.reader-progress {
  position: sticky; top: 60px; background: var(--beige);
  padding: 8px 0 14px;
  display: flex; align-items: center; gap: 12px;
  font-size: 13px; color: var(--muted);
  z-index: 10;
}
.reader-progress .bar { flex: 1; height: 6px; background: var(--beige-dark); border-radius: 99px; overflow: hidden; }
.reader-progress .bar > div { background: var(--salmon); height: 100%; transition: width 200ms; }
.page-card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  padding: 32px 36px;
  min-height: 60vh;
}
.page-card h2 { color: var(--green-dark); margin-top: 0; }
.page-body { font-size: 16px; line-height: 1.65; color: var(--ink); }
.page-body img { max-width: 100%; border-radius: var(--radius); margin: 12px 0; }
.page-body h2, .page-body h3 { color: var(--green-dark); }
.page-body ul, .page-body ol { padding-left: 22px; }
.video-embed { position: relative; padding-bottom: 56.25%; height: 0; overflow: hidden; border-radius: var(--radius); margin: 16px 0; background: #000; }
.video-embed iframe { position: absolute; top: 0; left: 0; width: 100%; height: 100%; border: 0; }
.reader-nav { margin-top: 20px; display: flex; justify-content: space-between; align-items: center; }
.reader-nav .pageno { color: var(--muted); font-size: 13px; }

/* Quiz */
.quiz-question { background: var(--white); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 24px; margin-bottom: 18px; }
.quiz-question h3 { margin: 0 0 14px; color: var(--green-dark); font-size: 17px; }
.choice {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px; border: 2px solid var(--line);
  border-radius: var(--radius); cursor: pointer; margin-bottom: 8px;
  transition: border-color 120ms, background 120ms;
}
.choice:hover { border-color: var(--green); background: var(--beige); }
.choice input { display: none; }
.choice .dot { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); flex: 0 0 auto; }
.choice.selected { border-color: var(--green); background: rgba(44,95,45,0.06); }
.choice.selected .dot { border-color: var(--green); background: var(--green); }
.choice.correct { border-color: var(--ok); background: rgba(46,125,50,0.08); }
.choice.incorrect { border-color: var(--danger); background: rgba(179,38,30,0.08); }

/* Quiz result + certificate */
.result-card { text-align: center; padding: 40px 32px; }
.score-circle {
  width: 140px; height: 140px; margin: 0 auto 18px;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-size: 36px; font-weight: 800; color: var(--white);
  box-shadow: var(--shadow-lg);
}
.score-circle.pass { background: var(--green); }
.score-circle.fail { background: var(--salmon-dark); }

/* Admin */
.admin-tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--line); }
.admin-tabs button {
  background: transparent; color: var(--muted);
  border-radius: 0; padding: 12px 16px; box-shadow: none;
  border-bottom: 3px solid transparent; font-weight: 600;
}
.admin-tabs button.active { color: var(--green-dark); border-bottom-color: var(--salmon); }
.admin-tabs button:hover { background: transparent; color: var(--green-dark); }

table { width: 100%; border-collapse: collapse; background: var(--white); border-radius: var(--radius-lg); overflow: hidden; box-shadow: var(--shadow-sm); }
table th, table td { padding: 12px 14px; text-align: left; border-bottom: 1px solid var(--line); font-size: 14px; }
table th { background: var(--beige-dark); color: var(--green-dark); font-size: 12px; text-transform: uppercase; letter-spacing: 0.4px; }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: var(--beige); }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 24px;
}
.modal {
  background: var(--white); border-radius: var(--radius-lg);
  width: 100%; max-width: 720px; max-height: 90vh; overflow: auto;
  box-shadow: var(--shadow-lg);
}
.modal header { padding: 20px 24px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }
.modal header h2 { margin: 0; color: var(--green-dark); font-size: 18px; }
.modal .modal-body { padding: 24px; }
.modal footer { padding: 16px 24px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; }
.modal-wide { max-width: 960px; }
.modal-xl { max-width: 1100px; }

/* Editor */
.page-editor { display: flex; flex-direction: column; gap: 14px; margin-bottom: 18px; padding: 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--beige); }
.page-editor .ql-container { background: var(--white); border-radius: var(--radius); min-height: 180px; }
.page-editor .ql-toolbar { background: var(--white); border-top-left-radius: var(--radius); border-top-right-radius: var(--radius); }

.question-editor { border: 1px solid var(--line); border-radius: var(--radius); background: var(--beige); padding: 16px; margin-bottom: 12px; }
.choice-row { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }
.choice-row input[type="radio"] { width: auto; }
.choice-row input[type="text"] { flex: 1; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--green-dark); color: var(--white);
  padding: 12px 20px; border-radius: var(--radius); box-shadow: var(--shadow-lg);
  z-index: 200; font-size: 14px;
  opacity: 0; transition: opacity 200ms, transform 200ms;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(-4px); }
.toast.error { background: var(--danger); }

@media print {
  .topbar, .reader-nav, .reader-progress, button { display: none !important; }
  body { background: #fff; }
  .main { padding: 0; }
}
