/* LITREAD Modern Minimalist Stylesheet */
:root {
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;

  /* Dark Theme Default */
  --bg-primary: #121212;
  --bg-secondary: #1a1a1a;
  --bg-tertiary: #242424;
  --bg-hover: #2e2e2e;

  --text-primary: #f0f0f0;
  --text-secondary: #a0a0a0;
  --text-muted: #666666;

  --border: #2a2a2a;
  --border-focus: #555555;

  --accent: #ffffff;
  --accent-inverted: #121212;

  --radius-sm: 4px;
  --radius-md: 8px;
  --radius-lg: 12px;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.6);

  --header-height: 64px;
}

[data-theme="light"] {
  --bg-primary: #f8f9fa;
  --bg-secondary: #ffffff;
  --bg-tertiary: #f1f3f5;
  --bg-hover: #e9ecef;

  --text-primary: #1a1a1a;
  --text-secondary: #555555;
  --text-muted: #888888;

  --border: #e0e0e0;
  --border-focus: #1a1a1a;

  --accent: #121212;
  --accent-inverted: #ffffff;

  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.12);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
  transition: background-color 0.2s ease, color 0.2s ease;
}

body.reading-mode {
  overflow: hidden;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
}

/* Offline Banner */
.offline-banner {
  display: none;
  background-color: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  color: var(--text-secondary);
  font-size: 0.85rem;
  padding: 8px 16px;
  text-align: center;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.offline-banner.active {
  display: flex;
}

.offline-banner svg {
  width: 16px;
  height: 16px;
}

/* App Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  height: var(--header-height);
  background-color: var(--bg-primary);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.header-inner {
  max-width: 1300px;
  height: 100%;
  margin: 0 auto;
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  user-select: none;
}

.brand-mark {
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.brand-mark svg {
  width: 22px;
  height: 22px;
}

.brand-title {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.15em;
  color: var(--text-primary);
}

/* Search Bar */
.search-bar {
  flex: 1;
  max-width: 460px;
}

.search-input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.search-icon {
  position: absolute;
  left: 12px;
  display: flex;
  align-items: center;
  pointer-events: none;
  color: var(--text-muted);
}

.search-icon svg {
  width: 16px;
  height: 16px;
}

.search-input-wrap input {
  width: 100%;
  height: 38px;
  padding: 0 16px 0 38px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s ease, background-color 0.15s ease;
}

.search-input-wrap input:focus {
  border-color: var(--border-focus);
}

.search-input-wrap input::placeholder {
  color: var(--text-muted);
}

/* Header Actions */
.header-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 38px;
  padding: 0 16px;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-md);
  cursor: pointer;
  border: 1px solid transparent;
  transition: all 0.15s ease;
  user-select: none;
}

.btn-primary {
  background-color: var(--accent);
  color: var(--accent-inverted);
}

.btn-primary:hover {
  opacity: 0.92;
}

.btn-secondary {
  background-color: var(--bg-secondary);
  border-color: var(--border);
  color: var(--text-primary);
}

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

.btn-block {
  width: 100%;
}

.btn-icon {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-icon:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.btn-icon.active {
  background-color: var(--bg-tertiary);
  color: var(--text-primary);
  border-color: var(--border-focus);
}

.btn-icon svg {
  width: 18px;
  height: 18px;
}

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-left: 8px;
  border-left: 1px solid var(--border);
}

.user-display {
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* Upload Progress Floating Bar */
.upload-progress-container {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  width: 320px;
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px 18px;
  box-shadow: var(--shadow-lg);
}

.upload-progress-container.active {
  display: block;
}

.upload-progress-header {
  font-size: 0.85rem;
  margin-bottom: 8px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.upload-track {
  height: 4px;
  background-color: var(--bg-hover);
  border-radius: 2px;
  overflow: hidden;
}

.upload-bar {
  height: 100%;
  width: 0%;
  background-color: var(--text-primary);
  transition: width 0.2s ease;
}

/* Dropzone Overlay */
.drop-zone-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background-color: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  align-items: center;
  justify-content: center;
}

.drop-zone-overlay.drag-active {
  display: flex;
}

.drop-zone-content {
  border: 2px dashed #ffffff;
  border-radius: var(--radius-lg);
  padding: 60px 80px;
  text-align: center;
  color: #ffffff;
  pointer-events: none;
}

.drop-icon svg {
  width: 48px;
  height: 48px;
  margin-bottom: 16px;
}

/* Main Layout */
.app-main {
  max-width: 1300px;
  margin: 0 auto;
  padding: 24px;
}

/* Library Toolbar */
.library-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.filter-tabs {
  display: flex;
  gap: 4px;
  background-color: var(--bg-secondary);
  padding: 4px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}

.filter-tab {
  background: transparent;
  border: none;
  padding: 6px 14px;
  font-size: 0.85rem;
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}

.filter-tab:hover {
  color: var(--text-primary);
}

.filter-tab.active {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  font-weight: 500;
}

.toolbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sort-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.sort-select {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-primary);
  font-size: 0.85rem;
  padding: 6px 10px;
  border-radius: var(--radius-md);
  outline: none;
  cursor: pointer;
}

.sort-select:focus {
  border-color: var(--border-focus);
}

.view-switch {
  display: flex;
  gap: 4px;
}

/* Stats */
.library-stats {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--text-muted);
  margin-bottom: 24px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.stat-num {
  font-weight: 600;
  color: var(--text-primary);
}

/* Books Grid */
.books-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
  gap: 24px;
}

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

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

/* Cover Image / Placeholder */
.book-cover-wrap {
  position: relative;
  aspect-ratio: 2 / 3;
  background-color: var(--bg-tertiary);
  overflow: hidden;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.book-cover-img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform 0.3s ease;
}

.book-card:hover .book-cover-img {
  transform: scale(1.03);
}

.book-cover-placeholder {
  width: 100%;
  height: 100%;
  padding: 20px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
  position: relative;
  border-left: 4px solid rgba(255, 255, 255, 0.08);
}

.placeholder-format {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  color: var(--text-muted);
}

.placeholder-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.placeholder-author {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.format-badge {
  position: absolute;
  top: 8px;
  right: 8px;
  background-color: rgba(0, 0, 0, 0.65);
  color: #ffffff;
  font-family: var(--font-mono);
  font-size: 0.65rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.offline-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background-color: rgba(0, 0, 0, 0.7);
  color: #ffffff;
  font-size: 0.68rem;
  padding: 3px 6px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  gap: 4px;
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.offline-badge svg {
  width: 12px;
  height: 12px;
}

/* Card Body */
.book-info {
  padding: 14px;
  display: flex;
  flex-direction: column;
  flex: 1;
}

.book-title {
  font-size: 0.95rem;
  font-weight: 600;
  line-height: 1.3;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}

.book-author {
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 12px;
}

.book-progress-wrap {
  margin-top: auto;
  margin-bottom: 12px;
}

.progress-bar {
  height: 4px;
  background-color: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
  margin-bottom: 6px;
}

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

.progress-text {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.book-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-read {
  flex: 1;
  height: 32px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 0.82rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-read:hover {
  background-color: var(--accent);
  color: var(--accent-inverted);
  border-color: var(--accent);
}

.btn-read svg {
  width: 14px;
  height: 14px;
}

.btn-delete {
  width: 32px;
  height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-delete:hover {
  background-color: var(--bg-hover);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-delete svg {
  width: 14px;
  height: 14px;
}

/* List View */
.books-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.books-list .book-card {
  flex-direction: row;
  align-items: center;
  padding: 10px 16px;
  height: 72px;
}

.books-list .book-cover-wrap {
  width: 44px;
  height: 56px;
  aspect-ratio: auto;
  border-radius: var(--radius-sm);
  flex-shrink: 0;
}

.books-list .format-badge,
.books-list .offline-badge {
  display: none;
}

.books-list .book-info {
  flex-direction: row;
  align-items: center;
  padding: 0 0 0 16px;
  gap: 20px;
}

.books-list .book-title {
  flex: 2;
  margin-bottom: 0;
}

.books-list .book-author {
  flex: 1.5;
  margin-bottom: 0;
}

.books-list .book-progress-wrap {
  flex: 1.5;
  margin: 0;
}

.books-list .book-actions {
  flex-shrink: 0;
}

/* Empty State */
.empty-state {
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 80px 20px;
}

.empty-state.active {
  display: flex;
}

.empty-icon-wrap {
  width: 64px;
  height: 64px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-icon-wrap svg {
  width: 100%;
  height: 100%;
}

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

.empty-state p {
  font-size: 0.95rem;
  color: var(--text-secondary);
  max-width: 380px;
  margin-bottom: 24px;
}

/* Auth Dialog */
.auth-dialog {
  border: none;
  background: transparent;
  max-width: 420px;
  width: 90%;
  margin: auto;
  padding: 0;
  color: var(--text-primary);
}

.auth-dialog[open],
.auth-dialog.active {
  display: block;
}

.auth-dialog::backdrop {
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.auth-card {
  background-color: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}

.auth-header {
  text-align: center;
  margin-bottom: 28px;
}

.auth-brand-logo {
  display: inline-flex;
  margin-bottom: 12px;
  color: var(--text-primary);
}

.auth-brand-logo svg {
  width: 32px;
  height: 32px;
}

.auth-header h2 {
  font-size: 1.4rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.auth-sub {
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.auth-form .form-group {
  margin-bottom: 18px;
}

.auth-form label {
  display: block;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.auth-form input {
  width: 100%;
  height: 42px;
  padding: 0 14px;
  background-color: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: 0.92rem;
  outline: none;
  transition: border-color 0.15s ease;
}

.auth-form input:focus {
  border-color: var(--border-focus);
}

.auth-error {
  color: #ff6b6b;
  font-size: 0.85rem;
  margin-bottom: 14px;
  min-height: 20px;
}

.auth-footer {
  text-align: center;
  margin-top: 18px;
}

.auth-footer a {
  color: var(--text-secondary);
  font-size: 0.85rem;
  text-decoration: none;
  transition: color 0.15s ease;
}

.auth-footer a:hover {
  color: var(--text-primary);
  text-decoration: underline;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  .header-inner {
    padding: 0 16px;
    gap: 12px;
  }
  .search-bar {
    max-width: 200px;
  }
  .books-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
  }
  .library-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .filter-tabs {
    overflow-x: auto;
  }
  .toolbar-right {
    justify-content: space-between;
  }
}
