:root {
  /* Quiet Luxury Palette */
  --bg-dark: hsl(220, 10%, 12%);
  --bg-panel: hsl(220, 10%, 16%);
  --bg-card: hsl(220, 10%, 20%);
  --text-primary: hsl(0, 0%, 95%);
  --text-secondary: hsl(0, 0%, 70%);
  --accent: hsl(210, 80%, 65%);
  --accent-hover: hsl(210, 80%, 75%);
  --border: hsl(220, 10%, 25%);
  --success: hsl(150, 60%, 50%);
  --error: hsl(350, 60%, 60%);
  
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.2);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.3);
  --glass-bg: rgba(30, 32, 36, 0.7);
  --glass-border: rgba(255, 255, 255, 0.08);

  /* Formats Colors */
  --color-epub: hsl(280, 60%, 65%);
  --color-pdf: hsl(0, 60%, 65%);
  --color-audio: hsl(180, 60%, 65%);
  --color-cbz: hsl(40, 80%, 60%);
  --color-other: hsl(220, 10%, 50%);
  
  --font-sans: 'Inter', system-ui, sans-serif;
  --font-display: 'Outfit', system-ui, sans-serif;
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-dark);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden; /* App-like feel */
}

/* Utils */
.hide { display: none !important; }
.screen { width: 100vw; height: 100vh; position: absolute; top: 0; left: 0; }

/* Buttons */
.btn {
  padding: 10px 20px;
  border-radius: 8px;
  border: none;
  font-family: var(--font-sans);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); }
.btn-block { width: 100%; }

.btn-icon {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px;
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  transition: all 0.2s ease;
}
.btn-icon:hover { background: var(--bg-card); color: var(--text-primary); }
.spinning { animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

/* Login Screen */
#login-screen {
  display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at top right, hsl(220, 15%, 20%), var(--bg-dark));
}
.login-card {
  width: 100%; max-width: 380px; padding: 40px 30px;
  border-radius: 16px; text-align: center;
}
.login-header { margin-bottom: 30px; }
.logo-icon { width: 56px; height: 56px; background: var(--accent); border-radius: 14px; display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; color: #fff; }
.logo-icon i { width: 28px; height: 28px; }
.login-header h1 { font-family: var(--font-display); font-weight: 600; font-size: 24px; margin-bottom: 4px; }
.login-header p { color: var(--text-secondary); font-size: 14px; }

.form-group { margin-bottom: 20px; text-align: left; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary); margin-bottom: 6px; }
.input-wrapper { position: relative; }
.input-icon { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-secondary); }
.input-wrapper input {
  width: 100%; background: var(--bg-dark); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 10px 10px 40px; color: var(--text-primary);
  font-family: var(--font-sans); outline: none; transition: border-color 0.2s;
}
.input-wrapper input:focus { border-color: var(--accent); }

/* App Layout */
#app-screen { display: flex; }

/* Sidebar */
.sidebar {
  width: 260px; background: var(--bg-panel); border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
}
.sidebar-header { padding: 24px 20px 24px 125px; border-bottom: 1px solid var(--border); }
.logo { display: flex; align-items: center; gap: 12px; font-family: var(--font-display); font-weight: 600; font-size: 18px; color: #fff; }
.sidebar-menu { flex: 1; padding: 20px 12px; overflow-y: auto; }
.menu-label { font-size: 11px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-secondary); margin: 16px 0 8px 8px; font-weight: 600; }
.menu-item {
  display: flex; align-items: center; gap: 12px; padding: 10px 12px;
  border-radius: 8px; color: var(--text-secondary); text-decoration: none; font-size: 14px; transition: all 0.2s;
}
.menu-item:hover { background: var(--bg-card); color: var(--text-primary); }
.menu-item.active { background: rgba(255,255,255,0.05); color: var(--text-primary); font-weight: 500; }
.menu-item i { width: 18px; height: 18px; }

.sidebar-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.user-info { display: flex; align-items: center; gap: 12px; }
.user-avatar { width: 36px; height: 36px; border-radius: 50%; background: var(--accent); display: flex; align-items: center; justify-content: center; font-weight: 600; color: #fff; font-size: 14px; }
.user-details { display: flex; flex-direction: column; }
.user-name { font-size: 14px; font-weight: 500; }
.user-role { font-size: 12px; color: var(--text-secondary); }

/* Main Content */
.main-content { flex: 1; display: flex; flex-direction: column; background: var(--bg-dark); }
.topbar { padding: 16px 32px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.search-bar-container { position: relative; width: 320px; }
.search-bar-container input { width: 100%; background: var(--bg-panel); border: 1px solid var(--border); border-radius: 20px; padding: 10px 16px 10px 42px; color: var(--text-primary); font-size: 14px; outline: none; }
.search-icon { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-secondary); }

.filter-tab { background: none; border: none; color: var(--text-secondary); font-size: 14px; padding: 6px 12px; cursor: pointer; border-radius: 16px; transition: 0.2s; }
.filter-tab:hover { color: var(--text-primary); }
.filter-tab.active { background: var(--bg-panel); color: var(--text-primary); }

.filter-toggle {
  background: var(--bg-panel); border: 1px solid var(--border); color: var(--text-secondary);
  font-size: 13px; padding: 6px 12px; border-radius: 16px; cursor: pointer;
  display: flex; align-items: center; gap: 6px; transition: 0.2s;
}
.filter-toggle:hover { color: var(--text-primary); border-color: var(--text-secondary); }

/* Library Grid */
.view-panel { flex: 1; padding: 32px; overflow-y: auto; }
.view-header { margin-bottom: 24px; display: flex; justify-content: space-between; align-items: flex-end; }
.view-header h2 { font-family: var(--font-display); font-size: 28px; font-weight: 600; }
.subtitle { color: var(--text-secondary); font-size: 14px; margin-top: 4px; }

.books-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 24px; }
.book-card {
  padding: 16px; border-radius: 12px; cursor: pointer;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  display: flex; flex-direction: column; gap: 16px;
}
.book-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-md); }
.book-card.empty-file { opacity: 0.5; }
.book-card.empty-file:hover { opacity: 0.8; }

.book-cover-placeholder {
  aspect-ratio: 2/3; background: var(--bg-dark); border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
}
.book-cover-placeholder i { width: 32px; height: 32px; opacity: 0.5; }
.book-info h3 { font-size: 15px; font-weight: 500; margin-bottom: 8px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book-meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; }
.badge { padding: 3px 8px; border-radius: 4px; font-weight: 600; font-size: 11px; letter-spacing: 0.5px; }
.format-epub { background: rgba(173, 102, 255, 0.1); color: var(--color-epub); }
.format-pdf { background: rgba(255, 102, 102, 0.1); color: var(--color-pdf); }
.format-audio { background: rgba(102, 255, 204, 0.1); color: var(--color-audio); }
.format-cbz { background: rgba(255, 190, 80, 0.1); color: var(--color-cbz); }
.empty-badge { background: rgba(255,0,0,0.2); color: #ff8888; border: 1px solid #ff8888; }
.size-info { color: var(--text-secondary); }

/* Glassmorphism */
.glass-card { background: var(--glass-bg); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); border: 1px solid var(--glass-border); }

/* Reader View */
#reader-view { display: flex; flex-direction: column; background: var(--bg-dark); z-index: 100; }
.reader-toolbar {
  height: 60px; background: var(--bg-panel); border-bottom: 1px solid var(--border);
  display: flex; justify-content: space-between; align-items: center; padding: 0 16px;
}
.reader-toolbar-left, .reader-toolbar-right { display: flex; align-items: center; gap: 16px; width: 250px; } .reader-toolbar-left { padding-left: 110px; }
.reader-title-container h2 { font-size: 15px; font-weight: 500; max-width: 200px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-toolbar-center { flex: 1; display: flex; justify-content: center; align-items: center; }
.reader-controls-group { display: flex; align-items: center; gap: 16px; }

.page-indicator { color: var(--text-secondary); font-size: 14px; }
.page-indicator input { width: 50px; background: var(--bg-dark); border: 1px solid var(--border); color: #fff; text-align: center; border-radius: 4px; padding: 2px 4px; }
.progress-indicator-text { font-variant-numeric: tabular-nums; width: 45px; text-align: center; color: var(--text-secondary); }

.reader-workspace { flex: 1; position: relative; overflow: hidden; }
.viewer-container { width: 100%; height: 100%; position: absolute; top: 0; left: 0; }

/* EPUB */
#epub-viewer { width: 100%; height: 100%; }
.epub-nav-area { position: absolute; top: 0; bottom: 0; width: 15%; z-index: 10; cursor: pointer; }
.epub-nav-left { left: 0; }
.epub-nav-right { right: 0; }

/* PDF */
.pdf-canvas-wrapper { width: 100%; height: 100%; overflow: auto; display: flex; justify-content: center; padding: 32px; }
#pdf-canvas { max-width: 100%; object-fit: contain; box-shadow: var(--shadow-md); }

/* Audio */
.audio-center { display: flex; align-items: center; justify-content: center; }
.audio-card { padding: 40px; border-radius: 20px; text-align: center; width: 400px; }
.audio-icon { width: 64px; height: 64px; color: var(--color-audio); margin-bottom: 20px; }
.audio-card h3 { margin-bottom: 30px; font-size: 18px; }
audio { width: 100%; }

/* CBZ (BD) */
.cbz-workspace { width: 100%; height: 100%; display: flex; justify-content: center; align-items: center; background: #000; overflow: hidden; }
#cbz-current-image { max-width: 100%; max-height: 100%; object-fit: contain; }

/* TXT */
.txt-scroll-area { width: 100%; height: 100%; overflow: auto; padding: 40px; display: flex; justify-content: center; }
.txt-content { max-width: 800px; width: 100%; background: var(--bg-panel); padding: 40px; border-radius: 8px; white-space: pre-wrap; font-family: var(--font-display); font-size: 16px; line-height: 1.6; color: var(--text-primary); box-shadow: var(--shadow-md); }

/* DOCX */
.docx-scroll-area { width: 100%; height: 100%; overflow: auto; padding: 40px; display: flex; justify-content: center; background: #f0f0f0; }
.docx-content { max-width: 800px; width: 100%; background: #ffffff; color: #333333; padding: 60px; border-radius: 4px; box-shadow: var(--shadow-md); font-family: serif; font-size: 18px; line-height: 1.6; }
.docx-content img { max-width: 100%; height: auto; }

/* Loader */
.reader-loader { position: absolute; inset: 0; background: var(--bg-dark); display: flex; flex-direction: column; justify-content: center; align-items: center; z-index: 50; }
.spinner { width: 40px; height: 40px; border: 3px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; margin-bottom: 16px; }

/* Footer Info (EPUB/PDF/CBZ) */
.reader-footer-info {
  position: absolute; bottom: 8px; left: 0; right: 0; text-align: center;
  font-size: 12px; color: var(--text-secondary); pointer-events: none; z-index: 10;
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .topbar { flex-direction: column; align-items: flex-start; gap: 16px; }
  .search-bar-container { width: 100%; }
  .format-tabs { overflow-x: auto; padding-bottom: 8px; }
  .reader-toolbar-right { display: none; }
  .reader-toolbar-left { width: auto; }
}
