:root {
  --ink: #182238;
  --ink-2: #24324c;
  --gold: #c4a35a;
  --gold-2: #e0c27a;
  --paper: #f4efe6;
  --paper-2: #fffaf2;
  --line: #d9d0c1;
  --teal: #2d6a66;
  --danger: #a33b32;
  --warn: #b06a1b;
  --ok: #2f6b45;
  --muted: #6b645a;
  --shadow: 0 12px 40px rgba(24, 34, 56, 0.12);
  --sidebar: 260px;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

h1, h2, h3, .brand strong, .book-title {
  font-family: Fraunces, Georgia, serif;
}

.app-body {
  display: flex;
  min-height: 100vh;
}

.app-sidebar {
  width: var(--sidebar);
  background: linear-gradient(180deg, var(--ink) 0%, #111827 100%);
  color: #f3ead8;
  padding: 1.4rem 1rem 1rem;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  gap: 0.8rem;
  align-items: center;
  color: inherit;
  text-decoration: none;
  margin-bottom: 1.8rem;
  padding: 0 0.4rem;
}

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--gold), #8c6a2b);
  color: #1a1408;
  font-family: Fraunces, serif;
  font-weight: 700;
  font-size: 1.3rem;
}

.brand strong { display: block; font-size: 1.15rem; }
.brand small { display: block; opacity: .7; font-size: .78rem; }

.side-nav { display: flex; flex-direction: column; gap: .35rem; flex: 1; }

.side-link {
  color: #d9d1c2;
  text-decoration: none;
  padding: .7rem .85rem;
  border-radius: 10px;
  display: flex;
  gap: .7rem;
  align-items: center;
}

.side-link i { width: 1.1rem; }
.side-link:hover, .side-link.active {
  background: rgba(196, 163, 90, .16);
  color: #fff;
}

.sidebar-foot {
  padding: .9rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .9rem;
}

.sidebar-foot small { display: block; opacity: .65; }

.app-main { flex: 1; min-width: 0; }

.app-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 1.4rem 1.8rem .4rem;
}

.app-topbar h1 { font-size: 1.7rem; margin: 0; }
.top-sub { margin: .2rem 0 0; color: var(--muted); }
.top-actions { display: flex; gap: .6rem; align-items: center; }

.app-content { padding: 1rem 1.8rem 2.5rem; }

.icon-btn, .user-chip {
  border: 1px solid var(--line);
  background: var(--paper-2);
  width: 42px;
  height: 42px;
  border-radius: 12px;
  position: relative;
}

.notify-dot {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: #fff;
  border-radius: 999px;
  font-size: .68rem;
  min-width: 18px;
  height: 18px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

.notify-menu { width: 320px; padding-bottom: .4rem; }
.notify-item {
  display: flex;
  flex-direction: column;
  gap: .15rem;
  width: 100%;
  border: 0;
  background: transparent;
  text-align: left;
  padding: .7rem 1rem;
  border-top: 1px solid var(--line);
}
.notify-item.unread { background: #f7f1e2; }
.notify-item span, .notify-item small { color: var(--muted); font-size: .82rem; }

.panel-card, .stat-card, .table-card, .form-card {
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
  margin-bottom: 1.4rem;
}

.stat-card { padding: 1.1rem 1.2rem; }
.stat-card span { color: var(--muted); font-size: .86rem; }
.stat-card strong { display: block; font-size: 1.8rem; margin-top: .2rem; font-family: Fraunces, serif; }

.table-card { overflow: hidden; }
.table-card .table { margin: 0; }
.table-card th { color: var(--muted); font-weight: 600; font-size: .82rem; letter-spacing: .03em; }

.badge-draft, .badge-review, .badge-wait, .badge-warn, .badge-ready, .badge-published {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: .28rem .7rem;
  font-size: .78rem;
  font-weight: 600;
}
.badge-draft { background: #ece7de; color: #5b5348; }
.badge-review { background: #dceaf3; color: #21526e; }
.badge-wait { background: #efe4c8; color: #7a5a16; }
.badge-warn { background: #f6d9d4; color: #8a2e26; }
.badge-ready { background: #d9efe3; color: #215c3d; }
.badge-published { background: #d4eee8; color: #1d5a55; }

.btn-gold {
  --bs-btn-color: #1a1408;
  --bs-btn-bg: var(--gold);
  --bs-btn-border-color: var(--gold);
  --bs-btn-hover-color: #1a1408;
  --bs-btn-hover-bg: var(--gold-2);
  --bs-btn-hover-border-color: var(--gold-2);
  --bs-btn-active-color: #1a1408;
  --bs-btn-active-bg: var(--gold-2);
  --bs-btn-active-border-color: var(--gold-2);
  background: linear-gradient(180deg, var(--gold-2), var(--gold));
  border-color: var(--gold);
  color: #1a1408;
  font-weight: 600;
}
.btn.btn-gold:hover,
.btn.btn-gold:focus,
.btn.btn-gold:active {
  color: #1a1408;
  background: var(--gold-2);
  border-color: var(--gold-2);
}

.btn-ink {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--ink);
  --bs-btn-border-color: var(--ink);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: var(--ink-2);
  --bs-btn-hover-border-color: var(--ink-2);
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: var(--ink-2);
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}
.btn.btn-ink:hover,
.btn.btn-ink:focus,
.btn.btn-ink:active {
  color: #fff;
  background: var(--ink-2);
  border-color: var(--ink-2);
}

.btn-teal {
  --bs-btn-color: #fff;
  --bs-btn-bg: var(--teal);
  --bs-btn-border-color: var(--teal);
  --bs-btn-hover-color: #fff;
  --bs-btn-hover-bg: #245854;
  --bs-btn-hover-border-color: #245854;
  --bs-btn-active-color: #fff;
  --bs-btn-active-bg: #1e4b48;
  --bs-btn-disabled-color: #fff;
  --bs-btn-disabled-bg: var(--teal);
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}
.btn.btn-teal:hover,
.btn.btn-teal:focus,
.btn.btn-teal:active {
  color: #fff;
  background: #245854;
  border-color: #245854;
}

.form-card { padding: 1.4rem; max-width: none; width: 100%; }
.page-actions { display: flex; gap: .6rem; flex-wrap: wrap; margin-bottom: 1rem; }

.timeline { list-style: none; padding: 0; margin: 0; }
.timeline li {
  position: relative;
  padding: 0 0 1.1rem 1.2rem;
  border-left: 2px solid var(--line);
}
.timeline li:last-child { border-left-color: transparent; }
.timeline li::before {
  content: "";
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--gold);
  position: absolute;
  left: -6px;
  top: .35rem;
}

.drive-frame {
  width: 100%;
  min-height: 640px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.drive-dual {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .85rem;
}

.drive-pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--paper-2, #fff);
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
}

.drive-pane-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .75rem;
  padding: .7rem .9rem;
  border-bottom: 1px solid var(--line);
  background: rgba(0, 0, 0, .02);
}

.drive-pane-head strong {
  font-size: .92rem;
}

.drive-frame-dual {
  min-height: 560px;
  border: 0;
  border-radius: 0;
}

.drive-pane-fallback {
  min-height: 220px;
  padding: 1.1rem;
  display: grid;
  align-content: center;
}

.lang-status {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.lang-chip {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  padding: .2rem .5rem;
  border-radius: 999px;
  border: 1px solid transparent;
}

.lang-chip-source {
  color: #1f4d3a;
  background: #e5f3ec;
  border-color: #b7dcc8;
}

.lang-chip-target {
  color: #5a3d12;
  background: #f7ecda;
  border-color: #e2c892;
}

.lang-chip-missing {
  color: #6b7280;
  background: #f3f4f6;
  border-color: #e5e7eb;
}

@media (max-width: 991.98px) {
  .drive-dual {
    grid-template-columns: 1fr;
  }

  .drive-frame-dual {
    min-height: 420px;
  }
}

.auth-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at top right, rgba(196,163,90,.22), transparent 40%),
    linear-gradient(160deg, #121a2b, #24324c 55%, #1b3d3a);
}

.auth-card {
  width: min(440px, calc(100vw - 2rem));
  background: var(--paper-2);
  border-radius: 20px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.auth-card h1 { font-size: 1.8rem; margin-bottom: .3rem; }
.hint-box {
  background: #f3ead6;
  border-radius: 12px;
  padding: .8rem 1rem;
  font-size: .86rem;
  margin-top: 1rem;
}

.blocker-list { margin: 0; padding-left: 1.1rem; color: var(--danger); }

.form-card {
  padding: 1.5rem 1.6rem 1.3rem;
  max-width: none;
  width: 100%;
}

.form-layout {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

.form-layout > input[type="hidden"],
.form-layout > .d-none {
  display: none !important;
}

.form-layout > .form-section {
  min-height: 100%;
}

.form-layout > .form-intro,
.form-layout > .form-actions,
.form-layout > .span-2,
.form-section.span-2 {
  grid-column: 1 / -1;
}

.form-layout > .form-intro {
  margin-bottom: 0;
}

.copy-row {
  display: flex;
  gap: .6rem;
  align-items: center;
}

.copy-value {
  flex: 1;
  display: block;
  padding: .65rem .8rem;
  background: var(--paper);
  border-radius: 10px;
  font-size: .95rem;
  word-break: break-all;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem 1.25rem;
}

.form-grid > .span-2 {
  grid-column: 1 / -1;
}

.form-grid .mb-0,
.form-grid .mb-3 {
  margin-bottom: 0 !important;
}

.form-intro {
  display: flex;
  gap: .9rem;
  align-items: flex-start;
  padding: .9rem 1rem;
  border-radius: 12px;
  background: #f7f1e4;
  margin-bottom: 1.2rem;
}

.form-intro i {
  font-size: 1.4rem;
  color: #8c6a2b;
  margin-top: .1rem;
}

.form-intro p { margin: .15rem 0 0; color: var(--muted); font-size: .92rem; }

.form-section {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.1rem .85rem;
  margin-bottom: 1rem;
  background: #fff;
}

.form-section h3 {
  font-size: 0.95rem;
  margin: 0 0 .8rem;
  color: var(--ink-2);
}

.req { color: var(--danger); }

.role-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: .75rem;
}

.role-card {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .85rem .9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  margin: 0;
  background: var(--paper-2);
}

.role-card:has(input:checked) {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(196, 163, 90, .18);
  background: #fffdf7;
}

.decision-grid {
  display: grid;
  gap: .65rem;
}

.decision-card {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .85rem .9rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  cursor: pointer;
  margin: 0;
  background: var(--paper-2);
}

.decision-card:has(input:checked) {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(196, 163, 90, .18);
  background: #fffdf7;
}

.decision-card input { margin-top: .3rem; flex-shrink: 0; }
.decision-card strong { display: block; }
.decision-card small { color: var(--muted); }
.decision-card.is-disabled {
  opacity: .55;
  cursor: not-allowed;
}

.password-wrap { position: relative; }
.hp-field {
  position: absolute;
  left: -10000px;
  width: 1px;
  height: 1px;
  overflow: hidden;
}
.password-wrap .form-control { padding-right: 2.6rem; }
.password-toggle {
  position: absolute;
  right: .35rem;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--muted);
  width: 2rem;
  height: 2rem;
}

.form-actions {
  display: flex;
  gap: .6rem;
  flex-wrap: wrap;
  padding-top: .4rem;
}

.toast-container { z-index: 1090; }
.serencam-toast {
  border: 0;
  border-radius: 14px;
  min-width: min(360px, calc(100vw - 2rem));
  box-shadow: var(--shadow);
}
.serencam-toast .toast-body {
  display: flex;
  gap: .7rem;
  align-items: flex-start;
  padding: .85rem 1rem;
}
.serencam-toast .toast-body span { flex: 1; }
.serencam-toast i { font-size: 1.15rem; margin-top: .1rem; }
.toast-success { background: #e7f6ee; color: #1b5c3b; }
.toast-error { background: #fbeceb; color: #8a2e26; }
.toast-info { background: #eaf3f8; color: #1f5270; }
.serencam-toast .btn-close { margin-left: .3rem; }

@media (max-width: 900px) {
  .role-grid,
  .form-layout,
  .form-grid { grid-template-columns: 1fr; }
}

.chapter-child td:nth-child(2) {
  padding-left: 1.6rem;
}
.chapter-child td:nth-child(2)::before {
  content: "↳ ";
  color: var(--muted);
}
.empty-state { padding: 2.4rem 1rem; text-align: center; color: var(--muted); }

.log-filters {
  display: grid;
  grid-template-columns: 1.4fr .9fr .7fr auto;
  gap: .65rem;
  margin-bottom: .75rem;
}

.activity-list { padding: .4rem 0; }
.activity-item {
  display: grid;
  grid-template-columns: 9.5rem 1fr;
  gap: .9rem;
  padding: .95rem 1.15rem;
  border-bottom: 1px solid var(--line);
}
.activity-item:last-child { border-bottom: 0; }
.activity-when {
  color: var(--muted);
  font-size: .86rem;
  padding-top: .15rem;
}
.activity-head {
  display: flex;
  gap: .55rem;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: .2rem;
}
.activity-details {
  margin-top: .55rem;
  font-size: .86rem;
}
.activity-details summary {
  cursor: pointer;
  color: var(--ink-2);
}
.activity-change { margin-top: .45rem; }
.activity-change ul {
  margin: .25rem 0 0;
  padding-left: 1.1rem;
}
.activity-pager {
  display: flex;
  gap: .7rem;
  align-items: center;
  justify-content: center;
  padding: .9rem 1rem;
  border-top: 1px solid var(--line);
}

.guide-article {
  max-width: 920px;
}

.guide-body h1 {
  font-size: 1.85rem;
  margin: 0 0 1.2rem;
}

.guide-body h3 {
  font-size: 1.15rem;
  margin: 1.6rem 0 .7rem;
  color: var(--ink-2);
}

.guide-body ul {
  margin: 0 0 .6rem;
  padding-left: 1.25rem;
}

.guide-body li {
  margin-bottom: .35rem;
  line-height: 1.55;
}

.guide-body p {
  line-height: 1.6;
  margin: .4rem 0 0;
}

.guide-body code {
  font-size: .95em;
  background: #f1ebe0;
  padding: .05rem .35rem;
  border-radius: 4px;
}

.guide-editor {
  min-height: 420px;
  background: #fff;
  border-radius: 0 0 12px 12px;
}

.guide-editor .ql-editor {
  min-height: 380px;
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  font-size: 1rem;
  line-height: 1.55;
}

.row-muted td { opacity: .72; }

.status-toggle-form { margin: 0; }
.status-toggle {
  display: inline-flex;
  align-items: center;
  gap: .55rem;
  cursor: pointer;
  user-select: none;
  margin: 0;
}
.status-toggle input {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}
.status-toggle-track {
  width: 42px;
  height: 24px;
  border-radius: 999px;
  background: #c9c2b6;
  position: relative;
  transition: background .2s ease;
  flex-shrink: 0;
}
.status-toggle-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
  transition: transform .2s ease;
}
.status-toggle input:checked + .status-toggle-track {
  background: var(--ok);
}
.status-toggle input:checked + .status-toggle-track::after {
  transform: translateX(18px);
}
.status-toggle-label {
  font-size: .86rem;
  font-weight: 600;
  color: var(--muted);
  min-width: 2.6rem;
}
.status-toggle input:checked ~ .status-toggle-label {
  color: var(--ok);
}
.status-toggle.is-disabled {
  cursor: not-allowed;
  opacity: .55;
}

.ql-toolbar.ql-snow {
  border: 1px solid var(--line) !important;
  border-radius: 12px 12px 0 0;
  background: #fffaf2;
}

.ql-container.ql-snow {
  border: 1px solid var(--line) !important;
  border-top: 0 !important;
  border-radius: 0 0 12px 12px;
}

@media (max-width: 900px) {
  .log-filters,
  .activity-item { grid-template-columns: 1fr; }
}

@media (max-width: 900px) {
  .app-body { flex-direction: column; }
  .app-sidebar { width: 100%; height: auto; position: relative; }
  .side-nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-foot { display: none; }
}

.validation-summary-errors {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
}
