:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --ink: #172033;
  --muted: #667085;
  --line: #e4e9f0;
  --primary: #e86f32;
  --primary-dark: #c94f19;
  --primary-soft: #fff2e9;
  --green: #16805b;
  --green-soft: #e9f8f1;
  --red: #c43d4b;
  --red-soft: #fff0f1;
  --shadow: 0 18px 48px rgba(31, 42, 68, .08);
  --radius: 18px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  color: var(--ink);
  background: var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }

.topbar {
  height: 72px;
  padding: 0 max(24px, calc((100vw - 1180px) / 2));
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(255, 255, 255, .92);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand, .login-brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--ink);
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -.02em;
  text-decoration: none;
}

.brand-mark {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(145deg, #ff985d, var(--primary));
  border-radius: 11px;
  box-shadow: 0 7px 16px rgba(232, 111, 50, .26);
}

.brand-mark-large { width: 42px; height: 42px; border-radius: 13px; }

.page { width: min(1180px, calc(100% - 48px)); margin: 0 auto; padding: 52px 0 80px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; margin-bottom: 30px; }
.page-heading.compact { margin-bottom: 26px; }
.page-heading h1, .login-card h1 { margin: 3px 0 6px; font-size: clamp(32px, 5vw, 46px); line-height: 1.08; letter-spacing: -.045em; }
.page-heading.compact h1 { font-size: clamp(30px, 4vw, 40px); }
.eyebrow { margin: 0; color: var(--primary-dark); font-size: 12px; font-weight: 800; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.page-heading .muted, .login-card .muted { margin: 0; }
.heading-actions { display: flex; align-items: center; gap: 12px; }
.view-switcher { padding: 4px; display: flex; gap: 3px; background: #e9edf3; border-radius: 12px; }
.view-switcher a { padding: 7px 12px; color: var(--muted); border-radius: 9px; font-size: 13px; font-weight: 750; text-decoration: none; }
.view-switcher a.selected { color: var(--ink); background: var(--surface); box-shadow: 0 2px 7px rgba(31, 42, 68, .1); }

.button {
  min-height: 42px;
  padding: 9px 15px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 1px solid transparent;
  border-radius: 11px;
  font-weight: 750;
  text-decoration: none;
  transition: transform .15s ease, background .15s ease, border-color .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: #fff; background: var(--primary); box-shadow: 0 8px 20px rgba(232, 111, 50, .2); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { color: var(--ink); background: var(--surface); border-color: var(--line); }
.button-secondary:hover { border-color: #cbd3df; background: var(--surface-soft); }
.button-quiet { color: var(--muted); background: transparent; }
.button-quiet:hover { color: var(--ink); background: #eef1f6; }
.button-danger { color: var(--red); background: transparent; }
.button-danger:hover { background: var(--red-soft); }
.button-run { color: var(--green); background: var(--green-soft); }
.button-run:hover { background: #d9f2e7; }
.button-full { width: 100%; }

.summary-grid { display: grid; grid-template-columns: 170px 170px 1fr; gap: 16px; margin-bottom: 28px; }
.summary-card, .worker-card, .form-card, .login-card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.summary-card { min-height: 116px; padding: 22px; display: flex; flex-direction: column; justify-content: space-between; }
.summary-card strong { font-size: 30px; line-height: 1; letter-spacing: -.04em; }
.summary-label { color: var(--muted); font-size: 13px; font-weight: 700; }
.summary-settings { justify-content: center; }
.summary-settings form { display: flex; align-items: flex-end; justify-content: flex-end; gap: 10px; }

.worker-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.worker-card { padding: 24px; }
.worker-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 20px; border-bottom: 1px solid var(--line); }
.worker-card h2 { margin: 8px 0 0; font-size: 23px; letter-spacing: -.025em; }
.worker-id { max-width: 45%; padding: 5px 8px; overflow: hidden; color: var(--muted); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 7px; font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; text-overflow: ellipsis; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 800; }
.status-active { color: var(--green); }
.status-inactive { color: var(--muted); }
.status-dot { width: 8px; height: 8px; display: inline-block; background: currentColor; border-radius: 50%; box-shadow: 0 0 0 4px currentColor; opacity: .8; }
.status .status-dot { box-shadow: none; }
.worker-details { display: grid; grid-template-columns: 1fr 1fr; gap: 17px 20px; margin: 22px 0; }
.worker-details div { min-width: 0; }
.worker-details dt { margin-bottom: 3px; color: var(--muted); font-size: 12px; font-weight: 700; }
.worker-details dd { margin: 0; overflow: hidden; font-size: 14px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.card-actions { display: flex; justify-content: flex-end; gap: 4px; padding-top: 17px; border-top: 1px solid var(--line); }
.quick-toggle { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; }
.quick-toggle input { width: 1px; height: 1px; position: absolute; opacity: 0; }
.quick-toggle input:checked + .toggle { background: var(--green); }
.quick-toggle input:checked + .toggle::after { transform: translateX(19px); }

.table-shell { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.worker-table { width: 100%; min-width: 940px; border-collapse: collapse; }
.worker-table th { padding: 14px 18px; color: var(--muted); background: var(--surface-soft); border-bottom: 1px solid var(--line); font-size: 11px; font-weight: 800; letter-spacing: .07em; text-align: left; text-transform: uppercase; }
.worker-table td { padding: 18px; border-bottom: 1px solid var(--line); font-size: 14px; vertical-align: middle; }
.worker-table tbody tr:last-child td { border-bottom: 0; }
.worker-table tbody tr:hover { background: #fcfcfd; }
.worker-table td > strong, .worker-table td > small { display: block; }
.worker-table td > small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.table-toggle .toggle { transform: scale(.9); transform-origin: left center; }
.table-actions { display: flex; justify-content: flex-end; gap: 3px; }
.table-actions .button { min-height: 36px; padding: 6px 10px; font-size: 12px; }
.sr-only { width: 1px; height: 1px; padding: 0; position: absolute; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.field { display: flex; flex-direction: column; gap: 7px; color: var(--ink); font-size: 13px; font-weight: 750; }
.field small { color: var(--muted); font-weight: 500; }
.field-inline { min-width: 210px; }
input, select, textarea {
  width: 100%;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid #d8dee8;
  border-radius: 10px;
  outline: 0;
  transition: border-color .15s ease, box-shadow .15s ease;
}
input, select { height: 44px; padding: 0 12px; }
textarea { min-height: 148px; padding: 12px; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.55; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(232, 111, 50, .13); }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 38px; }
.input-suffix span { position: absolute; right: 13px; top: 11px; color: var(--muted); }

.breadcrumb { display: flex; gap: 9px; margin-bottom: 28px; color: var(--muted); font-size: 13px; }
.breadcrumb a { color: var(--primary-dark); font-weight: 700; text-decoration: none; }
.editor-layout { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 24px; align-items: start; }
.editor-form { display: flex; flex-direction: column; gap: 16px; }
.form-card { padding: 25px; }
.section-heading { display: flex; align-items: flex-start; gap: 13px; margin-bottom: 23px; }
.section-heading h2 { margin: 0 0 2px; font-size: 19px; }
.section-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.step { width: 28px; height: 28px; flex: 0 0 auto; display: grid; place-items: center; color: var(--primary-dark); background: var(--primary-soft); border-radius: 9px; font-size: 12px; font-weight: 850; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 19px; }
.field-wide { grid-column: 1 / -1; }
.toggle-field { grid-column: 1 / -1; min-height: 68px; padding: 14px 15px; display: flex; align-items: center; justify-content: space-between; gap: 16px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; cursor: pointer; }
.toggle-field > span:first-child { display: flex; flex-direction: column; }
.toggle-field small { color: var(--muted); }
.toggle-field input { width: 1px; height: 1px; position: absolute; opacity: 0; }
.toggle { width: 44px; height: 25px; flex: 0 0 auto; padding: 3px; background: #c8d0dc; border-radius: 20px; transition: background .15s ease; }
.toggle::after { content: ""; width: 19px; height: 19px; display: block; background: #fff; border-radius: 50%; box-shadow: 0 2px 6px rgba(0, 0, 0, .15); transition: transform .15s ease; }
.toggle-field input:checked + .toggle { background: var(--green); }
.toggle-field input:checked + .toggle::after { transform: translateX(19px); }
.token-list { display: flex; flex-wrap: wrap; gap: 7px; margin-top: 12px; }
.token-list code { padding: 5px 8px; color: #5b6473; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 7px; font-size: 12px; }
.form-actions { padding: 6px 2px; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.form-actions > div { display: flex; gap: 9px; }

.preview-column { position: sticky; top: 96px; }
.preview-label { margin: 0 0 10px 3px; display: flex; align-items: center; gap: 8px; color: var(--green); font-size: 12px; font-weight: 800; letter-spacing: .06em; text-transform: uppercase; }
.preview-label .status-dot { width: 6px; height: 6px; box-shadow: none; }
.preview-empty, .telegram-card { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.preview-empty { min-height: 310px; padding: 40px 30px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; }
.preview-empty > span { width: 48px; height: 48px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 15px; font-size: 24px; }
.preview-empty h2 { margin: 18px 0 6px; font-size: 18px; }
.preview-empty p { margin: 0; color: var(--muted); font-size: 14px; }
.telegram-card img { width: 100%; max-height: 310px; display: block; object-fit: cover; background: var(--surface-soft); }
.telegram-card pre { margin: 0; padding: 18px; overflow-wrap: anywhere; color: var(--ink); font: 14px/1.5 ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; white-space: pre-wrap; }
.preview-note { margin: 10px 4px 0; color: var(--muted); font-size: 12px; }

.notice { margin-bottom: 22px; padding: 13px 15px; border: 1px solid; border-radius: 11px; font-size: 14px; font-weight: 700; }
.notice-success { color: var(--green); background: var(--green-soft); border-color: #bce8d6; }
.notice-error { color: var(--red); background: var(--red-soft); border-color: #f0c8cd; }
.empty-state { padding: 70px 24px; display: flex; flex-direction: column; align-items: center; text-align: center; background: var(--surface); border: 1px dashed #cbd3df; border-radius: var(--radius); }
.empty-state h2 { margin: 13px 0 3px; }
.empty-state p { margin: 0 0 20px; }
.empty-icon { width: 50px; height: 50px; display: grid; place-items: center; color: var(--primary); background: var(--primary-soft); border-radius: 15px; font-size: 28px; }

.activity-section { margin-top: 42px; }
.section-title-row { margin-bottom: 14px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.section-title-row h2 { margin: 3px 0 0; font-size: 24px; letter-spacing: -.03em; }
.section-title-row > .muted { font-size: 12px; }
.activity-list { overflow: hidden; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.activity-row { min-height: 82px; padding: 16px 19px; display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 14px; border-bottom: 1px solid var(--line); }
.activity-row:last-child { border-bottom: 0; }
.activity-icon { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 10px; font-size: 14px; font-weight: 900; }
.activity-success { color: var(--green); background: var(--green-soft); }
.activity-error { color: var(--red); background: var(--red-soft); }
.activity-main { min-width: 0; display: flex; flex-direction: column; }
.activity-main strong { font-size: 14px; }
.activity-main span, .activity-main small { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.activity-main small { color: var(--red); }
.activity-meta { display: flex; flex-direction: column; align-items: flex-end; }
.activity-meta strong { font-size: 13px; }
.activity-meta time { color: var(--muted); font-size: 11px; }
.activity-empty { padding: 36px; color: var(--muted); background: var(--surface); border: 1px dashed #cbd3df; border-radius: var(--radius); text-align: center; }

.login-page { min-height: 100vh; padding: 28px; display: grid; place-items: center; background: radial-gradient(circle at 20% 10%, #fff2e9 0, transparent 30%), radial-gradient(circle at 80% 90%, #e7eef9 0, transparent 34%), var(--bg); }
.login-card { width: min(430px, 100%); padding: 38px; }
.login-brand { margin-bottom: 34px; }
.login-card h1 { font-size: 38px; }
.login-card .stack { margin-top: 27px; }
.stack { display: flex; flex-direction: column; gap: 16px; }

@media (max-width: 860px) {
  .page { width: min(100% - 32px, 680px); padding-top: 34px; }
  .summary-grid { grid-template-columns: 1fr 1fr; }
  .summary-settings { grid-column: 1 / -1; }
  .worker-grid { grid-template-columns: 1fr; }
  .editor-layout { grid-template-columns: 1fr; }
  .preview-column { position: static; }
}

@media (max-width: 560px) {
  .topbar { height: 64px; padding: 0 16px; }
  .page { width: calc(100% - 24px); padding: 28px 0 52px; }
  .page-heading { align-items: stretch; flex-direction: column; }
  .heading-actions { align-items: stretch; flex-direction: column-reverse; }
  .heading-actions > .button { width: 100%; }
  .view-switcher a { flex: 1; text-align: center; }
  .summary-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .summary-card { min-height: 102px; padding: 17px; }
  .summary-settings { grid-column: 1 / -1; }
  .summary-settings form { align-items: stretch; flex-direction: column; }
  .worker-card, .form-card { padding: 19px; }
  .worker-card-head { flex-direction: column-reverse; }
  .worker-id { max-width: 100%; }
  .worker-details { grid-template-columns: 1fr; }
  .card-actions { justify-content: space-between; }
  .activity-row { grid-template-columns: auto 1fr; }
  .activity-meta { grid-column: 2; align-items: flex-start; }
  .form-grid { grid-template-columns: 1fr; }
  .field-wide, .toggle-field { grid-column: auto; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions > div { flex-direction: column; }
  .form-actions .button { width: 100%; }
  .login-page { padding: 14px; }
  .login-card { padding: 27px 22px; }
}
