:root {
  --bg: #F5EDE6;
  --bg-header: #E8D5C4;
  --text: #5C4033;
  --text-light: #8A7565;
  --accent: #C4956A;
  --accent-hover: #B07E55;
  --white: #FFFFFF;
  --border: rgba(92, 64, 51, 0.12);
  --shadow: rgba(92, 64, 51, 0.08);
  --overlay: rgba(92, 64, 51, 0.35);

  --font-title: 'Playfair Display', Georgia, serif;
  --font-body: 'Lora', Georgia, serif;

  --sidebar-w: min(88vw, 340px);
  --header-h: 56px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 400 1rem/1.75 var(--font-body);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

img { display: block; max-width: 100%; }
a { color: inherit; text-decoration: none; }

/* ===== Header ===== */
header {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  height: var(--header-h);
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  height: 100%;
  padding: 0 16px;
  gap: 14px;
}

.header-title {
  font: 400 1.15rem/1 var(--font-title);
  color: var(--text);
  letter-spacing: 0.15em;
}

.header-logo {
  margin-left: auto;
}

.header-logo img {
  height: 28px;
  width: auto;
}

/* Menu toggle (hamburger) */
#menu-toggle {
  background: none;
  border: 0;
  cursor: pointer;
  padding: 8px;
  margin-left: -8px;
  line-height: 0;
  display: block;
}

#menu-toggle span {
  display: block;
  width: 22px;
  height: 1.5px;
  background: var(--text);
  margin: 5px 0;
  transition: transform 0.28s ease, opacity 0.2s ease;
}

body.menu-open #menu-toggle span:nth-child(1) {
  transform: translateY(6.5px) rotate(45deg);
}
body.menu-open #menu-toggle span:nth-child(2) {
  opacity: 0;
}
body.menu-open #menu-toggle span:nth-child(3) {
  transform: translateY(-6.5px) rotate(-45deg);
}

/* ===== Overlay ===== */
#overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.3s ease, visibility 0.3s;
  z-index: 45;
}

body.menu-open #overlay {
  opacity: 1;
  visibility: visible;
}

/* ===== Sidebar ===== */
#sidebar {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg);
  z-index: 50;
  transform: translateX(-100%);
  transition: transform 0.32s cubic-bezier(0.4, 0, 0.2, 1);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
}

body.menu-open #sidebar {
  transform: translateX(0);
}

.sidebar-header {
  padding: 24px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.sidebar-logo {
  height: 32px;
  width: auto;
  margin-bottom: 6px;
}

.sidebar-subtitle {
  display: block;
  font: 400 0.75rem/1 var(--font-title);
  color: var(--text-light);
  letter-spacing: 0.2em;
  margin-top: 4px;
}

#sidebar-menu {
  flex: 1;
  padding: 8px 0;
  overflow-y: auto;
}

/* Series item in sidebar */
.menu-series {
  border-bottom: 1px solid var(--border);
}

.menu-series-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  background: none;
  border: 0;
  cursor: pointer;
  text-align: left;
  padding: 14px 24px;
  font: 700 0.95rem/1.4 var(--font-body);
  color: var(--text);
  gap: 8px;
}

.menu-series-title .chevron {
  font-style: normal;
  color: var(--accent);
  font-size: 1.1rem;
  transition: transform 0.26s ease;
  flex-shrink: 0;
}

.menu-series.open .menu-series-title .chevron {
  transform: rotate(90deg);
}

.menu-chapters {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.34s ease;
}

.menu-series.open .menu-chapters {
  max-height: 800px;
}

.menu-chapters ol {
  list-style: none;
  padding: 0 0 10px;
}

.menu-chapter-link {
  display: block;
  padding: 8px 24px 8px 36px;
  font-size: 0.9rem;
  color: var(--text-light);
  border-left: 2px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}

.menu-chapter-link:hover,
.menu-chapter-link.active {
  color: var(--text);
  border-left-color: var(--accent);
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

.login-avatar {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--text-light);
  padding: 4px;
  transition: color 0.2s;
}

.login-avatar:hover {
  color: var(--accent);
}

/* ===== Banner ===== */
#banner-area {
  max-width: 1200px;
  margin: 0 auto;
}

.banner-img {
  width: 100%;
  height: auto;
}

/* ===== Main content ===== */
main {
  max-width: 700px;
  margin: 0 auto;
  padding: 32px 16px 80px;
  min-height: 50vh;
}

.loading {
  text-align: center;
  padding: 60px 0;
  color: var(--text-light);
  font-size: 0.95rem;
}

/* ===== Home: series list ===== */
.series-section {
  margin-bottom: 32px;
}

.series-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  cursor: pointer;
  padding: 16px 0 8px;
  border-bottom: 1px solid var(--border);
}

.series-title {
  font: 400 1.5rem/1.35 var(--font-title);
  color: var(--text);
}

.series-toggle {
  font-style: normal;
  color: var(--accent);
  font-size: 1.4rem;
  transition: transform 0.26s ease;
}

.series-section.open .series-toggle {
  transform: rotate(45deg);
}

.series-chapters {
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.34s ease;
}

.series-section.open .series-chapters {
  max-height: 600px;
}

.series-chapters ol {
  list-style: none;
  padding: 12px 0 4px;
}

.chapter-item a {
  display: block;
  padding: 10px 0 10px 16px;
  font-size: 1rem;
  color: var(--text);
  border-left: 2px solid var(--border);
  transition: border-color 0.2s, color 0.2s;
}

.chapter-item a:hover {
  border-left-color: var(--accent);
  color: var(--accent);
}

/* ===== Reading view ===== */
.reading-breadcrumb {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 20px;
}

.reading-breadcrumb a {
  color: var(--accent);
}

.reading-breadcrumb a:hover {
  text-decoration: underline;
}

article h2 {
  font: 400 1.7rem/1.35 var(--font-title);
  color: var(--text);
  margin-bottom: 6px;
}

article .meta {
  font-size: 0.88rem;
  color: var(--text-light);
  margin-bottom: 28px;
}

article p {
  margin-bottom: 20px;
}

article p.quote {
  font-style: italic;
  color: var(--text);
  padding-left: 16px;
  border-left: 2px solid var(--accent);
  margin: 24px 0;
}

.author-footer {
  margin-top: 40px;
  padding-top: 24px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 16px;
}

.author-photo {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-header);
}

.author-photo-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--bg-header);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-light);
  font-size: 1.4rem;
  font-family: var(--font-title);
}

.author-info {
  flex: 1;
}

.author-info strong {
  display: block;
  font-weight: 700;
  font-size: 1rem;
}

.author-info .about-preview {
  font-size: 0.88rem;
  color: var(--text-light);
  margin-top: 2px;
}

.about-more {
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
}

/* Navigation between chapters */
.chapter-nav {
  margin-top: 40px;
  display: flex;
  justify-content: space-between;
  gap: 16px;
}

.chapter-nav a {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  color: var(--text);
  transition: border-color 0.2s, background 0.2s;
}

.chapter-nav a:hover {
  border-color: var(--accent);
  background: var(--bg);
}

.back-link {
  display: inline-block;
  margin-top: 24px;
  font-size: 0.9rem;
  color: var(--accent);
}

.back-link:hover {
  text-decoration: underline;
}

/* ===== Desktop: sidebar fixed ===== */
@media (min-width: 1024px) {
  #menu-toggle { display: none; }
  #overlay { display: none; }

  #sidebar {
    transform: translateX(0);
    position: fixed;
    top: var(--header-h);
    bottom: 0;
    width: 280px;
    border-right: 1px solid var(--border);
  }

  .sidebar-header {
    padding: 20px 24px 14px;
  }

  header {
    padding-left: 280px;
  }

  #banner-area {
    margin-left: 280px;
  }

  main {
    margin-left: 280px;
    max-width: calc(700px + 280px);
    padding-left: calc((100% - 280px - 700px) / 2 + 16px);
    padding-right: 16px;
  }
}

/* ===== Mobile: header + toggle fixed ===== */
@media (max-width: 1023px) {
  header {
    position: sticky;
    top: 0;
  }

  main {
    padding: 24px 16px 60px;
  }

  article h2 {
    font-size: 1.45rem;
  }
}

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  position: relative;
  box-shadow: 0 8px 32px var(--shadow);
}

.modal-card h2 {
  font: 400 1.4rem/1 var(--font-title);
  color: var(--text);
  margin-bottom: 20px;
}

.modal-close {
  position: absolute;
  top: 12px;
  right: 16px;
  background: none;
  border: 0;
  font-size: 1.6rem;
  color: var(--text-light);
  cursor: pointer;
  line-height: 1;
}

.modal-hint {
  font-size: 0.88rem;
  color: var(--text-light);
  margin-bottom: 16px;
}

/* ===== Form fields ===== */
.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 700;
  color: var(--text);
  margin-bottom: 6px;
}

.field input[type="text"],
.field input[type="password"],
.field input[type="tel"],
.field input[type="number"],
.field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--white);
  color: var(--text);
  font: 400 1rem/1.5 var(--font-body);
  outline: none;
  transition: border-color 0.2s;
}

.field input:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field-row {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}

.field-row input,
.field-row textarea {
  flex: 1;
}

.field-prefix {
  padding: 10px 0 10px 12px;
  color: var(--text-light);
  font-size: 0.95rem;
  white-space: nowrap;
}

.field-error {
  color: #C0392B;
  font-size: 0.85rem;
  margin-bottom: 12px;
  min-height: 1.2em;
}

.field-warn {
  color: #C0392B;
  font-size: 0.8rem;
  margin-top: 4px;
  display: none;
}

.char-count {
  font-weight: 400;
  font-size: 0.8rem;
  color: var(--text-light);
  margin-left: 8px;
}

.char-count.over {
  color: #C0392B;
  font-weight: 700;
}

/* ===== Buttons ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px 20px;
  background: var(--accent);
  color: var(--white);
  border: 0;
  border-radius: 4px;
  font: 400 0.95rem/1 var(--font-body);
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  font: 400 0.9rem/1 var(--font-body);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}

.btn-outline:hover {
  background: var(--accent);
  color: var(--white);
}

.btn-icon {
  background: none;
  border: 0;
  cursor: pointer;
  color: var(--text-light);
  font-size: 1.1rem;
  padding: 4px 8px;
  transition: color 0.2s;
}

.btn-icon:hover {
  color: var(--accent);
}

.btn-copy {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  color: var(--text-light);
  font-size: 1.1rem;
  padding: 8px 10px;
  transition: color 0.2s, border-color 0.2s;
  flex-shrink: 0;
}

.btn-copy:hover {
  color: var(--accent);
  border-color: var(--accent);
}

/* ===== Badge ===== */
.badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 400;
  padding: 2px 6px;
  border-radius: 3px;
  background: var(--bg-header);
  color: var(--text-light);
  vertical-align: middle;
}

.badge-master { background: var(--accent); color: var(--white); }
.badge-new { background: #F39C12; color: var(--white); }

/* ===== Toast ===== */
#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--text);
  color: var(--bg);
  padding: 10px 20px;
  border-radius: 4px;
  font-size: 0.9rem;
  z-index: 200;
  transition: transform 0.3s ease, opacity 0.3s;
  opacity: 0;
  pointer-events: none;
}

#toast.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

/* ===== Toggle group ===== */
.toggle-group {
  display: flex;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
  width: fit-content;
}

.toggle-btn {
  padding: 8px 20px;
  background: var(--white);
  border: 0;
  cursor: pointer;
  font: 400 0.9rem/1 var(--font-body);
  color: var(--text-light);
  transition: background 0.2s, color 0.2s;
}

.toggle-btn + .toggle-btn {
  border-left: 1px solid var(--border);
}

.toggle-btn.active {
  background: var(--accent);
  color: var(--white);
}

/* ===== Author space ===== */
.author-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.author-header h2 {
  font: 400 1.5rem/1 var(--font-title);
  margin: 0;
}

.author-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.author-series-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  margin-bottom: 16px;
}

.asc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.asc-header h3 {
  font: 700 1.1rem/1.3 var(--font-body);
  color: var(--text);
  flex: 1;
}

.asc-chapters {
  margin-bottom: 12px;
}

.asc-chapter {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
}

.asc-chapter:last-child { border: 0; }

.asc-chapter a {
  color: var(--text);
  font-size: 0.95rem;
}

.asc-chapter a:hover { color: var(--accent); }

.asc-status {
  font-size: 0.75rem;
  padding: 2px 8px;
  border-radius: 3px;
}

.asc-status.pub { background: #27AE60; color: #fff; }
.asc-status.draft { background: var(--bg-header); color: var(--text-light); }

.asc-empty {
  font-size: 0.9rem;
  color: var(--text-light);
  padding: 8px 0;
}

/* ===== Editor ===== */
.editor-breadcrumb {
  font-size: 0.85rem;
  color: var(--text-light);
  margin-bottom: 20px;
}

.editor-breadcrumb a { color: var(--accent); }
.editor-breadcrumb a:hover { text-decoration: underline; }

.editor-form {
  max-width: 640px;
}

.editor-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 20px;
  align-items: center;
}

.btn-publish {
  width: 38px;
  height: 38px;
  padding: 0;
  font-size: 1rem;
}

.btn-whatsapp {
  font-size: 0.85rem;
}

/* ===== Preview ===== */
.preview-card {
  background: var(--bg);
  border-radius: 8px;
  padding: 0;
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  overflow-y: auto;
  position: relative;
}

.preview-bar {
  position: sticky;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  background: #F1C40F;
  border-radius: 8px 8px 0 0;
  z-index: 1;
}

.preview-tag {
  font: 700 0.8rem/1 var(--font-body);
  text-transform: uppercase;
  color: #7D6608;
}

.preview-exit {
  background: none;
  border: 0;
  cursor: pointer;
  color: #7D6608;
  font: 400 0.9rem/1 var(--font-body);
}

.preview-card article {
  padding: 24px 20px 40px;
}

/* ===== Profile preview ===== */
.profile-preview {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 20px;
  margin: 16px 0;
}

/* ===== Users list ===== */
.users-list {
  max-width: 640px;
}

.user-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}

.user-row > div:first-child { flex: 1; }
.user-row > div:nth-child(2) { color: var(--text-light); font-size: 0.9rem; }

/* ===== Menu extras ===== */
.menu-divider {
  height: 1px;
  background: var(--border);
  margin: 8px 0;
}

.menu-author-link {
  display: block;
  padding: 14px 24px;
  font: 400 0.95rem/1.4 var(--font-body);
  color: var(--accent);
  transition: color 0.2s;
}

.menu-author-link:hover {
  color: var(--accent-hover);
}

.menu-author-link.flash,
.menu-chapter-link.flash {
  animation: flash-highlight 2s ease;
}

@keyframes flash-highlight {
  0%, 100% { background: transparent; }
  15%, 85% { background: rgba(196, 149, 106, 0.2); }
}

/* ===== Reduced motion ===== */
@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
