/* views.css — styles for the Reader, Stats, Decks and Admin views.
   Mobile-first (390px baseline). Uses the shell's CSS variables with
   fallbacks so these views still look reasonable if a variable is missing.
   Variables expected from the shell: --bg --surface --surface-2 --border
   --text --text-2 --accent --success --warning --danger --radius
*/

:root {
  --eb-bg: var(--bg, #16181c);
  --eb-surface: var(--surface, #1c1f24);
  --eb-surface-2: var(--surface-2, #23262b);
  --eb-border: var(--border, #33383f);
  --eb-text: var(--text, #e8eaed);
  --eb-text-2: var(--text-2, #9aa0a6);
  --eb-accent: var(--accent, #4d88ff);
  --eb-success: var(--success, #3ecf8e);
  --eb-warning: var(--warning, #e0a536);
  --eb-danger: var(--danger, #e05c5c);
  --eb-radius: var(--radius, 8px);
}

.muted {
  color: var(--eb-text-2);
}
.error {
  color: var(--eb-danger);
}

.btn-primary,
.btn-secondary,
.btn-sm {
  font: inherit;
  border-radius: var(--eb-radius);
  border: 1px solid var(--eb-border);
  background: var(--eb-surface-2);
  color: var(--eb-text);
  padding: 8px 14px;
  cursor: pointer;
}
.btn-primary {
  background: var(--eb-accent);
  border-color: var(--eb-accent);
  color: #0b0d10;
  font-weight: 600;
}
.btn-sm {
  padding: 4px 10px;
  font-size: 0.85rem;
}
.btn-danger {
  border-color: var(--eb-danger);
  color: var(--eb-danger);
}
a.btn-sm {
  display: inline-block;
  text-decoration: none;
}

input[type="text"],
input[type="email"],
input[type="number"],
input[type="search"],
input[type="file"],
input[type="color"],
select,
textarea {
  font: inherit;
  background: var(--eb-surface-2);
  border: 1px solid var(--eb-border);
  color: var(--eb-text);
  border-radius: var(--eb-radius);
  padding: 8px 10px;
}
.checkbox-row {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.form-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 8px 0;
}

/* ============================== Reader ============================== */
.reader-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 100vh;
  background: var(--eb-bg);
}

.reader-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: var(--eb-surface);
  border-bottom: 1px solid var(--eb-border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.tb-group {
  display: flex;
  align-items: center;
  gap: 4px;
}
.tb-btn,
.tool-btn {
  min-width: 34px;
  height: 34px;
  border-radius: var(--eb-radius);
  border: 1px solid var(--eb-border);
  background: var(--eb-surface-2);
  color: var(--eb-text);
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.tool-btn.active {
  background: var(--eb-accent);
  color: #0b0d10;
  border-color: var(--eb-accent);
}
.page-num-input {
  width: 48px;
  text-align: center;
}
.page-indicator {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--eb-text-2);
}
.zoom-display {
  min-width: 42px;
  text-align: center;
  font-size: 0.85rem;
  color: var(--eb-text-2);
}
.color-btn-wrap {
  position: relative;
}
.color-btn {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--eb-border);
  cursor: pointer;
}
.color-popup {
  position: absolute;
  top: 40px;
  left: 0;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 8px;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.color-swatches {
  display: grid;
  grid-template-columns: repeat(4, 22px);
  gap: 6px;
}
.color-swatch {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
}
.color-swatch.active {
  border-color: var(--eb-text);
}

.reader-body {
  flex: 1;
  display: flex;
  min-height: 0;
  position: relative;
}
.reader-viewport {
  flex: 1;
  overflow: auto;
  display: flex;
  justify-content: center;
  padding: 12px;
  background: var(--eb-bg);
}
.pdf-loading {
  color: var(--eb-text-2);
  padding: 40px;
}
.pdf-canvas-container {
  position: relative;
  background: #fff;
  box-shadow: 0 0 0 1px var(--eb-border);
}
.pdf-canvas-container canvas:first-child {
  display: block;
}
.highlight-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 1;
  pointer-events: none;
}
.hl-mark {
  position: absolute;
  pointer-events: none;
  mix-blend-mode: multiply;
}
.text-layer {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 2;
  overflow: hidden;
  line-height: 1;
  opacity: 1;
}
.text-layer > span {
  color: transparent;
  position: absolute;
  white-space: pre;
  cursor: text;
  transform-origin: 0% 0%;
}
.text-layer ::selection {
  background: rgba(77, 136, 255, 0.4);
}
.fabric-canvas {
  position: absolute;
  top: 0;
  left: 0;
  z-index: 3;
}

.notes-drawer {
  width: 0;
  overflow: hidden;
  background: var(--eb-surface);
  border-left: 1px solid var(--eb-border);
  transition: width 0.2s ease;
  display: flex;
  flex-direction: column;
}
.notes-drawer.open {
  width: min(320px, 90vw);
}
.notes-drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--eb-border);
}
.notes-toolbar {
  display: flex;
  gap: 6px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--eb-border);
}
.notes-editor {
  flex: 1;
  padding: 12px;
  overflow: auto;
  outline: none;
  min-height: 200px;
}
.notes-status {
  padding: 6px 12px;
  font-size: 0.8rem;
  color: var(--eb-text-2);
}
.icon-btn {
  background: none;
  border: none;
  color: var(--eb-text);
  font-size: 1.2rem;
  cursor: pointer;
}

@media (max-width: 480px) {
  .reader-toolbar {
    position: fixed;
    bottom: 0;
    top: auto;
    left: 0;
    right: 0;
    flex-wrap: nowrap;
    overflow-x: auto;
    justify-content: flex-start;
    border-top: 1px solid var(--eb-border);
    border-bottom: none;
    padding: 6px 8px;
  }
  .reader-body {
    padding-bottom: 54px;
  }
  .tb-history {
    display: none;
  }
  .notes-drawer.open {
    position: fixed;
    inset: 0 0 54px 0;
    width: auto;
    z-index: 25;
  }
}

/* ============================== Stats ============================== */
.stats-view h1 {
  margin-bottom: 4px;
}
.stat-section {
  margin: 22px 0;
  padding: 14px;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
}
.stat-section h2 {
  margin: 0 0 10px;
  font-size: 1rem;
}
.chart-caption {
  margin-top: 8px;
  font-size: 0.82rem;
  color: var(--eb-text-2);
}
.stat-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 10px;
}
.stat-tile {
  background: var(--eb-surface-2);
  border-radius: var(--eb-radius);
  padding: 10px;
  text-align: center;
}
.stat-tile-value {
  font-size: 1.4rem;
  font-weight: 700;
}
.stat-tile-label {
  font-size: 0.75rem;
  color: var(--eb-text-2);
  margin-top: 2px;
}
.calibration-table,
.admin-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.calibration-table th,
.calibration-table td,
.admin-table th,
.admin-table td {
  border-bottom: 1px solid var(--eb-border);
  padding: 6px 8px;
  text-align: left;
}
.group-list {
  list-style: none;
  margin: 0;
  padding: 0;
}
.group-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--eb-border);
}
.group-check {
  width: 20px;
  text-align: center;
  color: var(--eb-text-2);
}
.group-check.yes {
  color: var(--eb-success);
  font-weight: 700;
}
.group-name {
  flex: 1;
}
.group-count {
  color: var(--eb-text-2);
  font-size: 0.85rem;
}

/* ============================== Decks ============================== */
.decks-view {
  padding: 12px;
  max-width: 780px;
  margin: 0 auto;
}
.decks-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
}
.deck-section {
  margin: 18px 0;
}
.deck-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.deck-card {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 10px 12px;
  flex-wrap: wrap;
}
.deck-card-main {
  flex: 1;
  min-width: 160px;
  cursor: pointer;
}
.deck-card-name {
  font-weight: 600;
}
.deck-card-desc,
.deck-card-meta {
  font-size: 0.82rem;
  color: var(--eb-text-2);
}
.deck-card-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}
.new-deck-form,
.import-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 10px 0;
  align-items: center;
}
.import-panel {
  margin: 10px 0;
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 8px 12px;
}
.deck-search {
  width: 100%;
  margin: 10px 0;
}
.card-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.card-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 8px 10px;
}
.card-row-kind {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--eb-text-2);
  width: 50px;
}
.card-row-front {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-row-actions {
  display: flex;
  gap: 6px;
}
.card-form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 12px;
}
.card-form label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.85rem;
  color: var(--eb-text-2);
}
.card-form textarea,
.card-form input,
.card-form select {
  color: var(--eb-text);
}
.mcq-builder {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.mcq-choice-row {
  display: flex;
  align-items: center;
  gap: 8px;
}
.mcq-choice-input {
  flex: 1;
}

/* ============================== Admin ============================== */
.admin-view {
  padding: 12px;
  max-width: 900px;
  margin: 0 auto;
}
.tab-bar {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 10px 0 16px;
  border-bottom: 1px solid var(--eb-border);
}
.tab-btn {
  background: none;
  border: none;
  color: var(--eb-text-2);
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab-btn.active {
  color: var(--eb-text);
  border-bottom-color: var(--eb-accent);
}
.upload-form,
.invite-form,
.pipeline-form {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  margin-bottom: 14px;
}
.pipeline-forms {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.pipeline-form {
  flex-direction: column;
  align-items: stretch;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 12px;
}
.invite-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.invite-row {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--eb-surface);
  border: 1px solid var(--eb-border);
  border-radius: var(--eb-radius);
  padding: 8px 10px;
}
.invite-url {
  flex: 1;
  overflow-x: auto;
  white-space: nowrap;
  font-size: 0.82rem;
}
.chapter-table input,
.chapter-table select {
  width: 100%;
  min-width: 70px;
}

@media (max-width: 600px) {
  .admin-table {
    display: block;
    overflow-x: auto;
  }
}
