:root {
  color-scheme: light;

  --bg-0: #f5f5f7;
  --bg-1: #ffffff;
  --bg-2: #ebebef;

  --glass-bg: rgba(255, 255, 255, 0.72);
  --glass-bg-strong: rgba(255, 255, 255, 0.9);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-shadow: 0 2px 10px rgba(0, 0, 0, 0.05), 0 1px 0 rgba(255, 255, 255, 0.6) inset;

  --text-0: #1d1d1f;
  --text-1: #55555a;
  --text-2: #86868b;

  --accent: #0071e3;
  --accent-strong: #0077ed;
  --accent-press: #005fc1;
  --accent-glow: rgba(0, 113, 227, 0.18);
  --accent-tint: rgba(0, 113, 227, 0.1);

  --danger: #ff3b30;
  --danger-glow: rgba(255, 59, 48, 0.16);

  --radius-lg: 18px;
  --radius-md: 13px;
  --radius-sm: 9px;

  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", "Inter", ui-sans-serif, system-ui, sans-serif;

  --sidebar-w: 250px;
}

:root[data-theme="dark"] {
  color-scheme: dark;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;

    --bg-0: #000000;
    --bg-1: #1c1c1e;
    --bg-2: #2c2c2e;

    --glass-bg: rgba(28, 28, 30, 0.72);
    --glass-bg-strong: rgba(44, 44, 46, 0.9);
    --glass-border: rgba(255, 255, 255, 0.09);
    --glass-shadow: 0 2px 10px rgba(0, 0, 0, 0.4), 0 1px 0 rgba(255, 255, 255, 0.03) inset;

    --text-0: #f5f5f7;
    --text-1: #c7c7cc;
    --text-2: #8e8e93;

    --accent: #0a84ff;
    --accent-strong: #3b9dff;
    --accent-press: #409cff;
    --accent-glow: rgba(10, 132, 255, 0.28);
    --accent-tint: rgba(10, 132, 255, 0.16);

    --danger: #ff453a;
    --danger-glow: rgba(255, 69, 58, 0.2);
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text-0);
  background: var(--bg-0);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.view[hidden] {
  display: none !important;
}

.glass {
  background: var(--glass-bg);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--glass-shadow);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
}

button {
  font-family: inherit;
}

input {
  font-family: inherit;
}

a {
  color: inherit;
}

/* ---------- Brand ---------- */

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 650;
  font-size: 1.05rem;
  letter-spacing: -0.015em;
  color: var(--text-0);
}

.brand svg {
  width: 26px;
  height: 26px;
  color: var(--accent);
}

/* ---------- Login / Setup ---------- */

#view-login,
#view-setup {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 900px 560px at 15% -8%, var(--accent-tint), transparent 60%),
    radial-gradient(ellipse 700px 500px at 105% 8%, var(--accent-tint), transparent 55%),
    var(--bg-0);
}

.login-card {
  width: 100%;
  max-width: 400px;
  padding: 40px 36px;
  text-align: center;
}

.login-card.wide {
  max-width: 440px;
}

.login-card .brand {
  justify-content: center;
  margin-bottom: 28px;
  font-size: 1.4rem;
}

.login-card .brand svg {
  width: 36px;
  height: 36px;
}

.login-card .lede {
  color: var(--text-1);
  font-size: 0.88rem;
  line-height: 1.5;
  margin: -16px 0 24px;
}

.field {
  text-align: left;
  margin-bottom: 16px;
}

.field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-1);
  margin-bottom: 6px;
}

.field input {
  width: 100%;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--bg-1);
  color: var(--text-0);
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.field input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.field-hint {
  font-size: 0.76rem;
  color: var(--text-2);
  margin-top: 6px;
  line-height: 1.5;
}

.password-field {
  position: relative;
}

.password-field input {
  padding-right: 40px;
}

.password-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
}

.password-toggle:hover {
  color: var(--text-0);
  background: var(--bg-2);
}

.password-toggle svg {
  width: 17px;
  height: 17px;
}

.field-hint svg {
  width: 12px;
  height: 12px;
  vertical-align: -1px;
  margin-right: 2px;
}

.field-hint code {
  background: var(--bg-2);
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.72rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--bg-1);
  color: var(--text-0);
  font-size: 0.9rem;
  font-weight: 550;
  cursor: pointer;
  transition: transform 0.1s, border-color 0.15s, background 0.15s, color 0.15s;
}

.btn:hover {
  border-color: rgba(0, 0, 0, 0.16);
  background: var(--bg-2);
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: default;
  pointer-events: none;
}

.btn-primary {
  width: 100%;
  background: var(--accent);
  border-color: transparent;
  color: #ffffff;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn-primary:hover {
  background: var(--accent-strong);
}

.btn-primary:active {
  background: var(--accent-press);
}

.btn-secondary {
  background: var(--accent-tint);
  border-color: transparent;
  color: var(--accent);
}

.btn-secondary:hover {
  background: var(--accent-glow);
}

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

.btn-icon {
  padding: 8px;
  width: 36px;
  height: 36px;
  flex: none;
}

.btn-icon.active {
  background: var(--accent-tint);
  border-color: transparent;
  color: var(--accent);
}

.error-text {
  color: var(--danger);
  font-size: 0.85rem;
  margin: -4px 0 16px;
  min-height: 1.1em;
}

.hint-text {
  color: var(--text-2);
  font-size: 0.8rem;
  margin-top: 18px;
}

.success-badge {
  width: 56px;
  height: 56px;
  margin: 0 auto 18px;
  color: var(--accent);
}

.success-badge svg {
  width: 100%;
  height: 100%;
}

/* ---------- App shell (sidebar layout) ---------- */

#view-dashboard {
  min-height: 100vh;
  display: flex;
}

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  height: 100vh;
  position: sticky;
  top: 0;
  padding: 18px 12px;
  background: var(--glass-bg);
  border-right: 1px solid var(--glass-border);
  backdrop-filter: blur(28px) saturate(180%);
  -webkit-backdrop-filter: blur(28px) saturate(180%);
}

.sidebar-brand {
  padding: 6px 10px 18px;
}

.sidebar-nav {
  flex: 1;
  overflow-y: auto;
}

.nav-section-label {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-2);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text-0);
  font-size: 0.88rem;
  text-align: left;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex: none;
  color: var(--text-1);
  transition: color 0.15s;
}

.nav-item:hover {
  background: rgba(0, 0, 0, 0.045);
}

.nav-item.active {
  background: var(--accent);
  color: #ffffff;
}

.nav-item.active svg {
  color: #ffffff;
}

.nav-item .badge {
  margin-left: auto;
  font-size: 0.72rem;
  color: var(--text-2);
}

.nav-item.active .badge {
  color: rgba(255, 255, 255, 0.8);
}

.sidebar-footer {
  border-top: 1px solid var(--glass-border);
  padding-top: 10px;
  margin-top: 6px;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 6px 4px;
}

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  font-weight: 650;
  flex: none;
  text-transform: uppercase;
}

.sidebar-user-info {
  flex: 1;
  min-width: 0;
}

.sidebar-user-name {
  font-size: 0.84rem;
  font-weight: 550;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.role-badge {
  font-size: 0.68rem;
  color: var(--text-2);
}

.role-badge.admin {
  color: var(--accent);
}

.row-name .role-badge {
  margin-left: 7px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--bg-2);
  font-weight: 550;
}

.row-name .role-badge.admin {
  background: var(--accent-tint);
}

/* ---------- Content ---------- */

.content {
  flex: 1;
  min-width: 0;
  padding: 24px 32px 60px;
}

.content-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.content-toolbar h1 {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0;
}

.content-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filters {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
  width: fit-content;
}

.filter-btn {
  padding: 7px 15px;
  border-radius: 999px;
  border: 1px solid var(--glass-border);
  background: var(--bg-1);
  color: var(--text-1);
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.filter-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: transparent;
}

.filter-btn:hover:not(.active) {
  border-color: rgba(0, 0, 0, 0.18);
  color: var(--text-0);
}

/* ---------- Grid ---------- */

.dropzone {
  position: relative;
  min-height: 40vh;
  border-radius: var(--radius-lg);
}

.dropzone.drag-active::after {
  content: "Drop to upload";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px dashed var(--accent);
  border-radius: var(--radius-lg);
  background: var(--accent-tint);
  color: var(--accent);
  font-size: 1.1rem;
  font-weight: 600;
  z-index: 5;
  pointer-events: none;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 14px;
}

.empty-state {
  text-align: center;
  color: var(--text-2);
  padding: 80px 20px;
  font-size: 0.95rem;
}

.file-card {
  position: relative;
  border-radius: var(--radius-md);
  overflow: hidden;
  cursor: default;
  background: var(--bg-1);
  border: 1px solid var(--glass-border);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
  transition: transform 0.15s, box-shadow 0.15s;
}

.file-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.1);
}

.file-thumb {
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-2);
  overflow: hidden;
}

.file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.file-thumb svg {
  width: 44%;
  height: 44%;
  opacity: 0.75;
  color: var(--text-2);
}

.file-meta {
  padding: 10px 12px 12px;
}

.file-name {
  font-size: 0.82rem;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-sub {
  font-size: 0.72rem;
  color: var(--text-2);
  margin-top: 2px;
}

.file-actions {
  position: absolute;
  top: 8px;
  right: 8px;
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity 0.15s;
}

.file-card:hover .file-actions {
  opacity: 1;
}

.file-actions .btn {
  width: 30px;
  height: 30px;
  padding: 0;
  background: rgba(255, 255, 255, 0.9);
  border-color: transparent;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.file-actions .btn:hover {
  background: #fff;
}

.file-actions svg {
  width: 15px;
  height: 15px;
}

/* ---------- Upload progress ---------- */

.upload-toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: max-content;
  max-width: min(360px, calc(100vw - 48px));
  padding: 16px 18px;
  z-index: 30;
}

.upload-toast-name {
  font-size: 0.8rem;
  color: var(--text-1);
  margin-bottom: 10px;
  line-height: 1.4;
}

/* The upload-progress toast specifically wants a single truncated line
   for the filename - a plain info/error toast (no progress bar) should
   wrap in full instead, since truncating something like a validation
   message defeats the point of showing it. */
.upload-toast:has(.progress-track) .upload-toast-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 10px;
}

.upload-toast:not(:has(.progress-track)) .upload-toast-name {
  margin-bottom: 0;
}

.progress-track {
  height: 6px;
  border-radius: 4px;
  background: var(--bg-2);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.15s;
}

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}

.modal {
  width: 100%;
  max-width: 380px;
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  padding: 28px;
  text-align: center;
}

.modal-wide {
  max-width: 520px;
  text-align: left;
}

.modal h2 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0 0 8px;
}

.modal p {
  color: var(--text-1);
  font-size: 0.85rem;
  line-height: 1.5;
}

.pairing-code {
  font-size: 2.2rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin: 18px 0 8px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 22px;
}

.modal-actions .btn {
  flex: 1;
}

.modal-tabs {
  display: flex;
  gap: 4px;
  margin: -4px 0 20px;
  padding: 4px;
  background: var(--bg-2);
  border-radius: var(--radius-sm);
  width: fit-content;
}

.modal-tab {
  padding: 7px 16px;
  border: none;
  background: transparent;
  border-radius: 7px;
  color: var(--text-1);
  font-size: 0.83rem;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.modal-tab.active {
  background: var(--bg-1);
  color: var(--text-0);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

/* ---------- Rows (users / shares) ---------- */

.row-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 12px 0;
  max-height: 280px;
  overflow-y: auto;
}

.user-row,
.share-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  background: var(--bg-1);
}

.user-row .avatar,
.share-row .avatar {
  width: 28px;
  height: 28px;
  font-size: 0.72rem;
}

.row-name {
  flex: 1;
  min-width: 0;
  font-size: 0.85rem;
  color: var(--text-0);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-sub {
  font-size: 0.72rem;
  color: var(--text-2);
}

.inline-form {
  display: flex;
  gap: 8px;
  margin-top: 4px;
}

.inline-form input {
  flex: 1;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--glass-border);
  background: var(--bg-1);
  color: var(--text-0);
  font-size: 0.88rem;
  outline: none;
}

.inline-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-glow);
}

.settings-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 2px;
}

.settings-row-label {
  font-size: 0.88rem;
  font-weight: 550;
  color: var(--text-0);
}

.settings-row-hint {
  font-size: 0.78rem;
  color: var(--text-2);
  margin-top: 2px;
}

.switch {
  position: relative;
  width: 46px;
  height: 27px;
  flex: none;
  border-radius: 999px;
  border: none;
  background: var(--bg-2);
  cursor: pointer;
  transition: background 0.2s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 2px;
  left: 2px;
  width: 23px;
  height: 23px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
}

.switch.on {
  background: var(--accent);
}

.switch.on::after {
  transform: translateX(19px);
}

/* ---------- Lightbox ---------- */

.file-thumb[data-open-lightbox] {
  cursor: pointer;
}

.lightbox-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.92);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.lightbox-close,
.lightbox-nav {
  border: none;
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  transition: background 0.15s;
}

.lightbox-close:hover,
.lightbox-nav:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-close {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  height: 40px;
}

.lightbox-close svg {
  width: 18px;
  height: 18px;
}

.lightbox-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 48px;
  height: 48px;
}

.lightbox-nav svg {
  width: 22px;
  height: 22px;
}

.lightbox-prev {
  left: 20px;
}

.lightbox-next {
  right: 20px;
}

.lightbox-stage {
  max-width: 90vw;
  max-height: 78vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.lightbox-stage img {
  max-width: 90vw;
  max-height: 78vh;
  object-fit: contain;
  border-radius: 8px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.lightbox-footer {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.65), transparent);
}

.lightbox-name {
  color: #fff;
  font-size: 0.88rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-actions {
  display: flex;
  gap: 8px;
  flex: none;
}

.lightbox-actions .btn {
  background: rgba(255, 255, 255, 0.12);
  border-color: transparent;
  color: #fff;
}

.lightbox-actions .btn:hover {
  background: rgba(255, 255, 255, 0.22);
}

.lightbox-actions .btn-danger:hover {
  color: var(--danger);
}

@media (max-width: 640px) {
  .lightbox-nav {
    width: 38px;
    height: 38px;
  }
  .lightbox-nav svg {
    width: 18px;
    height: 18px;
  }
  .lightbox-prev {
    left: 8px;
  }
  .lightbox-next {
    right: 8px;
  }
}

@media (max-width: 860px) {
  #view-dashboard {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    padding: 10px 14px;
  }
  .sidebar-brand {
    padding: 0 14px 0 0;
  }
  .sidebar-nav {
    display: flex;
    flex: none;
    overflow: visible;
  }
  .nav-section-label {
    display: none;
  }
  .nav-item {
    width: auto;
    white-space: nowrap;
  }
  .sidebar-footer {
    display: flex;
    align-items: center;
    border-top: none;
    border-left: 1px solid var(--glass-border);
    padding: 0 0 0 12px;
    margin: 0 0 0 8px;
  }
  .sidebar-user {
    padding: 0;
  }
  .content {
    padding: 18px 16px 60px;
  }
}
