:root {
  color-scheme: dark;
  --black: #050505;
  --panel: #101010;
  --panel-2: #171717;
  --line: rgba(255, 255, 255, 0.14);
  --line-strong: rgba(255, 255, 255, 0.28);
  --white: #f7f7f7;
  --muted: rgba(255, 255, 255, 0.62);
  --danger: #ff4d57;
  --header-height: 74px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--black);
  color: var(--white);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.035), transparent 210px),
    var(--black);
  color: var(--white);
}

button, input, select { font: inherit; letter-spacing: 0; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }

:focus-visible {
  outline: 2px solid var(--white);
  outline-offset: 2px;
}

h1, h2, p { margin: 0; }
h1 { font-size: clamp(1.25rem, 2vw, 1.65rem); line-height: 1.1; }
h2 { font-size: 1.25rem; }

.muted { color: var(--muted); }
.eyebrow {
  color: var(--muted);
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .14em;
}

.brand-mark {
  display: inline-block;
  width: 12px;
  height: 36px;
  border-radius: 2px;
  background: linear-gradient(180deg, #fff 0 48%, #777 48% 57%, #222 57%);
}

.button, .selection-actions button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 15px;
  color: var(--white);
  text-decoration: none;
  white-space: nowrap;
  transition: background-color .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}

.button:active, .selection-actions button:active { transform: scale(.98); }
.button-primary { background: var(--white); color: var(--black); font-weight: 700; }
.button-primary:hover { background: #d8d8d8; }
.button-secondary { background: rgba(255,255,255,.07); border-color: var(--line); }
.button-secondary:hover { background: rgba(255,255,255,.12); border-color: var(--line-strong); }
.button-quiet { background: transparent; border-color: var(--line); align-self: end; }
.button-danger { background: var(--danger); color: #fff; font-weight: 700; }

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255,255,255,.06);
  color: var(--white);
  font-size: 1.35rem;
  line-height: 1;
}

.app-header {
  position: sticky;
  z-index: 20;
  top: 0;
  display: flex;
  min-height: var(--header-height);
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 12px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: rgba(5,5,5,.88);
  backdrop-filter: blur(18px);
}

.header-title, .header-actions, .header-actions form {
  display: flex;
  align-items: center;
  gap: 12px;
}

.workspace { padding-bottom: 110px; }

.filter-band {
  display: grid;
  gap: 14px;
  padding: 18px clamp(16px, 3vw, 36px);
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255,255,255,.035), rgba(255,255,255,.012));
}

.status-tabs {
  display: inline-grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  justify-self: start;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.status-tab {
  min-width: 95px;
  height: 38px;
  border: 0;
  border-right: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}
.status-tab:last-child { border-right: 0; }
.status-tab.active { background: var(--white); color: var(--black); font-weight: 700; }

.filter-grid {
  display: grid;
  grid-template-columns: minmax(160px, 1.3fr) minmax(160px, 1.1fr) repeat(2, minmax(135px, .8fr)) minmax(140px, .8fr) auto;
  gap: 10px;
  align-items: end;
}

.filter-grid label, .auth-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: .76rem;
  font-weight: 650;
}

input, select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 11px;
  background: #121212;
  color: var(--white);
}
input:hover, select:hover { border-color: var(--line-strong); }

.gallery-section { padding: 18px clamp(16px, 3vw, 36px) 30px; }
.gallery-heading { display: flex; min-height: 28px; align-items: center; justify-content: space-between; }

.loading-line {
  width: 88px;
  height: 2px;
  overflow: hidden;
  background: rgba(255,255,255,.15);
}
.loading-line::after {
  display: block;
  width: 45%;
  height: 100%;
  content: "";
  background: var(--white);
  animation: loading 1s ease-in-out infinite alternate;
}
@keyframes loading { from { transform: translateX(0); } to { transform: translateX(122%); } }

.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 10px;
  margin-top: 12px;
}

.photo-card {
  position: relative;
  min-width: 0;
  overflow: hidden;
  aspect-ratio: 4 / 3;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #151515;
  cursor: pointer;
  animation: card-in .22s ease both;
}
@keyframes card-in { from { opacity: 0; transform: translateY(5px); } }
.photo-card:hover { border-color: var(--line-strong); }
.photo-card.selected { border: 2px solid var(--white); }

.photo-card > img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: transform .24s ease, opacity .2s ease;
}
.photo-card:hover > img { transform: scale(1.018); }
.photo-card.selected > img { opacity: .62; }

.photo-check {
  position: absolute;
  z-index: 3;
  top: 8px;
  right: 8px;
  width: 24px;
  height: 24px;
  min-height: 0;
  margin: 0;
  accent-color: #fff;
}

.photo-status {
  position: absolute;
  z-index: 2;
  top: 9px;
  left: 9px;
  border: 1px solid rgba(255,255,255,.22);
  border-radius: 5px;
  padding: 4px 7px;
  background: rgba(0,0,0,.72);
  color: #fff;
  font-size: .65rem;
  font-weight: 800;
  text-transform: uppercase;
}
.photo-status.added { background: rgba(247,247,247,.9); color: #090909; }

.photo-caption {
  position: absolute;
  z-index: 2;
  right: 0;
  bottom: 0;
  left: 0;
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 32px 10px 10px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.88));
}
.photo-caption strong, .photo-caption span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.photo-caption strong { font-size: .82rem; }
.photo-caption span { color: rgba(255,255,255,.72); font-size: .7rem; }
.category-line { display: flex; align-items: center; gap: 7px; min-width: 0; }
.category-swatch { flex: 0 0 auto; width: 5px; height: 15px; border-radius: 2px; }

.empty-state {
  display: grid;
  min-height: 280px;
  place-content: center;
  gap: 7px;
  margin-top: 12px;
  border: 1px dashed var(--line);
  color: var(--muted);
  text-align: center;
}
.empty-state strong { color: var(--white); }
.load-more { display: flex; margin: 22px auto 0; }

.selection-bar {
  position: fixed;
  z-index: 30;
  right: 18px;
  bottom: 18px;
  left: 18px;
  display: flex;
  max-width: 920px;
  min-height: 64px;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin: auto;
  padding: 10px 12px 10px 18px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: rgba(17,17,17,.94);
  box-shadow: 0 20px 60px rgba(0,0,0,.45);
  backdrop-filter: blur(18px);
}
.selection-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }
.selection-actions button { min-height: 38px; background: rgba(255,255,255,.08); border-color: var(--line); }
.selection-actions button.danger { color: #ff747b; }

dialog {
  color: var(--white);
  border: 1px solid var(--line-strong);
  background: var(--panel);
}
dialog::backdrop { background: rgba(0,0,0,.78); backdrop-filter: blur(6px); }

.viewer-dialog {
  width: 100vw;
  max-width: none;
  height: 100dvh;
  max-height: none;
  margin: 0;
  padding: 0;
  border: 0;
  background: #000;
}
.viewer-stage { position: relative; width: 100%; height: 100%; overflow: hidden; }
.viewer-stage > img { width: 100%; height: 100%; object-fit: contain; user-select: none; }
.viewer-close, .viewer-arrow {
  position: absolute;
  z-index: 2;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(0,0,0,.58);
  color: #fff;
}
.viewer-close { top: 16px; left: 16px; width: 44px; height: 44px; font-size: 1.7rem; }
.viewer-arrow { top: 50%; width: 48px; height: 48px; font-size: 2.2rem; transform: translateY(-50%); }
.viewer-previous { left: 16px; }
.viewer-next { right: 16px; }
.viewer-footer {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  display: flex;
  min-width: 0;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  padding: 54px 20px 18px;
  background: linear-gradient(180deg, transparent, rgba(0,0,0,.9));
}
.viewer-footer > div:first-child { display: grid; gap: 5px; min-width: 0; }
.viewer-footer strong, .viewer-footer span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-footer span { color: rgba(255,255,255,.7); font-size: .78rem; }
.viewer-footer-actions { display: flex; align-items: center; gap: 12px; }

.panel-dialog {
  width: min(760px, calc(100vw - 28px));
  max-height: min(760px, calc(100dvh - 28px));
  overflow: auto;
  border-radius: 8px;
  padding: 0;
}
.dialog-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
  background: rgba(16,16,16,.94);
  backdrop-filter: blur(12px);
}
.pairing-panel {
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}
.pairing-panel p { margin-top: 4px; font-size: .78rem; }
.pairing-code {
  grid-column: 1 / -1;
  padding: 14px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: #050505;
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: clamp(1.4rem, 4vw, 2rem);
  font-weight: 800;
  text-align: center;
  letter-spacing: .16em;
}
.devices-list { display: grid; }
.device-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--line);
}
.device-main { display: grid; gap: 7px; min-width: 0; }
.device-name-row { display: flex; gap: 8px; }
.device-name-row input { min-width: 0; }
.device-meta { color: var(--muted); font-size: .75rem; }
.device-actions { display: flex; align-items: center; gap: 7px; }
.device-revoked { color: #ff747b; font-weight: 700; }

.confirm-dialog {
  width: min(430px, calc(100vw - 28px));
  border-radius: 8px;
  padding: 22px;
}
.confirm-dialog p { margin: 9px 0 20px; color: var(--muted); }
.confirm-actions { display: flex; justify-content: flex-end; gap: 8px; }

.toast {
  position: fixed;
  z-index: 100;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 12px 15px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--white);
  color: var(--black);
  box-shadow: 0 12px 35px rgba(0,0,0,.45);
  font-weight: 650;
}

.auth-page { background: radial-gradient(circle at 50% 0, #222, #050505 42%); }
.auth-shell { display: grid; min-height: 100dvh; place-items: center; padding: 18px; }
.auth-panel {
  width: min(400px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(13,13,13,.9);
  box-shadow: 0 30px 90px rgba(0,0,0,.45);
}
.auth-panel .brand-mark { margin-bottom: 18px; }
.auth-panel h1 { margin: 7px 0 8px; font-size: 1.65rem; }
.auth-form { display: grid; gap: 12px; margin-top: 22px; }
.auth-form .button { margin-top: 5px; }
.form-error { margin-top: 14px; color: #ff747b; font-size: .82rem; }

[hidden] { display: none !important; }

@media (max-width: 980px) {
  .filter-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .photo-grid { grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); }
}

@media (max-width: 680px) {
  :root { --header-height: 66px; }
  .app-header { padding: 10px 14px; }
  .header-actions .button { width: 40px; padding: 0; overflow: hidden; color: transparent; }
  .header-actions .button::after { content: "⚙"; color: var(--white); font-size: 1.05rem; }
  .filter-band, .gallery-section { padding-right: 12px; padding-left: 12px; }
  .status-tabs { width: 100%; }
  .status-tab { min-width: 0; }
  .filter-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-grid label:first-child, .filter-grid label:nth-child(2) { grid-column: span 2; }
  .photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .photo-caption { padding: 25px 8px 8px; }
  .photo-caption strong { font-size: .74rem; }
  .selection-bar { right: 8px; bottom: 8px; left: 8px; display: grid; gap: 8px; padding: 10px; }
  .selection-actions { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .selection-actions .icon-button { position: absolute; top: 7px; right: 7px; width: 34px; height: 34px; }
  .viewer-arrow { display: none; }
  .viewer-footer { align-items: stretch; padding: 48px 12px 12px; }
  .viewer-footer-actions { flex-direction: column; align-items: flex-end; }
  .device-row { grid-template-columns: 1fr; }
  .device-actions { justify-content: flex-end; }
}
