:root {
  --bg: #F5F7FB;
  --surface: #FFFFFF;
  --surface-soft: #EEF2F8;
  --text: #0F172A;
  --muted: #526075;
  --border: #E2E8F0;
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-soft: #EFF6FF;
  --success: #16A34A;
  --success-soft: #DCFCE7;
  --warn: #B45309;
  --warn-soft: #FEF3C7;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --radius: 20px;
  --radius-sm: 14px;
  --shadow: 0 8px 28px rgba(15, 23, 42, 0.06);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  min-height: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 14px; }
.center-text { text-align: center; }
.center-box { display: flex; justify-content: center; margin: 24px 0; }

/* BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 14px;
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  padding: 12px 20px;
  cursor: pointer;
  text-decoration: none;
  transition: transform 0.12s ease, background 0.15s ease, box-shadow 0.15s ease;
  min-height: 46px;
}
.btn:active { transform: scale(0.98); }
.btn-lg { min-height: 50px; padding: 13px 22px; font-size: 17px; }
.btn-xl { width: 100%; min-height: 56px; font-size: 18px; border-radius: 16px; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 18px rgba(37, 99, 235, 0.25); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-soft); color: var(--text); }
.btn-secondary:hover { background: #E2E8F0; }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-soft); color: var(--text); }
.btn-danger-soft { background: var(--danger-soft); color: var(--danger); }
.btn-danger-soft:hover { background: #FECACA; }
.btn-icon {
  width: 44px; height: 44px;
  border-radius: 50%;
  border: none;
  background: var(--surface-soft);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.upload-label { user-select: none; }

/* INPUTS */
.text-input, .select-input {
  width: 100%;
  min-height: 50px;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
  outline: none;
}
.text-input:focus, .select-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12);
}
.field-label { display: block; font-weight: 600; font-size: 16px; margin-bottom: 10px; }

/* ALERTS */
.alert {
  margin-top: 14px;
  padding: 13px 16px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 500;
}
.alert-error { background: var(--danger-soft); color: #991B1B; }
.alert-warn { background: var(--warn-soft); color: var(--warn); margin-bottom: 16px; }

/* LOGIN SCREEN */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top right, #DBEAFE 0%, #F5F7FB 55%);
}
.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border-radius: 28px;
  padding: 36px 28px;
  box-shadow: 0 20px 60px rgba(15, 23, 42, 0.09);
  text-align: center;
}
.login-logo { margin-bottom: 12px; }
.login-card h1 { margin: 0 0 8px; font-size: 28px; letter-spacing: -0.02em; }
.login-sub { margin: 0 0 26px; color: var(--muted); font-size: 16px; }
.code-box, .invite-auto { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.code-input {
  width: 100%;
  text-align: center;
  font-size: 34px;
  font-weight: 700;
  letter-spacing: 0.16em;
  padding: 16px 12px;
  border: 2px solid var(--border);
  border-radius: 18px;
  outline: none;
  color: var(--text);
  background: #FAFBFD;
}
.code-input:focus { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 4px rgba(37, 99, 235, 0.12); }
.login-hint { margin: 6px 0 0; font-size: 14px; color: var(--muted); text-align: center; }
.invite-badge {
  align-self: center;
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 700;
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 15px;
}
.invite-auto-text { margin: 0; text-align: center; font-size: 16px; color: var(--text); }

/* TOPBAR & SHELL */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 19px; }
.top-nav { display: flex; gap: 6px; background: var(--surface-soft); padding: 5px; border-radius: 16px; }
.nav-btn {
  border: none;
  background: transparent;
  padding: 10px 18px;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}
.nav-btn.active { background: #fff; color: var(--primary); box-shadow: 0 2px 8px rgba(15, 23, 42, 0.08); }
.user-pill {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 15px;
  padding: 6px 14px 6px 6px;
  background: var(--surface-soft);
  border-radius: 999px;
}
.avatar-dot {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}
.avatar-lg {
  width: 58px; height: 58px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 24px;
  flex-shrink: 0;
}

/* MAIN */
.main-content {
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 20px 18px 96px;
  flex: 1;
}
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* UPLOAD PROGRESS */
.upload-banner {
  background: #fff;
  border: 1.5px solid #BFDBFE;
  border-radius: 18px;
  padding: 14px 18px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.upload-banner-top { display: flex; justify-content: space-between; font-weight: 600; margin-bottom: 8px; }
.progress-track { height: 10px; background: var(--surface-soft); border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--primary); transition: width 0.2s ease; border-radius: 999px; }

/* HERO STATUS */
.hero-status {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
  margin-bottom: 18px;
}
.status-line { display: flex; align-items: center; gap: 10px; font-size: 19px; font-weight: 700; }
.status-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.status-dot.offline { background: #EA580C; }
.hero-sub { color: var(--muted); margin-top: 4px; font-size: 15px; }

/* FILTERS */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 20px;
}
.pill-group { display: flex; flex-wrap: wrap; gap: 8px; }
.pill {
  border: 1.5px solid var(--border);
  background: #fff;
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  min-height: 42px;
}
.pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* PHOTO GRID */
.month-group { margin-bottom: 26px; }
.month-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 12px 4px;
  color: var(--text);
}
.photo-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.photo-tile {
  position: relative;
  aspect-ratio: 1 / 1;
  border-radius: 16px;
  overflow: hidden;
  background: #E2E8F0;
  cursor: pointer;
  border: none;
  padding: 0;
  transition: transform 0.14s ease;
}
.photo-tile:hover { transform: translateY(-2px); }
.photo-tile img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}
.video-tile {
  width: 100%;
  height: 100%;
  background: linear-gradient(135deg, #1E293B, #334155);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px;
  text-align: center;
}
.video-play {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}
.video-name {
  font-size: 13px;
  opacity: 0.9;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-badge {
  position: absolute;
  bottom: 8px;
  left: 8px;
  background: rgba(15, 23, 42, 0.72);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 8px;
}

.empty-state {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 46px 24px;
  text-align: center;
  box-shadow: var(--shadow);
}
.empty-ico { font-size: 48px; margin-bottom: 10px; }
.empty-state h3 { margin: 0 0 6px; font-size: 21px; }

/* FILES */
.quick-cards {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
  margin-bottom: 18px;
}
.quick-card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
  box-shadow: var(--shadow);
}
.quick-card:hover { border-color: var(--primary); }
.qc-icon { font-size: 28px; }
.qc-title { font-size: 17px; font-weight: 700; color: var(--text); }
.qc-sub { font-size: 14px; color: var(--muted); }

.files-toolbar {
  background: var(--surface);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}
.breadcrumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; font-size: 16px; }
.crumb-btn {
  border: none;
  background: var(--surface-soft);
  color: var(--text);
  font-weight: 600;
  font-size: 15px;
  padding: 7px 12px;
  border-radius: 10px;
  cursor: pointer;
}
.crumb-btn:hover { background: #DBEAFE; color: var(--primary); }
.files-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.files-list {
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.file-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.file-row:last-child { border-bottom: none; }
.file-row:hover { background: #F8FAFC; }
.file-ico {
  width: 44px; height: 44px;
  border-radius: 12px;
  background: var(--surface-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
}
.file-ico img { width: 100%; height: 100%; object-fit: cover; }
.file-info { flex: 1; min-width: 0; }
.file-name { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 14px; color: var(--muted); }
.file-row-actions { display: flex; gap: 8px; }

/* CLOUD / ADMIN */
.cloud-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 18px;
}
.card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}
.card h2 { margin: 0 0 10px; font-size: 21px; }
.card h3 { margin: 0 0 10px; font-size: 17px; }
.profile-row { display: flex; align-items: center; gap: 14px; margin-bottom: 20px; }
.profile-row h2 { margin: 0; }
.info-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 20px; }
.info-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  background: var(--bg);
  border-radius: 12px;
  font-size: 15px;
}
.card-actions { display: flex; flex-direction: column; gap: 10px; }
.invite-form { display: flex; flex-direction: column; gap: 10px; margin: 14px 0 20px; }
.sub-block { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

.device-row, .invite-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--bg);
  border-radius: 14px;
  margin-bottom: 10px;
}
.device-title { font-weight: 700; font-size: 16px; }
.device-sub { font-size: 13.5px; color: var(--muted); }
.revoked-tag {
  background: var(--danger-soft);
  color: var(--danger);
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

/* MODALS */
.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(15, 23, 42, 0.82);
  backdrop-filter: blur(6px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.modal-card {
  width: 100%;
  max-width: 440px;
  background: #fff;
  border-radius: 26px;
  padding: 24px;
}
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.modal-head h2 { margin: 0; font-size: 20px; }
.qr-svg-box {
  width: 240px;
  height: 240px;
  margin: 16px auto;
  padding: 12px;
  border-radius: 20px;
  background: #fff;
  border: 2px solid var(--border);
}
.qr-svg-box svg { width: 100%; height: 100%; display: block; }
.qr-code-digits {
  text-align: center;
  font-size: 36px;
  font-weight: 800;
  letter-spacing: 0.14em;
  color: var(--primary);
  margin: 6px 0;
}
.modal-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }

/* LIGHTBOX */
.lightbox-inner {
  width: 100%;
  height: 100%;
  max-width: 1120px;
  display: flex;
  flex-direction: column;
  color: #fff;
}
.lightbox-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 6px 4px 12px;
}
.lb-title { font-size: 18px; font-weight: 700; word-break: break-word; }
.lb-sub { font-size: 14px; color: #CBD5E1; }
.lightbox-stage {
  flex: 1;
  min-height: 0;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-media {
  max-width: 100%;
  max-height: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lb-media img, .lb-media video {
  max-width: 100%;
  max-height: 72vh;
  border-radius: 14px;
  object-fit: contain;
  background: #000;
}
.lb-nav {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 32px;
  cursor: pointer;
}
.lb-nav:hover { background: rgba(255, 255, 255, 0.35); }
.lb-prev { left: 8px; }
.lb-next { right: 8px; }
.lightbox-bottom {
  display: flex;
  justify-content: center;
  gap: 12px;
  padding-top: 14px;
  flex-wrap: wrap;
}

/* BOTTOM NAV (MOBILE) */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 40;
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
  border-top: 1px solid var(--border);
  padding: 6px 10px calc(8px + env(safe-area-inset-bottom));
  justify-content: space-around;
}
.bnav-btn {
  border: none;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  padding: 6px 18px;
  border-radius: 14px;
  cursor: pointer;
}
.bnav-btn.active { color: var(--primary); background: var(--primary-soft); }
.bnav-ico { font-size: 22px; }

/* TOAST */
.toast {
  position: fixed;
  bottom: 84px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  background: #0F172A;
  color: #fff;
  padding: 13px 22px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 15px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
  max-width: 92vw;
  text-align: center;
}

@media (max-width: 760px) {
  .top-nav { display: none; }
  .bottom-nav { display: flex; }
  .quick-cards { grid-template-columns: 1fr; }
  .photo-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .photo-tile { border-radius: 10px; }
  .main-content { padding: 14px 12px 92px; }
  .hero-status { padding: 16px; }
  .brand-title { font-size: 17px; }
}
