:root {
  --canvas: #fbfbfa;
  --panel: #f7f6f3;
  --surface: #ffffff;
  --ink: #20211f;
  --muted: #787774;
  --soft-muted: #a1a19a;
  --rule: #e9e9e4;
  --rule-strong: #dcdcd6;
  --rail: #20211f;
  --rail-muted: #a6a69f;
  --rail-rule: rgba(255, 255, 255, .13);
  --accent: #e8d4b6;
  --accent-ink: #6a5232;
  --green-bg: #edf3ec;
  --green-ink: #346538;
  --yellow-bg: #fbf3db;
  --yellow-ink: #956400;
  --red-bg: #fdebec;
  --red-ink: #9f2f2d;
  --blue-bg: #e1f3fe;
  --blue-ink: #1f6c9f;
  --sans: "Helvetica Neue", "SF Pro Display", Arial, sans-serif;
  --serif: "Newsreader", Georgia, serif;
  --mono: "SF Mono", "Cascadia Code", Consolas, monospace;
}

* { box-sizing: border-box; }

html { background: var(--canvas); color: var(--ink); font-family: var(--sans); }

body { margin: 0; min-width: 320px; line-height: 1.55; }

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

button { cursor: pointer; }

button:disabled { cursor: not-allowed; opacity: .52; }

a { color: inherit; text-decoration: none; }

img { display: block; max-width: 100%; }

:focus-visible { outline: 2px solid var(--ink); outline-offset: 3px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }

.sidebar { background: var(--rail); color: #fff; padding: 24px 16px 18px; display: flex; flex-direction: column; }

.brand-lockup { display: flex; align-items: center; gap: 11px; padding: 0 8px 28px; }

.brand-mark { width: 38px; height: 38px; border-radius: 7px; background: #fff; object-fit: contain; padding: 5px; }

.brand-name { margin: 0; font-size: 13px; font-weight: 600; letter-spacing: .015em; }

.brand-caption { margin: 2px 0 0; color: var(--rail-muted); font-size: 11px; }

.sidebar-section-label { color: #777870; font: 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; padding: 0 10px 9px; }

.sidebar-nav { display: grid; gap: 4px; }

.nav-item { min-height: 42px; display: flex; align-items: center; gap: 11px; border: 1px solid transparent; border-radius: 6px; color: var(--rail-muted); padding: 0 10px; font-size: 13px; transition: background .18s ease, color .18s ease, border-color .18s ease; }

.nav-item:hover { background: rgba(255, 255, 255, .06); color: #fff; }

.nav-item.is-active { background: rgba(255, 255, 255, .1); border-color: var(--rail-rule); color: #fff; }

.nav-icon { width: 17px; height: 17px; color: currentColor; flex: 0 0 auto; }

.sidebar-footer { margin-top: auto; border-top: 1px solid var(--rail-rule); padding-top: 16px; }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 0 8px 15px; }

.avatar { width: 29px; height: 29px; border-radius: 50%; display: grid; place-items: center; background: var(--accent); color: var(--accent-ink); font-size: 11px; font-weight: 700; }

.user-name { margin: 0; font-size: 12px; font-weight: 600; }

.user-role { margin: 2px 0 0; color: var(--rail-muted); font: 10px var(--mono); }

.logout-button { width: 100%; border: 1px solid var(--rail-rule); border-radius: 5px; background: transparent; color: var(--rail-muted); padding: 9px 10px; font-size: 12px; text-align: left; transition: background .18s ease, color .18s ease; }

.logout-button:hover { background: rgba(255, 255, 255, .08); color: #fff; }

.main-content { min-width: 0; padding: 34px clamp(24px, 5vw, 72px) 60px; }

.content-frame { width: min(1120px, 100%); margin: 0 auto; }

.workspace-header { display: flex; justify-content: space-between; gap: 24px; align-items: flex-start; margin-bottom: 34px; }

.eyebrow { margin: 0 0 9px; color: var(--muted); font: 10px var(--mono); letter-spacing: .12em; text-transform: uppercase; }

.page-title { margin: 0; color: var(--ink); font: 400 clamp(32px, 4vw, 48px)/1.04 var(--serif); letter-spacing: -.035em; }

.page-intro { max-width: 570px; margin: 12px 0 0; color: var(--muted); font-size: 14px; }

.header-meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font: 11px var(--mono); white-space: nowrap; padding-top: 5px; }

.readiness-dot { width: 7px; height: 7px; border-radius: 50%; background: #7e9b7b; }

.readiness-dot.is-muted { background: #b4a480; }

.page-grid { display: grid; grid-template-columns: minmax(0, 1.28fr) minmax(270px, .72fr); gap: 18px; align-items: start; }

.section-stack { display: grid; gap: 18px; }

.card { background: var(--surface); border: 1px solid var(--rule); border-radius: 10px; padding: 24px; }

.card-tight { padding: 18px 20px; }

.card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 21px; }

.card-title { margin: 0; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }

.card-description { margin: 5px 0 0; color: var(--muted); font-size: 12px; }

.section-label { margin: 0 0 9px; color: var(--muted); font: 10px var(--mono); letter-spacing: .1em; text-transform: uppercase; }

.muted { color: var(--muted); }

.soft-muted { color: var(--soft-muted); }

.mono { font-family: var(--mono); }

.small { font-size: 11px; }

.form-stack { display: grid; gap: 18px; }

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

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

.field.is-wide { grid-column: 1 / -1; }

.field-label { color: var(--ink); font-size: 12px; font-weight: 600; }

.field-label span { color: var(--muted); font-weight: 400; }

.text-input, .select-input, .textarea-input { width: 100%; border: 1px solid var(--rule-strong); border-radius: 5px; background: var(--surface); color: var(--ink); padding: 11px 12px; font-size: 13px; transition: border-color .18s ease, background .18s ease; }

.text-input::placeholder, .textarea-input::placeholder { color: #aaa9a2; }

.text-input:hover, .select-input:hover, .textarea-input:hover { border-color: #bdbdb5; }

.text-input:focus, .select-input:focus, .textarea-input:focus { border-color: var(--ink); outline: 0; }

.textarea-input { min-height: 108px; resize: vertical; line-height: 1.6; }

.field-hint { margin: 0; color: var(--muted); font-size: 11px; }

.field-error { margin: 0; color: var(--red-ink); font-size: 11px; }

.dropzone { min-height: 146px; display: grid; place-items: center; border: 1px dashed #c8c8c1; border-radius: 7px; background: var(--panel); padding: 22px; text-align: center; transition: border-color .18s ease, background .18s ease; }

.dropzone:hover, .dropzone.is-active { border-color: var(--ink); background: #f3f0ea; }

.dropzone.has-file { min-height: auto; display: block; text-align: left; border-style: solid; background: var(--surface); }

.dropzone-icon { width: 25px; height: 25px; margin: 0 auto 9px; color: var(--muted); }

.dropzone-title { margin: 0; font-size: 13px; font-weight: 600; }

.dropzone-copy { margin: 4px 0 12px; color: var(--muted); font-size: 11px; }

.file-row { display: flex; align-items: center; gap: 11px; }

.file-icon { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 5px; background: var(--red-bg); color: var(--red-ink); font: 10px var(--mono); font-weight: 700; }

.file-details { min-width: 0; flex: 1; }

.file-name { margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }

.file-size { margin: 2px 0 0; color: var(--muted); font: 10px var(--mono); }

.icon-button { width: 30px; height: 30px; display: grid; place-items: center; border: 1px solid var(--rule); border-radius: 5px; background: transparent; color: var(--muted); }

.icon-button:hover { color: var(--ink); border-color: var(--rule-strong); background: var(--panel); }

.btn { min-height: 38px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border: 1px solid transparent; border-radius: 5px; padding: 0 15px; font-size: 12px; font-weight: 600; transition: background .18s ease, border-color .18s ease, color .18s ease, transform .12s ease; }

.btn:active { transform: scale(.98); }

.btn-primary { background: var(--ink); color: #fff; }

.btn-primary:hover { background: #363734; }

.btn-secondary { border-color: var(--rule-strong); background: var(--surface); color: var(--ink); }

.btn-secondary:hover { border-color: var(--ink); background: var(--panel); }

.btn-quiet { border-color: transparent; background: transparent; color: var(--muted); padding-inline: 8px; }

.btn-quiet:hover { color: var(--ink); background: var(--panel); }

.btn-danger { border-color: #e6c4c6; background: var(--red-bg); color: var(--red-ink); }

.btn-danger:hover { border-color: var(--red-ink); }

.btn-icon { width: 15px; height: 15px; }

.form-actions { display: flex; justify-content: flex-end; align-items: center; gap: 10px; padding-top: 4px; }

.template-card { background: var(--panel); border: 1px solid var(--rule); border-radius: 8px; padding: 18px; }

.template-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin-bottom: 19px; }

.template-name { margin: 0; font-size: 13px; font-weight: 600; }

.template-channel { margin: 3px 0 0; color: var(--muted); font: 10px var(--mono); }

.template-body { margin: 0; padding: 14px; border-left: 2px solid var(--accent); background: var(--surface); color: #494944; font-size: 12px; line-height: 1.65; }

.template-footnote { margin: 15px 0 0; color: var(--muted); font-size: 11px; }

.status-badge { display: inline-flex; align-items: center; gap: 6px; border-radius: 9999px; padding: 4px 8px; font: 10px var(--mono); letter-spacing: .03em; white-space: nowrap; }

.status-badge::before { width: 5px; height: 5px; border-radius: 50%; background: currentColor; content: ""; }

.status-sent, .status-active { background: var(--green-bg); color: var(--green-ink); }

.status-ready, .status-running { background: var(--green-bg); color: var(--green-ink); }

.status-queued, .status-invited, .status-draft { background: var(--yellow-bg); color: var(--yellow-ink); }

.status-not-connected { background: var(--yellow-bg); color: var(--yellow-ink); }

.status-failed { background: var(--red-bg); color: var(--red-ink); }

.status-info { background: var(--blue-bg); color: var(--blue-ink); }

.status-muted { background: var(--panel); color: var(--muted); }

.stats-strip { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--rule); border-radius: 10px; background: var(--surface); overflow: hidden; }

.stat { min-width: 0; padding: 17px 19px; border-right: 1px solid var(--rule); }

.stat:last-child { border-right: 0; }

.stat-label { margin: 0 0 8px; color: var(--muted); font: 10px var(--mono); letter-spacing: .08em; text-transform: uppercase; }

.stat-value { margin: 0; font: 400 26px/1 var(--serif); letter-spacing: -.025em; }

.table-card { padding: 0; overflow: hidden; }

.table-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding: 18px 20px; border-bottom: 1px solid var(--rule); }

.toolbar-group { display: flex; align-items: center; gap: 9px; }

.toolbar-search { width: min(250px, 35vw); }

.toolbar-search .text-input { padding-block: 9px; }

.table-wrap { overflow-x: auto; }

.data-table { width: 100%; border-collapse: collapse; min-width: 700px; }

.data-table th { padding: 12px 20px; background: #fcfcfb; color: var(--muted); font: 10px var(--mono); letter-spacing: .07em; text-align: left; text-transform: uppercase; white-space: nowrap; }

.data-table td { padding: 15px 20px; border-top: 1px solid var(--rule); color: #44443f; font-size: 12px; vertical-align: middle; }

.data-table tr:hover td { background: #fdfdfc; }

.row-primary { margin: 0; color: var(--ink); font-weight: 600; }

.row-secondary { margin: 2px 0 0; color: var(--muted); font: 10px var(--mono); }

.link-action { border: 0; background: transparent; color: var(--blue-ink); padding: 0; font-size: 12px; font-weight: 600; }

.link-action:hover { text-decoration: underline; }

.empty-state { padding: 48px 24px; text-align: center; }

.empty-mark { width: 38px; height: 38px; display: grid; place-items: center; margin: 0 auto 13px; border: 1px solid var(--rule-strong); border-radius: 8px; color: var(--muted); }

.empty-title { margin: 0; font-size: 14px; font-weight: 600; }

.empty-copy { max-width: 360px; margin: 5px auto 17px; color: var(--muted); font-size: 12px; }

.tabs { display: inline-flex; gap: 4px; border-bottom: 1px solid var(--rule); }

.tab-button { border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); padding: 9px 4px 11px; margin-right: 16px; font-size: 12px; font-weight: 600; }

.tab-button:hover { color: var(--ink); }

.tab-button.is-active { border-color: var(--ink); color: var(--ink); }

.upload-panel { display: grid; gap: 16px; }

.sample-banner { display: flex; justify-content: space-between; align-items: center; gap: 15px; border: 1px solid #dfd5c3; border-radius: 7px; background: #fbf7f0; padding: 13px 15px; }

.sample-banner-copy { margin: 0; color: #6e5a3f; font-size: 11px; }

.preview-card { border: 1px solid var(--rule); border-radius: 8px; background: var(--panel); padding: 17px; }

.preview-heading { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 13px; }

.preview-heading p { margin: 0; color: var(--muted); font: 10px var(--mono); letter-spacing: .06em; text-transform: uppercase; }

.preview-window { background: var(--surface); border: 1px solid var(--rule); border-radius: 6px; padding: 17px; }

.preview-window p { margin: 0; color: #4b4b46; font-size: 12px; line-height: 1.7; white-space: pre-wrap; }

.preview-variable { color: var(--accent-ink); font-weight: 600; }

.csv-preview { overflow-x: auto; border: 1px solid var(--rule); border-radius: 7px; }

.csv-preview table { width: 100%; border-collapse: collapse; min-width: 520px; }

.csv-preview th, .csv-preview td { padding: 10px 12px; border-bottom: 1px solid var(--rule); text-align: left; font-size: 11px; white-space: nowrap; }

.csv-preview th { background: #fcfcfb; color: var(--muted); font: 10px var(--mono); text-transform: uppercase; }

.csv-preview tr:last-child td { border-bottom: 0; }

.validation-note { margin: 0; padding: 10px 12px; border-radius: 5px; background: var(--green-bg); color: var(--green-ink); font-size: 11px; }

.validation-note.has-errors { background: var(--red-bg); color: var(--red-ink); }

.bulk-summary { display: flex; flex-wrap: wrap; align-items: center; gap: 15px; padding: 14px 16px; border: 1px solid var(--rule); border-radius: 7px; background: var(--surface); }

.bulk-summary-item { display: flex; align-items: baseline; gap: 7px; color: var(--muted); font-size: 11px; }

.bulk-summary-item strong { color: var(--ink); font: 600 16px var(--serif); }

.progress-wrap { display: grid; gap: 8px; }

.progress-label { display: flex; justify-content: space-between; color: var(--muted); font: 10px var(--mono); }

.progress-track { height: 7px; overflow: hidden; border-radius: 9999px; background: var(--rule); }

.progress-fill { height: 100%; border-radius: inherit; background: var(--ink); transition: width .25s ease; }

.run-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.admin-grid { display: grid; gap: 18px; }

.settings-card { padding: 0; overflow: hidden; }

.settings-card .card-header { padding: 21px 22px 17px; margin: 0; border-bottom: 1px solid var(--rule); }

.settings-body { padding: 19px 22px 22px; }

.add-user-panel { display: grid; gap: 17px; border: 1px solid #dfd5c3; border-radius: 7px; background: #fbf7f0; padding: 17px; margin-bottom: 19px; }

.connection-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; }

.connection-details { display: grid; gap: 4px; }

.connection-name { margin: 0; font-size: 13px; font-weight: 600; }

.connection-meta { margin: 0; color: var(--muted); font: 10px var(--mono); }

.connection-state { display: grid; justify-items: end; gap: 6px; text-align: right; }

.settings-note { margin: 18px 0 0; border-top: 1px solid var(--rule); padding-top: 15px; color: var(--muted); font-size: 11px; }

.user-list { display: grid; }

.user-row { display: grid; grid-template-columns: minmax(190px, 1.2fr) minmax(110px, .7fr) minmax(140px, .9fr) auto; gap: 13px; align-items: end; border-bottom: 1px solid var(--rule); padding: 15px 0; }

.user-row:first-child { padding-top: 0; }

.user-row:last-child { border-bottom: 0; padding-bottom: 0; }

.user-identity { align-self: center; }

.user-email { margin: 3px 0 0; color: var(--muted); font: 10px var(--mono); }

.user-control { display: grid; gap: 5px; }

.control-label { color: var(--muted); font: 9px var(--mono); text-transform: uppercase; }

.template-editor { display: grid; grid-template-columns: minmax(170px, .7fr) minmax(0, 1.3fr); gap: 20px; }

.template-list { display: grid; align-content: start; gap: 5px; }

.template-list-item { border: 1px solid transparent; border-radius: 6px; background: transparent; padding: 12px; text-align: left; }

.template-list-item:hover { background: var(--panel); }

.template-list-item.is-selected { border-color: var(--rule-strong); background: var(--panel); }

.template-list-name { margin: 0; font-size: 12px; font-weight: 600; }

.template-list-meta { margin: 3px 0 0; color: var(--muted); font: 10px var(--mono); }

.variable-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }

.variable-chip { border-radius: 9999px; background: var(--blue-bg); color: var(--blue-ink); padding: 4px 7px; font: 10px var(--mono); }

.toast-region { position: fixed; right: 22px; bottom: 22px; z-index: 8; display: grid; gap: 8px; width: min(360px, calc(100vw - 44px)); }

.toast { display: flex; align-items: flex-start; gap: 10px; border: 1px solid var(--rule-strong); border-radius: 7px; background: var(--ink); color: #fff; padding: 13px 14px; box-shadow: 0 10px 26px rgba(32, 33, 31, .04); font-size: 12px; }

.toast-icon { width: 15px; height: 15px; color: var(--accent); flex: 0 0 auto; }

.icon-text { display: inline-flex; align-items: center; gap: 7px; }

.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; }

.hidden { display: none !important; }

@media (max-width: 1040px) {
  .main-content { padding-inline: 36px; }
  .page-grid { grid-template-columns: minmax(0, 1fr); }
  .page-grid > .side-column { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; }
}

@media (max-width: 840px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; top: 0; z-index: 4; padding: 12px 16px; }
  .brand-lockup { padding: 0 0 11px; }
  .brand-mark { width: 32px; height: 32px; }
  .brand-caption { display: none; }
  .sidebar-nav { display: flex; overflow-x: auto; gap: 4px; padding-bottom: 2px; scrollbar-width: thin; }
  .sidebar-section-label, .sidebar-footer { display: none; }
  .nav-item { min-height: 35px; flex: 0 0 auto; padding-inline: 10px; font-size: 12px; }
  .main-content { padding: 28px 20px 46px; }
  .workspace-header { display: block; margin-bottom: 26px; }
  .header-meta { padding-top: 13px; }
  .page-grid > .side-column { grid-template-columns: 1fr; }
  .user-row { grid-template-columns: 1fr 1fr; align-items: stretch; }
  .user-identity { grid-column: 1 / -1; }
  .user-row .btn { grid-column: 1 / -1; }
  .template-editor { grid-template-columns: 1fr; }
}

@media (max-width: 620px) {
  .main-content { padding-inline: 14px; }
  .page-title { font-size: 36px; }
  .card { padding: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .field.is-wide { grid-column: auto; }
  .stats-strip { grid-template-columns: 1fr; }
  .stat { border-right: 0; border-bottom: 1px solid var(--rule); }
  .stat:last-child { border-bottom: 0; }
  .table-toolbar { align-items: stretch; flex-direction: column; }
  .toolbar-group { justify-content: space-between; }
  .toolbar-search { width: 100%; }
  .sample-banner, .connection-row { align-items: flex-start; flex-direction: column; }
  .connection-state { justify-items: start; text-align: left; }
  .form-actions, .run-actions { justify-content: stretch; }
  .form-actions .btn, .run-actions .btn { flex: 1; }
}

@media (prefers-reduced-motion: no-preference) {
  .reveal { animation: reveal .55s cubic-bezier(.16, 1, .3, 1) both; }
  .reveal:nth-child(2) { animation-delay: 70ms; }
  .reveal:nth-child(3) { animation-delay: 140ms; }
  @keyframes reveal { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: translateY(0); } }
}

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