/* Base styles */
:root {
  --bg: #0b0d10;
  --panel: #12161a;
  --panel-2: #181d22;
  --text: #e6eef8;
  --muted: #9fb2c7;
  --primary: #4f8cff;
  --primary-2: #3a6fe0;
  --accent: #ff4d4f;
  --success: #22c55e;
  --shadow: 0 10px 30px rgba(0,0,0,0.35);
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica Neue, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
  background: radial-gradient(1200px 600px at 80% -20%, rgba(79,140,255,0.15), transparent 50%),
              radial-gradient(1000px 500px at -10% 10%, rgba(255,77,79,0.1), transparent 40%),
              var(--bg);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  position: sticky;
  top: 0;
  background: rgba(11,13,16,0.7);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid rgba(255,255,255,0.06);
  z-index: 10;
}
.brand { display: flex; align-items: center; gap: 14px; }
.logo { font-size: 28px; filter: drop-shadow(0 4px 10px rgba(0,0,0,0.4)); }
.title h1 { margin: 0; font-size: 20px; font-weight: 700; }
.subtitle { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid rgba(255,255,255,0.08);
  padding: 10px 14px;
  border-radius: 10px;
  cursor: pointer;
  transition: transform .15s ease, background .2s ease, border-color .2s ease;
}
.btn:hover { transform: translateY(-1px); border-color: rgba(255,255,255,0.18); }
.btn:active { transform: translateY(0); }
.btn.primary { background: linear-gradient(180deg, var(--primary), var(--primary-2)); border: none; box-shadow: 0 8px 16px rgba(79,140,255,0.3); }
.btn.primary:hover { filter: brightness(1.05); }
.btn.danger { background: linear-gradient(180deg, #ff6b6d, var(--accent)); border: none; }

.user-info { display: flex; align-items: center; gap: 12px; }
.hidden { display: none !important; }

.content { max-width: 1200px; margin: 0 auto; padding: 16px; }
.toolbar { display: flex; align-items: center; justify-content: space-between; margin: 14px 6px; }
.status { color: var(--muted); font-size: 14px; }

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}
.card {
  position: relative;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255,255,255,0.07);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: transform .18s ease, box-shadow .2s ease, border-color .2s ease;
}
.card:hover { transform: translateY(-3px); border-color: rgba(255,255,255,0.18); box-shadow: 0 14px 40px rgba(0,0,0,0.45); }
.card .thumb { width: 100%; aspect-ratio: 3/4; background: #0c0f13; display: grid; place-items: center; }
.card .thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.card .thumb .thumb-fallback { font-size: 42px; opacity: .6; }
.card .meta { padding: 12px; }
.card .title { font-size: 14px; font-weight: 600; margin: 0 0 8px; color: #f7fbff; line-height: 1.25; max-height: 3.2em; overflow: hidden; }
.card .sub { font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; }

.empty { display: grid; place-items: center; padding: 80px 20px; }
.empty-card {
  width: 480px; max-width: 90vw; text-align: center;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.spinner, .spinner:before, .spinner:after { border-radius: 50%; }
.spinner { width: 28px; height: 28px; background: conic-gradient(from 0deg, var(--primary), transparent 60%); animation: spin 1s linear infinite; margin: 0 auto 12px; }
.spinner.large { width: 42px; height: 42px; margin: 12px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Overlay viewer */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 50; }
.overlay.hidden { pointer-events: none; opacity: 0; }
.overlay .overlay-bg { position: absolute; inset: 0; background: rgba(0,0,0,0.5); backdrop-filter: blur(4px); opacity: 0; transition: opacity .25s ease; }
.overlay:not(.hidden) .overlay-bg { opacity: 1; }
.viewer {
  position: relative; width: min(1000px, 96vw); height: min(92vh, 900px);
  background: #0f1317; border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px; box-shadow: 0 30px 80px rgba(0,0,0,0.6);
  transform: translateY(10px) scale(0.98); opacity: 0;
  transition: transform .28s ease, opacity .28s ease;
}
.overlay:not(.hidden) .viewer { transform: translateY(0) scale(1); opacity: 1; }
.viewer-header {
  position: sticky; top: 0; z-index: 2; display: flex; align-items: center; justify-content: space-between;
  height: 54px; padding: 0 12px 0 16px; background: linear-gradient(180deg, rgba(23,28,34,0.95), rgba(23,28,34,0.8));
  border-bottom: 1px solid rgba(255,255,255,0.07);
}
.viewer-title { font-weight: 600; color: #f2f7ff; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-controls { display: flex; align-items: center; gap: 8px; }
.icon-btn { background: #1b2127; border: 1px solid rgba(255,255,255,0.08); color: var(--text); border-radius: 10px; padding: 6px 10px; cursor: pointer; }
.icon-btn:hover { border-color: rgba(255,255,255,0.18); }
.icon-btn.danger { background: #281818; border-color: rgba(255,255,255,0.12); }
.zoom-label, .page-label { color: var(--muted); font-size: 12px; }
.divider { width: 1px; height: 20px; background: rgba(255,255,255,0.1); margin: 0 4px; }
.viewer-body { position: absolute; inset: 54px 0 0 0; overflow: auto; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 16px; }
.page { position: relative; border-radius: 10px; overflow: hidden; background: #0f1317; border: 1px solid rgba(255,255,255,0.05); }
.page .canvas { display: block; width: 100%; height: auto; background: #0e1116; }
.page .page-number { position: absolute; bottom: 8px; right: 10px; font-size: 11px; color: rgba(255,255,255,0.6); background: rgba(0,0,0,0.35); padding: 2px 6px; border-radius: 6px; }
.viewer-loading { position: absolute; inset: 0; display: grid; place-items: center; background: linear-gradient(180deg, rgba(15,19,23,0.9), rgba(15,19,23,0.9)); }
.loading-text { margin-top: 6px; color: var(--muted); font-size: 13px; text-align: center; }

/* Scrollbar aesthetics */
.viewer-body::-webkit-scrollbar, body::-webkit-scrollbar { width: 10px; height: 10px; }
.viewer-body::-webkit-scrollbar-thumb, body::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.14); border-radius: 10px; }
.viewer-body::-webkit-scrollbar-track, body::-webkit-scrollbar-track { background: rgba(0,0,0,0.2); }

/* Responsive tweaks */
@media (max-width: 600px) {
  .brand .title h1 { font-size: 18px; }
  .viewer { width: 98vw; height: 94vh; }
}
