:root {
  --bg: #f7f7f4;
  --surface: #ffffff;
  --surface-soft: #f0f1ed;
  --ink: #161616;
  --muted: #60645f;
  --line: #dedfd8;
  --accent: #f5c542;
  --accent-ink: #201600;
  --tomato: #e84f3d;
  --banana: #f5c542;
  --green: #2f8f65;
  --blue: #376f9f;
  --violet: #7652a8;
  --danger: #b73b32;
  --shadow: 0 12px 30px rgb(0 0 0 / 9%);
  color-scheme: light;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

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

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

button {
  cursor: pointer;
}

a {
  color: inherit;
}

.sprite {
  display: none;
}

.icon {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.app-shell {
  width: min(1180px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  padding: 14px 14px calc(92px + env(safe-area-inset-bottom));
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin: -14px -14px 12px;
  padding: calc(14px + env(safe-area-inset-top)) 14px 12px;
  background: rgb(247 247 244 / 92%);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
}

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

h1 {
  font-size: 22px;
  line-height: 1.1;
}

h2 {
  font-size: 22px;
  line-height: 1.15;
}

h3 {
  font-size: 15px;
  line-height: 1.2;
}

.eyebrow {
  margin-bottom: 3px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-status {
  display: flex;
  align-items: center;
  gap: 8px;
}

#syncBadge {
  display: inline-flex;
  min-height: 20px;
  align-items: center;
  padding: 2px 7px;
  color: #5f4500;
  background: #fff0ad;
  border: 1px solid #e2c452;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 900;
}

#syncBadge.is-ok {
  color: #1d6f4b;
  background: #dff3e8;
  border-color: #a8d8bd;
}

#syncBadge.is-error {
  color: #8f2e20;
  background: #ffe6df;
  border-color: #efb6aa;
}

.view {
  display: none;
}

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

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin: 8px 0 14px;
}

.panel,
.form-section,
.record-card,
.metric-card,
.mini-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 0 rgb(0 0 0 / 2%);
}

.panel,
.form-section {
  padding: 14px;
}

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

.split-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}

.metric-card {
  min-height: 104px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  line-height: 1;
}

.metric-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.metric-note {
  margin-top: 8px;
  color: var(--muted);
  font-size: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 10px;
  margin-bottom: 10px;
}

.search-field {
  position: relative;
}

.search-field .icon {
  position: absolute;
  top: 50%;
  left: 12px;
  color: var(--muted);
  transform: translateY(-50%);
}

.search-field input {
  padding-left: 40px;
}

label,
fieldset {
  min-width: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

fieldset {
  margin: 0;
  padding: 0;
  border: 0;
}

legend {
  margin-bottom: 7px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  margin-top: 7px;
  padding: 10px 11px;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  outline: none;
}

textarea {
  min-height: 92px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  border-color: #111;
  box-shadow: 0 0 0 3px rgb(245 197 66 / 28%);
}

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

.form-section h3 {
  margin-bottom: 12px;
}

.field-grid {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

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

.field-grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

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

.service-grid.compact {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 10px;
}

.chip-check {
  position: relative;
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 8px;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 800;
}

.chip-check input {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: 0;
  opacity: 0;
}

.chip-check:has(input:checked) {
  background: #fff7d8;
  border-color: #e0b426;
}

.segmented {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 4px;
  padding: 4px;
  background: var(--surface-soft);
  border-radius: 8px;
}

.segmented button {
  min-height: 36px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 800;
}

.segmented button.is-active {
  color: var(--ink);
  background: #fff;
  box-shadow: 0 1px 4px rgb(0 0 0 / 10%);
}

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

.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 10px 11px;
  color: var(--ink);
  background: var(--surface-soft);
  border-radius: 8px;
}

.toggle-line input {
  width: 18px;
  min-height: auto;
  margin: 0;
}

.button-row,
.quick-actions,
.data-actions,
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chips-row {
  margin-bottom: 10px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-button,
.text-button,
.icon-button,
.chip-button {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-radius: 8px;
  font-weight: 900;
  text-decoration: none;
}

.primary-button {
  color: var(--accent-ink);
  background: var(--accent);
  border: 1px solid #d8ae23;
}

.secondary-button {
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

.ghost-button {
  color: var(--ink);
  background: var(--surface-soft);
  border: 1px solid transparent;
}

.danger-button {
  color: #fff;
  background: var(--danger);
  border: 1px solid var(--danger);
}

.text-button {
  min-height: 34px;
  padding: 0 4px;
  color: var(--ink);
  background: transparent;
  border: 0;
}

.chip-button {
  min-height: 34px;
  padding: 0 11px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  font-size: 12px;
}

.chip-button.is-active {
  color: var(--accent-ink);
  background: #fff4c4;
  border-color: #e2b72a;
}

.icon-button {
  width: 42px;
  padding: 0;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
}

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

.record-card,
.mini-card {
  padding: 12px;
}

.record-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.record-title {
  display: grid;
  gap: 5px;
}

.record-title p,
.muted-line {
  color: var(--muted);
  font-size: 13px;
}

.record-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  margin: 12px 0;
}

.meta-pill,
.status-pill {
  display: inline-flex;
  min-height: 28px;
  align-items: center;
  gap: 6px;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
}

.meta-pill {
  color: var(--ink);
  background: var(--surface-soft);
}

.status-pill {
  white-space: nowrap;
}

.status-contact { background: #eef0f2; color: #2e3133; }
.status-follow { background: #ffe6df; color: #8f2e20; }
.status-wait { background: #fff3c6; color: #7a5300; }
.status-booked { background: #fff0ad; color: #624400; }
.status-done { background: #dff3e8; color: #1d6f4b; }
.status-lost { background: #ede4f7; color: #5a3a83; }

.quick-actions {
  border-top: 1px solid var(--line);
  padding-top: 10px;
}

.quick-actions .icon-button {
  width: 38px;
  min-height: 38px;
}

.quick-actions .secondary-button,
.quick-actions .ghost-button {
  min-height: 38px;
  padding: 0 10px;
  font-size: 12px;
}

.empty-state {
  padding: 18px;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: 8px;
  text-align: center;
}

.sticky-actions {
  position: sticky;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  padding: 10px;
  background: rgb(247 247 244 / 92%);
  border: 1px solid var(--line);
  border-radius: 8px;
  backdrop-filter: blur(14px);
}

.bottom-nav {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom));
  background: rgb(255 255 255 / 94%);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.nav-item {
  display: grid;
  min-height: 52px;
  place-items: center;
  gap: 3px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  font-size: 11px;
  font-weight: 900;
}

.nav-item.is-active {
  color: var(--ink);
  background: var(--surface-soft);
}

.nav-add {
  color: var(--accent-ink);
  background: var(--accent);
}

.nav-add.is-active {
  background: #e8bb31;
}

.goal-box {
  display: grid;
  gap: 12px;
}

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

.progress span {
  display: block;
  width: 0;
  height: 100%;
  background: linear-gradient(90deg, var(--green), var(--accent));
}

.stats-lines {
  display: grid;
  gap: 8px;
}

.stat-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}

.stat-line:last-child {
  border-bottom: 0;
}

.bars {
  display: grid;
  gap: 10px;
}

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

.bar-label {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

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

.bar-track span {
  display: block;
  height: 100%;
  background: var(--ink);
}

dialog {
  width: min(560px, calc(100% - 24px));
  padding: 0;
  background: transparent;
  border: 0;
}

dialog::backdrop {
  background: rgb(0 0 0 / 38%);
}

.dialog-card {
  padding: 14px;
  background: var(--surface);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.dialog-body {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 14px;
}

.dialog-body ul {
  margin: 0;
  padding-left: 18px;
}

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

.toast {
  position: fixed;
  right: 14px;
  bottom: calc(84px + env(safe-area-inset-bottom));
  z-index: 30;
  max-width: min(420px, calc(100% - 28px));
  padding: 12px 14px;
  color: #fff;
  background: #111;
  border-radius: 8px;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(8px);
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 820px) {
  .app-shell {
    padding-right: 10px;
    padding-left: 10px;
  }

  .topbar {
    margin-right: -10px;
    margin-left: -10px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .split-grid,
  .kpi-grid,
  .field-grid.two,
  .field-grid.three,
  .service-grid,
  .service-grid.compact,
  .toggle-grid,
  .toolbar {
    grid-template-columns: 1fr;
  }

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

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

  .section-title {
    align-items: flex-start;
  }
}

@media (max-width: 430px) {
  h2 {
    font-size: 20px;
  }

  .primary-button,
  .secondary-button,
  .ghost-button,
  .danger-button {
    padding-right: 10px;
    padding-left: 10px;
    font-size: 13px;
  }

  .metric-card strong {
    font-size: 22px;
  }

  .sticky-actions {
    grid-template-columns: 1fr;
  }
}
