:root {
  --bg: #f8fafc;
  --surface: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --primary: #6366f1;
  --primary-dark: #4f46e5;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0,0,0,0.07);
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.55;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 100;
}
.topbar .logo { font-weight: 700; color: var(--primary); font-size: 1.15rem; }
.topbar nav { display: flex; align-items: center; gap: 1rem; }
.topbar nav a { color: var(--text); padding: .35rem .7rem; border-radius: .375rem; }
.topbar nav a:hover { background: var(--bg); text-decoration: none; }
.user-pill { background: var(--bg); padding: .35rem .7rem; border-radius: 999px; font-size: .85rem; }
.user-pill em { font-style: normal; color: var(--primary); font-weight: 600; }

.btn-primary {
  background: var(--primary); color: white !important;
  padding: .55rem 1.1rem; border-radius: .375rem;
  border: 0; cursor: pointer; font: inherit; font-weight: 500;
  display: inline-block; text-decoration: none;
}
.btn-primary:hover { background: var(--primary-dark); text-decoration: none; }
.btn-primary.btn-sm { padding: .35rem .75rem; font-size: .85rem; }
.btn-ghost {
  border: 1px solid var(--border); background: transparent;
  padding: .35rem .9rem; border-radius: .375rem;
}

.main { max-width: 1280px; margin: 1.5rem auto; padding: 0 1rem; }

.flash {
  max-width: 680px; margin: .75rem auto; padding: .75rem 1rem;
  border-radius: .5rem; border-left: 4px solid var(--muted);
}
.flash-success { background: #d1fae5; border-color: var(--success); color: #064e3b; }
.flash-error   { background: #fee2e2; border-color: var(--danger); color: #7f1d1d; }

/* Auth */
.auth-card {
  max-width: 420px; margin: 4rem auto; background: var(--surface);
  padding: 2rem; border-radius: .75rem; box-shadow: var(--shadow);
}
.auth-card h1 { margin: 0 0 1.5rem; }
.muted { color: var(--muted); }

.form { display: flex; flex-direction: column; gap: 1rem; }
.form label { display: flex; flex-direction: column; font-size: .875rem; gap: .35rem; font-weight: 500; }
.form input, .form select, .form textarea {
  padding: .65rem; border: 1px solid var(--border); border-radius: .375rem;
  font: inherit; background: white;
}
.form input:focus, .form select:focus, .form textarea:focus {
  outline: 2px solid var(--primary); outline-offset: -1px;
}
.form-card {
  max-width: 600px; margin: 2rem auto; background: var(--surface);
  padding: 2rem; border-radius: .75rem; box-shadow: var(--shadow);
}

/* Dashboard */
.dash-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.empty { text-align: center; padding: 3rem; background: var(--surface); border-radius: .75rem; box-shadow: var(--shadow); }
.empty p { margin-bottom: 1rem; color: var(--muted); }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 1rem; }
.card {
  background: var(--surface); padding: 1.25rem; border-radius: .75rem;
  box-shadow: var(--shadow); color: var(--text); display: block;
  border: 1px solid transparent; transition: all .15s;
}
.card:hover { border-color: var(--primary); transform: translateY(-2px); text-decoration: none; }
.card h3 { margin: 0 0 .25rem; }
.card .subtitle { color: var(--muted); margin: 0 0 .75rem; font-size: .9rem; }
.card .meta { display: flex; gap: .75rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); }
.card .epoca { margin-top: .75rem; padding: .35rem .65rem; background: #fef3c7; border-radius: .375rem; font-size: .8rem; }

.badge { display: inline-block; padding: .15rem .55rem; border-radius: 999px; font-size: .7rem; text-transform: uppercase; }
.badge-borrador { background: #f1f5f9; color: #475569; }
.badge-revisado { background: #dbeafe; color: #1e40af; }
.badge-final    { background: #d1fae5; color: #065f46; }
.badge-en_progreso { background: #fef3c7; color: #92400e; }

/* Novela detail */
.novel-head { background: var(--surface); padding: 2rem; border-radius: .75rem; box-shadow: var(--shadow); margin-bottom: 1.5rem; }
.back-link { font-size: .875rem; }
.novel-head h1 { margin: .5rem 0; }
.novel-head .meta { display: flex; gap: 1rem; color: var(--muted); font-size: .9rem; margin: 1rem 0; }
.novel-head .sinopsis { color: var(--text); border-top: 1px solid var(--border); padding-top: 1rem; margin-top: 1rem; }

.grid-two { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }
.panel { background: var(--surface); padding: 1.5rem; border-radius: .75rem; box-shadow: var(--shadow); }
.panel-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; }
.panel-head h2 { margin: 0; font-size: 1.1rem; }
.chapter-list { padding-left: 1.5rem; }
.chapter-list li { margin: .5rem 0; }
.chapter-list a { display: flex; gap: .75rem; align-items: center; color: var(--text); padding: .35rem; border-radius: .25rem; }
.chapter-list a:hover { background: var(--bg); text-decoration: none; }
.chapter-list a small { margin-left: auto; color: var(--muted); }
.character-list { list-style: none; padding: 0; }
.character-list li { display: flex; align-items: center; gap: .5rem; padding: .35rem 0; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 50%; }

/* Editor */
.editor-shell {
  display: grid;
  grid-template-columns: 220px 1fr 320px;
  gap: 1rem;
  height: calc(100vh - 110px);
}
.sidebar-left, .sidebar-right {
  background: var(--surface); border-radius: .75rem;
  padding: 1rem; box-shadow: var(--shadow); overflow-y: auto;
}
.sidebar-left h3 { margin: 0 0 .5rem; }
.sidebar-left .back { display: inline-block; margin-bottom: 1rem; font-size: .875rem; }
.era { padding: .5rem; background: #fef3c7; border-radius: .375rem; font-size: .85rem; }

.editor-main {
  background: var(--surface); border-radius: .75rem;
  padding: 1rem 1.5rem; box-shadow: var(--shadow);
  display: flex; flex-direction: column; overflow: hidden;
}
.editor-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: .75rem; border-bottom: 1px solid var(--border); margin-bottom: .5rem; gap: 1rem; }
.capitulo-titulo {
  font-size: 1.5rem; font-weight: 600; border: 0; outline: 0;
  flex: 1; padding: .25rem; border-radius: .25rem; background: transparent;
}
.capitulo-titulo:focus { background: var(--bg); }
.status { color: var(--muted); font-size: .85rem; white-space: nowrap; }
#editor { flex: 1; overflow-y: auto; min-height: 300px; }
.ql-editor { font-family: 'Georgia', serif; font-size: 1.05rem; line-height: 1.75; max-width: 720px; margin: 0 auto; }

.action-bar { padding-top: .75rem; border-top: 1px solid var(--border); display: flex; gap: .5rem; flex-wrap: wrap; }
.action-bar button {
  background: var(--bg); border: 1px solid var(--border);
  padding: .45rem .8rem; border-radius: .375rem;
  cursor: pointer; font-size: .875rem;
}
.action-bar button:hover { background: var(--primary); color: white; border-color: var(--primary); }

.panel h4 { margin: 0 0 .5rem; font-size: .8rem; text-transform: uppercase; color: var(--muted); letter-spacing: .05em; }
.sugg { background: var(--bg); padding: .65rem; border-radius: .375rem; border-left: 3px solid var(--primary); margin-bottom: .5rem; font-size: .85rem; }
.sugg-snippet { font-style: italic; color: var(--muted); margin: .25rem 0; }
.sugg-msg { font-weight: 500; }
.sugg-fix { color: var(--success); }
.sugg-summary { background: #ede9fe; padding: .65rem; border-radius: .375rem; margin-bottom: .75rem; font-size: .9rem; }
.r-item { padding: .65rem; border-bottom: 1px solid var(--border); font-size: .85rem; }
.r-item.ai { background: #eff6ff; border-radius: .375rem; border-bottom: 0; margin-bottom: .5rem; }

.bottom { text-align: center; padding: 2rem; color: var(--muted); font-size: .85rem; }

@media (max-width: 1024px) {
  .editor-shell { grid-template-columns: 1fr; height: auto; }
  .grid-two { grid-template-columns: 1fr; }
}
