:root {
  --bg: #0f0f1a;
  --bg2: #1a1a2e;
  --bg3: #25253d;
  --bg4: #2f2f4a;
  --text: #e8e8f0;
  --text2: #9999b3;
  --text-dim: #55556a;
  --accent: #6C5CE7;
  --accent2: #FF6B95;
  --danger: #FF4757;
  --ok: #2ed573;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

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

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

body {
  font-family: 'Nunito', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  overscroll-behavior: none;
}

a {
  color: inherit;
  text-decoration: none;
}

.safe-shell {
  min-height: 100dvh;
  padding-top: var(--safe-top);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
}

/* ── Auth pages ── */
.auth-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: max(24px, var(--safe-top)) 24px max(24px, var(--safe-bottom));
  background: linear-gradient(160deg, var(--bg) 0%, var(--bg2) 50%, #1e1e3a 100%);
}

.auth-logo { text-align: center; margin-bottom: 40px; }
.auth-icon { font-size: 64px; margin-bottom: 12px; }

.auth-logo h1 {
  font-size: 36px;
  font-weight: 800;
  background: linear-gradient(135deg, #6C5CE7, #FF6B95);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.auth-subtitle {
  color: var(--text2);
  font-size: 16px;
  margin-top: 4px;
}

.auth-form {
  width: 100%;
  max-width: 360px;
}

.field { margin-bottom: 14px; }

.field input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg3);
  border: 1px solid var(--bg4);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  outline: none;
  transition: border-color .2s;
}

.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--text-dim); }

.btn-primary {
  width: 100%;
  padding: 14px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #6C5CE7, #a855f7);
  color: #fff;
  font-family: inherit;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  transition: opacity .2s;
}

.btn-primary:active { opacity: .8; }

.auth-error {
  color: #ffd4da;
  background: rgba(255, 71, 87, .14);
  border: 1px solid rgba(255, 71, 87, .35);
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 14px;
  margin-bottom: 10px;
  min-height: 20px;
}

.auth-link {
  display: block;
  text-align: center;
  margin-top: 20px;
  color: var(--text2);
  text-decoration: none;
  font-size: 14px;
}

.auth-link:hover { color: var(--accent); }
.auth-link--install { margin-top: 12px; }

/* ── Generic buttons ── */
.btn-secondary {
  padding: 12px 14px;
  border: 1px solid var(--bg4);
  border-radius: var(--radius);
  background: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}

.btn-secondary:active { background: var(--bg3); }

.btn-danger {
  padding: 12px 14px;
  border: 1px solid rgba(255, 71, 87, .35);
  border-radius: var(--radius);
  background: none;
  color: var(--danger);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
}

.btn-danger:active { background: rgba(255, 71, 87, .08); }

.btn-icon,
.icon-btn {
  background: none;
  border: none;
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
  padding: 6px;
  border-radius: 8px;
}

.btn-icon:active,
.icon-btn:active { background: var(--bg3); }

/* ── App layout ── */
.app-page,
.lists-page,
.list-page,
.install-page,
.admin-page {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

.app-header,
.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: calc(16px + var(--safe-top)) 16px 16px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--bg3);
  position: sticky;
  top: 0;
  z-index: 10;
}

.app-header h1,
.brand {
  flex: 1;
  min-width: 0;
  font-size: 20px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.btn-back {
  color: var(--text);
  text-decoration: none;
  font-size: 24px;
  line-height: 1;
  padding: 4px;
  flex-shrink: 0;
}

.header-actions,
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.user-name {
  color: var(--text2);
  font-size: 14px;
}

/* ── Lists page ── */
.lists-container,
.lists-page {
  flex: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-bottom: calc(80px + var(--safe-bottom));
}

.lists-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.lists-section h1,
.lists-section h2 {
  font-size: 22px;
  font-weight: 800;
  margin-top: 4px;
}

.lists-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-card {
  display: block;
  padding: 18px;
  background: var(--bg2);
  border-radius: var(--radius);
  text-decoration: none;
  color: var(--text);
  border: 1px solid var(--bg3);
  transition: transform .15s, border-color .15s;
}

.list-card:active { transform: scale(.98); }

.list-card--shared,
.list-card.shared { border-left: 3px solid var(--accent); }

.list-card-name,
.list-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 4px;
}

.list-card-meta,
.list-meta {
  font-size: 13px;
  color: var(--text2);
}

.new-list-form,
.add-list-form {
  display: flex;
  gap: 10px;
}

.add-list-form {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--bg3);
}

.new-list-form input,
.add-list-input {
  flex: 1;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--bg4);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  outline: none;
}

.new-list-form input:focus,
.add-list-input:focus { border-color: var(--accent); }

.new-list-form input::placeholder,
.add-list-input::placeholder { color: var(--text-dim); }

.new-list-form .btn-primary {
  width: auto;
  min-width: 120px;
}

.btn-add-list {
  width: 48px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #6C5CE7, #a855f7);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text2);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
}

/* ── Items page ── */
.items-container {
  flex: 1;
  padding: 8px 12px;
  padding-bottom: calc(80px + var(--safe-bottom));
  overflow-y: auto;
}

.item {
  display: flex;
  align-items: stretch;
  background: var(--bg2);
  border-radius: 12px;
  margin-bottom: 6px;
  overflow: hidden;
  position: relative;
  transition: transform .2s ease, opacity .2s ease;
  border: 1px solid var(--bg3);
}

.item-color-bar { width: 5px; flex-shrink: 0; }
.color-none { background: transparent; }
.color-red { background: #FF6B6B; }
.color-orange { background: #FFA94D; }
.color-yellow { background: #FFD93D; }
.color-green { background: #51CF66; }
.color-blue { background: #339AF0; }
.color-purple { background: #B197FC; }

.item-content,
.item-main {
  flex: 1;
  padding: 14px 12px;
  min-width: 0;
  display: flex;
  align-items: center;
  cursor: pointer;
}

.item-text {
  font-size: 16px;
  word-break: break-word;
}

.item--checked,
.item.checked { opacity: .45; }

.item--checked .item-text,
.item.checked .item-text,
.item.checked .item-main {
  text-decoration: line-through;
  color: var(--text2);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 8px;
  opacity: 0;
  transition: opacity .15s;
  flex-shrink: 0;
}

.item:hover .item-actions { opacity: 1; }

@media (hover: none) {
  .item-actions { opacity: .6; }
}

.item-action-btn {
  background: none;
  border: none;
  font-size: 15px;
  padding: 8px 5px;
  cursor: pointer;
  color: var(--text2);
  border-radius: 6px;
}

.item-action-btn:active { background: var(--bg4); }

.add-item-bar,
.add-item-form {
  display: flex;
  gap: 10px;
}

.add-item-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px 16px;
  padding-bottom: calc(12px + var(--safe-bottom));
  background: var(--bg2);
  border-top: 1px solid var(--bg3);
  z-index: 10;
}

#newItemText,
.add-item-form input {
  flex: 1;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--bg4);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  outline: none;
}

#newItemText:focus,
.add-item-form input:focus { border-color: var(--accent); }

#newItemText::placeholder,
.add-item-form input::placeholder { color: var(--text-dim); }

.btn-add {
  width: 48px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, #6C5CE7, #a855f7);
  color: #fff;
  font-size: 24px;
  font-weight: 700;
  cursor: pointer;
}

.btn-add:active { opacity: .8; }

.color-picker {
  position: fixed;
  display: none;
  flex-direction: row;
  gap: 6px;
  background: var(--bg3);
  padding: 10px 14px;
  border-radius: 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  z-index: 50;
}

.color-picker.visible { display: flex; }

.color-dot {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform .15s;
}

.color-dot:active { transform: scale(1.2); }

.dropdown-menu {
  position: fixed;
  top: calc(56px + var(--safe-top));
  right: 12px;
  background: var(--bg3);
  border-radius: 12px;
  padding: 6px;
  display: none;
  box-shadow: 0 4px 20px rgba(0,0,0,.5);
  z-index: 50;
  min-width: 200px;
}

.dropdown-menu.visible { display: block; }

.dropdown-item {
  display: block;
  width: 100%;
  padding: 12px 14px;
  background: none;
  border: none;
  color: var(--text);
  font-family: inherit;
  font-size: 15px;
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
}

.dropdown-item:active { background: var(--bg4); }
.dropdown-item--danger { color: var(--danger); }

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.visible { display: flex; }

.modal {
  background: var(--bg2);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--bg3);
}

.modal h3 {
  font-size: 18px;
  margin-bottom: 16px;
}

.share-link-box,
.share-row {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}

.share-link-box input,
.share-row input {
  flex: 1;
  padding: 10px 12px;
  background: var(--bg3);
  border: 1px solid var(--bg4);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.btn-copy {
  padding: 10px 14px;
  background: var(--bg4);
  border: none;
  border-radius: 10px;
  font-size: 16px;
  color: var(--text);
  cursor: pointer;
}

.share-hint {
  font-size: 13px;
  color: var(--text2);
  margin-bottom: 16px;
}

/* ── Sheet / install / admin base cards ── */
.share-box,
.install-card,
.admin-card,
.sheet {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 18px;
  padding: 16px;
}

.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  justify-content: space-between;
  margin-bottom: 12px;
}

.sheet-sub {
  color: var(--text2);
  margin-top: 6px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* ── Install ── */
.install-page {
  padding: 16px;
  gap: 14px;
}

.install-card h1 {
  font-size: 24px;
  margin-bottom: 14px;
}

.install-card ol {
  padding-left: 20px;
}

.install-card li {
  margin-bottom: 10px;
}

.install-note {
  margin-top: 14px;
  font-size: 13px;
  color: var(--text2);
}

/* ── Admin page: styles exactly for current template ── */
.admin-page {
  width: 100%;
  max-width: 1120px;
  margin: 0 auto;
  padding: 16px;
  gap: 16px;
}

.admin-dashboard {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 12px;
}

.admin-metric {
  background: var(--bg2);
  border: 1px solid var(--bg3);
  border-radius: 16px;
  padding: 16px;
}

.admin-metric-label {
  color: var(--text2);
  font-size: 12px;
  line-height: 1.25;
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: .03em;
}

.admin-metric-value {
  font-size: 28px;
  font-weight: 800;
  line-height: 1;
}

.admin-note {
  background: rgba(108, 92, 231, .10);
  border: 1px solid rgba(108, 92, 231, .22);
  color: var(--text2);
  border-radius: 14px;
  padding: 14px 16px;
  font-size: 14px;
}

.admin-users {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.admin-card {
  padding: 18px;
}

.admin-card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.admin-user-name {
  font-size: 20px;
  font-weight: 800;
  line-height: 1.1;
}

.admin-user-login {
  margin-top: 6px;
  color: var(--text2);
  font-size: 14px;
}

.admin-badges {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  background: rgba(108, 92, 231, .18);
  border: 1px solid rgba(108, 92, 231, .28);
  color: #d7d1ff;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .04em;
}

.admin-stats {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.admin-stats > div {
  background: var(--bg);
  border: 1px solid var(--bg3);
  border-radius: 12px;
  padding: 12px 14px;
  color: var(--text2);
  font-size: 14px;
  line-height: 1.35;
}

.admin-actions-row {
  display: flex;
  justify-content: flex-start;
}

.admin-pass-form {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: nowrap;
}

.admin-pass-form input {
  min-width: 200px;
  padding: 12px 14px;
  background: var(--bg3);
  border: 1px solid var(--bg4);
  border-radius: 10px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  outline: none;
}

.admin-pass-form input:focus {
  border-color: var(--accent);
}

.admin-pass-form .btn-secondary {
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── Keep list header buttons in one line ── */
.app-header .header-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
  flex-shrink: 0;
}

.app-header .btn-icon,
.app-header .icon-btn {
  width: 36px;
  height: 36px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  flex-shrink: 0;
}

.app-header .list-title {
  min-width: 0;
}

/* ── Swipe hint ── */
@media (max-width: 600px) {
  .item { touch-action: pan-y; }
}

/* ── Mobile tweaks ── */
@media (max-width: 900px) {
  .admin-dashboard {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .admin-stats {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 640px) {
  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    flex-wrap: wrap;
  }

  .app-header {
    align-items: center;
    flex-wrap: nowrap;
  }

  .app-header h1,
  .brand {
    font-size: 18px;
  }

  .header-actions {
    gap: 4px;
  }

  .app-header .btn-icon,
  .app-header .icon-btn {
    width: 34px;
    height: 34px;
    font-size: 18px;
  }

  .new-list-form,
  .share-row,
  .share-link-box {
    flex-direction: column;
    align-items: stretch;
  }

  .new-list-form .btn-primary {
    width: 100%;
  }

  .admin-page {
    padding: 12px;
  }

  .admin-dashboard {
    grid-template-columns: 1fr;
  }

  .admin-card-head {
    flex-direction: column;
    align-items: flex-start;
  }

  .admin-pass-form {
    flex-direction: column;
    align-items: stretch;
    width: 100%;
  }

  .admin-pass-form input {
    min-width: 0;
    width: 100%;
  }
}