/* ============================================================
   KITHUB — MODERN GITHUB-INSPIRED THEME
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg-canvas:     #0d1117;
  --bg-overlay:    #161b22;
  --bg-subtle:     #1c2128;
  --bg-hover:      #21262d;
  --bg-active:     #2d333b;

  --border-default: #30363d;
  --border-muted:   #21262d;
  --border-focus:   #388bfd;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;
  --text-link:      #58a6ff;

  --green-500:  #3fb950;
  --green-400:  #2ea043;
  --green-bg:   rgba(35, 134, 54, 0.15);
  --green-border: rgba(63, 185, 80, 0.3);

  --amber-500:  #e3b341;
  --amber-bg:   rgba(187, 128, 9, 0.15);
  --amber-border: rgba(187, 128, 9, 0.35);

  --red-500:    #f85149;
  --red-bg:     rgba(248, 81, 73, 0.12);
  --red-border: rgba(248, 81, 73, 0.3);

  --blue-500:   #58a6ff;
  --blue-bg:    rgba(88, 166, 255, 0.1);

  --radius-sm:  6px;
  --radius-md:  8px;
  --radius-lg:  12px;

  --font-main: 'Sora', -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --nav-height: 60px;
}

html { scroll-behavior: smooth; }

body {
  background: var(--bg-canvas);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   NAVBAR
   ============================================================ */

.navbar {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--nav-height);
  background: rgba(13, 17, 23, 0.85);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-default);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  gap: 16px;
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 20px;
  flex: 1;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Logo */
.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  font-family: var(--font-mono);
  font-weight: 600;
  font-size: 16px;
  color: var(--text-primary);
  white-space: nowrap;
  user-select: none;
}

.logo svg {
  color: var(--green-500);
  flex-shrink: 0;
}

/* Search */
.nav-search {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 7px 12px;
  max-width: 320px;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.nav-search svg { color: var(--text-muted); flex-shrink: 0; }

.nav-search input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 13px;
  width: 100%;
}

.nav-search input::placeholder { color: var(--text-muted); }

.nav-search:focus-within {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.15);
}

/* ============================================================
   BUTTONS
   ============================================================ */

button { cursor: pointer; font-family: var(--font-main); }

.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--green-400);
  color: #fff;
  border: 1px solid rgba(240, 246, 252, 0.1);
  border-radius: var(--radius-md);
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  transition: background 0.15s, transform 0.1s;
  white-space: nowrap;
}

.btn-primary:hover { background: #26a641; }
.btn-primary:active { transform: scale(0.98); }
.btn-primary.full { width: 100%; justify-content: center; padding: 10px; margin-top: 4px; }

.btn-ghost {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-overlay);
  color: var(--text-primary);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s, border-color 0.15s;
  white-space: nowrap;
}

.btn-ghost:hover { background: var(--bg-hover); border-color: #8b949e; }
.btn-ghost:active { background: var(--bg-active); }

.btn-danger {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  color: var(--red-500);
  border: 1px solid var(--red-border);
  border-radius: var(--radius-md);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 500;
  transition: background 0.15s;
}

.btn-danger:hover { background: var(--red-bg); }

/* ============================================================
   MAIN PAGE
   ============================================================ */

main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-family: var(--font-mono);
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 4px;
}

.header-stats { display: flex; align-items: center; gap: 8px; margin-top: 4px; }

.stat-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-default);
  border-radius: 20px;
  padding: 4px 12px;
  font-size: 12px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
}

.stat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green-500);
  box-shadow: 0 0 6px var(--green-500);
  flex-shrink: 0;
}

/* ============================================================
   TOOLBAR
   ============================================================ */

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  gap: 12px;
}

.view-toggle {
  display: flex;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  overflow: hidden;
}

.view-btn {
  background: none;
  border: none;
  padding: 7px 10px;
  color: var(--text-muted);
  transition: background 0.12s, color 0.12s;
  display: flex;
  align-items: center;
}

.view-btn:hover { color: var(--text-primary); background: var(--bg-hover); }
.view-btn.active { color: var(--text-primary); background: var(--bg-active); }

.sort-select {
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 13px;
  padding: 7px 12px;
  outline: none;
  cursor: pointer;
  transition: border-color 0.15s;
}

.sort-select:hover { border-color: #8b949e; color: var(--text-primary); }
.sort-select option { background: var(--bg-overlay); }

/* ============================================================
   BOOKS GRID
   ============================================================ */

.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.books-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ============================================================
   BOOK CARD (GRID)
   ============================================================ */

.book-card {
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 20px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s, transform 0.12s;
  position: relative;
  overflow: hidden;
  animation: fadeUp 0.3s ease both;
}

.book-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, rgba(63, 185, 80, 0.04) 0%, transparent 60%);
  opacity: 0;
  transition: opacity 0.2s;
}

.book-card:hover {
  border-color: #3fb950;
  background: var(--bg-subtle);
  transform: translateY(-2px);
}

.book-card:hover::before { opacity: 1; }
.book-card:active { transform: translateY(0); }

.book-card-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 14px;
}

.book-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--green-bg);
  border: 1px solid var(--green-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--green-500);
  flex-shrink: 0;
}

.book-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-canvas);
  border: 1px solid var(--border-muted);
  border-radius: 20px;
  padding: 3px 8px;
}

.book-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  line-height: 1.3;
  margin-bottom: 6px;
  font-family: var(--font-mono);
}

.book-meta {
  font-size: 12px;
  color: var(--text-muted);
}

.book-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 16px;
  padding-top: 14px;
  border-top: 1px solid var(--border-muted);
}

.book-action {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-link);
  font-weight: 500;
}

/* ============================================================
   BOOK ROW (LIST VIEW)
   ============================================================ */

.book-row {
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 14px 20px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: border-color 0.15s, background 0.15s;
  animation: fadeUp 0.2s ease both;
}

.book-row:hover { border-color: #3fb950; background: var(--bg-subtle); }

.book-row .book-icon { width: 32px; height: 32px; flex-shrink: 0; }

.book-row-name {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
  flex: 1;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.book-row-meta { font-size: 12px; color: var(--text-muted); white-space: nowrap; }

.book-row-chevron { color: var(--text-muted); flex-shrink: 0; }

/* ============================================================
   EMPTY STATE
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 80px 20px;
  border: 1px dashed var(--border-default);
  border-radius: var(--radius-lg);
  color: var(--text-secondary);
}

.empty-icon { color: var(--text-muted); margin-bottom: 20px; opacity: 0.5; }
.empty-state h3 { font-size: 18px; font-weight: 600; margin-bottom: 8px; color: var(--text-primary); }
.empty-state p { font-size: 14px; margin-bottom: 24px; color: var(--text-muted); }

/* ============================================================
   MODALS
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: overlayIn 0.15s ease;
}

.modal-box {
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.6);
  animation: modalIn 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);
  overflow: hidden;
}

.modal-header {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border-muted);
}

.modal-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.modal-icon.green { background: var(--green-bg); color: var(--green-500); border: 1px solid var(--green-border); }
.modal-icon.amber { background: var(--amber-bg); color: var(--amber-500); border: 1px solid var(--amber-border); }

.modal-header > div:nth-child(2) { flex: 1; }

.modal-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-primary);
  font-family: var(--font-mono);
  line-height: 1.3;
}

.modal-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 3px; }

.close-btn {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  flex-shrink: 0;
  transition: color 0.15s, background 0.15s;
}

.close-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.modal-body { padding: 20px; }

/* ============================================================
   FORM FIELDS
   ============================================================ */

.field-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 8px;
}

.field-input {
  width: 100%;
  background: var(--bg-canvas);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font-main);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
  margin-bottom: 14px;
}

.field-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(56, 139, 253, 0.12);
}

.field-input::placeholder { color: var(--text-muted); }

.token-input-wrap { position: relative; }

.token-field {
  font-family: var(--font-mono);
  font-size: 20px;
  letter-spacing: 8px;
  padding-right: 48px;
  text-align: center;
}

.peek-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-55%);
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 4px;
  display: flex;
  transition: color 0.15s;
}

.peek-btn:hover { color: var(--text-primary); }

/* ============================================================
   BOOK INNER UI (replaces body after unlock)
   ============================================================ */

.book-ui header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 16px 24px;
  background: var(--bg-overlay);
  border-bottom: 1px solid var(--border-default);
  position: sticky;
  top: 0;
  z-index: 50;
}

.book-ui .back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-family: var(--font-main);
  font-size: 13px;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  transition: color 0.15s, background 0.15s;
}

.book-ui .back-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

.book-ui .book-title {
  font-family: var(--font-mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--text-primary);
  flex: 1;
}

.book-content { max-width: 900px; margin: 0 auto; padding: 32px 24px; }

/* Upload zone */
.upload-zone {
  border: 2px dashed var(--border-default);
  border-radius: var(--radius-lg);
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
  background: var(--bg-subtle);
  transition: border-color 0.15s, background 0.15s;
  margin-bottom: 28px;
  cursor: pointer;
  position: relative;
}

.upload-zone:hover, .upload-zone.drag-over {
  border-color: var(--green-500);
  background: var(--green-bg);
  color: var(--green-500);
}

.upload-zone input[type="file"] {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  font-size: 0;
}

.upload-zone-icon { margin-bottom: 12px; opacity: 0.6; }
.upload-zone-text { font-size: 14px; font-weight: 500; margin-bottom: 4px; }
.upload-zone-hint { font-size: 12px; opacity: 0.7; }

.upload-controls {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
  justify-content: center;
}

/* Files section */
.files-section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.section-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.files-list { display: flex; flex-direction: column; gap: 6px; }

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-muted);
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--text-primary);
  transition: border-color 0.15s, background 0.15s;
  animation: fadeUp 0.2s ease both;
}

.file-item:hover { border-color: var(--border-default); background: var(--bg-subtle); }

.file-icon {
  width: 32px;
  height: 32px;
  background: var(--blue-bg);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue-500);
  flex-shrink: 0;
  font-size: 11px;
  font-family: var(--font-mono);
  font-weight: 700;
  text-transform: uppercase;
}

.file-name {
  flex: 1;
  font-size: 13px;
  font-family: var(--font-mono);
  color: var(--text-primary);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.file-ext-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--text-muted);
  background: var(--bg-canvas);
  border: 1px solid var(--border-muted);
  border-radius: 4px;
  padding: 2px 6px;
  flex-shrink: 0;
}

.file-download-icon { color: var(--text-muted); flex-shrink: 0; }
.file-item:hover .file-download-icon { color: var(--text-link); }

/* Files empty */
.files-empty {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-muted);
  border: 1px dashed var(--border-muted);
  border-radius: var(--radius-lg);
}

.files-empty p { font-size: 13px; margin-top: 10px; }

/* Upload progress */
.upload-progress {
  height: 3px;
  background: var(--bg-active);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 12px;
  display: none;
}

.upload-progress-bar {
  height: 100%;
  background: var(--green-500);
  width: 0%;
  transition: width 0.3s ease;
  border-radius: 3px;
}

/* ============================================================
   TOAST
   ============================================================ */

#toastContainer {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 9999;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: var(--bg-overlay);
  border: 1px solid var(--border-default);
  color: var(--text-primary);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  min-width: 240px;
  max-width: 380px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  animation: toastIn 0.2s ease;
  pointer-events: all;
  line-height: 1.4;
}

.toast-icon {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 1px;
}

.toast.success { border-left: 3px solid var(--green-500); }
.toast.success .toast-icon { background: var(--green-bg); color: var(--green-500); }

.toast.error { border-left: 3px solid var(--red-500); }
.toast.error .toast-icon { background: var(--red-bg); color: var(--red-500); }

.toast.info { border-left: 3px solid var(--blue-500); }
.toast.info .toast-icon { background: var(--blue-bg); color: var(--blue-500); }

/* ============================================================
   ANIMATIONS
   ============================================================ */

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
  from { opacity: 0; transform: scale(0.93) translateY(8px); }
  to   { opacity: 1; transform: scale(1)   translateY(0); }
}

@keyframes overlayIn {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes toastIn {
  from { opacity: 0; transform: translateX(20px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ============================================================
   UTILS
   ============================================================ */

.hidden { display: none !important; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

@media (max-width: 640px) {
  main { padding: 20px 16px 48px; }
  .navbar { padding: 0 16px; }
  .nav-search { max-width: 160px; }
  .books-grid { grid-template-columns: 1fr; }
  .page-header { flex-direction: column; gap: 12px; }
}