:root {
  color-scheme: light;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #172033;
  background: #eef2f6;
  --surface: #ffffff;
  --surface-soft: #f7f9fc;
  --border: #dce3eb;
  --border-strong: #c8d1dc;
  --muted: #667085;
  --blue: #1769e0;
  --blue-dark: #0e55bc;
  --green: #137a4c;
  --red: #b42318;
}

* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; background: #eef2f6; }
button, input, textarea, select { font: inherit; letter-spacing: 0; }
button { min-height: 38px; border: 1px solid var(--border-strong); border-radius: 6px; padding: 0 14px; color: #27364a; background: white; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .48; }
button.primary { color: white; border-color: var(--blue); background: var(--blue); font-weight: 600; }
button.primary:hover:not(:disabled) { background: var(--blue-dark); }
button.secondary:hover:not(:disabled) { border-color: #aeb9c6; background: #f6f8fa; }
input, textarea, select { width: 100%; border: 1px solid var(--border-strong); border-radius: 6px; color: #172033; background: white; padding: 10px 12px; outline: none; }
input::placeholder, textarea::placeholder { color: #98a2b3; }
select { padding: 8px 10px; }
textarea { resize: vertical; line-height: 1.6; }
input:focus, textarea:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 224, .1); }
label { display: block; margin-bottom: 7px; color: #344054; font-size: 13px; font-weight: 600; }
code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }
.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; }

.topbar { color: white; background: #1d2939; border-bottom: 3px solid #2878e6; }
.topbar-inner { width: min(1180px, 100%); min-height: 82px; margin: 0 auto; padding: 16px 30px; display: flex; align-items: center; justify-content: space-between; gap: 24px; }
.topbar h1 { margin: 0; font-size: 20px; font-weight: 650; }
.topbar p { margin: 5px 0 0; color: #cbd5e1; font-size: 12px; line-height: 1.5; }
.shell { width: min(1180px, calc(100% - 32px)); margin: 20px auto 36px; overflow: hidden; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 0 8px 28px rgba(22, 34, 51, .06); }

.connection-band { padding: 18px 28px; display: grid; grid-template-columns: minmax(260px, .8fr) minmax(420px, 1.2fr); align-items: center; gap: 28px; border-bottom: 1px solid var(--border); background: #f4f7fb; }
.connection-band h2 { margin: 0; font-size: 15px; }
.connection-band p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.auth { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; }
.status-badge { padding: 6px 10px; border: 1px solid rgba(255,255,255,.16); border-radius: 4px; color: #d0d5dd; background: rgba(255,255,255,.08); font-size: 12px; white-space: nowrap; }
.status-badge.ready { color: #d1fadf; border-color: #287a55; background: #16623e; }
.status-badge.blocked { color: #fee4e2; border-color: #a7372f; background: #912018; }

.overview, .workspace { padding: 30px; border-bottom: 1px solid var(--border); }
.workspace:last-child { border-bottom: 0; }
.section-heading, .list-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; }
.section-heading > div { max-width: 820px; }
.section-heading h2 { margin: 3px 0 0; font-size: 19px; font-weight: 650; }
.section-heading p, .subheading p { margin: 7px 0 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.eyebrow { color: var(--blue); font-size: 11px; font-weight: 700; }
.stats { margin-top: 20px; display: grid; grid-template-columns: repeat(4, 1fr); border: 1px solid var(--border); border-radius: 6px; background: var(--surface-soft); }
.stats div { min-width: 0; padding: 17px 20px; border-right: 1px solid var(--border); }
.stats div:last-child { border-right: 0; }
.stats strong { display: block; color: #172033; font-size: 25px; font-weight: 650; line-height: 1.15; }
.stats span { display: block; margin-top: 4px; color: var(--muted); font-size: 12px; }

.tag-workspace { background: #fbfcfe; }
.inline-form { margin-top: 20px; padding-top: 20px; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto; align-items: end; gap: 12px; border-top: 1px solid var(--border); }
.inline-form button { min-width: 136px; }
.subheading { margin-top: 30px; }
.subheading h3 { margin: 0; font-size: 16px; font-weight: 650; }
.tag-list-heading { margin-top: 24px; }
.tag-list { margin-top: 11px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: white; }
.tag-group { border-bottom: 1px solid var(--border); }
.tag-group:last-child { border-bottom: 0; }
.tag-group-header { min-height: 48px; padding: 10px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: #f6f8fb; }
.tag-group-header > div { min-width: 0; display: flex; align-items: baseline; gap: 9px; }
.tag-group-header h4 { margin: 0; color: #27364a; font-size: 13px; font-weight: 650; overflow-wrap: anywhere; }
.tag-group-header span { color: var(--muted); font-size: 11px; white-space: nowrap; }
.tag-items { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.tag-item { min-height: 43px; padding: 8px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-top: 1px solid #edf0f4; }
.tag-item:nth-child(odd) { border-right: 1px solid #edf0f4; }
.tag-item > span { min-width: 0; color: #344054; font-size: 12px; overflow-wrap: anywhere; }
.danger-text-button { min-height: 28px; padding: 0 5px; border: 0; color: #b42318; background: transparent; font-size: 11px; white-space: nowrap; }
.danger-text-button:hover:not(:disabled) { color: #8f1c13; text-decoration: underline; background: #fff5f4; }

.rule-form { margin-top: 22px; border-top: 1px solid var(--border); }
.rule-form-section { padding: 24px 0; display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 28px; border-bottom: 1px solid var(--border); }
.form-section-heading h3 { margin: 0; color: #27364a; font-size: 14px; font-weight: 650; }
.form-section-heading p { margin: 5px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.audience-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.schedule-fields { display: grid; gap: 14px; }
.schedule-control-row { display: grid; grid-template-columns: minmax(240px, 1fr) minmax(150px, .55fr); align-items: end; gap: 14px; }
.schedule-control-row.once { grid-template-columns: minmax(240px, 1fr) minmax(170px, .7fr) minmax(150px, .55fr); }
.schedule-control-row > [hidden] { display: none; }
.field-title { display: block; margin-bottom: 7px; color: #344054; font-size: 13px; font-weight: 600; }
.segmented-control { height: 42px; padding: 3px; display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--border-strong); border-radius: 6px; background: #f3f5f8; }
.segmented-control label { min-width: 0; margin: 0; display: block; cursor: pointer; }
.segmented-control input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.segmented-control span { height: 34px; padding: 0 12px; display: flex; align-items: center; justify-content: center; border: 1px solid transparent; border-radius: 4px; color: #667085; font-size: 12px; font-weight: 600; white-space: nowrap; }
.segmented-control input:checked + span { border-color: #c9d9ef; color: #175cae; background: white; box-shadow: 0 1px 2px rgba(22, 34, 51, .08); }
.segmented-control input:focus-visible + span { outline: 2px solid rgba(23, 105, 224, .35); outline-offset: 1px; }
.field-label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.field-label-row label { margin-bottom: 7px; }
.selection-summary { color: var(--blue); font-size: 11px; font-weight: 600; white-space: nowrap; }
.select-actions { min-height: 27px; display: flex; align-items: center; justify-content: flex-end; gap: 12px; }
.text-button { min-height: 26px; padding: 0; border: 0; color: var(--blue); font-size: 11px; background: transparent; }
.text-button:hover:not(:disabled) { color: var(--blue-dark); text-decoration: underline; }
.rule-multi-select { min-height: 176px; padding: 5px 7px; font-size: 12px; line-height: 1.4; }
.rule-multi-select option { padding: 4px 6px; }
.weekday-field { min-height: 42px; margin: 0; padding: 7px 12px 9px; display: flex; flex-wrap: wrap; align-items: center; gap: 8px 14px; border: 1px solid var(--border-strong); border-radius: 6px; }
.weekday-field[hidden] { display: none; }
.weekday-field legend { padding: 0 5px; color: #344054; font-size: 12px; font-weight: 600; }
.weekday-field label, .check-line { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12px; font-weight: 400; }
.weekday-field input, .check-line input { width: 15px; height: 15px; margin: 0; box-shadow: none; }
.template-help { margin: 7px 0 0; color: var(--muted); font-size: 11px; line-height: 1.55; }
.template-help code { padding: 1px 4px; border-radius: 3px; color: #24528d; background: #eef5ff; }
.schedule-context { margin: 0 0 9px; padding: 8px 10px; border-left: 3px solid #8eb9ef; color: #475467; background: #f4f8fd; font-size: 11px; line-height: 1.55; }
.form-actions { padding: 18px 0 4px 198px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.form-actions button { min-width: 150px; }
.list-heading { margin-top: 34px; align-items: center; }
.rule-action-guide { margin-top: 14px; padding: 14px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 24px; border: 1px solid #d7e4f5; border-radius: 6px; background: #f6f9fd; }
.rule-action-guide div { min-width: 0; display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 9px; align-items: baseline; }
.rule-action-guide strong { color: #24405f; font-size: 11px; font-weight: 650; }
.rule-action-guide span { color: var(--muted); font-size: 11px; line-height: 1.55; }

.data-list { margin-top: 12px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: white; }
.data-row { padding: 17px 18px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 20px; border-bottom: 1px solid var(--border); }
.data-row:last-child { border-bottom: 0; }
.data-row:hover { background: #fafcff; }
.data-name { color: #172033; font-size: 14px; font-weight: 650; }
.data-meta { margin-top: 5px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.rule-status { display: inline-block; margin-right: 8px; padding: 3px 7px; border-radius: 4px; font-size: 11px; font-weight: 600; vertical-align: 1px; }
.rule-status.enabled { color: var(--green); background: #e9f7ef; }
.rule-status.disabled { color: #667085; background: #eef1f4; }
.chip-list { margin-top: 9px; display: flex; flex-wrap: wrap; gap: 5px; }
.chip { display: inline-flex; align-items: center; min-height: 23px; padding: 0 8px; border: 1px solid #c9daf5; border-radius: 4px; color: #24528d; background: #f0f6ff; font-size: 11px; }
.chip.muted { color: #667085; border-color: #dce1e7; background: #f7f8fa; }
.rule-content-preview { max-width: 720px; margin-top: 9px; overflow: hidden; color: #475467; font-size: 12px; line-height: 1.5; text-overflow: ellipsis; white-space: nowrap; }
.data-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.data-actions button { min-height: 32px; padding: 0 10px; font-size: 12px; }

.result { min-height: 42px; margin-top: 16px; padding: 11px 12px; display: none; border: 1px solid transparent; border-radius: 6px; background: #f1f5f9; font-size: 13px; line-height: 1.5; }
.result.visible { display: block; }
.result.success { color: var(--green); border-color: #b7e4cd; background: #edf8f2; }
.result.error { color: var(--red); border-color: #f2c4c0; background: #fff1f0; }
.empty { padding: 32px 16px; color: var(--muted); text-align: center; }

.preview-dialog { width: min(620px, calc(100% - 32px)); max-height: calc(100vh - 48px); padding: 0; overflow: hidden; border: 0; border-radius: 8px; color: #172033; background: white; box-shadow: 0 24px 70px rgba(15, 31, 53, .24); }
.preview-dialog::backdrop { background: rgba(24, 37, 55, .54); backdrop-filter: blur(2px); }
.preview-dialog-header { padding: 20px 22px 17px; display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
.preview-dialog-header h2 { margin: 4px 0 0; font-size: 19px; font-weight: 650; }
.preview-dialog-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; }
.dialog-close { width: 34px; min-width: 34px; min-height: 34px; padding: 0; border: 0; color: #667085; background: transparent; font-size: 25px; font-weight: 300; line-height: 1; }
.dialog-close:hover { color: #172033; background: #f2f4f7; }
.preview-dialog-body { max-height: calc(100vh - 210px); padding: 20px 22px; overflow-y: auto; }
.preview-schedule { padding: 9px 11px; border-left: 3px solid var(--blue); color: #344054; background: #f3f7fd; font-size: 12px; }
.preview-stats { margin-top: 16px; display: grid; grid-template-columns: repeat(2, 1fr); border: 1px solid var(--border); border-radius: 6px; background: #fafbfd; }
.preview-stats div { padding: 14px 16px; border-right: 1px solid var(--border); }
.preview-stats div:last-child { border-right: 0; }
.preview-stats strong { display: block; color: #172033; font-size: 24px; font-weight: 650; line-height: 1.1; }
.preview-stats span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.preview-message-block { margin-top: 19px; }
.preview-message-block h3 { margin: 0 0 8px; color: #344054; font-size: 13px; font-weight: 650; }
.preview-message { min-height: 112px; max-height: 240px; padding: 14px 15px; overflow-y: auto; border: 1px solid var(--border-strong); border-radius: 6px; color: #27364a; background: white; font-size: 14px; line-height: 1.7; white-space: pre-wrap; overflow-wrap: anywhere; }
.preview-message.error { color: var(--red); border-color: #f2c4c0; background: #fff5f4; }
.preview-note { margin: 14px 0 0; color: #59677a; font-size: 11px; line-height: 1.6; }
.preview-dialog-footer { padding: 14px 22px; display: flex; justify-content: flex-end; border-top: 1px solid var(--border); background: #fafbfd; }
.preview-dialog-footer button { min-width: 112px; }

.smart-workspace { background: #fbfcfd; }
.smart-heading { align-items: center; }
.inline-status { padding: 5px 9px; border: 1px solid #cbd5df; border-radius: 4px; color: #59677a; background: #f4f6f8; font-size: 11px; font-weight: 650; white-space: nowrap; }
.inline-status.ready { color: #12633e; border-color: #adddc4; background: #eaf7f0; }
.inline-status.blocked { color: #9f2d20; border-color: #efc0b9; background: #fff2f0; }
.smart-stats { margin-top: 20px; display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 6px; background: white; }
.smart-stats div { min-width: 0; padding: 15px 17px; border-right: 1px solid var(--border); }
.smart-stats div:last-child { border-right: 0; }
.smart-stats strong { display: block; overflow: hidden; color: #172033; font-size: 17px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.smart-stats span { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.smart-toolbar { margin-top: 14px; display: flex; justify-content: flex-end; flex-wrap: wrap; gap: 7px; }
.smart-toolbar .primary { margin-left: 6px; }
.smart-columns { margin-top: 25px; display: grid; grid-template-columns: minmax(280px, .8fr) minmax(420px, 1.2fr); gap: 22px; }
.rpa-test-panel { margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }
.rpa-target-panel { margin: 12px 0 18px; padding: 14px; border: 1px solid var(--border); background: var(--surface-soft); }
.rpa-target-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.rpa-target-form select {
  padding-right: 46px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16' fill='none'%3E%3Cpath d='M4 6l4 4 4-4' stroke='%23667085' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 18px center;
  background-size: 16px 16px;
}
.rpa-target-actions { grid-column: 1 / -1; display: flex; align-items: center; gap: 12px; }
.rpa-target-actions span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.rpa-test-form { margin-top: 12px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.rpa-test-content, .rpa-test-actions { grid-column: 1 / -1; }
.rpa-test-actions { display: flex; align-items: center; gap: 12px; }
.rpa-test-actions span { color: var(--muted); font-size: 11px; line-height: 1.5; }
.compact-heading { min-height: 45px; margin-top: 0; }
.compact-heading h3 { font-size: 14px; }
.compact-heading p { margin-top: 3px; font-size: 11px; }
.compact-list { margin-top: 8px; }
.compact-row { min-height: 58px; padding: 11px 12px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--border); }
.compact-row:last-child { border-bottom: 0; }
.compact-row > div:first-child { min-width: 0; display: grid; gap: 4px; }
.compact-row strong { min-width: 0; color: #27364a; font-size: 12px; font-weight: 650; overflow-wrap: anywhere; }
.compact-row > div:first-child > span { color: var(--muted); font-size: 10px; line-height: 1.45; overflow-wrap: anywhere; }
.compact-row button { min-height: 29px; padding: 0 8px; font-size: 10px; }
.compact-actions { display: flex; gap: 5px; }
.task-status { display: inline-block; margin-right: 6px; padding: 2px 5px; border-radius: 3px; color: #475467; background: #edf0f3; font-size: 9px; font-weight: 650; vertical-align: 1px; }
.task-status.sent { color: #12633e; background: #e7f6ee; }
.task-status.unknown, .task-status.failed, .task-status.manual_required { color: #9f2d20; background: #fff0ee; }
.task-status.generating, .task-status.generated, .task-status.sending { color: #81550a; background: #fff4d7; }

@media (max-width: 820px) {
  .shell { width: 100%; margin: 0; border-width: 0; border-radius: 0; box-shadow: none; }
  .topbar-inner { padding: 16px; align-items: flex-start; }
  .connection-band { padding: 18px 16px; grid-template-columns: 1fr; gap: 12px; }
  .auth, .inline-form, .audience-grid, .schedule-control-row { grid-template-columns: 1fr; }
  .overview, .workspace { padding: 24px 16px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats div:nth-child(2) { border-right: 0; }
  .stats div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .rule-form-section, .rule-action-guide, .tag-items { grid-template-columns: 1fr; gap: 14px; }
  .form-actions { padding-left: 0; }
  .section-heading, .list-heading, .form-actions { align-items: stretch; flex-direction: column; }
  .data-row { grid-template-columns: 1fr; }
  .data-actions { justify-content: flex-start; }
  .rule-content-preview { max-width: 100%; white-space: normal; }
  .smart-stats { grid-template-columns: repeat(2, 1fr); }
  .smart-stats div:nth-child(2) { border-right: 0; }
  .smart-stats div:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
  .smart-columns { grid-template-columns: 1fr; }
  .rpa-test-form { grid-template-columns: 1fr; }
  .rpa-target-form { grid-template-columns: 1fr; }
  .rpa-target-actions { grid-column: auto; align-items: flex-start; flex-direction: column; }
  .rpa-test-content, .rpa-test-actions { grid-column: auto; }
  .rpa-test-actions { align-items: flex-start; flex-direction: column; }
}

@media (max-width: 460px) {
  .topbar-inner { min-height: 92px; }
  .topbar h1 { font-size: 18px; }
  .stats strong { font-size: 22px; }
  .stats div { padding: 15px; }
  .weekday-field { gap: 9px 12px; }
  .data-actions button { flex: 1 1 calc(50% - 6px); }
  .tag-item:nth-child(odd) { border-right: 0; }
  .rule-action-guide div { grid-template-columns: 1fr; gap: 2px; }
  .preview-dialog-header, .preview-dialog-body, .preview-dialog-footer { padding-left: 16px; padding-right: 16px; }
  .smart-toolbar button { flex: 1 1 calc(50% - 7px); }
  .smart-toolbar .primary { margin-left: 0; }
  .compact-row.task-row { align-items: flex-start; flex-direction: column; }
}
