:root {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --primary-light: #60a5fa;
  --secondary: #64748b;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 6px;
  --radius-lg: 12px;
}

/* Dark Theme (default) */
:root, [data-theme="dark"] {
  --bg: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --bg-card: #1e293b;
  --bg-sidebar: #1e293b;
  --text: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --text-light: #64748b;
  --text-sidebar: #e2e8f0;
  --border: #475569;
  --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.4);
}

/* Light Theme */
[data-theme="light"] {
  --bg: #f1f5f9;
  --bg-secondary: #ffffff;
  --bg-tertiary: #e2e8f0;
  --bg-card: #ffffff;
  --bg-sidebar: #ffffff;
  --text: #1e293b;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --text-sidebar: #1e293b;
  --border: #cbd5e1;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 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;
}

/* Layout */
.app {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 260px;
  background: var(--bg-secondary);
  color: var(--text-sidebar);
  display: flex;
  flex-direction: column;
  position: fixed;
  height: 100vh;
  z-index: 100;
  border-right: 1px solid var(--border);
}

.sidebar-header {
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  height: 64px;
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 1.25rem;
  font-weight: 600;
  color: var(--text);
}

.sidebar-logo svg {
  width: 32px;
  height: 32px;
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  padding: 1rem 0;
  overflow-y: auto;
}

.nav-section {
  padding: 0.5rem 1.5rem;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-top: 1rem;
}

.nav-section:first-child {
  margin-top: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  color: var(--text-secondary);
  transition: all 0.2s;
  cursor: pointer;
  margin: 0.125rem 0.5rem;
  border-radius: var(--radius);
}

.nav-item:hover {
  background: var(--bg-tertiary);
  color: var(--text);
  text-decoration: none;
}

.nav-item.active {
  background: var(--primary);
  color: #fff;
}

.nav-item svg {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  width: 100%;
}

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
}

.user-details {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.user-role {
  font-size: 0.75rem;
  color: var(--text-light);
}

/* Main Content */
.main {
  flex: 1;
  margin-left: 260px;
  display: flex;
  flex-direction: column;
}

.header {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-title {
  font-size: 1.5rem;
  font-weight: 600;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.content {
  flex: 1;
  padding: 2rem;
}

/* Cards */
.card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-secondary);
}

.card-title {
  font-size: 1rem;
  font-weight: 600;
}

.card-body {
  padding: 1.5rem;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  font-weight: 500;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.2s ease;
}

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-outline {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  color: var(--text);
}

.btn-outline:hover {
  background: var(--border);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
}

.btn-danger:hover {
  background: #dc2626;
}

.btn-sm {
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
}

.btn-icon {
  padding: 0.5rem;
}

/* Forms */
.form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
}

.form-input,
.form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text);
  transition: border-color 0.2s ease;
}

.form-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-input::placeholder {
  color: var(--text-light);
}

/* Search */
.search-box {
  position: relative;
  max-width: 400px;
}

.search-box input {
  padding-left: 2.5rem;
}

.search-box svg {
  position: absolute;
  left: 0.875rem;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  color: var(--text-light);
}

/* Tables */
.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 0.875rem 1rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table th {
  font-weight: 600;
  font-size: 0.8125rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  background: var(--bg-tertiary);
}

.table tbody tr:hover {
  background: var(--bg-tertiary);
}

.table-link {
  color: var(--primary);
  font-weight: 500;
}

/* Grid */
.grid {
  display: grid;
  gap: 1.5rem;
}

.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

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

.book-card {
  background: var(--bg-secondary);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  transition: transform 0.2s, box-shadow 0.2s;
}

.book-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.book-cover {
  aspect-ratio: 2/3;
  background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 3rem;
}

.book-cover img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.book-info {
  padding: 1rem;
}

.book-title {
  font-weight: 600;
  font-size: 0.9375rem;
  margin-bottom: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

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

/* Alphabet Filter */
.alphabet-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-bottom: 1.5rem;
}

.alphabet-btn {
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-tertiary);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.alphabet-btn:hover,
.alphabet-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

/* List */
.list-item {
  display: flex;
  align-items: center;
  padding: 1rem;
  border-bottom: 1px solid var(--border);
  transition: background 0.2s;
}

.list-item:hover {
  background: var(--bg-tertiary);
}

.list-item:last-child {
  border-bottom: none;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.75rem;
  font-size: 0.75rem;
  font-weight: 500;
  border-radius: 9999px;
  background: var(--bg-tertiary);
  color: var(--text-secondary);
  text-transform: uppercase;
}

.badge-primary {
  background: rgba(59, 130, 246, 0.2);
  color: var(--primary);
}

.badge-success {
  background: rgba(34, 197, 94, 0.2);
  color: var(--success);
}

.badge-warning {
  background: rgba(245, 158, 11, 0.2);
  color: var(--warning);
}

.badge-danger {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1.5rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-lg);
  padding: 1.5rem;
  border: 1px solid var(--border);
}

.stat-value {
  font-size: 2rem;
  font-weight: 700;
  color: var(--primary);
}

.stat-label {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

/* Login Page */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e293b 0%, #0f172a 100%);
}

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

.login-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.login-logo svg {
  width: 64px;
  height: 64px;
  color: var(--primary);
}

.login-title {
  text-align: center;
  font-size: 1.5rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
}

.login-subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: 2rem;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 1rem;
  opacity: 0.5;
}

.empty-state h3 {
  font-size: 1.25rem;
  margin-bottom: 0.5rem;
  color: var(--text);
}

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4rem;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  margin-top: 2rem;
}

.page-btn {
  min-width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  color: var(--text);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
}

.page-btn:hover,
.page-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.page-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ========== Mobile Responsive Styles ========== */

/* Tablet and below - collapsible sidebar */
@media (max-width: 1024px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.3s;
  }
  
  .sidebar.open {
    transform: translateX(0);
  }
  
  .main {
    margin-left: 0;
  }
  
  .grid-3, .grid-4 {
    grid-template-columns: repeat(2, 1fr);
  }
}

/* Mobile - comprehensive adaptations */
@media (max-width: 768px) {
  /* General layout adjustments */
  .content {
    padding: 1rem;
  }
  
  .header {
    padding: 0 1rem;
    height: 56px;
  }
  
  .header-title {
    font-size: 1.125rem;
  }
  
  /* Grid adjustments */
  .grid-2, .grid-3, .grid-4 {
    grid-template-columns: 1fr;
  }
  
  .book-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
  }
  
  /* Browser layout - mobile adaptations */
  .toolbar {
    flex-wrap: wrap;
    padding: 0.5rem;
    gap: 0.5rem;
  }
  
  .toolbar-group {
    gap: 0.5rem;
  }
  
  .toolbar-divider {
    display: none;
  }
  
  .app-logo span {
    display: none;
  }
  
  .library-selector {
    flex: 1;
    min-width: 0;
  }
  
  .library-selector label {
    display: none;
  }
  
  .library-selector select {
    min-width: 120px;
    max-width: 100%;
    font-size: 0.8125rem;
    padding: 0.375rem 1.5rem 0.375rem 0.5rem;
  }
  
  .library-stats {
    display: none;
  }
  
  .search-box {
    width: 100% !important;
    order: 10;
    flex-basis: 100%;
  }
  
  /* Three-panel layout becomes single-panel on mobile */
  .browser-layout {
    position: relative;
  }
  
  .panel-left,
  .panel-right {
    position: fixed;
    top: 0;
    bottom: 0;
    z-index: 200;
    width: 85% !important;
    max-width: 320px !important;
    background: var(--bg-secondary);
    box-shadow: var(--shadow-lg);
    transition: transform 0.3s ease;
  }
  
  .panel-left {
    left: 0;
    border-right: 1px solid var(--border);
    transform: translateX(0);
  }
  
  .panel-left.mobile-closed {
    transform: translateX(-100%);
  }
  
  .panel-right {
    right: 0;
    left: auto;
    border-left: 1px solid var(--border);
    transform: translateX(100%);
  }
  
  .panel-right.mobile-open {
    transform: translateX(0);
  }
  
  .panel-resizer {
    display: none;
  }
  
  .panel-center {
    min-width: 100%;
    width: 100%;
  }
  
  /* Mobile overlay for panels */
  .mobile-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 199;
    display: block;
  }
  
  .mobile-overlay.hidden {
    display: none;
  }
  
  /* Mobile panel toggle buttons */
  .mobile-panel-toggle {
    position: fixed;
    bottom: 1rem;
    z-index: 150;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 50%;
    width: 56px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    cursor: pointer;
    transition: transform 0.2s;
  }
  
  .mobile-panel-toggle:active {
    transform: scale(0.95);
  }
  
  .mobile-panel-toggle.left {
    left: 1rem;
  }
  
  .mobile-panel-toggle.right {
    right: 1rem;
  }
  
  .mobile-panel-toggle svg {
    width: 24px;
    height: 24px;
  }
  
  /* Hide desktop panel toggle on mobile */
  .mobile-panel-toggle {
    display: flex;
  }
  
  /* Books table - touch-friendly */
  .books-table {
    font-size: 0.75rem;
  }
  
  .books-table th,
  .books-table td {
    padding: 0.5rem 0.375rem;
  }
  
  .books-table th {
    font-size: 0.75rem;
  }
  
  /* Hide some columns on mobile for better readability */
  .books-table .col-genre,
  .books-table .col-date {
    display: none;
  }
  
  .books-table .col-size {
    font-size: 0.6875rem;
  }
  
  /* Touch-friendly panel items */
  .panel-item {
    padding: 0.75rem;
    font-size: 0.875rem;
    min-height: 44px;
  }
  
  /* Tabs - scrollable on mobile */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  
  .tabs::-webkit-scrollbar {
    display: none;
  }
  
  .tab {
    padding: 0.75rem 1rem;
    white-space: nowrap;
    flex-shrink: 0;
  }
  
  /* Status bar adjustments */
  .status-bar {
    font-size: 0.6875rem;
    padding: 0.25rem 0.5rem;
  }
  
  /* Book details - optimized for mobile */
  .book-details {
    padding: 0.75rem;
  }
  
  .book-cover-large {
    max-width: 150px;
  }
  
  .book-cover-placeholder {
    width: 120px;
    height: 160px;
    font-size: 3rem;
  }
  
  .book-title-large {
    font-size: 1rem;
  }
  
  .book-meta {
    font-size: 0.8125rem;
  }
  
  .book-meta-label {
    width: 70px;
  }
  
  .book-actions {
    flex-direction: column;
  }
  
  .book-actions .btn {
    width: 100%;
  }
  
  /* Touch-friendly buttons */
  .btn {
    min-height: 44px;
    padding: 0.625rem 1.25rem;
  }
  
  .btn-sm {
    min-height: 36px;
    padding: 0.5rem 1rem;
  }
  
  .btn-icon {
    min-width: 44px;
    min-height: 44px;
  }
  
  /* Alphabet filter - compact on mobile */
  .alphabet-bar {
    padding: 0.375rem;
    gap: 1px;
  }
  
  .alphabet-letter {
    padding: 0.375rem 0.5rem;
    font-size: 0.6875rem;
    min-width: 28px;
    min-height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  
  /* Modal adjustments */
  .modal-dialog {
    width: 95%;
    max-width: 100%;
    margin: 0.5rem;
  }
  
  .modal-body {
    padding: 1rem;
  }
  
  /* Login page mobile */
  .login-card {
    padding: 1.5rem;
    margin: 1rem;
  }
  
  /* Stats grid mobile */
  .stats-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }
  
  /* Toast notifications - adjust position */
  .toast-container {
    bottom: 5rem;
    right: 1rem;
    left: 1rem;
  }
  
  .toast {
    font-size: 0.8125rem;
    padding: 0.75rem 1rem;
  }
}

/* Desktop only - show panels by default */
@media (min-width: 769px) {
  .mobile-panel-toggle {
    display: none !important;
  }
  
  .mobile-overlay {
    display: none !important;
  }
  
  .panel-left,
  .panel-right {
    position: relative;
    transform: none !important;
  }
}

/* Very small mobile devices */
@media (max-width: 480px) {
  .toolbar {
    padding: 0.375rem;
  }
  
  .app-logo svg {
    width: 18px;
    height: 18px;
  }
  
  .library-selector select {
    font-size: 0.75rem;
    min-width: 100px;
  }
  
  .book-grid {
    grid-template-columns: 1fr;
  }
  
  .books-table {
    font-size: 0.6875rem;
  }
  
  .books-table th,
  .books-table td {
    padding: 0.375rem 0.25rem;
  }
  
  /* Hide author column on very small screens, keep only title */
  .books-table .col-author {
    display: none;
  }
  
  .panel-left,
  .panel-right {
    width: 90% !important;
    max-width: 100% !important;
  }
  
  .mobile-panel-toggle {
    width: 48px;
    height: 48px;
    bottom: 0.75rem;
  }
  
  .mobile-panel-toggle.left {
    left: 0.75rem;
  }
  
  .mobile-panel-toggle.right {
    right: 0.75rem;
  }
  
  .mobile-panel-toggle svg {
    width: 20px;
    height: 20px;
  }
}

/* Landscape mobile optimization */
@media (max-width: 768px) and (orientation: landscape) {
  .toolbar {
    height: auto;
    min-height: 48px;
  }
  
  .mobile-panel-toggle {
    width: 48px;
    height: 48px;
    bottom: 0.5rem;
  }
  
  .mobile-panel-toggle.left {
    left: 0.5rem;
  }
  
  .mobile-panel-toggle.right {
    right: 0.5rem;
  }
  
  .panel-left,
  .panel-right {
    width: 50% !important;
    max-width: 400px !important;
  }
}

/* Modal - Dark Theme Style */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal-dialog {
  background: #1e293b;
  border-radius: 12px;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  width: 90%;
  max-width: 420px;
  max-height: 90vh;
  overflow: hidden;
  border: 1px solid #475569;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid #475569;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #1e293b;
}

.modal-title {
  font-size: 1.125rem;
  font-weight: 600;
  margin: 0;
  color: #f8fafc;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  color: #64748b;
  cursor: pointer;
  padding: 0;
  line-height: 1;
  transition: color 0.2s ease;
}

.modal-close:hover {
  color: #f8fafc;
}

.modal-body {
  padding: 1.5rem;
  overflow-y: auto;
  background: #1e293b;
}

.modal-body .form-group {
  margin-bottom: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.modal-body .form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: #94a3b8;
}

.modal-body .form-control {
  width: 100%;
  padding: 0.75rem 1rem;
  background: #334155;
  border: 1px solid #475569;
  border-radius: 6px;
  font-size: 1rem;
  color: #f8fafc;
  transition: border-color 0.2s ease;
}

.modal-body .form-control::placeholder {
  color: #64748b;
}

.modal-body .form-control:focus {
  outline: none;
  border-color: #3b82f6;
}

.modal-body select.form-control {
  cursor: pointer;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-end;
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid #475569;
}

.modal-actions .btn {
  padding: 0.75rem 1.5rem;
  border-radius: 6px;
  font-size: 1rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s ease;
}

.modal-actions .btn-outline {
  background: #334155;
  color: #f8fafc;
  border: 1px solid #475569;
}

.modal-actions .btn-outline:hover {
  background: #475569;
}

.modal-actions .btn-primary {
  background: #3b82f6;
  color: white;
  border: none;
}

.modal-actions .btn-primary:hover {
  background: #2563eb;
}

.form-error {
  color: #ef4444;
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.form-error:empty {
  display: none;
}

/* File Picker */
.file-picker {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.file-picker-path {
  display: flex;
  gap: 0.5rem;
}

.file-picker-list {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  max-height: 300px;
  overflow-y: auto;
}

.file-picker-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.file-picker-item:last-child {
  border-bottom: none;
}

.file-picker-item:hover {
  background: var(--bg-tertiary);
}

.file-picker-item.is-dir {
  font-weight: 500;
}

.file-icon {
  font-size: 1.25rem;
}

.file-size {
  margin-left: auto;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.file-picker-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Input with button */
.input-with-btn {
  display: flex;
  gap: 0.5rem;
}

.input-with-btn .form-input {
  flex: 1;
}

/* Progress bar */
.progress-bar {
  height: 6px;
  background: var(--bg-tertiary);
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 0.5rem;
}

.progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  transition: width 0.3s ease;
}

.progress-text {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Indeterminate progress animation for ZIP imports */
@keyframes progress-indeterminate {
  0% {
    background-position: 0 0;
  }
  100% {
    background-position: 40px 0;
  }
}

.progress-fill.indeterminate {
  width: 100%;
  background-image: linear-gradient(
    -45deg,
    var(--primary) 25%,
    transparent 25%,
    transparent 50%,
    var(--primary) 50%,
    var(--primary) 75%,
    transparent 75%,
    transparent
  );
  background-size: 40px 40px;
  animation: progress-indeterminate 1s linear infinite;
}

/* Theme Toggle */
.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  background: var(--bg-tertiary);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--text);
  transition: all 0.2s ease;
}

.theme-toggle:hover {
  background: var(--border);
}

.theme-toggle svg {
  width: 20px;
  height: 20px;
}

/* Hide icons based on theme */
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="light"] .theme-toggle .icon-sun { display: none; }
[data-theme="light"] .theme-toggle .icon-moon { display: block; }

/* Default to dark theme icons */
.theme-toggle .icon-sun { display: block; }
.theme-toggle .icon-moon { display: none; }

/* Utilities */
.text-center { text-align: center; }
.text-muted { color: var(--text-muted); }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-4 { margin-top: 2rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-4 { margin-bottom: 2rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* ========== FreeLib-style Layout ========== */

/* Top toolbar */
.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar .search-box {
  position: relative;
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.toolbar-divider {
  width: 1px;
  height: 24px;
  background: var(--border);
  margin: 0 0.5rem;
}

/* Library selector */
.library-selector {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.library-selector label {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

.library-selector select {
  min-width: 200px;
  max-width: 400px;
  padding: 0.5rem 2rem 0.5rem 0.75rem;
  font-size: 0.875rem;
  background: var(--bg-tertiary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
}

.library-stats {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.tab {
  padding: 0.75rem 1.25rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
  cursor: pointer;
  border: none;
  background: none;
  border-bottom: 2px solid transparent;
  transition: all 0.2s;
}

.tab:hover {
  color: var(--text);
  background: var(--bg-tertiary);
}

.tab.active {
  color: var(--primary);
  border-bottom-color: var(--primary);
}

/* Three-panel layout */
.browser-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0; /* Critical for flex children to respect overflow */
}

/* Left panel - Authors/Series list */
.panel-left {
  width: 280px;
  min-width: 200px;
  max-width: 400px;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  min-height: 0; /* Critical for flex children to respect overflow */
  overflow: hidden;
}

.panel-header {
  padding: 0.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.panel-filter {
  width: 100%;
  padding: 0.5rem;
  font-size: 0.875rem;
  background: var(--bg-secondary);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.panel-list {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0; /* Critical for flex children to respect overflow */
}

/* Load more button in virtual scroll */
.vs-load-more {
  padding: 0.25rem 0.5rem;
}

.vs-loading {
  padding: 0.5rem;
  color: var(--text-muted);
  font-size: 0.75rem;
  text-align: center;
}

.panel-item {
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.panel-item:hover {
  background: var(--bg-tertiary);
}

.panel-item.selected {
  background: var(--primary);
  color: #fff;
}

.panel-item-count {
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  padding: 0.125rem 0.5rem;
  border-radius: 10px;
}

.panel-item.selected .panel-item-count {
  background: rgba(255,255,255,0.2);
  color: #fff;
}

/* Center panel - Books table */
.panel-center {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 400px;
  min-height: 0; /* Critical for flex children to respect overflow */
}

.books-table-wrapper {
  flex: 1;
  overflow-y: auto;
  overflow-x: auto;
  min-height: 0; /* Critical for flex children to respect overflow */
}

.books-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8125rem;
}

.books-table th {
  position: sticky;
  top: 0;
  background: var(--bg-tertiary);
  padding: 0.5rem 0.75rem;
  text-align: left;
  font-weight: 600;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.books-table th:hover {
  background: var(--border);
}

.books-table:focus {
  outline: none;
}

.books-table th.sortable {
  cursor: pointer;
  position: relative;
  padding-right: 1.5rem;
}

.books-table th.sortable::after {
  content: '';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-top-color: var(--text-muted);
  margin-top: 2px;
}

.books-table th.sortable::before {
  content: '';
  position: absolute;
  right: 0.5rem;
  top: 50%;
  transform: translateY(-50%);
  border: 4px solid transparent;
  border-bottom-color: var(--text-muted);
  margin-top: -6px;
}

.books-table th.sorted-asc::after {
  border-top-color: var(--primary);
}

.books-table th.sorted-desc::before {
  border-bottom-color: var(--primary);
}

.books-table td {
  padding: 0.375rem 0.75rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.books-table tr:hover td {
  background: var(--bg-tertiary);
}

.books-table tr.selected td {
  background: var(--primary);
  color: #fff;
}

.books-table .col-title {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-table .col-size,
.books-table .col-rating,
.books-table .col-date {
  text-align: right;
  white-space: nowrap;
}

.books-table .col-author {
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.books-table .col-genre {
  max-width: 150px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Right panel - Book details */
.panel-right {
  width: 320px;
  min-width: 250px;
  max-width: 450px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  overflow-y: auto;
  min-height: 0; /* Critical for flex children to respect overflow */
}

.book-details {
  padding: 1rem;
}

.book-cover-large {
  width: 100%;
  max-width: 200px;
  margin: 0 auto 1rem;
  display: block;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.book-cover-placeholder {
  width: 150px;
  height: 200px;
  margin: 0 auto 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--primary-light), var(--primary-dark));
  border-radius: var(--radius);
  font-size: 4rem;
}

.book-title-large {
  font-size: 1.125rem;
  font-weight: 600;
  margin-bottom: 0.5rem;
  text-align: center;
}

.book-meta {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 1rem;
}

.book-meta-row {
  display: flex;
  padding: 0.375rem 0;
  border-bottom: 1px solid var(--border);
}

.book-meta-label {
  width: 80px;
  flex-shrink: 0;
  color: var(--text-muted);
}

.book-meta-value {
  flex: 1;
}

.book-meta-value a {
  color: var(--primary);
}

.book-description {
  margin-top: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.book-description-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
  text-transform: uppercase;
}

.book-description-text {
  font-size: 0.875rem;
  line-height: 1.6;
  color: var(--text-secondary);
  max-height: 300px;
  overflow-y: auto;
}

.book-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

/* Alphabet filter bar */
.alphabet-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 0.5rem;
  background: var(--bg-tertiary);
  border-bottom: 1px solid var(--border);
}

.alphabet-letter {
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  color: var(--text-secondary);
  border-radius: 3px;
}

.alphabet-letter:hover {
  background: var(--bg-secondary);
  color: var(--text);
}

.alphabet-letter.active {
  background: var(--primary);
  color: #fff;
}

/* Resizable panels */
.panel-resizer {
  width: 4px;
  cursor: col-resize;
  background: transparent;
  transition: background 0.2s;
}

.panel-resizer:hover {
  background: var(--primary);
}

/* Status bar */
.status-bar {
  padding: 0.375rem 1rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  background: var(--bg-tertiary);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
}

/* No sidebar layout for browser */
.app-browser {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Compact header for browser */
.header-compact {
  padding: 0 1rem;
  height: 48px;
}

.header-compact .header-title {
  font-size: 1.125rem;
}

/* Toast notifications */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  padding: 0.875rem 1.25rem;
  border-radius: var(--radius);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  animation: toastSlideIn 0.3s ease;
  pointer-events: auto;
  font-size: 0.875rem;
}

.toast.success {
  border-color: var(--success);
}

.toast.error {
  border-color: var(--danger);
}

.toast.info {
  border-color: var(--primary);
}

.toast.warning {
  border-color: var(--warning);
}

.toast.loading {
  border-color: var(--success);
}

@keyframes toastSlideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }
  to {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Reading History Dropdown */
.reading-history-dropdown {
  position: relative;
}

.reading-history-dropdown .btn {
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.reading-history-label {
  font-size: 0.8125rem;
}

.reading-history-menu {
  position: absolute;
  top: 100%;
  right: 0;
  margin-top: 0.5rem;
  width: 320px;
  max-height: 400px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  z-index: 1000;
  display: none;
  overflow: hidden;
}

.reading-history-menu.active {
  display: block;
}

.reading-history-header {
  padding: 0.75rem 1rem;
  font-weight: 600;
  font-size: 0.875rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-tertiary);
}

.reading-history-list {
  max-height: 340px;
  overflow-y: auto;
}

.reading-history-empty {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.875rem;
}

.reading-history-item {
  padding: 0.75rem 1rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background 0.15s;
}

.reading-history-item:last-child {
  border-bottom: none;
}

.reading-history-item:hover {
  background: var(--bg-tertiary);
}

.reading-history-item-title {
  font-weight: 500;
  font-size: 0.875rem;
  margin-bottom: 0.25rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-history-item-meta {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.reading-history-item-author {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reading-history-item-progress {
  color: var(--primary);
  font-weight: 500;
}

.reading-history-item-time {
  white-space: nowrap;
}

/* Hide label on smaller screens */
@media (max-width: 900px) {
  .reading-history-label {
    display: none;
  }
  
  .reading-history-menu {
    width: 280px;
  }
}
