:root {
  color-scheme: light;
  --bg: #f4f6fb;
  --surface: rgba(255, 255, 255, .96);
  --surface-solid: #ffffff;
  --surface-muted: #f8f9ff;
  --surface-purple: #f1f0ff;
  --border: #e4e7ec;
  --border-strong: #cfd4dc;
  --text: #111827;
  --heading: #24205d;
  --muted: #667085;
  --muted-soft: #98a2b3;
  --primary: #4f46e5;
  --primary-hover: #4338ca;
  --primary-light: #eef2ff;
  --primary-border: #c7d2fe;
  --accent: #f59e0b;
  --success: #16825d;
  --warning: #b45309;
  --danger: #d92d20;
  --radius-sm: 10px;
  --radius: 16px;
  --radius-lg: 20px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .04), 0 10px 28px rgba(79, 70, 229, .045);
  --shadow-floating: 0 24px 80px rgba(16, 24, 40, .18);
  --content-width: 1480px;
  --page-gutter: clamp(16px, 3vw, 44px);
}

* { box-sizing: border-box; }

html {
  min-width: 320px;
  min-height: 100%;
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 0 0, rgba(79, 70, 229, .14), transparent 32%),
    radial-gradient(circle at 100% 0, rgba(245, 158, 11, .13), transparent 30%),
    var(--bg);
  background-attachment: fixed;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  overflow-x: hidden;
}

#dashboardApp { min-height: 100vh; min-height: 100dvh; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; -webkit-tap-highlight-color: transparent; }
button:disabled { cursor: not-allowed; opacity: .55; filter: grayscale(.15); }

input, textarea, select {
  width: 100%;
  min-width: 0;
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
  transition: border-color .18s ease, box-shadow .18s ease, background-color .18s ease;
}

input, select { min-height: 44px; padding: 9px 12px; }
textarea { min-height: 130px; padding: 11px 12px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--muted-soft); opacity: 1; }

input:hover, textarea:hover, select:hover { border-color: #b9c0cc; }
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .12);
}

button:focus-visible {
  outline: 3px solid rgba(79, 70, 229, .28);
  outline-offset: 3px;
}

::selection { color: #fff; background: var(--primary); }
h1, h2, h3, p { margin-top: 0; }
h1, h2, h3 { color: var(--heading); letter-spacing: -.02em; }
.hidden { display: none !important; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* License */
.license-pending { overflow: hidden; }
.license-pending #dashboardApp { visibility: hidden; }
.license-gate {
  position: fixed;
  inset: 0;
  z-index: 1000;
  padding: clamp(16px, 4vw, 48px);
  display: grid;
  place-items: center;
  background:
    radial-gradient(circle at 4% 5%, rgba(79, 70, 229, .2), transparent 34%),
    radial-gradient(circle at 96% 7%, rgba(245, 158, 11, .17), transparent 32%),
    var(--bg);
}
.license-authorized .license-gate { display: none; }
.license-card {
  width: min(720px, 100%);
  padding: clamp(28px, 5vw, 50px);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-floating);
  text-align: center;
}
.license-card h1 { margin-bottom: 12px; font-size: clamp(27px, 3.8vw, 36px); line-height: 1.18; }
.license-card label {
  display: block;
  margin: 28px 0 9px;
  color: #475467;
  font-size: 14px;
  font-weight: 800;
  letter-spacing: .035em;
  text-align: left;
  text-transform: uppercase;
}
.license-mark {
  width: 78px;
  height: 78px;
  margin: 0 auto 20px;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 22px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  box-shadow: 0 16px 28px rgba(79, 70, 229, .24);
  font-size: 16px;
  font-weight: 900;
  letter-spacing: .1em;
}
.license-instruction { margin: 0; color: var(--muted); font-size: 16px; }
.license-instruction strong { color: var(--primary); white-space: nowrap; }
.license-key-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 11px; }
.license-key-row input {
  min-height: 54px;
  color: var(--primary);
  background: var(--primary-light);
  border-color: var(--primary-border);
  font-family: Consolas, "Courier New", monospace;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .035em;
}
.license-key-row button { min-width: 126px; white-space: nowrap; }
.license-status { margin: 17px 0 0; color: var(--muted); font-size: 15px; }
.license-status[data-state="error"] { color: var(--danger); }
.license-status[data-state="waiting"] { color: var(--warning); }
.license-status[data-state="ok"] { color: var(--success); }
.license-retry-button { margin-top: 16px; }

/* Header */
.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid rgba(228, 231, 236, .9);
  background: rgba(255, 255, 255, .88);
  box-shadow: 0 1px 0 rgba(16, 24, 40, .02);
  backdrop-filter: blur(18px) saturate(150%);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
}
.header-inner {
  width: min(var(--content-width), calc(100% - (var(--page-gutter) * 2)));
  margin: 0 auto;
  min-height: 64px;
  padding: 9px 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: nowrap;
  gap: 16px;
}
.app-brand { flex: 0 0 auto; display: flex; align-items: center; gap: 11px; }
.brand-logo {
  width: 42px;
  height: 42px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  box-shadow: 0 8px 16px rgba(79, 70, 229, .18);
}
.brand-logo-image { width: 32px; height: 32px; display: block; border-radius: 9px; object-fit: contain; }
.brand-title {
  color: var(--heading);
  font-size: 16px;
  font-weight: 850;
  letter-spacing: -.015em;
  line-height: 1.15;
  white-space: nowrap;
}
.header-nav {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: nowrap;
  gap: 6px;
  overflow-x: auto;
  scrollbar-width: thin;
}
.nav-button, .secondary-button {
  min-height: 40px;
  padding: 8px 12px;
  color: #344054;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255, 255, 255, .92);
  box-shadow: 0 1px 2px rgba(16, 24, 40, .025);
  font-size: 13px;
  font-weight: 700;
  transition: color .18s ease, border-color .18s ease, background-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.nav-button { min-height: 37px; padding: 7px 10px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; gap: 5px; white-space: nowrap; font-size: 12.5px; }
.nav-button:hover, .nav-button.is-active, .secondary-button:hover {
  color: var(--primary);
  border-color: var(--primary-border);
  background: var(--primary-light);
  box-shadow: 0 8px 18px rgba(79, 70, 229, .09);
  transform: translateY(-1px);
}
.nav-button.is-active { box-shadow: inset 0 0 0 1px rgba(79, 70, 229, .08); }

/* Dashboard */
.app-main {
  width: min(var(--content-width), calc(100% - (var(--page-gutter) * 2)));
  margin: 0 auto;
  padding: clamp(20px, 3vw, 36px) 0 clamp(34px, 5vw, 62px);
}
.status-card {
  padding: clamp(18px, 1.8vw, 26px);
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(420px, .92fr);
  gap: clamp(18px, 2vw, 28px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.status-overview, .status-console { min-width: 0; }
.status-overview { padding: clamp(2px, .6vw, 10px); }
.status-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }
.status-title-group { min-width: 0; display: flex; align-items: center; gap: 11px; }
.status-icon {
  width: 46px;
  height: 46px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  color: #fff;
  border-radius: 13px;
  background: linear-gradient(135deg, var(--primary), #7c3aed);
  box-shadow: 0 14px 26px rgba(79, 70, 229, .2);
  font-size: 21px;
}
.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
}
.status-heading h1 { margin: 0; font-size: clamp(23px, 2vw, 30px); line-height: 1.15; }
.terminal-state-badge {
  flex: 0 0 auto;
  padding: 7px 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface-muted);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: .045em;
}
.terminal-state-badge.is-ready, .terminal-state-badge.is-ok { color: var(--success); border-color: #a6dfc8; background: #ecfdf3; }
.terminal-state-badge.is-running { color: var(--primary); border-color: var(--primary-border); background: var(--primary-light); }
.terminal-state-badge.is-wait, .terminal-state-badge.is-next, .terminal-state-badge.is-stop { color: var(--warning); border-color: #fed7aa; background: #fff7ed; }
.terminal-state-badge.is-error { color: var(--danger); border-color: #fecdca; background: #fef3f2; }
.current-process {
  margin-top: 22px;
  padding: 16px;
  border: 1px solid var(--primary-border);
  border-radius: 15px;
  background: linear-gradient(135deg, var(--surface-purple), #f8f8ff);
}
.current-process strong { display: block; color: var(--heading); font-size: 17px; line-height: 1.35; }
.current-process p { margin: 6px 0 0; color: var(--muted); font-size: 13px; }
.process-meta, .status-counts {
  margin-top: 11px;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.process-meta span, .status-counts span, .process-countdown {
  min-width: 0;
  padding: 10px 11px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  font-size: 12.5px;
}
.process-meta span, .status-counts span { display: flex; flex-direction: column; gap: 2px; }
.process-meta strong, .status-counts strong, .status-counts time { color: var(--heading); font-size: 14px; }
.status-counts span:first-child { border-color: #b7e6d1; background: #f2fcf7; }
.status-counts span:nth-child(2) { border-color: #fed7aa; background: #fffbf5; }
.status-counts span:nth-child(3) { border-color: #fecdca; background: #fff7f6; }
.process-target {
  margin-top: 11px;
  padding: 11px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
}
.process-target span { display: block; color: var(--muted); font-size: 12px; font-weight: 800; letter-spacing: .055em; }
.process-target strong { display: block; margin-top: 4px; color: var(--heading); font-size: 13px; overflow-wrap: anywhere; }
.process-countdown { margin-top: 14px; display: flex; align-items: center; justify-content: space-between; }
.process-countdown time { color: var(--primary); font-size: 17px; font-weight: 900; }
.progress-row { margin-top: 15px; display: flex; align-items: center; gap: 12px; }
.progress-track { height: 11px; flex: 1; overflow: hidden; border-radius: 999px; background: #e9eaf5; box-shadow: inset 0 1px 2px rgba(16, 24, 40, .06); }
.progress-track i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--primary), #7c3aed);
  box-shadow: 0 0 14px rgba(79, 70, 229, .42);
  transition: width .25s ease;
}
.progress-row > strong { width: 48px; color: var(--primary); font-size: 15px; text-align: right; }
.status-console {
  padding: clamp(18px, 1.8vw, 26px);
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 20px;
  background: linear-gradient(145deg, #171c32, #111827);
  box-shadow: 0 18px 44px rgba(17, 24, 39, .18);
}
.status-console-heading { display: flex; align-items: center; justify-content: space-between; gap: 16px; color: #e8e9ff; }
.status-console-heading > div { display: flex; align-items: center; gap: 9px; }
.status-console-heading > div span { color: #43d69c; font-size: 12px; text-shadow: 0 0 12px rgba(67, 214, 156, .72); }
.status-console-heading strong { font-size: 14px; }
.status-console-heading > span { color: #a5b4fc; font-size: 11px; font-weight: 900; letter-spacing: .12em; }
.terminal-log {
  min-height: 290px;
  max-height: 46vh;
  margin-top: 13px;
  padding: 13px;
  flex: 1 1 auto;
  overflow-y: auto;
  color: #dce6f5;
  border: 1px solid rgba(255, 255, 255, .07);
  border-radius: 13px;
  background: rgba(6, 12, 27, .68);
  scrollbar-color: #4f5775 transparent;
  font-family: Consolas, "Courier New", monospace;
  font-size: 12px;
  line-height: 1.55;
}
.terminal-line { display: grid; grid-template-columns: 16px minmax(0, 1fr) auto; gap: 9px; padding: 6px 0; }
.terminal-line em { font-style: normal; overflow-wrap: anywhere; }
.terminal-line b { color: #98a2b3; font-size: 11px; }
.terminal-line.is-ok b { color: #65e0aa; }
.terminal-line.is-running b { color: #9ca8ff; }
.terminal-line.is-warn b { color: #ffd48a; }
.terminal-line.is-error b { color: #ff9e98; }
.primary-button, .danger-button {
  min-height: 43px;
  padding: 9px 15px;
  color: #fff;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: linear-gradient(135deg, var(--primary), #5b54ee);
  box-shadow: 0 10px 18px rgba(79, 70, 229, .18);
  font-weight: 800;
  transition: background-color .18s ease, box-shadow .18s ease, transform .18s ease, filter .18s ease;
}
.primary-button:hover { background: linear-gradient(135deg, var(--primary-hover), #5145cd); box-shadow: 0 14px 24px rgba(79, 70, 229, .24); transform: translateY(-1px); }
.primary-button:active, .danger-button:active { transform: translateY(0); }
.danger-button { background: var(--danger); box-shadow: 0 10px 18px rgba(217, 45, 32, .16); }
.danger-button:hover { background: #b42318; box-shadow: 0 14px 24px rgba(217, 45, 32, .22); }
.auto-run-actions { margin-top: 14px; display: flex; align-items: stretch; gap: 9px; }
.auto-run-button { min-height: 46px; flex: 1 1 190px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-size: 13px; }
.status-console .secondary-button { color: #e7e9ff; border-color: rgba(199, 210, 254, .25); background: rgba(255, 255, 255, .07); }
.status-console .secondary-button:hover { color: #fff; border-color: rgba(199, 210, 254, .48); background: rgba(99, 102, 241, .18); }
.auto-stop-button { min-height: 46px; flex: 0 0 auto; font-size: 13px; }
.small-button { width: auto; min-height: 35px; padding: 6px 10px; font-size: 12px; }

/* Dashboard pages */
.dashboard-page {
  width: min(var(--content-width), calc(100% - (var(--page-gutter) * 2)));
  margin: 0 auto;
  padding: clamp(20px, 3vw, 36px) 0 clamp(34px, 5vw, 62px);
  display: none;
}
.dashboard-page.show { display: block; animation: page-in .18s ease-out; }
.dashboard-home[hidden] { display: none !important; }
.page-card {
  width: 100%;
  margin: 0 auto;
  overflow: visible;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}
.wide-page { width: 100%; }
.settings-page { width: 100%; }
.prompt-editor-page { width: 100%; }
.page-heading {
  min-height: 58px;
  padding: 0 0 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  border: 0;
  border-radius: 0;
  background: transparent;
}
.page-heading > div { min-width: 0; }
.page-heading h2 { margin: 0; font-size: clamp(19px, 1.7vw, 23px); line-height: 1.2; }
.page-heading p { margin: 4px 0 0; color: var(--muted); font-size: 12.5px; }
.page-back-button { flex: 0 0 auto; white-space: nowrap; }
.page-content { padding: 0; }
#apiSettingsModal .page-content,
#templateModal .page-content {
  padding: clamp(16px, 1.8vw, 23px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.page-actions { display: flex; justify-content: flex-end; padding-top: 4px; }

/* Prompt editor */
.prompt-editor-content { display: grid; gap: 15px; }
.prompt-editor-notice {
  margin: 0;
  padding: 12px 14px;
  color: #3730a3;
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  font-size: 13px;
}
.prompt-editor-card { margin: 0 !important; }
.prompt-editor-heading { margin-bottom: 13px; display: flex; align-items: flex-start; justify-content: space-between; gap: 14px; }
.prompt-editor-heading strong { display: block; color: var(--heading); font-size: 14px; }
.prompt-editor-heading span { display: block; margin-top: 3px; color: var(--muted); font-size: 12.5px; }
.prompt-editor-heading button { flex: 0 0 auto; }
.prompt-textarea { min-height: 260px; font-family: Consolas, "Courier New", monospace; font-size: 13px; line-height: 1.6; tab-size: 2; }
.prompt-textarea-tall { min-height: 440px; }
.prompt-editor-card code { color: #4338ca; font-family: Consolas, "Courier New", monospace; }
.prompt-editor-actions {
  position: sticky;
  bottom: 0;
  z-index: 2;
  margin: 0;
  padding: 12px 0 0;
  display: flex;
  justify-content: flex-end;
  gap: 11px;
  border-top: 0;
  background: transparent;
}

/* Workspace and forms */
.workspace-panel { display: none; }
.workspace-panel.is-workspace-active { display: block; }
.records-grid.is-workspace-active { display: grid; }
.panel {
  min-width: 0;
  padding: clamp(15px, 1.6vw, 21px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}
.panel + .panel { margin-top: 15px; }
.panel h3 { margin-bottom: 14px; font-size: 16px; }
.panel-toolbar { min-height: 40px; margin-bottom: 13px; display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.panel-toolbar > div { display: flex; align-items: center; gap: 10px; }
.counter-badge { padding: 6px 11px; color: var(--primary); border: 1px solid var(--primary-border); border-radius: 999px; background: var(--primary-light); font-size: 13px; font-weight: 800; }
.two-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: clamp(18px, 2vw, 28px); }
.input-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.daily-comment-limit-setting { grid-column: 1 / -1; }
#dailyCommentLimitStatus[data-state="reached"] { color: var(--danger); font-weight: 800; }
.form-stack { display: grid; gap: 15px; }
.form-group { min-width: 0; }
.form-group label { display: block; margin-bottom: 7px; color: #344054; font-size: 13px; font-weight: 800; }
.label-row, .field-status { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.label-row label { margin-bottom: 8px; }
.hint, .counter, .link-preview { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.counter { flex: 0 0 auto; white-space: nowrap; }
.link-preview { min-width: 0; overflow-wrap: anywhere; }
.link-preview.warn { color: var(--warning); }
.link-preview.ok { color: var(--success); }
.output-panel #output {
  min-height: 170px;
  padding: 16px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-muted);
  font-size: 14px;
}
.output-panel #output.loading { color: var(--primary); }
.output-panel #output.error { color: var(--danger); }

/* Comment composer tabs */
.composer-tabs {
  width: fit-content;
  max-width: 100%;
  padding: 5px;
  display: grid;
  grid-template-columns: repeat(2, minmax(150px, 1fr));
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface-muted);
}
.composer-tab {
  min-height: 44px;
  padding: 9px 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: var(--muted);
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  font-weight: 800;
  transition: color .18s ease, border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.composer-tab:hover { color: var(--primary); background: #fff; }
.composer-tab.is-active {
  color: var(--primary);
  border-color: var(--primary-border);
  background: #fff;
  box-shadow: 0 5px 14px rgba(79, 70, 229, .1);
}
.composer-tab-panel { padding-top: 22px; }
.composer-tab-panel[hidden] { display: none; }
.manual-auto-comment-layout {
  width: min(100%, 920px);
  display: grid;
  gap: 16px;
}
#manualCommentInput { min-height: 260px; }
.manual-random-format,
.manual-auto-comment-note {
  min-width: 0;
  padding: 14px 15px;
  display: grid;
  gap: 5px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.manual-random-format {
  color: var(--text);
  background: var(--surface-muted);
}
.manual-random-format strong,
.manual-auto-comment-note strong { color: var(--heading); font-size: 14px; }
.manual-random-format span,
.manual-random-format small,
.manual-auto-comment-note span { color: var(--muted); font-size: 12px; line-height: 1.5; }
.manual-random-format code {
  width: fit-content;
  max-width: 100%;
  padding: 8px 10px;
  overflow-wrap: anywhere;
  color: var(--primary);
  border: 1px solid var(--primary-border);
  border-radius: 8px;
  background: #fff;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  font-weight: 700;
}
.manual-auto-comment-note {
  color: var(--muted);
  border-color: var(--primary-border);
  background: var(--primary-light);
}
.manual-auto-comment-note strong { color: var(--success); }
.manual-comment-status { margin: 0; color: var(--muted); font-size: 13px; }
.manual-comment-status[data-state="working"] { color: var(--primary); font-weight: 700; }
.manual-comment-status[data-state="success"] { color: var(--success); font-weight: 700; }
.manual-comment-status[data-state="warning"] { color: var(--warning); font-weight: 700; }
.manual-comment-status[data-state="error"] { color: var(--danger); font-weight: 700; }
.records-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.records-grid .panel { margin: 0; }
.records-grid textarea { min-height: 310px; }
.record-success { border-top: 4px solid var(--success); }
.record-removed { border-top: 4px solid var(--warning); }
.record-error { border-top: 4px solid var(--danger); }
.record-link-count { flex: 0 0 auto; color: var(--muted); font-size: 13px; white-space: nowrap; }
.record-link-list {
  min-height: 310px;
  max-height: 310px;
  padding: 5px 8px;
  overflow-y: auto;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  scrollbar-gutter: stable;
}
.record-link-list:focus-visible, .record-link-view:focus-visible {
  outline: 3px solid rgba(79, 70, 229, .28);
  outline-offset: 3px;
}
.record-link-item {
  min-width: 0;
  padding: 10px 4px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
  gap: 10px;
}
.record-link-item + .record-link-item { border-top: 1px solid var(--border); }
.record-link-content { min-width: 0; display: grid; gap: 4px; }
.record-link-url { min-width: 0; color: var(--text); overflow-wrap: anywhere; word-break: break-word; }
.record-link-reason { color: var(--danger); font-size: 12px; }
.record-link-view {
  min-width: 52px;
  min-height: 33px;
  padding: 5px 9px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  white-space: nowrap;
}
.record-link-empty {
  min-height: 296px;
  margin: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}
.record-summary { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 11px; }
.record-summary span { padding: 10px 13px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-solid); }
.tpl-list { display: grid; gap: 11px; }
.tpl-empty { padding: 28px; color: var(--muted); border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-muted); text-align: center; }
.tpl-item {
  min-width: 0;
  padding: 14px;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) auto;
  align-items: center;
  gap: 13px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-solid);
  transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.tpl-item:hover, .tpl-item.active { border-color: var(--primary-border); background: #fafaff; box-shadow: 0 8px 20px rgba(79, 70, 229, .07); }
.tpl-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 11px; background: var(--primary-light); font-size: 19px; }
.tpl-name { color: var(--heading); font-weight: 800; }
.tpl-meta { color: var(--muted); font-size: 13px; }
.tpl-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 7px; }

/* Settings */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.settings-grid .panel { margin: 0; }
.settings-wide { grid-column: 1 / -1; }
.selling-filter-setting {
  margin-top: 18px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}
.setting-switch {
  min-width: 0;
  padding: 14px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  color: var(--text);
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  cursor: pointer;
  transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.setting-switch:hover {
  border-color: #a5b4fc;
  background: #e9edff;
}
.setting-switch-copy { min-width: 0; }
.setting-switch-copy strong { display: block; color: var(--heading); font-size: 14px; }
.setting-switch-copy small { display: block; margin-top: 3px; color: var(--muted); font-size: 12px; line-height: 1.45; }
.setting-switch-action {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 9px;
}
.setting-switch-state {
  min-width: 67px;
  color: var(--success);
  font-size: 12px;
  font-weight: 850;
  text-align: right;
  white-space: nowrap;
}
.setting-switch-state[data-state="off"] { color: var(--danger); }
.setting-switch-control {
  position: relative;
  width: 48px;
  height: 26px;
  flex: 0 0 48px;
}
.setting-switch-control input {
  position: absolute;
  inset: 0;
  z-index: 1;
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  margin: 0;
  padding: 0;
  opacity: 0;
  cursor: pointer;
}
.setting-switch-track {
  position: absolute;
  inset: 0;
  border: 1px solid #b6bdc9;
  border-radius: 999px;
  background: #cfd4dc;
  box-shadow: inset 0 1px 2px rgba(16, 24, 40, .12);
  transition: border-color .18s ease, background-color .18s ease, box-shadow .18s ease;
}
.setting-switch-track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(16, 24, 40, .28);
  transition: transform .18s ease;
}
.setting-switch-control input:checked + .setting-switch-track {
  border-color: var(--primary);
  background: var(--primary);
}
.setting-switch-control input:checked + .setting-switch-track::after { transform: translateX(22px); }
.setting-switch-control input:focus-visible + .setting-switch-track {
  box-shadow: 0 0 0 4px rgba(79, 70, 229, .18);
}
.auth-bar {
  padding: 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  border: 1px solid var(--primary-border);
  border-radius: var(--radius-sm);
  background: var(--primary-light);
}
.auth-bar > span { min-width: 44px; padding: 9px; color: var(--primary); border-radius: 10px; background: #fff; text-align: center; font-weight: 900; }
.auth-status { font-weight: 700; }
.auth-status.ok { color: var(--success); }
.secret-input-row { display: flex; align-items: flex-start; gap: 10px; }
.secret-input-row input, .secret-input-row textarea { min-width: 0; flex: 1 1 auto; }
.secret-input-row button { flex: 0 0 auto; white-space: nowrap; }
textarea.masked-api-keys { -webkit-text-security: disc; }
.notice { display: none; padding: 13px 14px; color: var(--danger); border: 1px solid #fecdca; border-radius: var(--radius-sm); background: #fef3f2; }
.notice.show { display: flex; flex-direction: column; }

/* Toasts */
.toast-host { position: fixed; right: clamp(14px, 2vw, 26px); bottom: clamp(14px, 2vw, 26px); z-index: 200; display: grid; gap: 10px; }
.toast { max-width: min(420px, calc(100vw - 28px)); padding: 13px 16px; color: #fff; border-radius: var(--radius-sm); background: var(--success); box-shadow: var(--shadow-floating); font-weight: 700; }
.toast.warning { background: var(--warning); }
.toast.error { background: var(--danger); }

@keyframes page-in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: translateY(0); } }

/* Large displays */
@media (min-width: 1800px) {
  :root { --content-width: 1560px; }
  body { font-size: 14px; }
  .header-inner { min-height: 70px; }
  .nav-button { min-height: 38px; padding-inline: 11px; }
  .app-main, .dashboard-page { padding-top: 32px; padding-bottom: 54px; }
  .status-card {
    padding: 28px;
    grid-template-columns: minmax(0, 1.08fr) minmax(460px, .92fr);
    gap: 30px;
  }
  .status-overview { padding: 6px; }
  .status-heading h1 { font-size: 29px; }
  .status-icon { width: 47px; height: 47px; border-radius: 13px; font-size: 21px; }
  .current-process { margin-top: 25px; padding: 17px; }
  .current-process strong { font-size: 17px; }
  .process-meta, .status-counts { margin-top: 12px; gap: 9px; }
  .process-meta span, .status-counts span, .process-countdown { padding: 10px 12px; }
  .process-target, .process-countdown { margin-top: 12px; }
  .process-target { padding: 12px 13px; }
  .progress-row { margin-top: 17px; }
  .status-console { padding: 22px; border-radius: 18px; }
  .terminal-log { min-height: 320px; margin-top: 13px; padding: 13px; font-size: 12px; }
  .auto-run-actions { margin-top: 15px; }
  .auto-run-button, .auto-stop-button { min-height: 46px; }
  input, select { min-height: 45px; }
  textarea { min-height: 135px; }
}

/* Laptop and tablet landscape */
@media (max-width: 1390px) {
  .header-inner { padding: 9px 0; align-items: center; flex-wrap: nowrap; }
  .header-nav { width: auto; justify-content: flex-end; }
  .status-card { grid-template-columns: minmax(0, 1fr) minmax(390px, .82fr); }
  .process-meta, .status-counts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 1080px) {
  .header-nav { justify-content: flex-start; }
  .status-card { grid-template-columns: 1fr; }
  .status-console { min-height: 370px; }
  .terminal-log { max-height: 420px; }
  .records-grid { grid-template-columns: 1fr; }
  .record-summary { grid-column: auto; }
}

/* Tablet */
@media (max-width: 860px) {
  :root { --page-gutter: 16px; }
  .header-inner { width: calc(100% - 28px); gap: 10px; }
  .app-brand { width: auto; }
  .header-nav {
    width: auto;
    padding: 2px 0 5px;
    justify-content: flex-start;
    flex-wrap: nowrap;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    scroll-snap-type: x proximity;
  }
  .nav-button { flex: 0 0 auto; scroll-snap-align: start; }
  .app-main, .dashboard-page { width: calc(100% - 28px); padding-top: 20px; }
  .two-column, .input-grid, .settings-grid { grid-template-columns: 1fr; }
  .settings-wide, .daily-comment-limit-setting { grid-column: auto; }
  .prompt-textarea-tall { min-height: 420px; }
}

/* Phones */
@media (max-width: 640px) {
  body { font-size: 13.5px; background-attachment: scroll; }
  .header-inner { min-height: 56px; padding: 7px 0; }
  .brand-logo { width: 37px; height: 37px; border-radius: 11px; }
  .brand-logo-image { width: 28px; height: 28px; border-radius: 8px; }
  .brand-title { font-size: 13.5px; }
  .setting-switch { align-items: flex-start; }
  .setting-switch-action { flex-direction: column-reverse; align-items: flex-end; gap: 5px; }
  .nav-button { min-height: 35px; padding: 7px 9px; font-size: 12px; }
  .status-card { padding: 15px; gap: 15px; border-radius: 16px; }
  .status-overview { padding: 2px; }
  .status-heading h1 { font-size: 23px; }
  .status-icon { width: 43px; height: 43px; border-radius: 12px; font-size: 20px; }
  .current-process { margin-top: 22px; padding: 16px; }
  .current-process strong { font-size: 16px; }
  .status-console { min-height: 350px; padding: 15px; border-radius: 15px; }
  .terminal-log { min-height: 260px; max-height: 42vh; padding: 13px; font-size: 12px; }
  .auto-run-actions { flex-direction: column; }
  .auto-run-button, .auto-stop-button { width: 100%; flex-basis: auto; }
  .page-card { border-radius: 0; }
  .page-heading { min-height: 62px; padding: 0 0 13px; border-radius: 0; }
  .page-heading h2 { font-size: 19px; }
  .page-heading p { font-size: 12px; }
  .page-back-button { min-height: 36px; padding: 7px 9px; font-size: 12px; }
  .page-content { padding: 0; }
  #apiSettingsModal .page-content, #templateModal .page-content { padding: 15px; }
  .panel { padding: 15px; border-radius: 14px; }
  .composer-tabs { width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .composer-tab { padding-inline: 10px; }
  .prompt-editor-heading { flex-direction: column; }
  .prompt-editor-heading button { width: 100%; }
  .prompt-editor-actions {
    bottom: 0;
    margin: 0;
    padding: 12px 0 max(12px, env(safe-area-inset-bottom));
    flex-direction: column-reverse;
  }
  .prompt-editor-actions button { width: 100%; }
  .tpl-item { grid-template-columns: 42px minmax(0, 1fr); }
  .tpl-actions { grid-column: 1 / -1; justify-content: stretch; }
  .tpl-actions button { flex: 1 1 auto; }
  .record-summary { flex-direction: column; }
}

@media (max-width: 430px) {
  .status-heading { flex-direction: column; }
  .terminal-state-badge { align-self: flex-start; }
  .process-meta, .status-counts { grid-template-columns: 1fr; }
  .license-gate { padding: 12px; }
  .license-card { padding: 27px 17px; border-radius: 20px; }
  .license-card h1 { font-size: 25px; }
  .license-key-row { grid-template-columns: 1fr; }
  .license-key-row button { width: 100%; }
  .label-row, .field-status { align-items: flex-start; }
  .label-row { flex-direction: column; }
  .label-row .small-button { width: 100%; }
  .secret-input-row { flex-direction: column; }
  .secret-input-row button { width: 100%; }
  .panel-toolbar { align-items: flex-start; flex-direction: column; }
  .panel-toolbar > div { width: 100%; flex-wrap: wrap; }
  .record-link-item { gap: 8px; }
  .record-link-view { min-width: 46px; padding-inline: 7px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .page-back-button { align-self: flex-start; }
}

@media (max-height: 620px) and (min-width: 641px) {
  .terminal-log { min-height: 240px; max-height: 50vh; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    transition-duration: .01ms !important;
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
  }
}
