:root {
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --success: #16a34a;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --bg: #f8fafc;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --mark-bg: #fef08a;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-size: .9em; }

/* ─── Header ─────────────────────────────────── */
header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: .75rem 1.5rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
}

.logo {
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  gap: .5rem;
  white-space: nowrap;
}
.logo:hover { text-decoration: none; }
.logo-icon { font-size: 1.4rem; }

.header-search {
  flex: 1;
  display: flex;
  gap: .5rem;
  max-width: 480px;
}
.header-search input {
  flex: 1;
  padding: .45rem .75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .95rem;
  outline: none;
}
.header-search input:focus { border-color: var(--primary); }
.header-search button { padding: .45rem 1rem; }

/* ─── Main ───────────────────────────────────── */
main {
  max-width: 960px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 2.5rem;
}

/* ─── Flash messages ─────────────────────────── */
.flash-messages { display: flex; flex-direction: column; gap: .5rem; }
.flash {
  padding: .75rem 1rem;
  border-radius: var(--radius);
  font-size: .95rem;
}
.flash-success { background: #dcfce7; color: #166534; border: 1px solid #bbf7d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }

/* ─── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .5rem 1rem;
  border-radius: var(--radius);
  font-size: .9rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
}
.btn-primary  { background: var(--primary); color: #fff; }
.btn-primary:hover  { background: var(--primary-hover); color: #fff; }
.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover  { background: #15803d; color: #fff; }
.btn-danger   { background: var(--danger); color: #fff; }
.btn-danger:hover   { background: var(--danger-hover); color: #fff; }
.btn-outline  {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--primary);
}
.btn-outline:hover { background: #ede9fe; color: var(--primary-hover); text-decoration: none; }
.btn-sm { padding: .3rem .65rem; font-size: .82rem; }

/* ─── Drop zone ──────────────────────────────── */
.upload-section h2 { margin-bottom: .75rem; font-size: 1.2rem; }

.drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 2rem;
  text-align: center;
  transition: border-color .2s, background .2s;
  cursor: default;
}
.drop-zone.drag-over {
  border-color: var(--primary);
  background: #ede9fe;
}
.drop-zone-inner { display: flex; flex-direction: column; align-items: center; gap: .5rem; }
.drop-icon { font-size: 2.5rem; }
.drop-zone p { color: var(--muted); }

.file-list {
  margin-top: 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  justify-content: center;
}
.file-tag {
  background: #ede9fe;
  color: var(--primary);
  border-radius: 999px;
  padding: .2rem .75rem;
  font-size: .85rem;
}

/* ─── Library section ────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.2rem; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 1rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
  box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.card:hover { box-shadow: 0 4px 12px rgba(0,0,0,.1); }
.card-select {
  display: flex;
  align-items: flex-start;
  gap: .5rem;
  cursor: pointer;
}
.card-select input[type="checkbox"] {
  margin-top: .2rem;
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
  flex-shrink: 0;
}
.card-selected {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px #c7d2fe;
}
.card-icon { font-size: 2rem; }
.card-body { flex: 1; }
.card-title {
  font-size: .95rem;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-meta { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.card-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.card-actions form { margin: 0; }

/* ─── Empty state ────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: .75rem;
}
.empty-icon { font-size: 3rem; }

/* ─── Page header ────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.back-link { font-size: .9rem; color: var(--muted); display: block; margin-bottom: .3rem; }
.back-link:hover { color: var(--primary); }
.page-header h1 { font-size: 1.5rem; font-weight: 700; word-break: break-word; }
.page-meta { color: var(--muted); font-size: .9rem; margin-top: .2rem; }

/* ─── Slides list ────────────────────────────── */
.slides-list { display: flex; flex-direction: column; gap: 1rem; }

.slide-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  gap: 1rem;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.slide-number {
  background: var(--bg);
  border-right: 1px solid var(--border);
  min-width: 80px;
  padding: 1rem .75rem;
  font-size: .8rem;
  font-weight: 600;
  color: var(--muted);
  text-align: center;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  flex-shrink: 0;
}
.slide-number a { color: var(--primary); }

.slide-body { padding: 1rem; flex: 1; display: flex; flex-direction: column; gap: .5rem; }
.slide-title { font-size: 1rem; font-weight: 600; }
.slide-content { font-size: .9rem; color: var(--muted); }
.slide-content p { margin: .1rem 0; }

.slide-notes {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.slide-notes summary {
  padding: .4rem .75rem;
  cursor: pointer;
  font-size: .85rem;
  font-weight: 500;
  color: var(--muted);
  background: var(--bg);
}
.notes-body {
  padding: .5rem .75rem;
  font-size: .85rem;
  color: var(--muted);
}
.notes-body p { margin: .1rem 0; }

.empty-slide { font-size: .85rem; color: #94a3b8; font-style: italic; }

/* ─── Search page ────────────────────────────── */
.search-form {
  display: flex;
  gap: .5rem;
}
.search-input {
  flex: 1;
  padding: .6rem 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 1rem;
  outline: none;
}
.search-input:focus { border-color: var(--primary); }

.search-results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: .5rem;
  font-size: .95rem;
}

.result-source { font-size: .82rem; color: var(--muted); }
.result-source a { color: var(--muted); }
.result-source a:hover { color: var(--primary); }

.slide-notes-snippet {
  font-size: .85rem;
  color: var(--muted);
  border-left: 3px solid var(--border);
  padding-left: .5rem;
}
.notes-label { font-weight: 600; }

mark { background: var(--mark-bg); border-radius: 2px; padding: 0 2px; }

.search-tip { font-size: .85rem; }

@media (max-width: 600px) {
  .header-inner { flex-wrap: wrap; }
  .page-header { flex-direction: column; }
  .slide-card { flex-direction: column; }
  .slide-number { border-right: none; border-bottom: 1px solid var(--border); min-width: unset; text-align: left; }
}
