:root {
  --bg: #f2f1ee;
  --surface: #EDEDED;
  --surface-solid: #ffffff;
  --surface-well: #17171b;
  --border: #e0ded8;
  --text: #1c1c1a;
  --muted: #8c8a84;
  --accent: #F5B027;
  --accent-secondary: #0711B6;
  --shadow: 0 8px 24px rgba(28, 28, 26, 0.28);
  --radius-sm: 10px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --font: "Space Grotesk", system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
}

body {
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(7, 17, 182, 0.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(7, 17, 182, 0.07) 1px, transparent 1px),
    linear-gradient(rgba(28, 28, 26, 0.045) 1px, transparent 1px),
    linear-gradient(90deg, rgba(28, 28, 26, 0.045) 1px, transparent 1px);
  background-size: 120px 120px, 120px 120px, 20px 20px, 20px 20px;
  background-attachment: fixed;
}

body { min-height: 100vh; }

a { color: inherit; }

button { font-family: inherit; }

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

:focus-visible {
  outline: 2px solid var(--accent-secondary);
  outline-offset: 2px;
}

.app-shell {
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: 96px;
}

/* Primary action, bottom-anchored so it's reachable without scrolling past
   an arbitrarily long list of cards/items (brand.md mobile-first rule). */
.bottom-action-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 15;
  display: flex;
  justify-content: center;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--border);
}

.bottom-action-bar .btn {
  width: 100%;
  max-width: 608px;
}

/* Header */
.app-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 20px 16px 8px;
}

.app-title {
  flex: 1;
  font-weight: 700;
  font-size: 22px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.app-title-compact {
  font-size: 18px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Panels / cards */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow);
  padding: 16px;
  margin: 0 16px 16px;
}

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

.section-label {
  display: block;
  color: var(--accent-secondary);
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 10px;
}

.empty-state {
  color: var(--muted);
  font-size: 14px;
  margin: 4px 0;
}

/* Buttons */
.btn {
  appearance: none;
  border-radius: var(--radius-sm);
  padding: 12px 20px;
  font-weight: 700;
  font-size: 13px;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  border: 1px solid transparent;
  min-height: 44px;
  min-width: 44px;
  cursor: pointer;
}

.btn-primary { background: var(--accent); color: #1c1c1a; border-color: var(--accent); }
.btn-secondary { background: var(--surface-solid); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--surface-solid); color: #b3261e; border-color: var(--border); }
.btn-block { display: block; width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  border: 1px solid var(--border);
  color: var(--text);
  text-decoration: none;
  font-size: 16px;
  cursor: pointer;
  flex-shrink: 0;
}

/* Home: list cards */
.list-grid {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.list-card {
  display: block;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px;
  text-decoration: none;
  color: var(--text);
}

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

.list-card-name { margin: 0; font-size: 16px; }

.list-card-date {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.list-card-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
  font-size: 13px;
  color: var(--muted);
}

/* Form fields */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field-label {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field input[type="text"],
.field input[type="date"],
.field input[type="number"],
.field input[type="url"],
.field select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  padding: 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  min-height: 44px;
}

.field-row {
  display: flex;
  gap: 12px;
}

.field-row .field { flex: 1; min-width: 0; }

.field-toggle {
  flex-direction: row;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.field-toggle input { width: 22px; height: 22px; }

.form-actions { margin-top: 4px; }

.form-actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Stat tiles */
.stat-tiles {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.stat-tile {
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.stat-value {
  font-weight: 700;
  font-size: 20px;
  color: var(--accent);
}

.stat-label {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Charts */
.charts-panel { display: flex; flex-direction: column; gap: 20px; }

.chart-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 8px;
}

.chart-empty { color: var(--muted); font-size: 13px; }

.meter-head {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 6px;
}

.meter-value { color: var(--accent); }

.meter-track {
  height: 14px;
  background: #f6e2bb;
  border-radius: 999px;
  overflow: hidden;
}

.meter-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
}

.meter-sublabel {
  margin-top: 6px;
  font-size: 12px;
  color: var(--muted);
}

.stacked-bar {
  display: flex;
  gap: 2px;
  height: 20px;
  border-radius: 10px;
  overflow: hidden;
  background: var(--border);
}

.stacked-segment { flex: none; height: 100%; }

.chart-legend {
  list-style: none;
  margin: 10px 0 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.chart-legend-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.chart-swatch {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.chart-legend-label { color: var(--text); }
.chart-legend-value { color: var(--text); font-weight: 700; }

/* Item list */
.item-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  user-select: none;
}

.item-row {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-solid);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px;
}

.item-row.is-packed { opacity: 0.6; }
.item-row.is-packed .item-name { text-decoration: line-through; }

.item-row.is-dragging {
  position: relative;
  z-index: 5;
  box-shadow: var(--shadow);
  cursor: grabbing;
}

.item-drag-handle {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  border: none;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: grab;
  touch-action: none;
}

.item-check {
  width: 44px;
  height: 44px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-solid);
  color: var(--accent);
  font-weight: 700;
  font-size: 16px;
  flex-shrink: 0;
  cursor: pointer;
}

.item-row.is-packed .item-check {
  background: var(--accent);
  color: #1c1c1a;
  border-color: var(--accent);
}

.item-thumb {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-sm);
  object-fit: cover;
  border: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--surface);
}

.item-thumb.is-broken { visibility: hidden; }

.item-thumb-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

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

.item-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.item-tag {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  font-size: 11px;
}

.item-link { color: var(--accent-secondary); text-decoration: none; font-weight: 600; }

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

.item-actions .icon-btn { width: 44px; height: 44px; font-size: 14px; border-color: transparent; background: transparent; }

.danger-panel { display: flex; }

/* Modal */
.modal-root { display: none; }
.modal-root.is-open { display: block; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(23, 23, 27, 0.5);
  display: flex;
  align-items: flex-end;
  z-index: 20;
}

.modal-sheet {
  background: var(--surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  padding: 20px 16px calc(20px + env(safe-area-inset-bottom));
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head .section-label { margin-bottom: 0; }

.settings-divider {
  border-top: 1px solid var(--border);
  margin: 4px 0;
}

/* Toast */
.toast {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  background: var(--surface-well);
  color: #fff;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 30;
  max-width: calc(100vw - 32px);
  text-align: center;
}

.toast.is-visible { display: block; }
.toast.is-error { background: #b3261e; }

/* Footer */
.app-footer {
  padding: 8px 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 4px 16px;
}

.app-footer a {
  color: var(--muted);
  font-size: 13px;
  text-decoration: none;
}

.app-footer a:hover { color: var(--text); }

/* Wider viewports: multi-column enhancements + centered modal */
@media (min-width: 640px) {
  .list-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .stat-tiles {
    grid-template-columns: repeat(4, 1fr);
  }

  .modal-backdrop {
    align-items: center;
    justify-content: center;
    padding: 20px;
  }

  .modal-sheet {
    max-width: 480px;
    border-radius: var(--radius-lg);
    max-height: 85vh;
  }
}
