:root {
  color-scheme: light dark;
  --bg: #f6f7f4;
  --ink: #17201b;
  --muted: #647067;
  --line: #d7ddd6;
  --panel: #ffffff;
  --accent: #176b5b;
  --accent-ink: #ffffff;
  --secondary: #e8f2ef;
  --danger: #a33131;
  --warn: #8a5a00;
  --success: #146d42;
  --dsl-bg: #f0f4f0;
  --dsl-line: #c5d4c8;
  --field-bg: #fbfcfb;
  --field-bg-invalid: #fdf3f3;
  --pill-x-hover: rgba(0, 0, 0, 0.08);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

.shell,
.options-shell {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.options-shell {
  max-width: 760px;
  margin: 0 auto;
}

.topbar,
.row,
.preset-row,
.checks {
  display: flex;
  gap: 8px;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  margin-bottom: 4px;
}

.header-content {
  display: flex;
  gap: 12px;
  align-items: center;
}

.logo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

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

h1,
h2 {
  margin: 0;
  line-height: 1.15;
}

h1 {
  font-size: 22px;
}

h2 {
  font-size: 15px;
}

/* ── Panel ── */
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.panel-header {
  display: flex;
  align-items: center;
  gap: 6px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: 0;
  border-radius: 0;
  color: var(--ink);
  cursor: pointer;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  min-height: 0;
  text-align: left;
  transition: background 0.12s;
}

.panel-header:hover {
  background: var(--secondary);
}

.panel-header > span:first-child {
  flex: 1;
}

.chevron {
  font-size: 12px;
  transition: transform 0.2s;
  display: inline-block;
}

.panel.collapsed .chevron {
  transform: rotate(-90deg);
}

.panel-body {
  display: grid;
  gap: 10px;
  padding: 0 12px 12px;
}

.panel.collapsed .panel-body {
  display: none;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

input,
textarea,
select {
  width: 100%;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
  color: var(--ink);
  font: inherit;
}

textarea {
  resize: vertical;
}

button {
  min-height: 32px;
  padding: 7px 10px;
  border: 0;
  border-radius: 6px;
  background: var(--accent);
  color: var(--accent-ink);
  cursor: pointer;
  font: inherit;
  font-weight: 700;
}

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

.secondary,
.ghost,
.preset,
.button-grid button {
  background: var(--secondary);
  color: var(--ink);
}

.ghost {
  border: 1px solid var(--line);
}

.danger {
  background: var(--danger);
  color: #fff;
}

.tiny {
  min-height: 0;
  padding: 3px 8px;
  font-size: 11px;
  font-weight: 600;
}

.grid.two {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.checks {
  flex-wrap: wrap;
}

.checks label {
  display: flex;
  align-items: center;
  color: var(--ink);
}

.checks input {
  width: auto;
}

.preset-row {
  flex-wrap: wrap;
}

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

.status,
.summary {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.summary {
  display: grid;
  gap: 4px;
  overflow-wrap: anywhere;
}

.screenshot {
  display: none;
  width: 100%;
  max-height: 260px;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #eef1ee;
}

.screenshot.has-image {
  display: block;
}

/* ── Content utility config editor ── */
.config-editor {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  background: var(--field-bg);
  min-height: 180px;
  resize: vertical;
}

.config-editor.invalid {
  border-color: var(--danger);
  background: var(--field-bg-invalid);
}

.config-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -2px;
}

.config-help {
  margin-top: 2px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
}

.config-help summary {
  padding: 8px 10px;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  list-style: none;
}

.config-help summary::-webkit-details-marker { display: none; }

.config-help[open] summary {
  border-bottom: 1px solid var(--line);
}

.config-help-body {
  padding: 8px 12px 10px;
  color: var(--ink);
  font-size: 12px;
  line-height: 1.5;
}

.config-help-body code {
  padding: 1px 4px;
  border-radius: 3px;
  background: var(--secondary);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11px;
}

.config-help-body ul {
  margin: 4px 0 0;
  padding-left: 18px;
}

.muted-inline {
  color: var(--muted);
  font-weight: 400;
  font-size: 11px;
}

.hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
}

.mono {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}

.status.mono {
  font-size: 11px;
}

#configStatus.error { color: var(--danger); }
#configStatus.ok    { color: var(--success); }

/* ── Log actions row in panel header ── */
.log-actions {
  display: flex;
  gap: 4px;
  align-items: center;
}

.log-actions button {
  pointer-events: all;
}

/* ── Log ── */
.log {
  display: grid;
  gap: 8px;
  max-height: 400px;
  overflow: auto;
  font-size: 12px;
}

.log-entry {
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
}

.log-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 4px;
  color: #718078;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.log-badge {
  padding: 1px 5px;
  border-radius: 3px;
  background: #e6eae6;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.log-entry.error .log-badge { background: #f0d4d4; color: var(--danger); }
.log-entry.warn  .log-badge { background: #f0e2c2; color: var(--warn);   }
.log-entry.success .log-badge { background: #d4ead8; color: var(--success); }

.log-title {
  font-weight: 700;
  font-size: 13px;
  margin-bottom: 2px;
}

.log-message {
  color: var(--muted);
  margin-bottom: 0;
}

/* Human-readable DSL / action list */
.log-actions-list {
  margin: 6px 0 0;
  padding: 6px 8px;
  border-left: 3px solid var(--accent);
  background: var(--dsl-bg);
  border-radius: 0 4px 4px 0;
  list-style: none;
  display: grid;
  gap: 3px;
}

.log-actions-list li {
  font-size: 11px;
  color: var(--ink);
}

.log-actions-list li::before {
  content: "→ ";
  color: var(--accent);
  font-weight: 700;
}

/* Expandable raw JSON toggle */
.log-raw-toggle {
  display: inline-block;
  margin-top: 6px;
  font-size: 10px;
  color: var(--muted);
  cursor: pointer;
  text-decoration: underline dotted;
  background: none;
  border: none;
  padding: 0;
  font-weight: 400;
  min-height: 0;
}

.log-raw {
  display: none;
  margin: 4px 0 0;
  max-height: 160px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 10.5px;
  background: var(--dsl-bg);
  border: 1px solid var(--dsl-line);
  border-radius: 4px;
  padding: 6px 8px;
}

.log-raw.visible {
  display: block;
}

.log-entry.error {
  border-color: #e3b4b4;
  color: var(--danger);
}

.log-entry.warn {
  border-color: #ead097;
  color: var(--warn);
}

.log-entry.platform-limit {
  border-color: #b7c7d9;
  color: #34536f;
  background: #f4f8fb;
}

/* ── Output box ── */
.output-box {
  min-height: 80px;
  padding: 10px 12px;
  background: var(--dsl-bg);
  border: 1px solid var(--dsl-line);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.output-placeholder {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

/* ── Skills panel ── */
.input-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
  margin-bottom: 2px;
}

.skill-desc {
  display: block;
  color: var(--muted);
  font-size: 11px;
  line-height: 1.4;
  margin-bottom: 4px;
}

.skill-history {
  max-height: 260px;
  overflow: auto;
  display: grid;
  gap: 6px;
}

.skill-exec-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  font-size: 11px;
  cursor: pointer;
  transition: background 0.12s;
}

.skill-exec-item:hover {
  background: var(--secondary);
}

.skill-exec-item .exec-status {
  padding: 1px 5px;
  border-radius: 3px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.skill-exec-item .exec-status.success { background: #d4ead8; color: var(--success); }
.skill-exec-item .exec-status.error { background: #f0d4d4; color: var(--danger); }
.skill-exec-item .exec-status.timeout { background: #f0e2c2; color: var(--warn); }

.output-command {
  margin: 0 0 8px;
  padding: 6px 8px;
  background: var(--secondary);
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
}

.output-text {
  margin: 0;
  white-space: pre-wrap;
}

/* ── System status ── */
.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.status-card {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
}

.status-label {
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.status-card strong {
  overflow-wrap: anywhere;
  font-size: 12px;
}

.status-card small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.system-details {
  padding: 8px;
  border: 1px solid var(--dsl-line);
  border-radius: 6px;
  background: var(--dsl-bg);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.45;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

/* ── Developer mode visibility ── */
body:not(.dev-mode) .dev-only {
  display: none !important;
}

/* ── Source-row stats preview ── */
.source-stats {
  margin: 6px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.source-stats strong {
  color: var(--ink);
  font-weight: 600;
}

/* ── Run result link (rendered in Last result panel) ── */
.run-result-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0 0 8px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
  font-size: 13px;
}

.run-result-link a {
  color: var(--accent, #146d42);
  text-decoration: none;
  font-weight: 600;
}

.run-result-link a:hover {
  text-decoration: underline;
}

/* ── Access check feedback ── */
.access-row {
  align-items: center;
  gap: 8px;
}

.access-check-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-weight: 700;
  font-size: 13px;
  line-height: 1;
}

.welcome-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--secondary);
  padding: 12px 14px;
  display: grid;
  gap: 6px;
}

.welcome-card h2 {
  margin: 0;
  font-size: 14px;
  color: var(--accent);
}

.welcome-card p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.welcome-card ul {
  margin: 0;
  padding-left: 18px;
  font-size: 12px;
  color: var(--muted);
  display: grid;
  gap: 4px;
}

.welcome-card ul li {
  line-height: 1.4;
}

.service-account-email {
  display: inline-block;
  margin-top: 2px;
  padding: 1px 6px;
  border-radius: 4px;
  background: var(--field-bg);
  border: 1px solid var(--line);
  font-size: 11px;
  overflow-wrap: anywhere;
}

.service-account-email.error {
  color: var(--danger);
  background: var(--field-bg-invalid);
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 4px 4px 10px;
  border-radius: 999px;
  background: var(--secondary);
  border: 1px solid var(--line);
  max-width: 100%;
  align-self: flex-start;
  font-size: 12px;
}

.status-pill-text {
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 240px;
}

a.status-pill-text {
  color: var(--accent);
}

a.status-pill-text:hover {
  text-decoration: underline;
}

.pill-x {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  padding: 0;
}

.pill-x:hover {
  background: var(--pill-x-hover);
  color: var(--ink);
}

.access-dialog {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 18px 20px;
  max-width: 380px;
  background: var(--bg);
  color: var(--ink);
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.access-dialog::backdrop {
  background: rgba(0, 0, 0, 0.35);
}

.access-dialog h2 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--danger);
}

.access-dialog-message {
  margin: 0 0 12px;
  font-size: 13px;
  line-height: 1.5;
  color: var(--ink);
}

.access-dialog-suggestion {
  margin: 0 0 6px;
  font-size: 12px;
  color: var(--muted);
}

.access-dialog-email-row {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 14px;
}

.access-dialog-email {
  flex: 1;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--field-bg);
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12px;
  overflow-wrap: anywhere;
}

.access-dialog-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 520px) {
  .status-grid {
    grid-template-columns: 1fr;
  }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #181918;
    --ink: #f0f2f0;
    --muted: #9ba6a0;
    --line: #3c443f;
    --panel: #1e211f;
    --accent: #2ba990;
    --accent-ink: #000000;
    --secondary: #27302c;
    --danger: #d94a4a;
    --warn: #c9880e;
    --success: #3fc278;
    --dsl-bg: #212824;
    --dsl-line: #374240;
    --field-bg: #242926;
    --field-bg-invalid: #3a2222;
    --pill-x-hover: rgba(255, 255, 255, 0.10);
  }

  .screenshot {
    background: #141715;
  }

  .log-meta {
    color: #a0a8a3;
  }

  .log-badge {
    background: #2e3730;
  }

  .log-entry.error { border-color: #8c3b3b; }
  .log-entry.warn  { border-color: #8a6c31; }

  .log-entry.platform-limit {
    border-color: #3b4e63;
    background: #1b232a;
  }

  .panel-header:hover {
    background: #232826;
  }
}

.copyright-footer {
  text-align: center;
  padding: 12px 8px 16px;
  color: var(--muted);
  font-size: 11px;
  border-top: 1px solid var(--line);
  margin-top: 16px;
}
