:root {
  color-scheme: dark;
  --bg: #0f1310;
  --surface: #161b17;
  --surface-2: #1f2521;
  --border: rgba(255, 255, 255, 0.08);
  --text: #f3f5f2;
  --muted: rgba(243, 245, 242, 0.6);
  --brand: #58d39d;
  --brand-strong: #36b07b;
  --accent: #f6b26b;
  --danger: #ff7a6e;
  --danger-strong: #d84b45;
  --shadow: 0 24px 48px rgba(7, 9, 8, 0.6);
}

[data-theme="light"] {
  color-scheme: light;
  --bg: #f5f2ea;
  --surface: #ffffff;
  --surface-2: #f3efe6;
  --border: rgba(16, 38, 31, 0.12);
  --text: #101b17;
  --muted: rgba(16, 27, 23, 0.6);
  --brand: #117a57;
  --brand-strong: #0e5f44;
  --accent: #d98d3c;
  --danger: #d45750;
  --danger-strong: #b33b36;
  --shadow: 0 24px 48px rgba(16, 27, 23, 0.12);
}

body {
  background: radial-gradient(circle at top right, rgba(88, 211, 157, 0.1), transparent 35%),
    radial-gradient(circle at top left, rgba(246, 178, 107, 0.08), transparent 40%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 2rem 0.5rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 14px;
  background: var(--brand);
  color: #0b1b14;
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: 0.08em;
}

.brand-title {
  font-size: 1.1rem;
  font-weight: 700;
}

.brand-subtitle {
  font-size: 0.8rem;
  color: var(--muted);
}

.auth {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.auth-meta {
  font-size: 0.8rem;
  color: var(--muted);
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  gap: 1.5rem;
  padding: 1rem 2rem 2rem;
}

.sidebar {
  background: var(--surface);
  border-radius: 18px;
  padding: 1rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-height: 70vh;
}

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

.sidebar nav ul {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 0;
  margin: 0;
}

.sidebar nav li {
  list-style: none;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.35rem;
}

.list-actions {
  display: flex;
  gap: 0.35rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: flex-start;
}

.reorder-btn {
  padding: 0.35rem 0.5rem;
  font-size: 0.8rem;
  line-height: 1;
  min-width: 2rem;
}

.sidebar nav li > button {
  width: 100%;
  flex: 1 1 auto;
  min-width: 0;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  padding: 0.65rem 0.8rem;
  border-radius: 12px;
  color: var(--text);
}

.list-actions button {
  width: auto;
}

.list-actions button.secondary:not(.reorder-btn) {
  width: auto;
  padding: 0.4rem 0.6rem;
  font-size: 0.75rem;
}

.sidebar nav li > button.active {
  background: var(--surface-2);
  border-color: var(--border);
  font-weight: 600;
}

.sidebar nav li > button small {
  display: block;
  color: var(--muted);
}

.sidebar-actions {
  display: flex;
  gap: 0.5rem;
}

.sidebar-footer {
  margin-top: auto;
}

.content {
  background: var(--surface);
  border-radius: 22px;
  padding: 1.5rem 1.75rem 2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

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

.list-meta {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.list-title {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.list-edit-actions {
  display: flex;
  gap: 0.5rem;
}

.content-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.subtitle {
  color: var(--muted);
  margin: 0.25rem 0 0;
}

.composer form {
  display: flex;
  gap: 0.75rem;
}

.items ul {
  padding-left: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin: 0;
}

.items li {
  list-style: none;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 0.75rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
}

.item-main {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  flex: 1;
}

.item-content {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
}

.item-qty-group {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.qty-btn {
  padding: 0.25rem 0.55rem;
  min-width: 2rem;
}

.item-qty {
  width: 4.5rem;
  text-align: center;
}

.item-unit {
  width: 4.5rem;
}

.item-meta {
  font-size: 0.75rem;
  color: var(--muted);
}

.item-edit-input {
  flex: 1;
}

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

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

.item-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.hidden {
  display: none !important;
}

.danger {
  border-color: var(--danger-strong);
  color: var(--danger-strong);
}

button,
[type="button"],
[type="submit"] {
  background: var(--brand);
  border-color: var(--brand);
  color: #0b1b14;
}

button.secondary,
[type="button"].secondary,
[type="submit"].secondary {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

button.danger,
[type="button"].danger,
[type="submit"].danger {
  background: var(--danger);
  border-color: var(--danger);
  color: #1b0b0b;
}

button:disabled,
[type="button"]:disabled,
[type="submit"]:disabled {
  opacity: 0.5;
  color: var(--muted);
  background: var(--surface-2);
  border-color: var(--border);
}

input,
select,
textarea {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text);
}

@media (max-width: 900px) {
  .app {
    grid-template-columns: 1fr;
  }

  .sidebar {
    min-height: unset;
  }

  .content-header {
    flex-direction: column;
    align-items: flex-start;
  }

  .composer form {
    flex-direction: column;
  }

  .sidebar nav ul {
    flex-direction: row;
    overflow-x: auto;
  }

  .sidebar nav li > button {
    white-space: nowrap;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-direction: column;
    align-items: flex-start;
    gap: 1rem;
  }

  .auth {
    width: 100%;
    flex-wrap: wrap;
  }

  .items li {
    flex-direction: column;
    align-items: flex-start;
  }

  .item-actions {
    width: 100%;
    justify-content: flex-end;
  }
}
