:root {
  color-scheme: light;
  --bg: #f3f7f6;
  --panel: #ffffff;
  --text: #172331;
  --muted: #667386;
  --line: #d8e2e7;
  --accent: #0aa789;
  --accent-dark: #087d68;
  --accent-soft: rgba(10, 167, 137, 0.12);
  --warn: #9f6b12;
  --danger: #b84a4a;
  --shadow: 0 12px 28px rgba(29, 45, 57, 0.08);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #101820;
  --panel: #18232d;
  --text: #edf4f3;
  --muted: #9cacbd;
  --line: #2b3b49;
  --accent: #16c8a4;
  --accent-dark: #65e6cf;
  --accent-soft: rgba(22, 200, 164, 0.14);
  --warn: #f1c76a;
  --danger: #ff8d8d;
  --shadow: 0 14px 30px rgba(0, 0, 0, 0.24);
}

* { box-sizing: border-box; }

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

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

.mobile-shell {
  min-height: 100svh;
  padding-bottom: calc(68px + env(safe-area-inset-bottom));
}

.mobile-header {
  align-items: center;
  display: flex;
  justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top)) 16px 8px;
  position: sticky;
  top: 0;
  z-index: 10;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(14px);
}

.mobile-header p {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0 0 3px;
}

.mobile-header h1 {
  font-size: 24px;
  line-height: 1.08;
  margin: 0;
}

.icon-action {
  align-items: center;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--accent-dark);
  display: grid;
  font-size: 20px;
  font-weight: 900;
  height: 42px;
  place-items: center;
  transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.18s ease;
  width: 42px;
}

.icon-action:active {
  transform: scale(0.96);
}

.icon-action span {
  display: block;
  line-height: 1;
}

.refresh-action.is-refreshing {
  background: var(--accent-soft);
  border-color: rgba(10, 167, 137, 0.42);
  color: var(--accent-dark);
}

.refresh-action.is-refreshing span {
  animation: refresh-spin 0.78s linear infinite;
}

.refresh-action.is-done {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  transform: scale(1.04);
}

@keyframes refresh-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.header-actions {
  display: flex;
  gap: 8px;
}

.mobile-main {
  padding: 8px 14px 18px;
}

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

.stack {
  display: grid;
  gap: 12px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 12px;
  padding: 15px;
}

.hero-card {
  gap: 14px;
}

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

.between {
  justify-content: space-between;
}

.top {
  align-items: flex-start;
}

.label {
  color: var(--muted);
  display: block;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2, h3 {
  margin: 0;
}

h2 {
  font-size: 20px;
  line-height: 1.16;
}

h3 {
  font-size: 17px;
  line-height: 1.22;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
  margin: 0;
}

.status-pill, .badge {
  border-radius: 999px;
  display: inline-flex;
  font-size: 12px;
  font-weight: 900;
  line-height: 1;
  padding: 8px 10px;
  white-space: nowrap;
}

.status-pill {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

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

.stats div {
  background: var(--accent-soft);
  border-radius: 14px;
  padding: 11px;
}

.stats b {
  display: block;
  font-size: 24px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.stats span {
  color: var(--muted);
  display: block;
  font-size: 10px;
  font-weight: 900;
  margin-top: 6px;
  text-transform: uppercase;
}

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

.result-summary div {
  background: var(--accent-soft);
  border-radius: 13px;
  padding: 10px;
}

.result-summary b {
  display: block;
  font-size: 20px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.result-summary span {
  color: var(--muted);
  display: block;
  font-size: 10px;
  font-weight: 900;
  margin-top: 5px;
  text-transform: uppercase;
}

.result-filter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  width: 100%;
}

.result-clear {
  justify-self: stretch;
  min-height: 38px;
}

.mobile-diagnostics {
  display: grid;
  gap: 6px;
}

.mobile-diagnostics div {
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  padding: 9px 10px;
}

:root[data-theme="dark"] .mobile-diagnostics div {
  background: #111b24;
}

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

.primary, .secondary, .wide-link {
  border-radius: 13px;
  border: 1px solid var(--line);
  font-weight: 900;
  min-height: 46px;
  padding: 12px 14px;
}

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

.secondary {
  background: #f7fafb;
  color: var(--text);
}

:root[data-theme="dark"] .secondary,
:root[data-theme="dark"] .wide-link,
:root[data-theme="dark"] .expand-result {
  background: #111b24;
}

.wide-link {
  background: #f7fafb;
  color: var(--accent-dark);
  width: 100%;
}

button:disabled {
  opacity: .48;
}

.primary.is-pending,
.secondary.is-pending {
  border-color: rgba(10, 167, 137, 0.48);
  box-shadow: 0 0 0 3px rgba(10, 167, 137, 0.12);
}

.primary.is-pending {
  background: var(--accent-dark);
}

.secondary.is-pending {
  background: var(--accent-soft);
  color: var(--accent-dark);
  opacity: 1;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip, .badge.neutral {
  background: #eef3f5;
  color: var(--muted);
}

.chip {
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  padding: 7px 10px;
}

.badge.good {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.badge.warn {
  background: rgba(159, 107, 18, 0.14);
  color: var(--warn);
}

.badge.error {
  background: rgba(184, 74, 74, 0.12);
  color: var(--danger);
}

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

.field span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

.field input,
.field select,
.field textarea {
  background: #f9fbfc;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  min-height: 44px;
  outline: 0;
  padding: 11px 12px;
  width: 100%;
}

:root[data-theme="dark"] .field input,
:root[data-theme="dark"] .field select,
:root[data-theme="dark"] .field textarea {
  background: #111b24;
}

.field textarea {
  line-height: 1.35;
  overflow: hidden;
  resize: none;
}

#mp-editor-card .field textarea {
  min-height: 64px;
}

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

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

.toggle-list {
  display: grid;
  gap: 8px;
}

.toggle-row,
.run-query-row {
  align-items: center;
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 13px;
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  min-height: 46px;
  padding: 9px 10px 9px 12px;
}

:root[data-theme="dark"] .toggle-row,
:root[data-theme="dark"] .run-query-row {
  background: #111b24;
}

.toggle-row span,
.run-query-row span {
  font-size: 13px;
  font-weight: 900;
}

.run-query-row span {
  display: grid;
  gap: 3px;
}

.run-query-row b {
  font-size: 13px;
  line-height: 1.25;
}

.run-query-row small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.25;
}

.toggle-row input,
.run-query-row input {
  display: none;
}

.toggle-row i,
.run-query-row i {
  background: #c8d2d8;
  border-radius: 999px;
  display: block;
  height: 24px;
  position: relative;
  width: 44px;
}

.toggle-row i::after,
.run-query-row i::after {
  background: #fff;
  border-radius: 50%;
  content: "";
  height: 18px;
  left: 3px;
  position: absolute;
  top: 3px;
  transition: transform .16s ease;
  width: 18px;
}

.toggle-row input:checked + i,
.run-query-row input:checked + i {
  background: var(--accent);
}

.toggle-row input:checked + i::after,
.run-query-row input:checked + i::after {
  transform: translateX(20px);
}

.run-query-list {
  display: grid;
  gap: 8px;
}

.result-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
  padding: 14px;
}

.run-result-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.run-result-card.open {
  border-color: rgba(10, 167, 137, 0.55);
}

.run-result-summary {
  align-items: center;
  background: transparent;
  border: 0;
  color: var(--text);
  display: flex;
  justify-content: space-between;
  min-height: 72px;
  padding: 14px;
  text-align: left;
  width: 100%;
}

.run-result-summary span {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.run-result-summary strong {
  font-size: 15px;
  line-height: 1.2;
}

.run-result-summary small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.run-result-content {
  border-top: 1px solid var(--line);
  display: grid;
  gap: 8px;
  padding: 10px;
}

.result-card:focus {
  outline: 2px solid rgba(10, 167, 137, 0.42);
  outline-offset: 2px;
}

.result-card.highlighted {
  border-color: rgba(10, 167, 137, 0.55);
}

.result-main {
  min-width: 0;
}

.result-card h3 {
  font-size: 16px;
  line-height: 1.25;
  margin: 0;
}

.result-description {
  color: var(--text);
  font-size: 13px;
  line-height: 1.45;
  margin: 7px 0 0;
  overflow-wrap: anywhere;
}

.result-side {
  align-items: flex-end;
  display: flex;
  flex-direction: column;
  gap: 9px;
  text-align: right;
}

.result-side strong {
  font-size: 18px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.result-side a {
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 900;
  text-decoration: none;
  white-space: nowrap;
}

.favorite-toggle {
  align-items: center;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  display: inline-flex;
  font-size: 20px;
  font-weight: 900;
  height: 34px;
  justify-content: center;
  line-height: 1;
  padding: 0;
  width: 38px;
}

.favorite-toggle.active {
  background: rgba(10, 167, 137, 0.12);
  border-color: rgba(10, 167, 137, 0.42);
  color: var(--accent-dark);
}

.meta {
  align-items: center;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.meta span {
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
}

.meta .new {
  background: var(--accent-soft);
  border-radius: 999px;
  color: var(--accent-dark);
  padding: 5px 7px;
}

.meta .best {
  background: rgba(159, 107, 18, 0.14);
  border-radius: 999px;
  color: var(--warn);
  padding: 5px 7px;
}

.meta .check {
  background: rgba(159, 107, 18, 0.14);
  border-radius: 999px;
  color: var(--warn);
  padding: 5px 7px;
}

.reason {
  color: var(--accent-dark);
  display: block;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  margin-top: 8px;
}

.expand-result {
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 11px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  grid-column: 1 / -1;
  min-height: 36px;
}

.result-card.open .expand-result {
  background: var(--accent-soft);
  border-color: rgba(10, 167, 137, 0.35);
  color: var(--accent-dark);
}

.more-list {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.more-item {
  align-items: center;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--text);
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  min-height: 70px;
  padding: 10px 12px;
  text-align: left;
  width: 100%;
}

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

.more-item:active:not(:disabled) {
  background: rgba(10, 167, 137, 0.08);
}

.more-item:disabled {
  opacity: 1;
}

.more-icon {
  background: var(--accent-soft);
  border-radius: 12px;
  display: block;
  height: 34px;
  position: relative;
  width: 34px;
}

.icon-list::before,
.icon-list::after,
.icon-list {
  background-clip: padding-box;
}

.icon-list::before {
  background: var(--accent-dark);
  border-radius: 999px;
  box-shadow: 0 7px 0 var(--accent-dark), 0 14px 0 var(--accent-dark);
  content: "";
  height: 3px;
  left: 9px;
  position: absolute;
  top: 8px;
  width: 16px;
}

.icon-edit::before {
  background: var(--accent-dark);
  border-radius: 999px;
  content: "";
  height: 4px;
  left: 9px;
  position: absolute;
  top: 16px;
  transform: rotate(-38deg);
  width: 17px;
}

.icon-edit::after {
  border-bottom: 4px solid transparent;
  border-left: 6px solid var(--accent-dark);
  border-top: 4px solid transparent;
  content: "";
  left: 21px;
  position: absolute;
  top: 11px;
  transform: rotate(-38deg);
}

.icon-link::before,
.icon-link::after {
  border: 3px solid var(--accent-dark);
  border-radius: 999px;
  content: "";
  height: 9px;
  position: absolute;
  top: 11px;
  width: 13px;
}

.icon-link::before {
  left: 7px;
}

.icon-link::after {
  right: 7px;
}

.more-text {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.more-text strong {
  color: var(--text);
  font-size: 15px;
  font-weight: 900;
  line-height: 1.2;
}

.more-text small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.more-arrow {
  color: var(--accent-dark);
  font-size: 24px;
  font-weight: 700;
  padding-left: 10px;
}

.more-badge {
  background: rgba(128, 145, 160, 0.14);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 900;
  padding: 6px 9px;
}

.muted-item .more-icon {
  background: rgba(128, 145, 160, 0.12);
}

.muted-item .more-icon::before,
.muted-item .more-icon::after {
  border-color: var(--muted);
}

.muted-item .more-text strong,
.muted-item .more-text small {
  color: var(--muted);
}

.prompt-profile-list {
  display: grid;
  gap: 8px;
}

.prompt-profile-item {
  background: #f7fafb;
  border: 1px solid var(--line);
  border-radius: 13px;
  color: var(--text);
  display: grid;
  gap: 4px;
  padding: 11px 12px;
  text-align: left;
  width: 100%;
}

:root[data-theme="dark"] .prompt-profile-item {
  background: #111b24;
}

.prompt-profile-item.active {
  background: var(--accent-soft);
  border-color: rgba(10, 167, 137, 0.36);
}

.prompt-profile-item strong {
  font-size: 14px;
}

.prompt-profile-item small {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
}

.danger-text {
  color: var(--danger);
}

.segmented {
  background: #eef3f5;
  border-radius: 14px;
  display: grid;
  gap: 4px;
  grid-template-columns: 1fr 1fr;
  padding: 4px;
}

:root[data-theme="dark"] .segmented {
  background: #111b24;
  border: 1px solid var(--line);
}

.segmented button {
  background: transparent;
  border: 0;
  border-radius: 11px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
  padding: 10px;
}

.segmented button.active {
  background: #fff;
  color: var(--text);
}

:root[data-theme="dark"] .segmented button.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

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

.segmented.result-filter button {
  min-width: 0;
  padding-left: 6px;
  padding-right: 6px;
  white-space: nowrap;
}

.run-log-card {
  appearance: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: 0 8px 18px rgba(29, 45, 57, 0.05);
  color: var(--text);
  display: grid;
  gap: 0;
  overflow: hidden;
  position: relative;
  width: 100%;
}

.run-log-card.open {
  border-color: rgba(10, 167, 137, 0.36);
  overflow: visible;
}

.run-log-card.open .run-log-header {
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 8px 16px rgba(12, 24, 34, 0.10);
  position: sticky;
  top: 8px;
  z-index: 5;
}

.run-log-header {
  align-items: stretch;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
}

.run-log-summary {
  background: transparent;
  border: 0;
  color: var(--text);
  display: grid;
  min-height: 64px;
  padding: 12px;
  text-align: left;
  width: 100%;
}

.run-log-summary strong {
  display: block;
  font-size: 14px;
  line-height: 1.25;
}

.run-log-summary small {
  color: var(--muted);
  display: block;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.35;
  margin-top: 4px;
}

.delete-log-btn {
  align-items: center;
  background: rgba(184, 74, 74, 0.10);
  border: 1px solid rgba(184, 74, 74, 0.22);
  border-radius: 11px;
  color: var(--danger);
  display: grid;
  font-size: 18px;
  font-weight: 900;
  height: 34px;
  margin: 14px 10px 0 0;
  place-items: center;
  width: 34px;
}

.run-log-full {
  background: #f7fafb;
  border-top: 1px solid var(--line);
  display: grid;
  gap: 0;
  padding: 6px 10px 8px;
}

:root[data-theme="dark"] .run-log-full {
  background: #111b24;
}

.run-log-loading {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  padding: 8px 0;
}

.run-log-line {
  align-items: baseline;
  border-bottom: 1px solid rgba(128, 145, 160, 0.16);
  column-gap: 7px;
  display: grid;
  grid-template-columns: 42px 42px minmax(0, 1fr);
  min-height: 25px;
  padding: 4px 0;
}

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

.run-log-line b {
  color: var(--muted);
  font-size: 10px;
  font-variant-numeric: tabular-nums;
  font-weight: 900;
}

.run-log-line em {
  border-radius: 999px;
  font-size: 9px;
  font-style: normal;
  font-weight: 900;
  line-height: 1;
  padding: 3px 5px;
  text-align: center;
  text-transform: uppercase;
}

.run-log-line em.info {
  background: #eef3f5;
  color: var(--muted);
}

.run-log-line em.ok {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.run-log-line em.warn {
  background: rgba(159, 107, 18, 0.14);
  color: var(--warn);
}

.run-log-line em.error {
  background: rgba(184, 74, 74, 0.12);
  color: var(--danger);
}

:root[data-theme="dark"] .run-log-line em.info {
  background: #23313d;
}

.run-log-line span {
  color: var(--text);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.old-logs-toggle {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--accent-dark);
  font-size: 13px;
  font-weight: 900;
  min-height: 44px;
}

.old-logs {
  display: none;
  gap: 12px;
}

.old-logs.open {
  display: grid;
}

.query-card h3 {
  font-size: 17px;
}

.empty {
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.bottom-nav {
  background: var(--panel);
  border-top: 1px solid var(--line);
  bottom: 0;
  box-shadow: 0 -12px 26px rgba(29, 45, 57, 0.10);
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  left: 0;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  position: fixed;
  right: 0;
  z-index: 20;
}

.bottom-nav button {
  align-items: center;
  background: transparent;
  border: 0;
  border-radius: 14px;
  color: var(--muted);
  display: grid;
  gap: 2px;
  justify-items: center;
  min-height: 44px;
  padding: 2px 0;
}

.bottom-nav button.active {
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.bottom-nav i {
  font-style: normal;
  font-size: 16px;
  font-weight: 900;
}

.bottom-nav span {
  font-size: 10px;
  font-weight: 900;
}

@media (min-width: 760px) {
  .mobile-shell {
    margin: 0 auto;
    max-width: 520px;
  }

  .bottom-nav {
    left: 50%;
    max-width: 520px;
    transform: translateX(-50%);
  }
}
/* Keep schedule fields compact and respect conditional controls. */
.schedule-fields { display: grid; gap: 12px; min-width: 0; margin-block: 16px; }
.schedule-fields [hidden] { display: none !important; }
#sms-settings { display: grid; gap: 14px; min-width: 0; }
#connection-freshness { font-size: 12px; margin: 0 0 12px; }
