:root {
  --bg: #faf5ee;
  --surface: #ffffff;
  --text: #2b2420;
  --text-muted: #8a7c6c;
  --border: #e9dfd0;
  --accent: #d9633a;
  --accent-hover: #c14f28;
  --accent-2: #b9862c;
  --danger: #c0392b;
  --danger-hover: #a52f22;
  --gold: #b9862c;
  --priority-high: #c0392b;
  --priority-medium: #b9862c;
  --priority-low: #3f7ea6;
  --radius: 14px;
  --shadow: 0 2px 10px rgba(80, 55, 30, 0.09);
}

:root[data-theme="dark"] {
  --bg: #1a1815;
  --surface: #242019;
  --text: #f3ece1;
  --text-muted: #a89985;
  --border: #3b352c;
  --accent: #ef8156;
  --accent-hover: #f3966f;
  --accent-2: #dcaa4e;
  --danger: #e0685a;
  --danger-hover: #e87f72;
  --gold: #dcaa4e;
  --priority-high: #e0685a;
  --priority-medium: #dcaa4e;
  --priority-low: #6cb0d6;
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    --bg: #1a1815;
    --surface: #242019;
    --text: #f3ece1;
    --text-muted: #a89985;
    --border: #3b352c;
    --accent: #ef8156;
    --accent-hover: #f3966f;
    --accent-2: #dcaa4e;
    --danger: #e0685a;
    --danger-hover: #e87f72;
    --gold: #dcaa4e;
    --priority-high: #e0685a;
    --priority-medium: #dcaa4e;
    --priority-low: #6cb0d6;
    --shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  }
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  transition: background-color 0.2s ease, color 0.2s ease;
}

/* --- Auth page --- */

.auth-container {
  max-width: 400px;
  margin: 8vh auto 0;
  padding: 32px;
  background: var(--surface);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.auth-header-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.auth-brand {
  display: flex;
  justify-content: center;
  margin: 0 0 16px;
}

.auth-logo {
  width: 140px;
  height: 140px;
  object-fit: contain;
  background: #fff;
  border-radius: 22px;
  padding: 10px;
}

h1 {
  font-size: 1.6rem;
  margin: 0 0 4px;
}

.subtitle {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 0.95rem;
}

.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
}

.tab-btn {
  flex: 1;
  padding: 8px;
  border: none;
  background: transparent;
  border-radius: 999px;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--text-muted);
  transition: background-color 0.15s ease, color 0.15s ease;
}

.tab-btn.active {
  background: var(--surface);
  color: var(--accent);
  font-weight: 600;
  box-shadow: var(--shadow);
}

/* --- Shared form / button / modal primitives --- */

form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 0.85rem;
  color: var(--text-muted);
  display: block;
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}

button {
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.95rem;
  font-weight: 600;
  transition: filter 0.15s ease, transform 0.1s ease;
}

.btn-primary:hover {
  filter: brightness(1.06);
  transform: translateY(-1px);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 0.9rem;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

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

.btn-danger {
  background: transparent;
  border: 1px solid var(--danger);
  color: var(--danger);
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  transition: background-color 0.15s ease, color 0.15s ease;
}

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

.icon-toggle {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background-color 0.15s ease, border-color 0.15s ease, transform 0.15s ease;
}

.icon-toggle:hover {
  background: var(--bg);
  border-color: var(--accent);
  transform: rotate(15deg);
}

.icon-btn-circle {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-size: 1.1rem;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.icon-btn-circle:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.icon-btn {
  background: transparent;
  border: none;
  font-size: 1rem;
  padding: 6px 8px;
  border-radius: 8px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
}

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

.error-msg {
  color: var(--danger);
  font-size: 0.85rem;
  min-height: 1.2em;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(20, 15, 10, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 8vh 20px;
  z-index: 60;
}

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

.modal {
  background: var(--surface);
  border-radius: calc(var(--radius) + 4px);
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.3);
}

.modal h2 {
  margin-top: 0;
  font-size: 1.2rem;
}

.modal-subtitle {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: -8px;
}

.modal-row {
  display: flex;
  gap: 10px;
}

.modal-row > div {
  flex: 1;
  min-width: 0;
}

.field-with-button {
  display: flex;
  align-items: center;
  gap: 6px;
}

.field-with-button select {
  flex: 1;
  min-width: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.share-list {
  list-style: none;
  padding: 0;
  margin: 12px 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.share-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.88rem;
  background: var(--bg);
  padding: 8px 12px;
  border-radius: 10px;
}

.badge {
  font-size: 0.72rem;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.badge.priority-high { color: var(--priority-high); border-color: var(--priority-high); }
.badge.priority-medium { color: var(--priority-medium); border-color: var(--priority-medium); }
.badge.priority-low { color: var(--priority-low); border-color: var(--priority-low); }
.badge.rating-badge { color: var(--gold); border-color: var(--gold); letter-spacing: 1px; }
.badge.category-badge { font-weight: 500; }

.item-desc {
  color: var(--text-muted);
  font-size: 0.87rem;
}

.item-meta {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.checkbox-wrap {
  position: relative;
  display: inline-flex;
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  cursor: pointer;
  margin: 0;
}

.item-checkbox-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}

.item-checkbox-input:disabled {
  cursor: default;
}

.checkbox-visual {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface);
  box-sizing: border-box;
  pointer-events: none;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.item-checkbox-input:checked + .checkbox-visual {
  background: var(--accent);
  border-color: var(--accent);
}

.item-checkbox-input:checked + .checkbox-visual::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 12px;
  font-weight: 700;
}

.item-checkbox-input:disabled + .checkbox-visual {
  opacity: 0.5;
}

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--text-muted);
  padding: 40px 0;
}

.hidden {
  display: none !important;
}

/* --- Dropdown menus --- */

.dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  padding: 6px;
  min-width: 170px;
  z-index: 55;
}

.dropdown-menu button {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 0.88rem;
  color: var(--text);
}

.dropdown-menu button:hover {
  background: var(--bg);
}

.dropdown-menu button.danger {
  color: var(--danger);
}

.dropdown-menu button.danger:hover {
  background: var(--danger);
  color: white;
}

/* --- Top bar --- */

.sidebar-brand {
  display: flex;
  justify-content: center;
  margin-bottom: 4px;
}

.brand-logo {
  width: 92px;
  height: 92px;
  object-fit: contain;
  background: #fff;
  border-radius: 16px;
  padding: 6px;
}

.sidebar-user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.user-menu {
  position: relative;
  min-width: 0;
}

.user-avatar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: transparent;
  border: 1px solid transparent;
  padding: 4px 10px 4px 4px;
  border-radius: 999px;
  min-width: 0;
  max-width: 100%;
}

.user-avatar-btn:hover {
  border-color: var(--border);
  background: var(--bg);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  font-weight: 700;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.username-label {
  color: var(--text-muted);
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}

.chevron {
  color: var(--text-muted);
  font-size: 0.7rem;
}

/* --- App shell: sidebar + main --- */

.app-shell {
  display: flex;
  align-items: flex-start;
  gap: 28px;
  max-width: 1180px;
  margin: 0 auto;
  padding: 24px 24px 100px;
}

.sidebar {
  width: 250px;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: sticky;
  top: 24px;
}

.sidebar-label {
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0 4px;
}

.sidebar-lists {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.sidebar-list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  padding: 9px 10px;
  border-radius: 10px;
  text-align: left;
  transition: background-color 0.15s ease, border-color 0.15s ease;
}

.sidebar-list-row:hover {
  background: var(--surface);
}

.sidebar-list-row.active {
  background: var(--surface);
  border-left-color: var(--accent);
  box-shadow: var(--shadow);
}

.sidebar-list-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.sidebar-list-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar-list-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-list-row.active .sidebar-list-name {
  color: var(--accent);
  font-weight: 600;
}

.sidebar-list-count {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.sidebar-new-list-btn {
  border: 1.5px dashed var(--border);
  background: transparent;
  color: var(--text-muted);
  padding: 10px;
  border-radius: 10px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: border-color 0.15s ease, color 0.15s ease;
}

.sidebar-new-list-btn:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.main-panel {
  flex: 1;
  min-width: 0;
}

.empty-state-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 80px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state-toolbar {
  display: flex;
  justify-content: flex-start;
}

/* --- Landing (all lists) --- */

.landing-title {
  font-size: 1.3rem;
  margin: 4px 0 16px;
}

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

.landing-list-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.landing-list-card:hover {
  transform: translateY(-2px);
  border-color: var(--accent);
}

.landing-list-card-top {
  display: flex;
  align-items: center;
  gap: 8px;
}

.landing-list-card-name {
  font-weight: 600;
  font-size: 1.05rem;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.landing-list-card-meta {
  font-size: 0.8rem;
  color: var(--text-muted);
}

/* --- List header --- */

.list-header-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: nowrap;
}

.list-dot {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  flex-shrink: 0;
}

.menu-wrap {
  position: relative;
}

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

.list-name-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  background: transparent;
  border: none;
  padding: 4px 8px;
  border-radius: 8px;
  min-width: 0;
  max-width: 100%;
  color: var(--text);
}

.list-name-btn:hover {
  background: var(--bg);
}

.list-name-text {
  font-size: 1.4rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-actions-wrap {
  margin-left: auto;
  flex-shrink: 0;
}

.list-subtitle {
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: 6px;
}

.progress-block {
  margin-top: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  box-shadow: var(--shadow);
}

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

.progress-percent {
  font-weight: 700;
  font-size: 1.3rem;
  color: var(--accent);
  min-width: 3.2em;
}

.progress-bar-track {
  flex: 1;
  height: 8px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: inherit;
  transition: width 0.3s ease;
}

.progress-caption {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 8px;
}

/* --- Toolbar / filters / sort --- */

.toolbar-row {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin: 22px 0 16px;
}

.search-input {
  flex: 1;
  min-width: 200px;
}

.popover-wrap {
  position: relative;
}

.popover {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18);
  padding: 16px;
  min-width: 230px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 10px;
}


/* --- Status tabs --- */

.status-tabs {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

.status-tab {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 500;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.status-tab .tab-count {
  opacity: 0.75;
  margin-left: 4px;
}

.status-tab.active {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

/* --- Goal cards --- */

.goals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px;
  align-items: stretch;
}

.goal-card {
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.goal-card:hover {
  transform: translateY(-3px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
}

.goal-card.completed .item-title {
  text-decoration: line-through;
  color: var(--text-muted);
}

.goal-card-title-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.goal-card-title-row .item-title {
  font-weight: 600;
  font-size: 0.98rem;
  flex: 1;
  margin-top: 1px;
}

.goal-card-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.goal-card-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* --- Completed section --- */

.completed-section {
  margin-top: 26px;
}

.completed-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: transparent;
  border: none;
  border-top: 1px solid var(--border);
  padding: 14px 4px;
  font-weight: 600;
  font-size: 0.92rem;
  color: var(--text-muted);
}

.completed-toggle:hover {
  color: var(--text);
}

.completed-section .goals-grid {
  margin-top: 14px;
}

/* --- Floating action button --- */

.fab {
  position: fixed;
  bottom: 28px;
  right: 28px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: white;
  border: none;
  font-size: 1.7rem;
  line-height: 1;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.28);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.15s ease;
  z-index: 30;
}

.fab:hover {
  transform: scale(1.08);
}

.sidebar-toggle-btn {
  display: none;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  font-size: 1.05rem;
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
  background: var(--bg);
}

.sidebar-backdrop {
  display: none;
}

@media (max-width: 760px) {
  .sidebar-toggle-btn {
    display: flex;
  }

  .app-shell {
    padding: 16px 16px 100px;
  }

  .toolbar-row {
    flex-direction: column;
    align-items: stretch;
  }

  .search-input {
    width: 100%;
    min-width: 0;
  }

  .toolbar-row .popover-wrap {
    flex: 1;
  }

  .toolbar-row .popover-wrap > .btn-secondary {
    width: 100%;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100vh;
    width: min(84vw, 300px);
    z-index: 50;
    background: var(--bg);
    padding: 20px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
    box-shadow: 0 0 30px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop.visible {
    display: block;
    position: fixed;
    inset: 0;
    background: rgba(15, 10, 5, 0.45);
    z-index: 45;
  }

  .popover,
  .dropdown-menu {
    position: fixed;
    left: 16px;
    right: 16px;
    width: auto;
    min-width: 0;
  }

  .empty-state-toolbar {
    margin-bottom: 12px;
  }
}
