/* ── Google Fonts ─────────────────────────────────────────────────────────── */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* ── Custom Properties ───────────────────────────────────────────────────── */
:root {
  --bg:       #F5F5F5;
  --surface:  #FFFFFF;
  --text:     #1C1C1C;
  --muted:    #6B7280;
  --border:   #E5E7EB;
  --accent:   #7B2D4E;
  --sidebar-w:240px;
  --topbar-h: 58px;
  --radius:   6px;
  --shadow:   0 1px 4px rgba(0,0,0,.08);

  --green:  #16a34a;
  --blue:   #1d4ed8;
  --red:    #dc2626;
  --orange: #ea580c;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { height: 100%; }
body { font-family: 'Inter', system-ui, sans-serif; font-size: .9rem; background: var(--bg); color: var(--text); min-height: 100vh; }
img  { display: block; max-width: 100%; }
a    { color: var(--accent); }
a:hover { text-decoration: underline; }
ul   { list-style: none; }
button { cursor: pointer; font: inherit; border: none; background: none; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: auto;
  min-height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar {
  grid-row: 1 / -1;
  background: var(--text);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-block: 0;
  width: var(--sidebar-w);
  overflow-y: auto;
  z-index: 200;
  transition: transform .3s;
}
.sidebar__brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar__brand a {
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  text-decoration: none;
  line-height: 1.3;
}
.sidebar__close {
  display: none;
  color: #ccc;
  font-size: 1.4rem;
  padding: .2rem .4rem;
}

.sidebar__nav {
  flex: 1;
  padding: .75rem 0;
  display: flex;
  flex-direction: column;
}
.sidebar__section {
  padding: .6rem 1rem .2rem;
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: rgba(255,255,255,.4);
}
.nav-item {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .55rem 1rem;
  color: rgba(255,255,255,.8);
  text-decoration: none;
  font-size: .875rem;
  border-left: 3px solid transparent;
  transition: background .15s, color .15s;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; text-decoration: none; }
.nav-item.active { background: rgba(123,45,78,.5); color: #fff; border-left-color: #C4734A; }

.sidebar__footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.08);
  font-size: .8rem;
  color: rgba(255,255,255,.5);
}
.sidebar__footer a { color: rgba(255,255,255,.6); }
.sidebar__footer a:hover { color: #fff; }

/* ── Main wrapper ────────────────────────────────────────────────────────── */
.main-wrapper {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  margin-left: var(--sidebar-w);
}

/* ── Top bar ─────────────────────────────────────────────────────────────── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 1rem;
  padding-inline: 1.5rem;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar__hamburger {
  display: none;
  font-size: 1.3rem;
  color: var(--muted);
  padding: .3rem;
}
.topbar__title {
  font-weight: 600;
  font-size: 1rem;
  flex: 1;
}
.topbar__user { font-size: .8rem; color: var(--muted); }
.topbar__logout {
  font-size: .8rem;
  color: var(--red);
  font-weight: 500;
}

/* ── Content ─────────────────────────────────────────────────────────────── */
.content {
  flex: 1;
  padding: 1.75rem;
  max-width: 1200px;
  width: 100%;
}

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
}
.page-title { font-size: 1.3rem; font-weight: 700; }

/* ── Dashboard cards ─────────────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  margin-bottom: 2rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .4rem;
}
.stat-card__value { font-size: 2rem; font-weight: 700; color: var(--accent); }
.stat-card__label { font-size: .8rem; color: var(--muted); font-weight: 500; text-transform: uppercase; letter-spacing: .06em; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35em;
  padding: .5em 1.1em;
  border-radius: var(--radius);
  font-size: .85rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: opacity .15s, filter .15s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; text-decoration: none; }
.btn-create { background: var(--green);  color: #fff; }
.btn-edit   { background: var(--blue);   color: #fff; }
.btn-delete { background: var(--red);    color: #fff; }
.btn-save   { background: var(--accent); color: #fff; }
.btn-cancel { background: var(--border); color: var(--text); }
.btn-preview{ background: var(--orange); color: #fff; }
.btn-sm { padding: .3em .7em; font-size: .8rem; }

/* ── Tables ──────────────────────────────────────────────────────────────── */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}
thead th {
  background: var(--bg);
  padding: .75rem 1rem;
  text-align: left;
  font-weight: 600;
  font-size: .78rem;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg); }
tbody td { padding: .7rem 1rem; vertical-align: middle; }
.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.thumb-circle { border-radius: 50%; }
.td-actions { display: flex; gap: .4rem; align-items: center; }

/* ── Badge / Status ──────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: .2em .6em;
  border-radius: 99px;
  font-size: .75rem;
  font-weight: 600;
}
.badge-success { background: #dcfce7; color: #15803d; }
.badge-warning { background: #fef9c3; color: #a16207; }
.badge-muted   { background: var(--bg); color: var(--muted); }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.form-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1fr;
}
@media (min-width: 640px) { .form-grid-2 { grid-template-columns: 1fr 1fr; } }

.form-group { display: flex; flex-direction: column; gap: .3rem; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: .82rem; font-weight: 600; }
.form-label .req { color: var(--red); }
.form-control {
  padding: .48rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font: inherit;
  font-size: .875rem;
  background: var(--surface);
  color: var(--text);
  width: 100%;
  transition: border-color .2s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
textarea.form-control { resize: vertical; }
select.form-control { cursor: pointer; }
.form-hint { font-size: .78rem; color: var(--muted); }
.form-error { font-size: .78rem; color: var(--red); }

.form-actions {
  display: flex;
  gap: .75rem;
  align-items: center;
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
}
.form-actions .ms-auto { margin-left: auto; }

/* ── File upload ─────────────────────────────────────────────────────────── */
.upload-group { display: flex; flex-direction: column; gap: .5rem; }
.upload-preview {
  width: 120px;
  height: 120px;
  object-fit: cover;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  display: none;
}
.upload-preview.visible { display: block; }

/* ── Quill overrides ─────────────────────────────────────────────────────── */
.ql-container { font-family: inherit; font-size: .9rem; min-height: 280px; }
.ql-toolbar { border-radius: var(--radius) var(--radius) 0 0; border-color: var(--border) !important; background: var(--bg); }
.ql-container.ql-snow { border-radius: 0 0 var(--radius) var(--radius); border-color: var(--border) !important; }

/* ── Alert / Flash ───────────────────────────────────────────────────────── */
.alert {
  padding: .85rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
  font-size: .875rem;
}
.alert-success { background: #dcfce7; color: #15803d; border: 1px solid #86efac; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

/* ── Confirm delete section ──────────────────────────────────────────────── */
.confirm-delete {
  display: none;
  background: #fee2e2;
  border: 1px solid #fca5a5;
  border-radius: var(--radius);
  padding: 1rem;
  margin-top: .75rem;
  gap: .75rem;
  align-items: center;
  font-size: .875rem;
}
.confirm-delete.open { display: flex; }

/* ── Checkboxes grid (libros relacionados) ───────────────────────────────── */
.checkboxes-grid {
  display: grid;
  gap: .4rem;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  max-height: 260px;
  overflow-y: auto;
  padding: .5rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.checkbox-item { display: flex; align-items: center; gap: .5rem; font-size: .85rem; }
.checkbox-item input[type="checkbox"] { width: 15px; height: 15px; cursor: pointer; accent-color: var(--accent); }

/* ── Quick links ─────────────────────────────────────────────────────────── */
.quick-links {
  display: grid;
  gap: .75rem;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.quick-link {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: .875rem;
  transition: border-color .2s, box-shadow .2s;
}
.quick-link:hover { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(123,45,78,.12); text-decoration: none; }
.quick-link__icon { font-size: 1.5rem; margin-bottom: .4rem; }

/* ── Mobile ──────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: none;
    box-shadow: 4px 0 24px rgba(0,0,0,.2);
  }
  .sidebar__close { display: block; }
  .main-wrapper { margin-left: 0; }
  .topbar__hamburger { display: block; }
  .layout { grid-template-columns: 1fr; }
}
