*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --primary-light: #eef2ff;
  --accent: #f59e0b;
  --success: #10b981;
  --success-light: #d1fae5;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --danger-light: #fee2e2;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #0f172a;
  --text-secondary: #64748b;
  --text-muted: #94a3b8;
  --border: #e2e8f0;
  --border-hover: #cbd5e1;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -2px rgba(0,0,0,0.1);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -4px rgba(0,0,0,0.1);
  --radius: 12px;
  --radius-sm: 8px;
  --radius-xs: 6px;
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --transition: 200ms ease;
  --max-width: 680px;
  --header-height: 64px;
}

[data-theme="dark"] {
  --primary-light: #1e1b4b;
  --success-light: #064e3b;
  --danger-light: #7f1d1d;
  --bg: #0f172a;
  --card-bg: #1e293b;
  --text: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --border-hover: #475569;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 3px rgba(0,0,0,0.3), 0 1px 2px rgba(0,0,0,0.2);
  --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.3), 0 2px 4px -2px rgba(0,0,0,0.2);
  --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.3), 0 4px 6px -4px rgba(0,0,0,0.2);
}

[data-theme="dark"] .toast {
  background: var(--card-bg);
  color: var(--text);
  border: 1px solid var(--border);
}

[data-theme="dark"] .modal-overlay {
  background: rgba(0,0,0,0.7);
}

#app svg {
  width: 20px;
  height: 20px;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  padding-top: var(--header-height);
}

/* ─── Header ─── */
.header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--primary);
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

#app .header-title svg {
  width: 24px;
  height: 24px;
}

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

.header-back {
  display: flex;
  align-items: center;
  gap: 4px;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 0.9rem;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius-xs);
  transition: background var(--transition), color var(--transition);
}

#app .header-back svg {
  width: 16px;
  height: 16px;
}

.header-back:hover {
  background: var(--bg);
  color: var(--text);
}

/* ─── Container ─── */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 24px 16px 48px;
}

/* ─── Buttons ─── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  font-size: 0.9rem;
  font-weight: 600;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}

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

.btn-primary {
  background: var(--primary);
  color: #fff;
}

.btn-primary:hover {
  background: var(--primary-hover);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

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

.btn-danger {
  background: var(--danger);
  color: #fff;
}

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

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  padding: 8px 10px;
}

.btn-ghost:hover {
  background: var(--bg);
  color: var(--text);
}

.btn-sm {
  font-size: 0.8rem;
  padding: 6px 12px;
}

.btn-icon {
  width: 36px;
  height: 36px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-xs);
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}

.btn-icon:hover {
  background: var(--bg);
  color: var(--text);
}

#app .btn svg,
#app .btn-icon svg {
  width: 20px;
  height: 20px;
}

/* ─── Cards ─── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-clickable {
  cursor: pointer;
  transition: box-shadow var(--transition), transform var(--transition);
}

.card-clickable:hover {
  box-shadow: var(--shadow-md);
  transform: translateY(-2px);
}

/* ─── Home Grid ─── */
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.checklist-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}

.checklist-card {
  padding: 20px;
}

.checklist-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.checklist-card-title {
  font-size: 1.1rem;
  font-weight: 600;
  color: var(--text);
  margin-right: 8px;
  word-break: break-word;
}

.checklist-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.checklist-card-progress-text {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

/* ─── Progress Bar ─── */
.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 99px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  border-radius: 99px;
  background: var(--primary);
  transition: width 400ms ease;
}

.progress-bar-fill.complete {
  background: var(--success);
}

/* ─── Empty State ─── */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

#app .empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: 16px;
  color: var(--text-muted);
  opacity: 0.5;
}

.empty-state h2 {
  font-size: 1.2rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 24px;
}

/* ─── Form ─── */
.form-group {
  margin-bottom: 20px;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input {
  width: 100%;
  font-family: var(--font);
  font-size: 1rem;
  padding: 12px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  background: var(--card-bg);
  color: var(--text);
}

.form-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

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

/* ─── Item List ─── */
.item-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.item-add-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.item-add-row .form-input {
  flex: 1;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
  cursor: pointer;
}

.item-row:hover {
  background: var(--bg);
}

.item-row .item-text {
  flex: 1;
  font-size: 0.95rem;
  color: var(--text);
  user-select: none;
}

.item-row .item-text.checked {
  text-decoration: line-through;
  color: var(--text-muted);
}

.item-row .item-remove {
  opacity: 0;
  transition: opacity var(--transition);
}

.item-row:hover .item-remove {
  opacity: 1;
}

.item-row .item-remove:focus-visible {
  opacity: 1;
}

/* ─── Custom Checkbox ─── */
.checkbox {
  width: 22px;
  height: 22px;
  flex-shrink: 0;
  border: 2px solid var(--border-hover);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  background: var(--card-bg);
}

.checkbox.checked {
  background: var(--primary);
  border-color: var(--primary);
}

#app .checkbox svg {
  width: 14px;
  height: 14px;
  color: #fff;
  opacity: 0;
  transition: opacity var(--transition);
}

#app .checkbox.checked svg {
  opacity: 1;
}

/* ─── Checklist View ─── */
.checklist-view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}

.checklist-view-title {
  font-size: 1.4rem;
  font-weight: 700;
  word-break: break-word;
  margin-right: 12px;
}

.checklist-view-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.checklist-progress-section {
  margin-bottom: 24px;
  padding: 16px 0;
}

.checklist-progress-stats {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-bottom: 10px;
}

.checklist-progress-percent {
  font-weight: 700;
  color: var(--primary);
}

.checklist-progress-percent.complete {
  color: var(--success);
}

.checklist-items {
  margin-bottom: 16px;
}

.checklist-add-item {
  display: flex;
  gap: 8px;
  padding: 12px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.checklist-add-item .form-input {
  flex: 1;
}

/* ─── Create/Edit Form ─── */
.form-card {
  padding: 24px;
}

.form-card-title {
  font-size: 1.2rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.form-item-list {
  margin-bottom: 8px;
}

.form-item-list .item-row {
  padding: 8px 8px 8px 4px;
  cursor: default;
}

.form-item-list .item-row:hover {
  background: transparent;
}

.form-footer {
  margin-top: 24px;
  display: flex;
  gap: 12px;
}

.form-footer .btn {
  flex: 1;
}

/* ─── Modal ─── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 20px;
  animation: fadeIn 150ms ease;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  padding: 24px;
  max-width: 400px;
  width: 100%;
  animation: slideUp 200ms ease;
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
}

.modal-text {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-bottom: 20px;
  line-height: 1.5;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* ─── Toast ─── */
.toast {
  position: fixed;
  top: 80px;
  right: 20px;
  background: var(--text);
  color: #fff;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  z-index: 300;
  animation: toastIn 300ms ease, toastOut 300ms ease 2.2s forwards;
  max-width: 320px;
}

.toast.hidden {
  display: none;
}

/* ─── Animations ─── */
@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

@keyframes toastOut {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

/* ─── Share Modal ─── */
.share-url {
  display: flex;
  gap: 8px;
  align-items: center;
  margin: 12px 0;
}

.share-url input {
  flex: 1;
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-xs);
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.share-url input:focus {
  border-color: var(--primary);
}

/* ─── Responsive ─── */
@media (min-width: 480px) {
  .checklist-grid {
    grid-template-columns: 1fr 1fr;
  }
}

@media (min-width: 768px) {
  .container {
    padding: 32px 24px 64px;
  }

  .page-title {
    font-size: 1.75rem;
  }

  .checklist-view-title {
    font-size: 1.6rem;
  }
}

/* ─── Utility ─── */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  border: 0;
}
