:root {
  --bg: oklch(0.975 0.004 240);
  --surface: oklch(1 0 0);
  --surface-hover: oklch(0.955 0.006 240);
  --sidebar-bg: oklch(0.96 0.005 240);
  --text: oklch(0.22 0.015 240);
  --text-muted: oklch(0.42 0.015 240);
  --border: oklch(0.89 0.007 240);
  --accent: oklch(0.42 0.11 155);
  --accent-hover: oklch(0.37 0.11 155);
  --accent-soft: oklch(0.42 0.11 155 / 12%);
  --accent-text: oklch(0.99 0 0);
  --danger: oklch(0.55 0.19 25);
  --danger-soft: oklch(0.55 0.19 25 / 12%);
  --success: oklch(0.5 0.13 155);
  --success-soft: oklch(0.5 0.13 155 / 14%);
  --radius: 12px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(20, 24, 22, 0.06);
  --shadow-md: 0 8px 24px rgba(20, 24, 22, 0.08);
  --shadow-lg: 0 16px 48px rgba(20, 24, 22, 0.16);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  color-scheme: light;

  /* escala z-index semântica */
  --z-sticky: 20;
  --z-modal-backdrop: 40;
  --z-modal: 50;
  --z-toast: 80;
}

:root[data-theme="dark"] {
  --bg: oklch(0.19 0.01 240);
  --surface: oklch(0.235 0.012 240);
  --surface-hover: oklch(0.285 0.014 240);
  --sidebar-bg: oklch(0.165 0.01 240);
  --text: oklch(0.95 0.006 240);
  --text-muted: oklch(0.7 0.014 240);
  --border: oklch(0.33 0.014 240);
  --accent: oklch(0.72 0.13 155);
  --accent-hover: oklch(0.78 0.13 155);
  --accent-soft: oklch(0.72 0.13 155 / 16%);
  --accent-text: oklch(0.17 0.02 155);
  --danger: oklch(0.68 0.16 25);
  --danger-soft: oklch(0.68 0.16 25 / 16%);
  --success: oklch(0.72 0.12 155);
  --success-soft: oklch(0.72 0.12 155 / 16%);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: oklch(0.19 0.01 240);
    --surface: oklch(0.235 0.012 240);
    --surface-hover: oklch(0.285 0.014 240);
    --sidebar-bg: oklch(0.165 0.01 240);
    --text: oklch(0.95 0.006 240);
    --text-muted: oklch(0.7 0.014 240);
    --border: oklch(0.33 0.014 240);
    --accent: oklch(0.72 0.13 155);
    --accent-hover: oklch(0.78 0.13 155);
    --accent-soft: oklch(0.72 0.13 155 / 16%);
    --accent-text: oklch(0.17 0.02 155);
    --danger: oklch(0.68 0.16 25);
    --danger-soft: oklch(0.68 0.16 25 / 16%);
    --success: oklch(0.72 0.12 155);
    --success-soft: oklch(0.72 0.12 155 / 16%);
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.5);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

body {
  min-height: 100vh;
  transition: background-color .18s var(--ease), color .18s var(--ease);
}

h1, h2, h3, p { margin: 0; }
h1, h2, h3 { text-wrap: balance; letter-spacing: -0.01em; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}

a { color: var(--accent); }

svg.icon { flex-shrink: 0; display: block; }

.hidden { display: none !important; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- Botões ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 10px 18px;
  border-radius: 999px;
  border: 1px solid transparent;
  background: var(--accent);
  color: var(--accent-text);
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  transition: background-color .15s var(--ease), border-color .15s var(--ease), transform .1s var(--ease);
}
.btn:hover { background: var(--accent-hover); }
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.secondary {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn.secondary:hover { background: var(--surface-hover); }
.btn.danger { background: transparent; color: var(--danger); border-color: var(--border); }
.btn.danger:hover { background: var(--danger-soft); border-color: var(--danger-soft); }
.btn.ghost {
  background: transparent;
  color: var(--text-muted);
  padding: 8px 10px;
  border-color: transparent;
}
.btn.ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn.block { width: 100%; }
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  transition: background-color .15s var(--ease), border-color .15s var(--ease);
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-hover); }

/* ---------- Formulários ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); letter-spacing: .01em; }
.field input, .field select, .field textarea {
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  transition: border-color .15s var(--ease);
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
}
.field textarea { resize: vertical; min-height: 80px; }
.field-row { display: flex; gap: 12px; }
.field-row .field { flex: 1; }

.input-icon { position: relative; }
.input-icon svg.icon { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); pointer-events: none; }
.input-icon input { padding-left: 40px; }

/* ---------- Tela de autenticação ---------- */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  position: relative;
}
.auth-shell > .icon-btn { position: absolute; top: 20px; right: 20px; }
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 34px 30px;
}
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
.auth-brand .icon-btn { position: static; background: var(--accent-soft); color: var(--accent); border: none; cursor: default; }
.auth-brand span { font-weight: 700; font-size: 17px; }
.auth-card h1 { font-size: 21px; margin-bottom: 4px; }
.auth-card .subtitle { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; display: block; }
.auth-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}
.auth-switch { text-align: center; margin-top: 18px; font-size: 14px; color: var(--text-muted); }
.auth-switch button { background: none; border: none; color: var(--accent); font-weight: 600; cursor: pointer; }

/* ---------- Layout do app ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 224px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border);
  padding: 22px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidebar .brand { display: flex; align-items: center; gap: 9px; padding: 4px 10px 22px; font-weight: 700; font-size: 16px; color: var(--text); }
.sidebar .brand svg.icon { color: var(--accent); }
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  background: none;
  border: none;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.nav-item:hover { background: var(--surface-hover); color: var(--text); }
.nav-item.active { background: var(--accent); color: var(--accent-text); }
.nav-item.active svg.icon { color: var(--accent-text); }
.sidebar-footer { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border); }

.main {
  flex: 1;
  min-width: 0;
  padding: 30px 36px 80px;
  max-width: 1180px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 26px;
  gap: 12px;
}
.topbar h2 { font-size: 22px; }
.topbar-actions { display: flex; align-items: center; gap: 10px; }

.page-intro { margin-bottom: 26px; }
.page-intro h2 { font-size: 23px; margin-bottom: 3px; }
.page-intro p { color: var(--text-muted); font-size: 14px; }

/* ---------- Bottom nav mobile ---------- */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: var(--z-sticky);
}
.bottom-nav-inner { display: flex; }
.bottom-nav .nav-item {
  flex: 1;
  flex-direction: column;
  gap: 3px;
  font-size: 11px;
  align-items: center;
  border-radius: var(--radius-sm);
  padding: 7px 4px 6px;
}

/* ---------- Dashboard ---------- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 32px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  align-items: flex-start;
  gap: 14px;
}
.stat-card .stat-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-card .value { font-size: 24px; font-weight: 700; line-height: 1.2; }
.stat-card .label { font-size: 12.5px; color: var(--text-muted); margin-top: 2px; }

.section-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 14px;
}
.section-heading h3 { font-size: 15px; font-weight: 700; }
.section-heading .count { font-size: 13px; color: var(--text-muted); }

/* ---------- Lista "continuar lendo" ---------- */
.reading-list { display: flex; flex-direction: column; gap: 2px; }
.reading-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color .12s var(--ease);
}
.reading-row:hover { background: var(--surface-hover); }
.reading-cover {
  width: 40px;
  height: 56px;
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.reading-info { flex: 1; min-width: 0; }
.reading-title { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading-author { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reading-progress { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.reading-progress .progress-bar { flex: 1; max-width: 220px; }
.reading-progress .pct { font-size: 12px; font-weight: 600; color: var(--text-muted); flex-shrink: 0; min-width: 32px; text-align: right; }

/* ---------- Filtros ---------- */
.filters { display: flex; gap: 8px; margin-bottom: 20px; flex-wrap: wrap; align-items: center; }
.segmented { display: inline-flex; gap: 3px; background: var(--surface); border: 1px solid var(--border); border-radius: 999px; padding: 3px; }
.chip {
  padding: 6px 13px;
  border-radius: 999px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color .15s var(--ease), color .15s var(--ease);
}
.chip.active { background: var(--accent); color: var(--accent-text); }
.search-input { flex: 1; min-width: 180px; }
.search-input.input-icon input {
  width: 100%;
  padding: 9px 14px 9px 40px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
}

/* ---------- Grade de livros ---------- */
.book-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 18px;
}
.book-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  cursor: pointer;
  transition: transform .15s var(--ease), box-shadow .15s var(--ease), border-color .15s var(--ease);
  display: flex;
  flex-direction: column;
  gap: 9px;
}
.book-card:hover { transform: translateY(-3px); box-shadow: var(--shadow-md); border-color: transparent; }
.book-cover {
  width: 100%;
  aspect-ratio: 2 / 3;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  background-size: cover;
  background-position: center;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
  font-size: 26px;
  font-weight: 700;
}
.book-title { font-weight: 700; font-size: 14.5px; line-height: 1.3; }
.book-author { font-size: 12.5px; color: var(--text-muted); }
.badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 700;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  background: var(--surface-hover);
  color: var(--text-muted);
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.lendo { background: var(--accent-soft); color: var(--accent); }
.badge.concluido { background: var(--success-soft); color: var(--success); }
.progress-bar { height: 5px; border-radius: 999px; background: var(--surface-hover); overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); border-radius: 999px; transition: width .2s var(--ease); }

.empty-state {
  text-align: center;
  padding: 52px 20px;
  color: var(--text-muted);
}
.empty-state .icon-btn { margin: 0 auto 14px; cursor: default; color: var(--text-muted); }
.empty-state h3 { color: var(--text); margin-bottom: 5px; font-size: 15px; }
.empty-state p { font-size: 13.5px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 11, .5);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: var(--z-modal);
}
.modal {
  width: 100%;
  max-width: 480px;
  background: var(--surface);
  border-radius: var(--radius);
  padding: 26px;
  box-shadow: var(--shadow-lg);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.modal-header h3 { font-size: 17px; }
.modal-actions { display: flex; gap: 10px; margin-top: 6px; }
.modal-actions .btn { flex: 1; }
.stars { display: flex; gap: 4px; font-size: 21px; cursor: pointer; user-select: none; }
.star { color: var(--border); transition: color .1s var(--ease); }
.star.filled { color: var(--accent); }

/* ---------- Toast / notificação ---------- */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: var(--z-toast);
  max-width: min(320px, calc(100vw - 32px));
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-md);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  animation: toast-in .18s var(--ease);
}
.toast svg.icon { color: var(--accent); flex-shrink: 0; }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: none; } }

/* ---------- Relatórios ---------- */
.report-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  max-width: 480px;
}
.report-panel .panel-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius-sm);
  background: var(--accent-soft);
  color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}

/* ---------- Responsivo ---------- */
@media (max-width: 860px) {
  .sidebar { display: none; }
  .main { padding: 20px 16px 92px; }
  .bottom-nav { display: block; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .auth-shell > .icon-btn { top: 14px; right: 14px; }
}
