:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-soft: #f8fafb;
  --surface-accent: #edf7f4;
  --ink: #18262f;
  --muted: #667781;
  --line: #dce4e8;
  --line-strong: #c8d4d9;
  --accent: #267363;
  --accent-dark: #185a4d;
  --accent-soft: #dff0eb;
  --blue: #356ca5;
  --purple: #7659a6;
  --warning: #a46612;
  --warning-bg: #fff5df;
  --danger: #a53b42;
  --danger-bg: #fcebed;
  --success: #1e7657;
  --success-bg: #e5f4ed;
  --shadow-sm: 0 1px 2px rgb(20 39 50 / 5%);
  --shadow-md: 0 10px 30px rgb(20 39 50 / 8%);
  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 20px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.5rem;
  --space-6: 2rem;
  --sidebar: 244px;
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}
a { color: var(--accent-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { display: block; max-width: 100%; }
h1, h2, h3, p { margin-top: 0; }
h1 { font-size: clamp(1.55rem, 2.4vw, 2.1rem); letter-spacing: -0.03em; line-height: 1.15; }
h2 { font-size: 1.12rem; letter-spacing: -0.01em; }
h3 { font-size: 1rem; }
small, .muted { color: var(--muted); }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: #172b34;
  color: #dce9ed;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  padding: 1.1rem 0.9rem;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand {
  align-items: center;
  color: white;
  display: flex;
  font-size: 1.05rem;
  font-weight: 800;
  gap: 0.7rem;
  padding: 0.35rem 0.5rem 1rem;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  background: #54aa94;
  border-radius: 10px;
  display: grid;
  height: 34px;
  place-items: center;
  width: 34px;
}
.portal-label {
  color: #8eabb5;
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.12em;
  margin: 0.25rem 0.65rem 0.7rem;
  text-transform: uppercase;
}
.sidebar nav { display: grid; gap: 0.3rem; }
.sidebar nav a {
  align-items: center;
  border-radius: 9px;
  color: #c8d9df;
  display: flex;
  font-weight: 650;
  gap: 0.65rem;
  padding: 0.68rem 0.75rem;
}
.sidebar nav a:hover,
.sidebar nav a.active {
  background: #23434e;
  color: white;
  text-decoration: none;
}
.nav-icon { color: #78bda9; width: 1rem; }
.sidebar-footer { margin-top: auto; }
.main-content { min-width: 0; padding: 0 var(--space-6) var(--space-6); }
.topbar {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  min-height: 66px;
  margin-bottom: var(--space-6);
}
.breadcrumb { color: var(--muted); font-size: 0.86rem; }
.account-menu summary {
  align-items: center;
  cursor: pointer;
  display: flex;
  font-weight: 700;
  gap: 0.55rem;
  list-style: none;
}
.account-avatar {
  background: var(--accent-soft);
  border-radius: 50%;
  color: var(--accent-dark);
  display: grid;
  height: 34px;
  place-items: center;
  width: 34px;
}
.mobile-nav-toggle { display: none; }

.page-heading {
  align-items: flex-start;
  display: flex;
  gap: var(--space-4);
  justify-content: space-between;
  margin-bottom: var(--space-5);
}
.page-heading h1 { margin-bottom: 0.35rem; }
.page-heading p { color: var(--muted); margin-bottom: 0; }
.page-actions, .form-actions, .inline-actions, .row-actions {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}
.back-link { display: inline-block; font-size: 0.85rem; margin-bottom: 0.45rem; }

button, .button, .button-secondary, .button-danger, .button-quiet {
  align-items: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 750;
  justify-content: center;
  min-height: 40px;
  padding: 0.55rem 0.85rem;
  text-decoration: none;
}
button, .button { background: var(--accent); color: white; }
button:hover, .button:hover { background: var(--accent-dark); text-decoration: none; }
.button-secondary {
  background: var(--surface);
  border-color: var(--line-strong);
  color: var(--ink);
}
.button-secondary:hover { background: var(--surface-soft); text-decoration: none; }
.button-danger { background: var(--danger-bg); border-color: #efc5c8; color: var(--danger); }
.button-quiet { background: transparent; color: var(--muted); }
.compact-button { min-height: 32px; padding: 0.35rem 0.6rem; }
button:disabled, .button.disabled { cursor: not-allowed; opacity: 0.5; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible,
textarea:focus-visible, summary:focus-visible, gmp-place-autocomplete:focus-within {
  outline: 3px solid rgb(38 115 99 / 25%);
  outline-offset: 2px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
  padding: var(--space-5);
}
.card + .card { margin-top: var(--space-4); }
.section-heading {
  align-items: center;
  display: flex;
  gap: 0.75rem;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.section-heading h2, .section-heading h3 { margin: 0; }
.content-grid, .dashboard-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.span-2 { grid-column: span 2; }
.span-3 { grid-column: span 3; }
.metric-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: var(--space-4);
}
.metric {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
}
.metric span { color: var(--muted); display: block; font-size: 0.78rem; font-weight: 700; }
.metric strong { display: block; font-size: 1.65rem; line-height: 1.2; margin-top: 0.25rem; }
.metric.accent { border-top: 3px solid var(--accent); }
.metric.blue { border-top: 3px solid var(--blue); }
.metric.purple { border-top: 3px solid var(--purple); }
.metric.warning { border-top: 3px solid #d99b38; }

.status, .badge {
  background: #edf1f3;
  border-radius: 999px;
  color: #4e626c;
  display: inline-flex;
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1;
  padding: 0.38rem 0.55rem;
  white-space: nowrap;
}
.status-active, .status-succeeded, .status-completed, .status-published {
  background: var(--success-bg);
  color: var(--success);
}
.status-failed, .status-rejected, .status-blocked { background: var(--danger-bg); color: var(--danger); }
.status-running, .status-in_progress, .status-reviewing { background: #e7f0fa; color: var(--blue); }
.status-warning, .status-delayed, .status-stale { background: var(--warning-bg); color: var(--warning); }

.message, .alert {
  background: #eaf3f8;
  border: 1px solid #c9dfea;
  border-radius: var(--radius-sm);
  color: #28586f;
  margin-bottom: var(--space-4);
  padding: 0.75rem 0.9rem;
}
.message.error, .alert.error { background: var(--danger-bg); border-color: #efc5c8; color: var(--danger); }
.message.warning, .alert.warning { background: var(--warning-bg); border-color: #efd9ad; color: #7b520f; }
.message.success { background: var(--success-bg); border-color: #bddfce; color: var(--success); }
.messages { margin-bottom: var(--space-4); }

label { color: #334851; font-size: 0.84rem; font-weight: 750; }
input, select, textarea {
  background: #f8fafb;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink);
  font: inherit;
  min-height: 42px;
  padding: 0.55rem 0.7rem;
  width: 100%;
}
textarea { min-height: 90px; resize: vertical; }
input[type="checkbox"], input[type="radio"] { min-height: auto; width: auto; }
input[type="range"] { min-height: 24px; padding: 0; }
.field { display: grid; gap: 0.35rem; min-width: 0; }
.field small { font-size: 0.75rem; }
.form-grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(2, minmax(0, 1fr));
}
.field-wide { grid-column: 1 / -1; }
.form-actions {
  border-top: 1px solid var(--line);
  justify-content: flex-end;
  margin-top: var(--space-5);
  padding-top: var(--space-4);
}
.errorlist { color: var(--danger); font-size: 0.78rem; margin: 0; padding-left: 1rem; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }
.filter-panel {
  align-items: end;
  display: grid;
  gap: var(--space-3);
  grid-template-columns: minmax(220px, 2fr) repeat(3, minmax(130px, 1fr)) auto;
  margin-bottom: var(--space-4);
}

.table-card { overflow: hidden; padding: 0; }
.responsive-table { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
th, td { border-bottom: 1px solid var(--line); padding: 0.85rem 1rem; text-align: left; vertical-align: middle; }
th { background: var(--surface-soft); color: var(--muted); font-size: 0.72rem; letter-spacing: 0.04em; text-transform: uppercase; }
td small { display: block; margin-top: 0.15rem; }
tbody tr:hover { background: #fbfcfc; }
.table-link { color: var(--ink); font-weight: 800; }
.table-link:hover { color: var(--accent-dark); }

.list { display: grid; }
.list-row {
  align-items: center;
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: var(--space-3);
  justify-content: space-between;
  padding: 0.8rem 0;
}
.list-row:last-child { border-bottom: 0; }
.list-row small { display: block; }
.empty-state {
  color: var(--muted);
  padding: var(--space-6);
  text-align: center;
}
.empty-state.compact { padding: var(--space-4); }
.empty-state h2, .empty-state h3 { color: var(--ink); }

.detail-list { display: grid; gap: 0; margin: 0; }
.detail-list > div {
  border-bottom: 1px solid var(--line);
  display: grid;
  gap: var(--space-3);
  grid-template-columns: 150px minmax(0, 1fr);
  padding: 0.65rem 0;
}
.detail-list > div:last-child { border-bottom: 0; }
.detail-list dt { color: var(--muted); font-size: 0.78rem; font-weight: 700; }
.detail-list dd { margin: 0; overflow-wrap: anywhere; }

.workflow-steps {
  display: grid;
  gap: 2px;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  margin-bottom: var(--space-5);
}
.workflow-step {
  background: #e7edef;
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 750;
  padding: 0.65rem;
  text-align: center;
}
.workflow-step:first-child { border-radius: 9px 0 0 9px; }
.workflow-step:last-child { border-radius: 0 9px 9px 0; }
.workflow-step.current, .workflow-step.complete { background: var(--accent-soft); color: var(--accent-dark); }
.workflow-step.current { box-shadow: inset 0 -3px var(--accent); }

.info-button {
  align-items: center;
  background: #edf1f3;
  border: 0;
  border-radius: 50%;
  color: var(--muted);
  display: inline-flex;
  font-size: 0.72rem;
  height: 24px;
  justify-content: center;
  min-height: 24px;
  padding: 0;
  width: 24px;
}
.tooltip { display: inline-flex; position: relative; }
.tooltip-content {
  background: #17313b;
  border-radius: 8px;
  color: white;
  display: none;
  font-size: 0.75rem;
  font-weight: 500;
  left: 50%;
  max-width: 260px;
  padding: 0.6rem;
  position: absolute;
  top: calc(100% + 7px);
  transform: translateX(-50%);
  width: max-content;
  z-index: 20;
}
.tooltip:focus-within .tooltip-content,
.tooltip:hover .tooltip-content { display: block; }
.tooltip.tooltip-open .tooltip-content { display: block; }

.template-preview {
  align-items: center;
  background: linear-gradient(135deg, var(--accent-soft), var(--surface-muted));
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--accent-dark);
  display: flex;
  font-size: 2rem;
  font-weight: 800;
  height: 7rem;
  justify-content: center;
  margin-bottom: 1rem;
}
.theme-preview { display: flex; gap: .5rem; margin-bottom: 1rem; }
.theme-preview span { background: var(--accent); border-radius: 50%; height: 2.5rem; width: 2.5rem; }
.theme-preview span:nth-child(2) { background: var(--success); }
.theme-preview span:nth-child(3) { background: var(--warning); }
.technical-output { overflow: auto; white-space: pre-wrap; }
details.collapsible-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-top: var(--space-4);
}
details.collapsible-card > summary {
  cursor: pointer;
  font-weight: 800;
  padding: 1rem 1.2rem;
}
.collapsible-content { border-top: 1px solid var(--line); padding: 1rem 1.2rem; }

.discovery-builder {
  align-items: start;
  display: grid;
  gap: var(--space-4);
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.72fr);
}
.discovery-form-column, .discovery-map-column { min-width: 0; }
.discovery-map-column { position: sticky; top: 1rem; }
.setup-card { margin-bottom: var(--space-4); padding: 1.15rem; }
.setup-card-heading { align-items: center; display: flex; justify-content: space-between; margin-bottom: 0.9rem; }
.setup-card-heading h2 { margin: 0; }
.interactive-map { border-radius: 11px; height: 370px; overflow: hidden; width: 100%; }
.map-placeholder { background: #e8eef0; border-radius: 11px; display: grid; height: 280px; place-items: center; }
.autocomplete-field { grid-template-columns: minmax(0, 1fr); min-width: 0; }
#map-autocomplete-host {
  display: block;
  max-width: 100%;
  min-height: 44px;
  min-width: 0;
  width: 100%;
  z-index: 4;
}
#map-address-search, gmp-place-autocomplete {
  background: #f8fafb;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  display: block;
  max-width: 100%;
  min-height: 44px;
  min-width: 0;
  width: 100%;
}
.map-status { color: var(--muted); font-size: 0.78rem; margin-top: 0.4rem; }
.map-status.success { color: var(--success); }
.map-status.error { color: var(--danger); }
.radius-compact {
  align-items: center;
  display: grid;
  gap: var(--space-3);
  grid-template-columns: auto minmax(120px, 1fr) 85px auto;
}
.radius-value { background: var(--accent-soft); border-radius: 999px; color: var(--accent-dark); font-weight: 800; padding: 0.35rem 0.55rem; }
.category-grid > div { display: grid; gap: 0.5rem; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.category-grid label {
  align-items: center;
  background: var(--surface-soft);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  gap: 0.45rem;
  padding: 0.55rem;
}
.category-grid label:has(input:checked) { background: var(--accent-soft); border-color: #8ac1b2; color: var(--accent-dark); }
.search-summary {
  background: #17313b;
  border-radius: var(--radius);
  color: white;
  margin-top: var(--space-4);
  padding: 1rem;
}
.search-summary p { font-weight: 750; margin-bottom: 0.45rem; }
.search-summary small { color: #bcd0d7; }
.sticky-actions {
  align-items: center;
  background: rgb(255 255 255 / 95%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  bottom: 0.75rem;
  box-shadow: var(--shadow-md);
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  margin-top: var(--space-4);
  padding: 0.7rem;
  position: sticky;
  z-index: 8;
}

.action-card-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(2, minmax(0, 1fr)); }
.action-card { border-top: 3px solid var(--accent); }
.action-card.secondary { border-top-color: var(--blue); }
.action-card.tertiary { border-top-color: var(--purple); }
.health-strip {
  background: #17313b;
  border-radius: var(--radius);
  color: white;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  justify-content: space-between;
  margin-bottom: var(--space-4);
  padding: 0.85rem 1rem;
}
.health-item { align-items: center; display: flex; font-size: 0.8rem; gap: 0.4rem; }
.health-dot { background: #6fd0a8; border-radius: 50%; height: 8px; width: 8px; }
.health-dot.off { background: #e9b55f; }

.funnel {
  display: grid;
  gap: var(--space-2);
  grid-template-columns: repeat(6, minmax(0, 1fr));
}
.funnel-step { background: var(--surface-soft); border-radius: 9px; padding: 0.8rem; text-align: center; }
.funnel-step strong { display: block; font-size: 1.35rem; }
.funnel-step span { color: var(--muted); font-size: 0.72rem; }

.media-grid { display: grid; gap: var(--space-4); grid-template-columns: repeat(3, minmax(0, 1fr)); }
.media-card { display: flex; flex-direction: column; padding: 0; overflow: hidden; }
.media-preview, .media-preview-placeholder { aspect-ratio: 4 / 3; background: #e6ecef; object-fit: cover; width: 100%; }
.media-preview-placeholder { align-items: center; color: var(--muted); display: flex; justify-content: center; padding: 1rem; text-align: center; }
.media-card-body { display: grid; gap: 0.65rem; padding: 1rem; }
.media-card.selected { box-shadow: 0 0 0 2px var(--accent); }
.add-media-card { align-items: stretch; border: 1px dashed #9fb3bb; display: flex; flex-direction: column; justify-content: center; }

.draft-card { border-left: 4px solid var(--purple); }
.tab-list { border-bottom: 1px solid var(--line); display: flex; gap: 0.25rem; overflow-x: auto; }
.tab-list a { color: var(--muted); font-weight: 700; padding: 0.65rem 0.8rem; white-space: nowrap; }
.tab-list a.active { border-bottom: 3px solid var(--accent); color: var(--accent-dark); }

.ai-shell { display: grid; gap: var(--space-4); grid-template-columns: 270px minmax(0, 1fr); }
.ai-sidebar { display: grid; gap: var(--space-3); align-content: start; }
.ai-thread { min-height: 520px; }
.ai-composer { background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; padding: 0.8rem; }
.quick-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }

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

@media (max-width: 1100px) {
  .dashboard-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .span-3 { grid-column: span 2; }
  .discovery-builder { grid-template-columns: 1fr; }
  .discovery-map-column { position: static; }
  .filter-panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-panel > :first-child { grid-column: span 2; }
}

@media (max-width: 860px) {
  .app-shell { display: block; }
  .sidebar { height: auto; min-height: 0; position: static; }
  .sidebar-head { align-items: center; display: flex; justify-content: space-between; }
  .mobile-nav-toggle { display: inline-flex; }
  .sidebar nav { display: none; margin-top: 0.6rem; }
  .sidebar.nav-open nav { display: grid; }
  .portal-label { display: none; }
  .sidebar-footer { display: none; }
  .main-content { padding: 0 1rem 1.5rem; }
  .topbar { margin-bottom: 1.25rem; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .content-grid, .dashboard-grid, .action-card-grid, .ai-shell { grid-template-columns: 1fr; }
  .span-2, .span-3 { grid-column: auto; }
  .media-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .category-grid > div { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .funnel { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 560px) {
  .page-heading { display: block; }
  .page-heading .page-actions { margin-top: 1rem; }
  .metric-grid, .form-grid, .filter-panel, .media-grid { grid-template-columns: 1fr; }
  .filter-panel > :first-child { grid-column: auto; }
  .category-grid > div { grid-template-columns: 1fr; }
  .radius-compact { grid-template-columns: 1fr 75px auto; }
  .radius-compact > label { grid-column: 1 / -1; }
  .workflow-steps { grid-template-columns: repeat(3, 1fr); }
  .workflow-step { border-radius: 6px !important; }
  .funnel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .sticky-actions { align-items: stretch; flex-direction: column; }
  .sticky-actions a, .sticky-actions button { width: 100%; }
  .detail-list > div { grid-template-columns: 1fr; gap: 0.2rem; }
  .table-card { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .responsive-table { overflow: visible; }
  table, thead, tbody, tr, th, td { display: block; }
  thead { clip: rect(0, 0, 0, 0); height: 1px; overflow: hidden; position: absolute; width: 1px; }
  tbody { display: grid; gap: 0.75rem; }
  tr { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 0.7rem; }
  td { align-items: baseline; border: 0; display: flex; gap: 0.6rem; justify-content: space-between; padding: 0.38rem; text-align: right; }
  td::before { color: var(--muted); content: attr(data-label); font-size: 0.7rem; font-weight: 800; text-align: left; text-transform: uppercase; }
  td:first-child { align-items: flex-start; display: grid; text-align: left; }
  td:first-child::before { display: none; }
}
