/* ────────────────────────────────────────────────────────────
   Tehiru Aerial Systems — Assembly Books
   Dark charcoal theme with amber accents
   ──────────────────────────────────────────────────────────── */

:root {
  --bg:          #0d1117;
  --bg-surface:  #161b22;
  --bg-elevated: #1c2128;
  --bg-hover:    #21262d;
  --border:      #30363d;
  --text:        #e6edf3;
  --text-muted:  #8b949e;
  --accent:      #d4a544;
  --accent-dim:  rgba(212, 165, 68, 0.12);
  --accent-glow: rgba(212, 165, 68, 0.25);
  --danger:      #e63946;
  --success:     #3fb950;
  --radius:      6px;
  --radius-lg:   10px;
  --shadow:      0 4px 24px rgba(0,0,0,0.5);
  --shadow-page: 0 8px 48px rgba(0,0,0,0.7), 0 2px 8px rgba(0,0,0,0.4);
  --font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:   'JetBrains Mono', 'Fira Code', ui-monospace, monospace;
  --transition:  0.18s ease;
}

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

html { scroll-behavior: smooth; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Top Nav ─────────────────────────────────────────────── */
.topnav {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  flex-shrink: 0;
}

.nav-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.nav-logo {
  height: 32px;
  width: auto;
  object-fit: contain;
}

.nav-title {
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--accent);
  text-transform: uppercase;
}

.nav-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.nav-link {
  color: var(--text-muted);
  font-size: 0.85rem;
  padding: 0.35rem 0.75rem;
  border-radius: var(--radius);
  transition: background var(--transition), color var(--transition);
  text-decoration: none;
}
.nav-link:hover {
  background: var(--bg-hover);
  color: var(--text);
  text-decoration: none;
}

/* ── Buttons ─────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent);
  color: #0d1117;
  border: none;
  padding: 0.55rem 1.25rem;
  border-radius: var(--radius);
  font-weight: 600;
  font-size: 0.875rem;
  cursor: pointer;
  transition: opacity var(--transition), transform var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
}
.btn-primary:hover { opacity: 0.88; text-decoration: none; }
.btn-primary:active { transform: scale(0.98); }

.btn-secondary {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn-secondary:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-muted);
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(230,57,70,0.4);
  padding: 0.5rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.875rem;
  cursor: pointer;
  transition: background var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn-danger:hover { background: rgba(230,57,70,0.12); }

/* ── Forms ───────────────────────────────────────────────── */
input[type="text"],
input[type="password"],
input[type="email"],
textarea,
select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 0.6rem 0.875rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  font-family: var(--font);
  width: 100%;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-bottom: 0.4rem;
}
.form-group { margin-bottom: 1.1rem; }
.form-error {
  color: var(--danger);
  font-size: 0.82rem;
  margin-top: 0.4rem;
}

/* ── Login Page ──────────────────────────────────────────── */
.login-wrap {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background:
    radial-gradient(ellipse at 20% 50%, rgba(212,165,68,0.04) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(212,165,68,0.03) 0%, transparent 50%);
}

.login-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}

.login-card .logo-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 2rem;
}

.login-card .logo-wrap img {
  height: 48px;
  width: auto;
  object-fit: contain;
}

.login-card .logo-fallback {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
}

.login-card .brand-name {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  color: var(--accent);
  text-transform: uppercase;
}

.login-card .brand-sub {
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.login-card h2 {
  font-size: 1rem;
  font-weight: 600;
  text-align: center;
  margin-bottom: 1.75rem;
  color: var(--text-muted);
}

/* ── Index / Book List ───────────────────────────────────── */
.index-main {
  flex: 1;
  padding: 2.5rem 2rem;
  max-width: 1200px;
  margin: 0 auto;
  width: 100%;
}

.index-header {
  margin-bottom: 2.5rem;
}

.index-header h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  margin-bottom: 0.25rem;
}

.index-header p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

.book-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  text-decoration: none;
  color: var(--text);
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
  display: flex;
  flex-direction: column;
}
.book-card:hover {
  border-color: var(--accent);
  transform: translateY(-3px);
  box-shadow: 0 8px 32px rgba(212,165,68,0.15);
  text-decoration: none;
}

.book-cover {
  position: relative;
  aspect-ratio: 3/4;
  background: var(--bg-elevated);
  overflow: hidden;
}
.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.book-cover-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0.5;
}
.book-cover-placeholder svg {
  width: 64px;
  height: 64px;
}

.book-info {
  padding: 1rem;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.book-title {
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.3;
}

.book-meta {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.book-pages {
  font-size: 0.75rem;
  color: var(--accent);
  margin-top: auto;
  padding-top: 0.5rem;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

/* ── Viewer Layout ───────────────────────────────────────── */
.viewer-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.viewer-body {
  flex: 1;
  display: flex;
  overflow: hidden;
  position: relative;
}

/* Sidebar / TOC */
.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width var(--transition), opacity var(--transition);
}

.sidebar.collapsed {
  width: 0;
  opacity: 0;
  pointer-events: none;
}

.sidebar-header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-muted);
  flex-shrink: 0;
}

.toc-list {
  overflow-y: auto;
  flex: 1;
  padding: 0.5rem 0;
}

.toc-item {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.45rem 0.875rem;
  cursor: pointer;
  font-size: 0.8rem;
  line-height: 1.3;
  color: var(--text-muted);
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  white-space: normal;
  word-break: break-word;
}
.toc-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.toc-item.active {
  border-left-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}
.toc-num {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
  font-size: 0.7rem;
  color: var(--border);
  min-width: 1.6rem;
  margin-top: 0.1rem;
}

/* Main viewer area */
.viewer-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
}

.page-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  overflow: auto;
  background:
    radial-gradient(ellipse at center, rgba(255,255,255,0.015) 0%, transparent 70%);
  position: relative;
}

.page-img-wrap {
  position: relative;
  display: inline-block;
  cursor: zoom-in;
  max-height: calc(100vh - 160px);
}

.page-img-wrap.zoomed {
  cursor: zoom-out;
  max-height: none;
}

.page-img {
  display: block;
  max-width: 100%;
  max-height: calc(100vh - 160px);
  width: auto;
  height: auto;
  border-radius: var(--radius);
  box-shadow: var(--shadow-page);
  border: 1px solid rgba(255,255,255,0.06);
  user-select: none;
  -webkit-user-drag: none;
  transition: max-height 0.25s ease, max-width 0.25s ease;
}

.page-img.zoomed {
  max-width: none;
  max-height: none;
  width: auto;
  height: auto;
  cursor: zoom-out;
}

/* Loading spinner */
.page-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(13,17,23,0.7);
  border-radius: var(--radius);
  z-index: 2;
  opacity: 1;
  transition: opacity 0.3s;
  pointer-events: none;
}
.page-loader.hidden { opacity: 0; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Nav bar at bottom of viewer */
.viewer-nav {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 0.625rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1.25rem;
  flex-shrink: 0;
}

.nav-btn {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.nav-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--accent);
  color: var(--accent);
}
.nav-btn:disabled {
  opacity: 0.3;
  cursor: not-allowed;
}

.page-counter {
  font-size: 0.85rem;
  color: var(--text-muted);
  min-width: 90px;
  text-align: center;
  white-space: nowrap;
}

.page-counter strong {
  color: var(--text);
}

/* Viewer toolbar */
.viewer-toolbar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
  flex-shrink: 0;
}
.toolbar-btn:hover {
  background: var(--bg-hover);
  color: var(--text);
  border-color: var(--text-muted);
}
.toolbar-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

/* Fullscreen */
.viewer-wrap:fullscreen,
.viewer-wrap:-webkit-full-screen {
  background: var(--bg);
}

/* ── Admin Panel ─────────────────────────────────────────── */
.admin-wrap {
  flex: 1;
  display: flex;
  overflow: hidden;
}

.admin-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.admin-nav-item {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.65rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-muted);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.admin-nav-item:hover {
  background: var(--bg-hover);
  color: var(--text);
}
.admin-nav-item.active {
  border-left-color: var(--accent);
  color: var(--accent);
  background: var(--accent-dim);
}

.admin-main {
  flex: 1;
  padding: 2rem;
  overflow-y: auto;
}

.admin-section {
  display: none;
}
.admin-section.active {
  display: block;
}

.admin-header {
  margin-bottom: 1.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 1rem;
}

.admin-header h2 {
  font-size: 1.25rem;
  font-weight: 700;
}

/* Table */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
.data-table th {
  text-align: left;
  padding: 0.6rem 0.875rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.75rem 0.875rem;
  border-bottom: 1px solid rgba(48,54,61,0.5);
  vertical-align: middle;
  color: var(--text);
}
.data-table tr:hover td { background: var(--bg-hover); }

/* Card */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}
.card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
}

/* Badge */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.55rem;
  border-radius: 99px;
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
}
.badge-amber { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(212,165,68,0.3); }
.badge-gray { background: rgba(139,148,158,0.1); color: var(--text-muted); border: 1px solid var(--border); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 1.5rem;
}
.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
}

/* Log table */
.log-time { font-family: var(--font-mono); font-size: 0.75rem; color: var(--text-muted); white-space: nowrap; }
.log-type { font-family: var(--font-mono); font-size: 0.75rem; }
.log-type.login { color: var(--success); }
.log-type.admin_login { color: var(--accent); }
.log-type.admin_delete { color: var(--danger); }
.log-type.book_view { color: #79c0ff; }

/* Upload area */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius-lg);
  padding: 2.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color var(--transition), background var(--transition);
}
.upload-area:hover, .upload-area.drag-over {
  border-color: var(--accent);
  background: var(--accent-dim);
}
.upload-area p { color: var(--text-muted); font-size: 0.875rem; margin-top: 0.5rem; }
.upload-area input[type="file"] { display: none; }

/* ── Footer ──────────────────────────────────────────────── */
.footer {
  background: var(--bg-surface);
  border-top: 1px solid var(--border);
  padding: 0.875rem 1.5rem;
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  flex-shrink: 0;
}

/* ── Scrollbars ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Toast notifications ─────────────────────────────────── */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.toast {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.75rem 1.1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  animation: slide-in 0.2s ease;
  max-width: 320px;
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }
@keyframes slide-in { from { transform: translateX(20px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Keyboard hint ───────────────────────────────────────── */
.kbd-hint {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-muted);
}
kbd {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  padding: 0.1rem 0.4rem;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.7rem;
}

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    z-index: 50;
    width: 240px;
    box-shadow: 4px 0 24px rgba(0,0,0,0.5);
  }
  .sidebar.collapsed {
    width: 0;
    opacity: 0;
  }

  .admin-wrap { flex-direction: column; }
  .admin-sidebar {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    padding: 0;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .admin-nav-item {
    border-left: none;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    padding: 0.875rem 1rem;
  }
  .admin-nav-item.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }

  .page-container { padding: 0.75rem; }
  .page-img { max-height: calc(100dvh - 200px); }

  .viewer-nav { gap: 0.75rem; padding: 0.5rem 1rem; }

  .kbd-hint { display: none; }
}

@media (max-width: 480px) {
  .topnav { padding: 0 1rem; }
  .nav-title { font-size: 0.75rem; }
  .index-main { padding: 1.5rem 1rem; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 1rem; }
}

/* ── Accent line ─────────────────────────────────────────── */
.accent-line {
  height: 2px;
  background: linear-gradient(90deg, var(--accent) 0%, transparent 100%);
  flex-shrink: 0;
}
