@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

:root {
  --bg: #161616;
  --bg-elevated: #1e1e1e;
  --bg-card: #1a1a1a;
  --bg-input: #121212;
  --primary: rgb(29, 185, 84);
  --primary-hover: rgb(24, 160, 72);
  --primary-soft: rgba(29, 185, 84, 0.14);
  --accent: #612BD3;
  --accent-hover: #7340e6;
  --accent-soft: rgba(97, 43, 211, 0.16);
  --text: #f5f5f5;
  --text-muted: #a3a3a3;
  --text-subtle: #737373;
  --stroke: #2a2a2a;
  --stroke-strong: #3a3a3a;
  --danger: #e0685f;
  --danger-hover: #ef4444;
  --danger-soft: rgba(224, 104, 95, 0.12);
  --danger-border: rgba(224, 104, 95, 0.3);
  --warning: #f59e0b;
  --info: #3b82f6;
  --white: #ffffff;
  --black: #000000;
  --overlay: rgba(0, 0, 0, 0.72);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.55);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
  --font-sans: 'Inter', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --transition: 0.15s ease;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
img { max-width: 100%; display: block; }
a { color: var(--primary); text-decoration: none; transition: color var(--transition); }
a:hover { text-decoration: underline; }
pre { white-space: pre-wrap; word-break: break-word; font-family: var(--font-mono); font-size: 12px; line-height: 1.5; }

/* Header */
header {
  height: 72px;
  border-bottom: 1px solid var(--stroke);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 var(--space-5);
  background: var(--bg-elevated);
  position: sticky;
  top: 0;
  z-index: 10;
  backdrop-filter: blur(8px);
}
header strong { font-size: 24px; font-weight: 700; letter-spacing: -0.01em; line-height: 1.2; }
header small { display: block; color: var(--text-muted); margin-top: 2px; font-size: 12px; line-height: 1.4; }
#topActions { display: flex; align-items: center; gap: var(--space-2); }
#usage { font-family: var(--font-mono); font-size: 12px; color: var(--text-muted); letter-spacing: 0.02em; line-height: 1.4; }

/* Layout */
main {
  max-width: 1280px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4);
}
@media (max-width: 640px) {
  main { padding: var(--space-4) var(--space-3); }
  header { padding: 0 var(--space-4); }
}
.narrow { max-width: 460px; margin: 8vh auto; }
.panel {
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
}
.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

/* Tabs / nav (white-pill) */
.tabs, #nav {
  display: flex;
  gap: var(--space-3);
  flex-wrap: wrap;
  margin-bottom: var(--space-5);
}
#nav .nav-group {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
}
.tabs button, #nav button {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-pill);
  padding: 6px 14px;
  font-weight: 500;
  font-size: 14px;
  line-height: 1.25;
  transition: background var(--transition), color var(--transition), border-color var(--transition);
}
.tabs button:hover, #nav button:hover {
  color: var(--text);
  background: var(--bg-card);
  border-color: var(--stroke-strong);
}
.tabs button.active, #nav button.active {
  background: var(--white);
  color: var(--black);
  border-color: var(--white);
}
.tabs button.active:hover, #nav button.active:hover {
  background: var(--white);
  color: var(--black);
}

/* Buttons */
button, .upload {
  font-family: var(--font-sans);
  border: 1px solid var(--stroke);
  background: var(--primary);
  color: var(--black);
  border-radius: var(--radius-sm);
  padding: 8px 16px;
  font-weight: 600;
  font-size: 14px;
  line-height: 1.25;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), transform 0.1s ease, opacity var(--transition), box-shadow var(--transition);
}
button:hover, .upload:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
button:active, .upload:active { transform: translateY(1px); }
button:focus-visible, .upload:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}
button:disabled, .upload:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
.ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--stroke);
}
.ghost:hover { background: var(--bg-card); border-color: var(--stroke-strong); }
.ghost:active { transform: translateY(1px); }
.danger {
  background: var(--danger);
  color: var(--white);
  border-color: var(--danger);
}
.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }
.danger:active { transform: translateY(1px); }
.cta {
  background: var(--accent);
  color: var(--white);
  border-color: var(--accent);
}
.cta:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.cta:active { transform: translateY(1px); }
.upload { display: inline-flex; align-items: center; gap: var(--space-2); }
.upload input { display: none; }

/* Forms */
label {
  display: grid;
  gap: 6px;
  margin: 12px 0;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  line-height: 1.4;
}
input, select, textarea {
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.4;
  transition: border-color var(--transition), box-shadow var(--transition);
}
input::placeholder { color: var(--text-subtle); }
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  outline: none;
  box-shadow: 0 0 0 2px var(--primary-soft);
}
.muted, .status {
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.5;
}

/* Gallery (Ente-style, edge-to-edge) */
.gallery {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-1);
}
@media (min-width: 768px) {
  .gallery { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
  .gallery { grid-template-columns: repeat(4, 1fr); }
}
.month-header {
  grid-column: 1 / -1;
  position: sticky;
  top: 72px;
  z-index: 5;
  font-size: 18px;
  font-weight: 600;
  padding: var(--space-4) var(--space-1) var(--space-2);
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.3;
  background: var(--bg);
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
}
.month-header .month-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
}
.asset {
  background: var(--bg-card);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  overflow: hidden;
  transition: transform var(--transition), box-shadow var(--transition);
}
.asset:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.thumb {
  width: 100%;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  background: var(--bg);
  display: block;
}
.placeholder {
  display: grid;
  place-items: center;
  font-size: 32px;
  color: var(--text-muted);
  background: var(--bg);
}
.meta { padding: var(--space-3); background: var(--bg-card); }
.name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 600;
  font-size: 14px;
  color: var(--text);
  line-height: 1.3;
}
.sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
  line-height: 1.4;
}
.actions {
  display: flex;
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
  flex-wrap: wrap;
}
.actions button {
  background: var(--bg-elevated);
  color: var(--text);
  border: 1px solid var(--stroke);
  padding: 6px 10px;
  font-size: 12px;
  border-radius: var(--radius-sm);
  font-weight: 500;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}
.actions button:hover { background: var(--stroke); border-color: var(--stroke-strong); }
.actions button.danger { background: var(--danger); color: var(--white); border-color: var(--danger); }
.actions button.danger:hover { background: var(--danger-hover); border-color: var(--danger-hover); }

/* Upload rows */
.upload-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-radius: var(--radius-md);
  background: var(--bg-elevated);
  margin-bottom: var(--space-2);
  gap: var(--space-4);
  border: 1px solid var(--stroke);
  transition: border-color var(--transition), box-shadow var(--transition);
}
.upload-row > div:first-child { flex: 1; min-width: 0; }
.upload-info { flex: 1; min-width: 0; display: grid; gap: 4px; }
.upload-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.pill {
  border: 1px solid var(--stroke);
  border-radius: var(--radius-pill);
  padding: 4px 10px;
  font-size: 12px;
  background: var(--bg);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  line-height: 1.2;
}
.job-progress { width: 100%; height: 8px; border-radius: 4px; accent-color: var(--primary); }
.pct { font-size: 12px; color: var(--text-muted); line-height: 1.4; }
.retry-status { color: var(--warning); font-size: 12px; line-height: 1.4; }
#uploadQueue h3 { font-size: 14px; color: var(--text-muted); margin: 0 0 var(--space-2); letter-spacing: 0.02em; line-height: 1.3; }

/* Admin */
.admin-grid { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-4); }
@media (max-width: 768px) { .admin-grid { grid-template-columns: 1fr; } }
.user-row, .device-row, .album-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr auto;
  gap: var(--space-3);
  align-items: center;
  border-top: 1px solid var(--stroke);
  padding: var(--space-3) 0;
}
.album-row b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 640px) {
  .user-row, .device-row, .album-row { grid-template-columns: 1fr; }
}

/* Modal */
.modal-ov {
  position: fixed;
  inset: 0;
  background: var(--overlay);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 60;
  padding: var(--space-4);
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  max-width: 480px;
  width: 100%;
  display: grid;
  gap: var(--space-3);
  box-shadow: var(--shadow-lg);
}
.modal h3 { margin: 0 0 var(--space-1); font-size: 18px; font-weight: 600; line-height: 1.3; }
.modal h4 { margin: var(--space-3) 0 var(--space-2); font-size: 16px; font-weight: 600; line-height: 1.3; }
.modal label { color: var(--text); margin: 4px 0; }
.modal-actions {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-2);
}
.chip {
  display: inline-block;
  font-size: 12px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--bg);
  color: var(--text-muted);
  border: 1px solid var(--stroke);
  line-height: 1.3;
}
.chip.dim {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: var(--danger-border);
}

/* Empty / loading states */
.empty-state, .loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-7) var(--space-4);
  text-align: center;
  color: var(--text-muted);
}
.empty-state h3, .empty-state .empty-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text);
  margin: 0;
  line-height: 1.3;
}
.empty-state p { margin: 0; line-height: 1.5; }
.empty-icon { font-size: 48px; line-height: 1; }
.loading-state .loading-text { font-size: 14px; color: var(--text-muted); }
.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--stroke);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Toast */
#toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 420px;
  background: var(--bg-elevated);
  border: 1px solid var(--stroke);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: none;
  z-index: 50;
  box-shadow: var(--shadow-lg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.4;
}

/* Misc */
.view { overflow-y: auto; -webkit-overflow-scrolling: touch; }
main { overflow-y: auto; -webkit-overflow-scrolling: touch; }
body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.shared-badge {
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 9px;
  background: var(--accent);
  color: var(--white);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.2;
}
#apiEndpoint { font-family: var(--font-mono); letter-spacing: 0.02em; }
footer { text-align: center; padding: 12px; color: var(--text-muted); font-size: 13px; line-height: 1.4; }
footer a { color: var(--text-muted); }

/* Responsive tweaks */
@media (max-width: 640px) {
  button, .upload { min-height: 44px; }
}
@media (max-width: 480px) {
  .modal { padding: var(--space-4); }
}

/* Mobile-first helpers */
@media (max-width: 375px) {
  .gallery { grid-template-columns: 1fr; }
  main { padding: var(--space-3) var(--space-2); }
}
/* Admin dashboard additions */
.admin-overview { display: grid; grid-template-columns: repeat(auto-fit,minmax(180px,1fr)); gap: var(--space-3); margin-bottom: var(--space-4); }
.admin-card { background: var(--bg-card); border: 1px solid var(--stroke); border-radius: var(--radius-md); padding: var(--space-3); }
.admin-card h3 { margin: 0 0 var(--space-2); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.admin-card p { margin: 0; font-size: 13px; line-height: 1.4; }
.progress-bar { margin-top: var(--space-2); height: 6px; background: var(--stroke); border-radius: 999px; overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--primary); border-radius: 999px; }
.admin-table { display: grid; gap: 2px; }
.admin-row { display: grid; grid-template-columns: repeat(auto-fit,minmax(80px,1fr)); gap: var(--space-2); align-items: center; border-top: 1px solid var(--stroke); padding: var(--space-2) 0; font-size: 12px; }
.admin-row span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.admin-head { font-weight: 600; color: var(--text-muted); border-top: none; }
.admin-actions { display: flex; gap: var(--space-1); flex-wrap: wrap; grid-column: 1 / -1; }
.admin-details { grid-column: 1 / -1; color: var(--text-muted); font-size: 12px; padding: var(--space-2) 0; }
@media (max-width: 768px) { .admin-row { grid-template-columns: 1fr; } .admin-actions { grid-column: auto; } }
