:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c1f26;
  --text-muted: #6b7280;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --radius: 10px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1d2026;
    --border: #2c303a;
    --text: #e7e9ee;
    --text-muted: #9aa1ad;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: var(--primary);
  color: #fff;
  font-size: 0.8rem;
}

.auth-box { display: flex; align-items: center; gap: 0.75rem; }
.whoami { color: var(--text-muted); font-size: 0.9rem; }

.btn {
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 0.5rem 0.9rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: filter 0.15s ease;
}
.btn:hover { filter: brightness(0.95); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-ghost { background: transparent; color: var(--text); border-color: var(--border); }

.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 1.25rem;
}

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  padding: 1.5rem;
  text-align: center;
  margin-bottom: 1.25rem;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.upload-zone.drag-over { border-color: var(--primary); background: rgba(37, 99, 235, 0.06); }
.upload-zone[aria-disabled="true"] { opacity: 0.65; }

.upload-title { font-weight: 600; margin: 0.25rem 0; }
.upload-sub { color: var(--text-muted); margin: 0.25rem 0; font-size: 0.85rem; }
.upload-hint { color: var(--text-muted); font-size: 0.8rem; margin-top: 0.75rem; }

.upload-progress-list { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; text-align: left; }
.upload-progress-item { font-size: 0.8rem; }
.upload-progress-item .bar-track {
  height: 6px; background: var(--border); border-radius: 4px; overflow: hidden; margin-top: 0.2rem;
}
.upload-progress-item .bar-fill { height: 100%; background: var(--primary); width: 0%; transition: width 0.15s ease; }

.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.search-input {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.logged-out-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 60vh;
}
.logged-out-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  text-align: center;
  max-width: 380px;
}
.logged-out-card h1 { margin: 0 0 0.5rem; font-size: 1.4rem; }
.logged-out-card p { color: var(--text-muted); margin: 0 0 1.25rem; }

.empty-state { color: var(--text-muted); text-align: center; padding: 2rem 0; }

.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  margin-top: 1.25rem;
}
.page-indicator { color: var(--text-muted); font-size: 0.85rem; }

.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 0.85rem;
}

.file-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
}

.file-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 120px;
  border-radius: 8px;
  background: var(--bg);
  overflow: hidden;
}
.file-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.file-icon { font-size: 2.5rem; }

.file-name {
  font-weight: 600;
  word-break: break-all;
  text-decoration: none;
  color: var(--text);
}
.file-name:hover { color: var(--primary); }

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

.file-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-top: 0.4rem; }
.file-actions .btn { padding: 0.3rem 0.6rem; font-size: 0.78rem; }

.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: center; justify-content: center;
  padding: 1rem;
  z-index: 100;
}
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 360px;
}
.modal h2 { margin: 0 0 0.25rem; }
.modal-sub { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 1rem; }
.modal label { display: block; font-size: 0.85rem; margin: 0.6rem 0 0.25rem; }
.modal input {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
}
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1.25rem; }

.error-text { color: var(--danger); font-size: 0.82rem; margin-top: 0.6rem; }

.toast {
  position: fixed;
  bottom: 1.25rem;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.85rem;
  z-index: 200;
}

@media (max-width: 520px) {
  .topbar { flex-wrap: wrap; gap: 0.5rem; }
  .file-grid { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
}
