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

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

:root {
  --primary: #7C3AED;
  --primary-dark: #5B21B6;
  --primary-mid: #6D28D9;
  --primary-light: #EDE9FE;
  --primary-xlight: #F5F3FF;
  --grad: linear-gradient(135deg, #6D28D9 0%, #7C3AED 60%, #9333EA 100%);
  --success: #059669;
  --success-light: #D1FAE5;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --surface: #FFFFFF;
  --surface-2: #F5F3FF;
  --surface-3: #F9FAFB;
  --text: #1E1B4B;
  --text-2: #4B5563;
  --text-3: #9CA3AF;
  --border: #E5E7EB;
  --border-focus: #7C3AED;
  --shadow-xs: 0 1px 2px rgba(0,0,0,0.06);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-md: 0 4px 20px rgba(109, 40, 217, 0.12);
  --shadow-lg: 0 12px 40px rgba(109, 40, 217, 0.18);
  --r-xs: 6px;
  --r-sm: 10px;
  --r-md: 16px;
  --r-lg: 20px;
  --r-xl: 28px;
  --r-2xl: 36px;
  --r-full: 9999px;
  --ease: 0.2s ease;
  --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  font-family: var(--font);
  background: var(--surface-2);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  line-height: 1.5;
  overflow-x: hidden;
}

a { color: inherit; }
button, input, textarea, select { font-family: var(--font); }

/* ─── Auth ────────────────────────────────────────────────── */

.auth-bg {
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--grad);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--r-xl);
  padding: 40px 32px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.4s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo-icon {
  font-size: 52px;
  display: block;
  margin-bottom: 10px;
  animation: bounceIn 0.6s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.auth-logo h1 {
  font-size: 30px;
  font-weight: 900;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -1px;
}

.auth-logo p {
  font-size: 14px;
  color: var(--text-3);
  margin-top: 4px;
  font-weight: 500;
}

.auth-footer {
  text-align: center;
  margin-top: 20px;
  font-size: 14px;
  color: var(--text-2);
}

.auth-footer a {
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
}

.auth-footer a:hover { text-decoration: underline; }

/* ─── Form elements ───────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  text-transform: uppercase;
  letter-spacing: 0.8px;
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  padding: 14px 16px;
  border: 2px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 16px;
  color: var(--text);
  background: var(--surface);
  transition: border-color var(--ease), box-shadow var(--ease);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
}

.form-input::placeholder { color: var(--text-3); }

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.12);
}

/* ─── Buttons ─────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 24px;
  border-radius: var(--r-sm);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  border: none;
  transition: all var(--ease);
  text-decoration: none;
  white-space: nowrap;
  letter-spacing: 0.2px;
  position: relative;
  overflow: hidden;
}

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

.btn-primary {
  background: var(--grad);
  color: white;
  box-shadow: 0 4px 16px rgba(109, 40, 217, 0.35);
  width: 100%;
}

.btn-primary:hover {
  box-shadow: 0 6px 22px rgba(109, 40, 217, 0.45);
  transform: translateY(-1px);
}

.btn-ghost {
  background: var(--primary-light);
  color: var(--primary);
  border: 2px solid transparent;
}

.btn-ghost:hover { background: var(--primary-xlight); }

.btn-danger-soft {
  background: var(--danger-light);
  color: var(--danger);
}

.btn-danger-soft:hover {
  background: var(--danger);
  color: white;
}

/* ─── Flash messages ──────────────────────────────────────── */

.flash {
  padding: 12px 16px;
  border-radius: var(--r-sm);
  margin-bottom: 16px;
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideDown 0.3s ease;
}

.flash-error {
  background: var(--danger-light);
  color: #991B1B;
  border: 1.5px solid #FCA5A5;
}

.flash-success {
  background: var(--success-light);
  color: #065F46;
  border: 1.5px solid #6EE7B7;
}

/* ─── App shell ───────────────────────────────────────────── */

.app {
  max-width: 600px;
  margin: 0 auto;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* ─── App header ──────────────────────────────────────────── */

.app-header {
  background: var(--grad);
  padding: 16px 20px;
  padding-top: max(16px, env(safe-area-inset-top, 16px));
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.brand-icon { font-size: 26px; }

.brand-name {
  font-size: 22px;
  font-weight: 900;
  color: white;
  letter-spacing: -0.8px;
}

.header-btns {
  display: flex;
  gap: 6px;
}

.hbtn {
  width: 38px;
  height: 38px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255,255,255,0.18);
  color: white;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: background var(--ease);
  flex-shrink: 0;
}

.hbtn:hover, .hbtn:active { background: rgba(255,255,255,0.3); }

.header-sub {
  margin-top: 6px;
  color: rgba(255,255,255,0.82);
  font-size: 13px;
  font-weight: 500;
}

/* ─── Main content ────────────────────────────────────────── */

.main {
  flex: 1;
  padding: 20px 16px;
  padding-bottom: max(88px, calc(24px + env(safe-area-inset-bottom, 0px)));
}

/* ─── Create button ───────────────────────────────────────── */

.create-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 16px 18px;
  background: white;
  border: 2.5px dashed var(--primary-light);
  border-radius: var(--r-lg);
  color: var(--primary);
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  transition: all var(--ease);
  margin-bottom: 20px;
  letter-spacing: 0.1px;
}

.create-btn:hover, .create-btn:active {
  background: var(--primary-xlight);
  border-style: solid;
  border-color: var(--primary);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.create-btn svg { flex-shrink: 0; }

/* ─── Section label ───────────────────────────────────────── */

.section-label {
  font-size: 11px;
  font-weight: 800;
  color: var(--text-3);
  text-transform: uppercase;
  letter-spacing: 1.2px;
  margin-bottom: 10px;
  padding-left: 2px;
}

/* ─── List cards ──────────────────────────────────────────── */

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

.list-card {
  background: var(--surface);
  border-radius: var(--r-lg);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform var(--ease), box-shadow var(--ease);
  position: relative;
}

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

.list-card-top {
  height: 5px;
  background: var(--cc, var(--primary));
}

.list-card-body {
  padding: 14px 16px 12px;
}

.list-card-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.list-card-link {
  text-decoration: none;
  flex: 1;
  min-width: 0;
}

.list-card-name {
  font-size: 17px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.3;
  letter-spacing: -0.2px;
  word-break: break-word;
}

.list-card-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 4px;
  flex-wrap: wrap;
}

.list-card-count {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-2);
}

.list-card-date {
  font-size: 12px;
  color: var(--text-3);
  font-weight: 500;
}

.progress-wrap {
  height: 5px;
  background: var(--border);
  border-radius: var(--r-full);
  overflow: hidden;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  background: var(--cc, var(--primary));
  border-radius: var(--r-full);
  transition: width 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.list-card-actions {
  display: flex;
  gap: 2px;
  flex-shrink: 0;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--text-3);
  transition: all var(--ease);
}

.icon-btn:hover { background: var(--surface-2); color: var(--text-2); }
.icon-btn.danger:hover { background: var(--danger-light); color: var(--danger); }
.icon-btn.archive-btn:hover { background: var(--primary-light); color: var(--primary); }

/* ─── Empty state ─────────────────────────────────────────── */

.empty-state {
  text-align: center;
  padding: 60px 20px;
  animation: fadeIn 0.4s ease;
}

.empty-icon {
  font-size: 72px;
  display: block;
  margin-bottom: 16px;
  animation: float 3s ease-in-out infinite;
}

.empty-state h2 {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 15px;
  color: var(--text-2);
}

/* ─── Modal / Bottom sheet ────────────────────────────────── */

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 10, 40, 0.55);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 100;
  display: none;
  align-items: flex-end;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}

.overlay.open { display: flex; animation: fadeIn 0.2s ease; }

.sheet {
  background: var(--surface);
  border-radius: var(--r-2xl) var(--r-2xl) 0 0;
  width: 100%;
  padding: 8px 24px 28px;
  animation: slideUp 0.35s cubic-bezier(0.34, 1.2, 0.64, 1);
  max-height: 90dvh;
  overflow-y: auto;
}

.sheet-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: var(--r-full);
  margin: 0 auto 20px;
}

.sheet-title {
  font-size: 20px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 20px;
  letter-spacing: -0.3px;
}

/* ─── Color picker ────────────────────────────────────────── */

.color-picker {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin: 8px 0 16px;
}

.cp-dot {
  width: 36px;
  height: 36px;
  border-radius: var(--r-full);
  cursor: pointer;
  border: 3px solid transparent;
  transition: all var(--ease);
  outline: none;
  flex-shrink: 0;
}

.cp-dot.active,
.cp-dot:hover {
  border-color: var(--text);
  transform: scale(1.2);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
}

/* ─── List view header ────────────────────────────────────── */

.list-header {
  padding: 20px 16px 16px;
  padding-top: max(20px, env(safe-area-inset-top, 20px));
  background: var(--lc, var(--primary));
  position: sticky;
  top: 0;
  z-index: 40;
}

.list-header-top {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 14px;
}

.back-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--r-full);
  background: rgba(255,255,255,0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  text-decoration: none;
  border: none;
  cursor: pointer;
  flex-shrink: 0;
  transition: background var(--ease);
}

.back-btn:hover, .back-btn:active { background: rgba(255,255,255,0.35); }

.list-title-wrap { flex: 1; min-width: 0; }

.list-title {
  font-size: 22px;
  font-weight: 900;
  color: white;
  letter-spacing: -0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.list-header-stats {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: rgba(255,255,255,0.85);
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}

.list-pbar {
  height: 6px;
  background: rgba(255,255,255,0.3);
  border-radius: var(--r-full);
  overflow: hidden;
}

.list-pbar-fill {
  height: 100%;
  background: white;
  border-radius: var(--r-full);
  transition: width 0.5s ease;
}

/* ─── Items ───────────────────────────────────────────────── */

.items-wrap {
  padding: 16px 12px;
  padding-bottom: max(100px, calc(90px + env(safe-area-inset-bottom, 0px)));
}

.items-section-label {
  font-size: 10px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-3);
  margin: 14px 4px 8px;
}

.item-list {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--surface);
  border-radius: var(--r-md);
  padding: 13px 12px;
  box-shadow: var(--shadow-xs);
  transition: all 0.3s ease;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
}

.item:active { transform: scale(0.985); }

.item.is-checked {
  background: var(--success-light);
  opacity: 0.75;
}

.item-checkbox {
  width: 30px;
  height: 30px;
  border-radius: var(--r-full);
  border: 2.5px solid var(--border);
  background: white;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.item.is-checked .item-checkbox {
  background: var(--success);
  border-color: var(--success);
  box-shadow: 0 0 0 3px rgba(5, 150, 105, 0.15);
}

.item-checkbox svg {
  opacity: 0;
  transform: scale(0.5);
  transition: all 0.2s ease;
}

.item.is-checked .item-checkbox svg {
  opacity: 1;
  transform: scale(1);
}

.item-body {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  transition: all 0.25s ease;
  word-break: break-word;
  line-height: 1.4;
}

.item.is-checked .item-name {
  text-decoration: line-through;
  color: var(--text-3);
}

.item-qty {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-2);
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: var(--r-full);
  margin-top: 3px;
}

.item-del {
  width: 30px;
  height: 30px;
  border-radius: var(--r-sm);
  border: none;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--ease);
  flex-shrink: 0;
  touch-action: manipulation;
}

.item-del:hover, .item-del:active {
  background: var(--danger-light);
  color: var(--danger);
}

/* ─── FAB ─────────────────────────────────────────────────── */

.fab {
  position: fixed;
  bottom: max(24px, calc(20px + env(safe-area-inset-bottom, 0px)));
  right: 20px;
  width: 58px;
  height: 58px;
  border-radius: var(--r-full);
  background: var(--grad);
  color: white;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 28px rgba(109, 40, 217, 0.42);
  transition: all var(--ease);
  z-index: 30;
  touch-action: manipulation;
}

.fab:hover { transform: scale(1.08) translateY(-2px); box-shadow: 0 12px 32px rgba(109, 40, 217, 0.5); }
.fab:active { transform: scale(0.94); }

/* ─── Add item sheet inputs ───────────────────────────────── */

.add-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
  margin-top: 4px;
}

.add-row .form-group { margin-bottom: 0; flex: 1; }
.qty-group { flex: 0 0 80px !important; }

/* ─── Archive / Search ────────────────────────────────────── */

.search-wrap {
  position: relative;
  margin-bottom: 16px;
}

.search-icon {
  position: absolute;
  left: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-3);
  pointer-events: none;
}

.search-input {
  width: 100%;
  padding: 13px 16px 13px 44px;
  border: 2px solid var(--border);
  border-radius: var(--r-md);
  font-size: 15px;
  background: white;
  outline: none;
  transition: border-color var(--ease), box-shadow var(--ease);
  color: var(--text);
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(124, 58, 237, 0.1);
}

.archive-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-3);
  background: var(--surface-3);
  border: 1.5px solid var(--border);
  padding: 2px 8px;
  border-radius: var(--r-full);
}

.no-results {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-3);
  font-weight: 600;
}

/* ─── Animations ──────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideUp {
  from { transform: translateY(60px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes slideDown {
  from { transform: translateY(-12px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes bounceIn {
  0% { transform: scale(0.5); opacity: 0; }
  70% { transform: scale(1.15); }
  100% { transform: scale(1); opacity: 1; }
}

@keyframes float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-8px); }
}

@keyframes fadeOut {
  to { opacity: 0; transform: scale(0.96) translateY(6px); }
}

@keyframes checkPop {
  0% { transform: scale(1); }
  50% { transform: scale(1.35); }
  100% { transform: scale(1); }
}

/* ─── Loading shimmer ─────────────────────────────────────── */

.item.toggling { pointer-events: none; }

.item.toggling .item-checkbox {
  animation: checkPop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

/* ─── Responsive ──────────────────────────────────────────── */

@media (min-width: 640px) {
  body {
    background: var(--grad);
    padding: 24px;
    display: flex;
    align-items: flex-start;
    justify-content: center;
  }

  .app {
    border-radius: var(--r-xl);
    overflow: hidden;
    box-shadow: var(--shadow-lg);
    min-height: calc(100vh - 48px);
  }

  .auth-bg { padding: 40px 24px; }
}

@media (max-width: 360px) {
  .brand-name { font-size: 19px; }
  .auth-card { padding: 32px 20px 28px; }
}
