/* Ensure [hidden] always wins over explicit display rules */
[hidden] { display: none !important; }

:root {
  color-scheme: light;
  --bg: #f4f1ec;
  --ink: #1c1917;
  --muted: rgba(28, 25, 23, 0.56);
  --line: rgba(28, 25, 23, 0.12);
  --paper: #fff;
  --accent: #6b2d3c;
  --accent-soft: rgba(107, 45, 60, 0.08);
  --ok: #1e5c36;
  --ok-bg: #e8f4ed;
  --danger: #9b1c1c;
  --danger-bg: #fef2f2;
  --warn-bg: #fffbeb;
  --warn: #92400e;
  --radius: 14px;
  --radius-sm: 10px;
  font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;
  font-size: 14px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
}

button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Login ---- */
.login {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100dvh;
  padding: 20px;
}

.login-card {
  width: min(400px, 100%);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(84, 35, 49, 0.10);
  padding: 36px 32px 32px;
}

.login-logo {
  font-size: 2.5rem;
  text-align: center;
  margin-bottom: 12px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 1.5rem;
  text-align: center;
  font-family: Georgia, serif;
}

.hint { color: var(--muted); font-size: 0.875rem; text-align: center; margin: 0 0 20px; }
.hint-inline { color: var(--muted); font-size: 0.8rem; font-weight: 400; }

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
  font-size: 0.875rem;
  font-weight: 500;
}

/* ---- Buttons ---- */
button.primary, .btn-primary {
  background: var(--accent);
  color: #fff;
  border: 0;
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 20px;
  font-weight: 500;
  cursor: pointer;
  transition: opacity 0.15s;
}

button.primary:hover { opacity: 0.88; }
button.primary:disabled { opacity: 0.5; cursor: default; }

button.ghost {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 16px;
  cursor: pointer;
  color: var(--ink);
  transition: border-color 0.15s, background 0.15s;
}

button.ghost:hover { border-color: rgba(28, 25, 23, 0.3); background: rgba(28, 25, 23, 0.04); }

button.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(155, 28, 28, 0.25);
  border-radius: var(--radius-sm);
  min-height: 44px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 500;
}

button.danger:hover { background: #fee2e2; }

button.sm, a.sm { min-height: 34px !important; padding: 0 12px !important; font-size: 0.8125rem; border-radius: 8px !important; }

.full-width { width: 100%; }

.link-btn {
  display: inline-flex;
  align-items: center;
  font-size: 0.875rem;
  color: var(--accent);
}

.btn-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 16px;
  min-height: 44px;
  color: var(--ink);
  font-size: inherit;
  cursor: pointer;
  text-decoration: none;
  background: transparent;
}

.btn-link:hover { background: rgba(28, 25, 23, 0.04); text-decoration: none; }
.icon-btn { min-width: 44px; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn.is-spinning svg { animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Inputs ---- */
input[type="text"], input[type="password"], select, input:not([type="checkbox"]):not([type="radio"]) {
  min-height: 44px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fff;
  width: 100%;
  transition: border-color 0.15s;
}

input:focus, select:focus { outline: none; border-color: var(--accent); }

/* ---- App header ---- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px max(20px, env(safe-area-inset-right)) 14px max(20px, env(safe-area-inset-left));
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header-left { display: flex; align-items: center; gap: 12px; flex-shrink: 0; }
.app-header-right { display: flex; align-items: center; gap: 10px; flex-shrink: 0; margin-left: auto; }

.app-title {
  margin: 0;
  font-size: 1rem;
  font-family: Georgia, serif;
  font-weight: 600;
}

/* Watch badge */
.watch-badge {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.75rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--line);
  border-radius: 99px;
  padding: 3px 10px 3px 7px;
}

.watch-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #d1d5db;
  flex-shrink: 0;
}

.watch-dot.is-active { background: #22c55e; }
.watch-dot.is-warn { background: #f59e0b; }
.watch-dot.is-dead { background: #ef4444; }

/* Quota */
.quota-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}

.quota-text { font-size: 0.75rem; color: var(--muted); white-space: nowrap; }

.quota-bar {
  width: 120px;
  height: 5px;
  border-radius: 99px;
  background: rgba(28, 25, 23, 0.10);
  overflow: hidden;
}

.quota-bar span {
  display: block;
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width 0.4s ease;
}

/* ---- Layout ---- */
.panel {
  min-height: calc(100dvh - 57px);
  display: flex;
  flex-direction: column;
}

.layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 0;
  flex: 1;
  min-height: 0;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
  .app-header { flex-wrap: wrap; gap: 8px; }
  .app-header-right { width: 100%; justify-content: flex-end; margin-left: 0; }
  .quota-wrap { display: none; }
}

/* ---- Sidebar ---- */
.list-pane {
  background: var(--paper);
  border-right: 1px solid var(--line);
  padding: 16px 12px;
  overflow-y: auto;
  max-height: calc(100dvh - 57px);
  position: sticky;
  top: 57px;
}

.album-list {
  list-style: none;
  margin: 14px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.album-list button {
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s;
}

.album-list button:hover { background: var(--accent-soft); }

.album-list button.is-on {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.album-list strong { display: block; font-size: 0.9rem; margin-bottom: 2px; }
.album-list span { color: var(--muted); font-size: 0.78rem; }

/* ---- Detail pane ---- */
.detail {
  padding: 20px 24px 40px;
  overflow-y: auto;
  max-height: calc(100dvh - 57px);
}

.detail-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.detail-head h2 { margin: 0 0 4px; font-family: Georgia, serif; font-size: 1.3rem; }
.detail-head-right { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }

/* QR panel */
.qr-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  padding: 20px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 16px;
}

.qr-url { font-size: 0.85rem; color: var(--muted); }

#qrCanvas {
  border: 1px solid var(--line);
  border-radius: 8px;
  width: 200px;
  height: 200px;
}

/* ---- Tab nav ---- */
.tab-nav {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 20px;
}

.tab-btn {
  background: transparent;
  border: 0;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--muted);
  transition: color 0.15s;
  margin-bottom: -1px;
}

.tab-btn.is-on {
  color: var(--ink);
  border-bottom-color: var(--accent);
}

.tab-btn:hover:not(.is-on) { color: var(--ink); }

.tab-pane { display: none; }
.tab-pane.is-on { display: block; }

/* ---- Settings form ---- */
.settings label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.875rem;
  font-weight: 500;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 14px;
}

.form-row-full {
  grid-template-columns: 1fr;
}

.settings textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--ink);
  font: inherit;
  font-size: 0.9rem;
  padding: 8px 10px;
  resize: vertical;
  min-height: 56px;
}

@media (max-width: 600px) {
  .form-row { grid-template-columns: 1fr; }
}

.settings fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  margin: 0 0 14px;
  padding: 12px 14px;
}

.settings fieldset legend {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 4px;
}

.check {
  display: flex !important;
  flex-direction: row !important;
  align-items: center;
  gap: 8px;
  font-weight: 400 !important;
  cursor: pointer;
}

.check input { width: auto; min-height: auto; margin: 0; }

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
  padding-top: 6px;
}

/* Watch info */
.watch-info {
  background: var(--warn-bg);
  border: 1px solid rgba(146, 64, 14, 0.2);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 0.85rem;
  color: var(--warn);
  margin-top: 14px;
}

/* ---- Media toolbar ---- */
.media-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.media-toolbar-left, .media-toolbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.select-all-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  font-weight: 500;
  cursor: pointer;
}

/* ---- Media grid ---- */
.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.media-card {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--bg);
  cursor: pointer;
  transition: box-shadow 0.15s;
}

.media-card:hover { box-shadow: 0 4px 20px rgba(0,0,0,0.15); }

.media-card.is-selected::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  pointer-events: none;
}

.media-card img, .media-card video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.media-card .card-check {
  position: absolute;
  top: 6px;
  left: 6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(255,255,255,0.9);
  border: 2px solid rgba(0,0,0,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  z-index: 2;
}

.media-card.is-selected .card-check {
  background: var(--accent);
  border-color: var(--accent);
}

.media-card.is-selected .card-check::after {
  content: "✓";
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}

.media-card .card-meta {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 20px 8px 8px;
  background: linear-gradient(transparent, rgba(0,0,0,0.65));
  color: #fff;
  font-size: 0.72rem;
  line-height: 1.3;
  opacity: 0;
  transition: opacity 0.15s;
}

.media-card:hover .card-meta { opacity: 1; }

.media-card .card-actions {
  position: absolute;
  top: 6px;
  right: 6px;
  display: flex;
  gap: 4px;
}

.media-card .card-btn {
  min-height: unset;
  width: 28px;
  height: 28px;
  padding: 0;
  border-radius: 7px;
  border: 0;
  background: rgba(255,255,255,0.2);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.8rem;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
}

.media-card:hover .card-btn { opacity: 1; }
.media-card .card-btn:hover { background: rgba(255,255,255,0.35); }
.media-card .card-btn.is-delete { background: rgba(200, 30, 30, 0.6); }

.media-card .card-type-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  background: rgba(0,0,0,0.45);
  color: #fff;
  font-size: 0.65rem;
  padding: 2px 5px;
  border-radius: 5px;
  font-weight: 500;
  pointer-events: none;
}

/* ---- Stats chart ---- */
.stats-head { margin-bottom: 12px; }
.stats-head h3 { margin: 0; font-size: 1rem; }

.chart-wrap {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stats-chart { width: 100%; height: auto; display: block; }

/* ---- Danger zone ---- */
.danger-zone {
  background: var(--danger-bg);
  border: 1px solid rgba(155, 28, 28, 0.2);
  border-radius: var(--radius);
  padding: 20px;
}

.danger-title { margin: 0 0 8px; color: var(--danger); }

.danger-actions { margin-top: 16px; display: flex; flex-direction: column; gap: 12px; }

.danger-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.danger-item .muted.sm { font-size: 0.8rem; margin: 2px 0 0; }
.sm { font-size: 0.8rem; }

/* ---- Create pane ---- */
#createPane .settings label {
  margin-bottom: 14px;
}

/* ---- Fullscreen viewer ---- */
.admin-viewer {
  margin: auto;
  max-width: 90vw;
  max-height: 90vh;
  border: 0;
  border-radius: 18px;
  background: #1a1a1a;
  color: #fff;
  padding: 0;
  box-shadow: 0 25px 80px rgba(0,0,0,0.6);
}

.admin-viewer::backdrop {
  background: rgba(0,0,0,0.75);
  backdrop-filter: blur(4px);
}

.viewer-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}

.viewer-meta { font-size: 0.8rem; color: rgba(255,255,255,0.7); }

.viewer-close {
  background: transparent;
  border: 0;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  min-height: auto;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  line-height: 1;
  opacity: 0.8;
}

.viewer-close:hover { opacity: 1; background: rgba(255,255,255,0.1); }

.viewer-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 50vw;
  min-height: 40vh;
  max-height: calc(90vh - 60px);
  position: relative;
}

.viewer-stage img, .viewer-stage video {
  max-width: 90vw;
  max-height: calc(90vh - 70px);
  object-fit: contain;
  display: block;
}

.viewer-loader {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.loader-ring {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ---- Toast ---- */
.toast-container {
  position: fixed;
  bottom: max(20px, env(safe-area-inset-bottom));
  right: max(16px, env(safe-area-inset-right));
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  width: min(360px, calc(100vw - 32px));
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.12);
  pointer-events: auto;
  animation: toast-in 0.2s ease;
  font-size: 0.875rem;
  line-height: 1.4;
  position: relative;
}

.toast.is-success { border-left: 3px solid var(--ok); }
.toast.is-error { border-left: 3px solid var(--danger); }
.toast.is-warn { border-left: 3px solid #f59e0b; }
.toast.is-info { border-left: 3px solid #3b82f6; }

.toast-icon { font-size: 1rem; flex-shrink: 0; line-height: 1.4; }
.toast-msg { flex: 1; }
.toast-close {
  background: none;
  border: 0;
  color: var(--muted);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0;
  min-height: auto;
  line-height: 1;
  flex-shrink: 0;
}

.toast-close:hover { color: var(--ink); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px) scale(0.96); }
  to { opacity: 1; transform: none; }
}

.toast.is-leaving {
  animation: toast-out 0.18s ease forwards;
}

@keyframes toast-out {
  to { opacity: 0; transform: translateY(6px) scale(0.97); height: 0; padding: 0; margin: 0; overflow: hidden; }
}

/* ---- Misc ---- */
.error, .msg.is-error { color: var(--danger); font-size: 0.85rem; margin-top: 8px; }
.msg.is-ok { color: var(--ok); font-size: 0.85rem; margin-top: 8px; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 20px 0; }

.note {
  font-size: 0.8rem;
  color: var(--muted);
  margin: 0;
}
