:root {
  color-scheme: light;
  --bg: #f8fafc;
  --surface: #ffffff;
  --surface-soft: #f1f5f9;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --primary: #2563eb;
  --primary-ink: #ffffff;
  --accent: #0f766e;
  --danger: #dc2626;
  --done: #f8fafc;
  --radius: 8px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #020617;
  --surface: #0f172a;
  --surface-soft: #111c32;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #1e293b;
  --primary: #60a5fa;
  --primary-ink: #06111f;
  --accent: #5eead4;
  --danger: #f87171;
  --done: #0b1220;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

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

.icon-sprite {
  display: none;
}

.app-shell {
  min-height: 100vh;
  max-width: 980px;
  margin: 0 auto;
  padding: max(18px, env(safe-area-inset-top)) 16px calc(84px + var(--safe-bottom));
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  gap: 12px;
}

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

.eyebrow {
  margin: 0 0 3px;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.75rem;
  line-height: 1.1;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 2px;
  font-size: 1rem;
  line-height: 1.3;
  letter-spacing: 0;
}

.content {
  padding-top: 18px;
}

.view {
  display: none;
}

.view.is-active {
  display: block;
}

.toolbar {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-bottom: 18px;
}

.welcome-dashboard {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
  margin-bottom: 18px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--primary) 9%, transparent), transparent 52%),
    var(--surface);
}

.welcome-copy {
  display: grid;
  gap: 8px;
}

.welcome-copy h2 {
  margin-bottom: 0;
  font-size: 1.3rem;
  line-height: 1.15;
}

.welcome-copy p {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.cloud-status {
  display: inline-flex;
  align-items: center;
  width: fit-content;
  min-height: 26px;
  padding: 4px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 700;
}

.cloud-status::before {
  content: "";
  width: 7px;
  height: 7px;
  margin-right: 8px;
  border-radius: 999px;
  background: var(--muted);
}

.cloud-status.is-live::before {
  background: var(--accent);
}

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

.search {
  display: flex;
  align-items: center;
  min-width: 0;
  flex: 1;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.search svg {
  width: 18px;
  height: 18px;
  margin-left: 13px;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.search input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  padding: 0 13px 0 9px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  margin-bottom: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.stat {
  min-height: 68px;
  padding: 13px 12px;
  background: var(--surface);
}

.stat span {
  display: block;
  color: var(--ink);
  font-size: 1.45rem;
  line-height: 1;
  font-weight: 760;
  letter-spacing: 0;
}

.stat p {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
}

.active-checklist {
  margin-bottom: 18px;
}

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

.checklist-card,
.empty-state,
.builder,
.settings-list,
.active-panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
}

.checklist-card {
  display: grid;
  gap: 12px;
  padding: 14px;
}

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

.checklist-title {
  min-width: 0;
}

.checklist-title h2 {
  overflow-wrap: anywhere;
}

.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 20px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 650;
}

.pill::before {
  content: "";
  width: 4px;
  height: 4px;
  margin-right: 8px;
  border-radius: 50%;
  background: currentColor;
}

.pill:first-child::before {
  display: none;
}

.pill.accent {
  color: var(--muted);
}

.progress {
  position: relative;
  width: 100%;
  height: 5px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.progress span {
  display: block;
  height: 100%;
  width: var(--progress, 0%);
  border-radius: inherit;
  background: var(--primary);
}

.card-actions,
.item-actions,
.icon-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}

.icon-button,
.file-trigger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.icon-button svg,
.file-trigger svg,
.tab svg {
  width: 19px;
  height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button.primary,
.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

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

.icon-button:focus-visible,
.button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.tab:focus-visible,
.file-trigger:focus-within {
  outline: 3px solid color-mix(in srgb, var(--primary) 25%, transparent);
  outline-offset: 2px;
}

.active-panel {
  padding: 14px;
}

.active-panel header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.active-panel h2 {
  font-size: 1.08rem;
}

.items {
  display: grid;
  gap: 6px;
  margin-top: 12px;
}

.item-row {
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr) auto;
  align-items: center;
  min-height: 46px;
  gap: 7px;
  padding: 3px;
  border-bottom: 1px solid var(--line);
}

.item-row:last-child {
  border-bottom: 0;
}

.item-row.is-done {
  background: var(--done);
}

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

.check-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  color: transparent;
  cursor: pointer;
}

.check-toggle svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.item-row.is-done .check-toggle {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-ink);
}

.item-text {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 0.96rem;
}

.quick-add {
  display: flex;
  align-items: stretch;
  gap: 8px;
  margin-top: 14px;
}

.quick-add input {
  min-width: 0;
  flex: 1;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 0 12px;
}

.empty-state {
  padding: 22px;
  text-align: center;
}

.empty-state svg {
  width: 34px;
  height: 34px;
  margin-bottom: 12px;
  color: var(--muted);
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.empty-state h2 {
  font-size: 1.05rem;
}

.empty-state p {
  max-width: 32rem;
  margin: 6px auto 16px;
  color: var(--muted);
  line-height: 1.45;
}

.builder {
  display: grid;
  gap: 15px;
  padding: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label,
.field legend {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 680;
}

.field input,
.field select,
.field textarea,
.setting-row select {
  width: 100%;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  padding: 10px 12px;
}

.field textarea {
  min-height: 188px;
  resize: vertical;
  line-height: 1.45;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.segmented-field {
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 0;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--line);
}

.segmented label {
  min-width: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 680;
  cursor: pointer;
}

.segmented input:checked + span {
  color: var(--primary);
  background: color-mix(in srgb, var(--primary) 8%, var(--surface));
}

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

.template-button {
  min-height: 52px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  padding: 10px 12px;
  cursor: pointer;
}

.template-button strong {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 720;
}

.template-button span {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.78rem;
}

.action-row {
  display: grid;
  grid-template-columns: minmax(94px, 0.42fr) minmax(0, 1fr);
  gap: 9px;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 46px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 760;
  cursor: pointer;
}

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

.button.compact {
  min-width: 88px;
  min-height: 42px;
  padding: 0 14px;
}

.settings-list {
  overflow: hidden;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 74px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.setting-row:last-child {
  border-bottom: 0;
}

.setting-row p {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.setting-row select {
  width: auto;
  min-width: 116px;
}

.setting-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.switch {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
}

.switch input {
  position: absolute;
  opacity: 0;
}

.switch span {
  position: relative;
  display: block;
  width: 52px;
  height: 30px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-soft);
  cursor: pointer;
}

.switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.18);
  transition: transform 160ms ease;
}

.switch input:checked + span {
  background: var(--primary);
}

.switch input:checked + span::after {
  transform: translateX(22px);
}

.file-trigger input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.tabbar {
  position: fixed;
  left: 50%;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  width: min(100%, 980px);
  min-height: calc(68px + var(--safe-bottom));
  padding: 8px 10px calc(8px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(18px);
  transform: translateX(-50%);
}

.tab {
  display: grid;
  justify-items: center;
  align-content: center;
  min-width: 0;
  min-height: 50px;
  border: 0;
  border-radius: var(--radius);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.tab span {
  margin-top: 4px;
  font-size: 0.72rem;
  font-weight: 680;
  line-height: 1;
}

.tab.is-active {
  color: var(--primary);
}

.sheet {
  width: min(560px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 28px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 18px 55px rgba(15, 23, 42, 0.22);
}

.sheet::backdrop {
  background: rgba(2, 6, 23, 0.48);
  backdrop-filter: blur(3px);
}

.sheet form header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.sheet form h2 {
  margin: 0;
}

.sheet form .icon-button svg {
  transform: rotate(45deg);
}

#dialogBody {
  padding: 14px;
  overflow: auto;
}

.dialog-form {
  display: grid;
  gap: 12px;
}

.sync-divider {
  height: 1px;
  background: var(--line);
}

.dialog-form textarea[readonly] {
  min-height: 112px;
  font-size: 0.84rem;
}

.sync-note {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.45;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(82px + var(--safe-bottom));
  z-index: 30;
  width: min(380px, calc(100vw - 32px));
  padding: 11px 13px;
  border-radius: var(--radius);
  background: var(--ink);
  color: var(--bg);
  text-align: center;
  font-weight: 680;
  transform: translate(-50%, 16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.is-hidden {
  display: none !important;
}

@media (min-width: 720px) {
  .app-shell {
    padding-inline: 28px;
  }

  .welcome-dashboard {
    grid-template-columns: minmax(0, 1.35fr) minmax(260px, 0.65fr);
    align-items: center;
  }

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

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

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

  .active-checklist + .list-stack {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 980px) {
  .app-shell {
    padding-bottom: 32px;
  }

  .tabbar {
    position: sticky;
    bottom: auto;
    top: 0;
    margin: 10px auto 0;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    width: min(580px, 100%);
    min-height: 62px;
    padding: 6px;
  }

  .topbar {
    margin-top: 8px;
  }
}
