:root {
  --bg: #f7f8fb;
  --surface: #ffffff;
  --surface-muted: #eef2f5;
  --surface-pressed: #e3ebee;
  --text: #202428;
  --muted: #5e6973;
  --border: #d9e0e6;
  --accent: #267c7e;
  --accent-strong: #166366;
  --accent-soft: #dff1ef;
  --danger: #b84747;
  --danger-soft: #fae6e4;
  --shadow: 0 16px 36px rgba(30, 36, 42, 0.08);
  --radius: 8px;
  --radius-soft: 6px;
}

[data-theme="dark"] {
  --bg: #101214;
  --surface: #181c1f;
  --surface-muted: #23282c;
  --surface-pressed: #2b3136;
  --text: #f1f4f2;
  --muted: #aab2b5;
  --border: #363d41;
  --accent: #62c3bc;
  --accent-strong: #9ee2db;
  --accent-soft: #173635;
  --danger: #ff8178;
  --danger-soft: #3d2220;
  --shadow: 0 18px 42px rgba(0, 0, 0, 0.32);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  color-scheme: light;
}

html[data-theme="dark"] {
  color-scheme: dark;
}

body {
  min-height: 100vh;
  min-height: 100svh;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.62;
}

img {
  display: block;
  max-width: 100%;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 920px);
  min-height: 100vh;
  min-height: 100svh;
  margin: 0 auto;
  padding: 18px 16px 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.site-header {
  display: grid;
  gap: 12px;
  padding-top: 4px;
}

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

.brand-mark {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
}

.eyebrow {
  margin: 0 0 2px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 2px;
  font-size: 2.55rem;
  line-height: 0.95;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 4px;
  font-size: 1.45rem;
  line-height: 1.12;
  letter-spacing: 0;
}

h3 {
  margin-bottom: 12px;
  font-size: 1rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.subtitle,
.signal-copy,
.section-heading p,
.settings-note {
  color: var(--muted);
}

.subtitle {
  margin-bottom: 0;
  font-size: 1rem;
}

.signal-copy {
  margin-bottom: 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.view-tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 6px;
  padding: 8px 0;
  background: var(--bg);
}

.tab-button,
.primary-button,
.secondary-button,
.quiet-button,
.danger-button,
.category-button,
.magnet-choice,
.delete-button {
  min-height: 46px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  letter-spacing: 0;
  transition: transform 150ms ease, border-color 150ms ease, background 150ms ease, color 150ms ease;
}

.tab-button {
  padding: 10px 8px;
  color: var(--muted);
}

.tab-button.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.primary-button,
.secondary-button,
.danger-button,
.quiet-button {
  width: 100%;
  padding: 12px 16px;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #ffffff;
}

[data-theme="dark"] .primary-button {
  color: #101214;
}

.secondary-button {
  border-color: var(--accent);
  color: var(--accent-strong);
}

.quiet-button {
  color: var(--muted);
}

.danger-button {
  border-color: var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
}

.tab-button:focus-visible,
.primary-button:focus-visible,
.secondary-button:focus-visible,
.quiet-button:focus-visible,
.danger-button:focus-visible,
.category-button:focus-visible,
.magnet-choice:focus-visible,
.delete-button:focus-visible,
input:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--accent) 40%, transparent);
  outline-offset: 2px;
}

@media (hover: hover) {
  button:hover {
    transform: translateY(-1px);
  }
}

.app-main {
  flex: 1;
}

.view-panel {
  display: grid;
  gap: 18px;
}

.section-heading {
  display: grid;
  gap: 2px;
}

.section-heading p {
  margin-bottom: 0;
}

.compact-heading {
  margin-bottom: -4px;
}

.dashboard-summary {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.summary-card,
.capture-form,
.settings-section,
.stats-section {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.summary-card {
  min-height: 72px;
  padding: 10px 12px;
  display: grid;
  align-content: space-between;
  gap: 6px;
}

.category-summary-card {
  grid-column: 1 / -1;
  min-height: 68px;
}

.summary-label {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
  line-height: 1.15;
}

.summary-value {
  font-size: 2rem;
  line-height: 1;
}

.category-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 28px;
}

.count-pill,
.category-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 28px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.count-pill.is-empty {
  color: var(--muted);
  font-weight: 600;
}

.capture-form {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.field-label {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 800;
}

input[type="text"] {
  width: 100%;
  min-height: 52px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 1rem;
}

input[type="text"]::placeholder {
  color: color-mix(in srgb, var(--muted) 76%, transparent);
}

.category-picker {
  display: grid;
  gap: 8px;
}

.category-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.category-button {
  min-width: 92px;
  padding: 10px 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.category-button.is-selected {
  border-color: var(--category-color, var(--accent));
  background: var(--category-bg, var(--accent-soft));
}

.swatch {
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: var(--swatch-color, var(--accent));
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--surface) 65%, transparent);
}

.status-line {
  min-height: 22px;
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.content-block {
  display: grid;
  gap: 10px;
}

.empty-state {
  margin: 0;
  padding: 16px;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
}

.impulse-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.history-panel {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.history-panel summary {
  min-height: 50px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  color: var(--text);
  font-weight: 800;
  cursor: pointer;
}

.history-count {
  min-width: 30px;
  padding: 3px 8px;
  border: 1px solid var(--border);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.compact-empty {
  margin: 0 14px 14px;
  padding: 12px;
}

.history-list {
  display: grid;
  gap: 0;
  margin: 0;
  padding: 0 14px 12px;
  list-style: none;
}

.history-item {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 2px 10px;
  padding: 10px 0;
  border-top: 1px solid var(--border);
}

.history-item time {
  grid-row: span 2;
  min-width: 68px;
  color: var(--muted);
  font-size: 0.82rem;
}

.history-item strong {
  color: var(--text);
  font-size: 0.92rem;
}

.history-item p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
}

.impulse-card {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.impulse-card.is-new {
  animation: soft-pop 540ms ease-out;
}

@keyframes soft-pop {
  0% {
    transform: translateY(8px);
    border-color: var(--accent);
  }
  100% {
    transform: translateY(0);
    border-color: var(--border);
  }
}

.impulse-main {
  display: grid;
  gap: 8px;
}

.impulse-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.9rem;
}

.impulse-text {
  margin-bottom: 0;
  overflow-wrap: anywhere;
  font-size: 1.04rem;
}

.impulse-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.action-magnet {
  position: relative;
  min-height: 46px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  overflow: hidden;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.magnet-cover {
  position: absolute;
  top: 3px;
  bottom: 3px;
  left: 3px;
  width: calc(50% - 3px);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) - 2px);
  background: var(--surface);
  box-shadow: 0 5px 18px rgba(24, 31, 36, 0.12);
  transition: transform 180ms ease, background 180ms ease, border-color 180ms ease;
}

.action-magnet[data-state="acted"] .magnet-cover {
  transform: translateX(100%);
  border-color: var(--accent);
  background: var(--accent-soft);
}

.magnet-choice {
  position: relative;
  z-index: 1;
  min-width: 0;
  padding: 10px 8px;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: center;
}

.magnet-choice.is-selected {
  color: var(--text);
}

.action-magnet[data-state="acted"] .magnet-choice.is-selected {
  color: var(--accent-strong);
}

.delete-button {
  min-width: 86px;
  padding: 10px 12px;
  color: var(--danger);
}

.acted-note-field {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
}

.note-label {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
}

.note-status {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.acted-note-input {
  grid-column: 1 / -1;
  min-height: 48px;
}

.stats-layout {
  display: grid;
  gap: 12px;
}

.stats-section {
  padding: 14px;
}

.bar-list {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  gap: 6px;
}

.bar-label-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 700;
}

.bar-label {
  overflow-wrap: anywhere;
}

.bar-track {
  height: 14px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-muted);
}

.bar-fill {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--bar-color, var(--accent));
  transition: width 220ms ease;
}

.settings-section {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.category-settings-list {
  display: grid;
  gap: 10px;
}

.category-edit-form {
  display: grid;
  gap: 8px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-soft);
  background: var(--surface-muted);
}

.inline-form-row,
.category-edit-row {
  display: grid;
  gap: 8px;
}

.color-label {
  min-height: 52px;
  display: grid;
  grid-template-columns: 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-weight: 700;
}

input[type="color"] {
  width: 48px;
  height: 36px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius-soft);
  background: var(--surface);
}

.add-category-form {
  display: grid;
  gap: 10px;
}

.theme-options {
  display: grid;
  gap: 8px;
  margin: 0;
  padding: 0;
  border: 0;
}

.choice-row {
  min-height: 52px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
  font-weight: 800;
}

.choice-row input {
  width: 22px;
  height: 22px;
  accent-color: var(--accent);
}

.data-actions {
  display: grid;
  gap: 8px;
}

.settings-note {
  margin-bottom: 0;
  font-size: 0.92rem;
}

.app-footer {
  padding: 8px 2px 0;
  color: var(--muted);
  font-size: 0.78rem;
  text-align: center;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 680px) {
  .app-shell {
    padding: 28px 24px 36px;
  }

  .site-header {
    grid-template-columns: minmax(0, 1.3fr) minmax(260px, 0.7fr);
    align-items: end;
  }

  h1 {
    font-size: 3.35rem;
  }

  .dashboard-summary {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .category-summary-card {
    grid-column: span 2;
  }

  .capture-form {
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: end;
  }

  .capture-form .field-label,
  .capture-form input,
  .category-picker,
  .capture-form .status-line {
    grid-column: 1 / -1;
  }

  .primary-button {
    width: auto;
    min-width: 180px;
    grid-column: 1 / -1;
    justify-self: start;
  }

  .full-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
  }

  .stats-layout {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    align-items: start;
  }

  .inline-form-row {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 0.38fr);
  }

  .category-edit-row {
    grid-template-columns: minmax(0, 1fr) minmax(160px, 0.34fr) auto;
    align-items: center;
  }

  .category-edit-row .secondary-button {
    width: auto;
    min-width: 92px;
  }

  .data-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}
