:root {
  --primary: #1e88e5;
  --primary-dark: #1565c0;
  --accent: #26a69a;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef1f4;
  --text: #1a1c1e;
  --text-muted: #5f6a76;
  --border: #e1e5ea;
  --danger: #d32f2f;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.18);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101418;
    --surface: #181d23;
    --surface-2: #20262d;
    --text: #eef1f4;
    --text-muted: #9aa5b1;
    --border: #2a313a;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  overflow-x: hidden;
}

a { color: var(--primary); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 10px;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
  transition: background 0.15s ease, transform 0.1s ease;
}
button:hover { background: var(--primary-dark); }
button:active { transform: scale(0.97); }
button.secondary {
  background: transparent;
  color: var(--primary);
  border: 1px solid var(--border);
}
button.secondary:hover { background: var(--surface-2); }
button.danger { background: var(--danger); }
button.danger:hover { background: #b71c1c; }
button:disabled { opacity: 0.5; cursor: default; }

input, select {
  width: 100%;
  padding: 11px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; }

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 18px; }
.brand-icon { font-size: 22px; }
.nav-links { display: flex; align-items: center; gap: 8px; }
.nav-links .user-email { color: var(--text-muted); font-size: 13px; margin-right: 6px; }
.nav-link {
  padding: 8px 14px;
  border-radius: 10px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
  font-weight: 600;
}
.nav-link.active { background: var(--surface-2); }

main { max-width: 1100px; margin: 0 auto; padding: 24px 18px 60px; }

.center-page {
  min-height: calc(100vh - 70px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 28px;
}

.auth-card { width: 100%; max-width: 380px; }
.auth-card h1 { font-size: 22px; margin: 0 0 6px; }
.auth-card p.subtitle { color: var(--text-muted); margin: 0 0 22px; font-size: 14px; }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.form-error {
  background: rgba(211, 47, 47, 0.1);
  color: var(--danger);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 13px;
  margin-bottom: 14px;
}
.form-success {
  background: rgba(38, 166, 154, 0.12);
  color: var(--accent);
  padding: 12px 14px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 14px;
}
.auth-switch { margin-top: 18px; text-align: center; font-size: 13px; color: var(--text-muted); }

.tabs { display: flex; gap: 6px; margin-bottom: 20px; overflow-x: auto; padding-bottom: 2px; }
.tab {
  padding: 9px 16px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}
.tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; flex-wrap: wrap; gap: 10px; }
.quota-pill {
  background: var(--surface-2);
  border-radius: 999px;
  padding: 7px 14px;
  font-size: 12.5px;
  color: var(--text-muted);
}

#uploadButton {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

#uploadPanel:not(:empty) {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 18px;
}

.gallery-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 14px;
}
.gallery-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  position: relative;
}
.gallery-item:hover { transform: translateY(-3px); box-shadow: var(--shadow-lg); }
.gallery-thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  display: block;
  background: var(--surface-2);
}
.gallery-thumb-fallback {
  width: 100%;
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 36px;
  background: var(--surface-2);
}
.gallery-meta { padding: 9px 10px; }
.gallery-name { font-size: 12.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gallery-size { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.gallery-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 10px;
  padding: 2px 7px;
  border-radius: 999px;
}
.gallery-delete {
  position: absolute;
  top: 6px;
  left: 6px;
  background: rgba(211,47,47,0.85);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 26px;
  height: 26px;
  font-size: 13px;
  line-height: 1;
  padding: 0;
}
.gallery-item.selected {
  outline: 3px solid var(--accent, #4f8cff);
  outline-offset: -3px;
}
.gallery-select-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  border: 2px solid #fff;
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1;
}

.empty-state { text-align: center; color: var(--text-muted); padding: 60px 20px; }

.pagination { display: flex; justify-content: center; gap: 10px; margin-top: 26px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 24px;
}
.modal-content {
  max-width: min(900px, 92vw);
  max-height: 88vh;
  width: 100%;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.modal-media { display: flex; align-items: center; justify-content: center; background: #000; min-height: 200px; }
.modal-media img { max-width: 100%; max-height: 76vh; display: block; }
.modal-media video { max-width: 100%; max-height: 76vh; }
.modal-media audio { width: 100%; margin: 40px 20px; }
.modal-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  gap: 12px;
}
.modal-footer .name { font-size: 13.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.modal-actions { display: flex; gap: 8px; flex-shrink: 0; }
.modal-close {
  position: absolute;
  top: 16px;
  right: 20px;
  background: rgba(0,0,0,0.5);
  color: #fff;
  border-radius: 50%;
  width: 36px;
  height: 36px;
  font-size: 18px;
}

section.panel { margin-bottom: 32px; }
section.panel h2 { font-size: 16px; margin: 0 0 14px; }
.list-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 13px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 8px;
  gap: 12px;
  flex-wrap: wrap;
}
.list-row .info { display: flex; flex-direction: column; gap: 2px; }
.list-row .info .primary { font-weight: 600; font-size: 14px; }
.list-row .info .secondary { font-size: 12px; color: var(--text-muted); }
.list-row .actions { display: flex; gap: 8px; }
.badge-pill {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
}
.badge-pill.approved { background: rgba(38,166,154,0.15); color: var(--accent); }

.loader { text-align: center; padding: 40px; color: var(--text-muted); font-size: 14px; }

@media (max-width: 520px) {
  .app-header { padding: 12px 14px; }
  .nav-links .user-email { display: none; }
  main { padding: 18px 12px 50px; }
}
