:root {
  color-scheme: dark;
  --bg: #08111d;
  --surface: #0d1928;
  --surface-2: #101f31;
  --line: #203247;
  --text: #eef5fb;
  --muted: #93a8bb;
  --cyan: #48d9d0;
  --blue: #4b8fff;
  --green: #63dda4;
  --orange: #ffad66;
  --red: #ff7180;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: var(--bg); color: var(--text); font-size: 16px; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
a { color: inherit; }
code, pre { font-family: "SFMono-Regular", Consolas, monospace; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(400px, 100%); padding: 34px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 24px 70px rgba(0,0,0,.3); }
.login-logo { display: block; width: 130px; height: 130px; margin: -8px auto 12px; object-fit: contain; }
.login-card h1 { margin: 0; font-size: 1.55rem; }
.login-card > .muted { margin: 8px 0 22px; }
.login-card form, #routing-form { display: grid; gap: 16px; }
.notice { margin-bottom: 18px; padding: 11px 13px; border: 1px solid rgba(255,173,102,.3); border-radius: 9px; background: rgba(255,173,102,.08); color: #ffd4ae; font-size: .875rem; }
.form-error { min-height: 20px; margin: -4px 0; color: var(--red); font-size: .875rem; }

.app-header { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 28px; min-height: 68px; padding: 10px max(24px, calc((100vw - 1440px) / 2)); border-bottom: 1px solid var(--line); background: rgba(8,17,29,.94); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 10px; min-width: 170px; text-decoration: none; }
.brand img { width: 40px; height: 40px; border-radius: 10px; object-fit: contain; }
.brand strong, .brand small { display: block; }
.brand strong { font-size: 1rem; }
.brand small { margin-top: 1px; color: var(--muted); font-size: .75rem; }
.app-header nav { display: flex; align-items: center; gap: 5px; }
.app-header nav a { padding: 9px 11px; border-radius: 8px; color: var(--muted); font-size: .875rem; font-weight: 650; text-decoration: none; }
.app-header nav a:hover { background: var(--surface-2); color: var(--text); }
.header-actions { display: flex; align-items: center; gap: 9px; margin-left: auto; }
.online-dot { display: flex; align-items: center; gap: 7px; color: #b8dcca; font-size: .8rem; }
.online-dot i { width: 7px; height: 7px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(99,221,164,.1); }
.user-name { color: var(--muted); font-size: .875rem; }

main { width: min(1440px, 100%); margin: 0 auto; padding: 30px 24px 70px; }
.section-anchor { scroll-margin-top: 88px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 20px; }
.page-heading h1 { margin: 2px 0 4px; font-size: 1.65rem; letter-spacing: -.03em; }
.page-heading p { margin: 0; color: var(--muted); }
.updated { color: var(--muted); font-size: .8rem; white-space: nowrap; }
.kicker { margin: 0 0 4px !important; color: var(--cyan) !important; font-size: .72rem !important; font-weight: 800; letter-spacing: .13em; }

.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
.stats article { display: flex; align-items: center; justify-content: space-between; min-height: 68px; padding: 15px 17px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); }
.stats span { color: var(--muted); font-size: .84rem; }
.stats strong { font-size: 1.45rem; }
.stats .failure-stat strong { color: var(--red); }

.primary-grid { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(390px, .75fr); gap: 14px; }
.panel { margin-bottom: 14px; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 17px; }
.panel-heading h2 { margin: 0; font-size: 1.08rem; }
.panel-heading p:not(.kicker) { margin: 5px 0 0; color: var(--muted); font-size: .875rem; }
.heading-actions, .inline-actions { display: flex; align-items: center; gap: 9px; }
.inline-actions { margin-top: 13px; }
.inline-actions span { color: var(--muted); font-size: .8rem; }

.button { min-height: 38px; padding: 0 13px; border: 1px solid transparent; border-radius: 8px; font-size: .875rem; font-weight: 700; transition: border-color .15s, background .15s, opacity .15s; }
.button.primary { background: var(--cyan); color: #041619; }
.button.secondary { border-color: var(--line); background: var(--surface-2); color: var(--text); }
.button.quiet { background: transparent; color: var(--muted); }
.button:hover:not(:disabled) { filter: brightness(1.08); }
.button:disabled { cursor: not-allowed; opacity: .45; }
.button.full { width: 100%; }
.link-button { padding: 4px; border: 0; background: transparent; color: var(--cyan); font-size: .8rem; }
.link-button.danger { color: var(--red); }

label { display: grid; gap: 7px; color: #c1cfda; font-size: .875rem; font-weight: 650; }
input, select, textarea { width: 100%; border: 1px solid var(--line); border-radius: 8px; outline: none; background: #081421; color: var(--text); }
input, select { height: 40px; padding: 0 11px; }
textarea { min-height: 88px; padding: 10px 11px; resize: vertical; font-family: "SFMono-Regular", Consolas, monospace; font-size: .8rem; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--cyan); box-shadow: 0 0 0 3px rgba(72,217,208,.08); }
textarea.invalid { border-color: var(--red); }
.input-action { position: relative; display: flex; }
.input-action input { padding-right: 65px; }
.input-action button { position: absolute; right: 4px; top: 4px; height: 32px; padding: 0 9px; border: 0; border-radius: 6px; background: var(--surface-2); color: var(--muted); font-size: .78rem; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 11px; }
.full-span { grid-column: 1 / -1; }
.muted { color: var(--muted); line-height: 1.5; }
.small { font-size: .82rem; }

.tabs { display: flex; gap: 4px; margin-top: 14px; padding: 4px; border-radius: 9px; background: #081421; }
.tab { flex: 1; min-height: 34px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); font-size: .78rem; font-weight: 700; }
.tab.active { background: var(--surface-2); color: var(--text); }
.code-block { overflow: auto; min-height: 205px; max-height: 330px; margin: 10px 0 0; padding: 14px; border: 1px solid #192c40; border-radius: 9px; background: #06101a; color: #c4d6e3; font-size: .75rem; line-height: 1.55; white-space: pre-wrap; word-break: break-word; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 0 10px 9px; color: #728ba1; text-align: left; font-size: .72rem; letter-spacing: .05em; text-transform: uppercase; white-space: nowrap; }
td { padding: 11px 10px; border-top: 1px solid var(--line); color: #bdcbd6; font-size: .82rem; vertical-align: middle; }
td strong { color: var(--text); }
.path-code { display: inline-block; max-width: 330px; overflow: hidden; color: #b8d1e2; font-size: .76rem; text-overflow: ellipsis; vertical-align: middle; white-space: nowrap; }
.status { display: inline-flex; align-items: center; gap: 6px; padding: 5px 8px; border-radius: 7px; font-size: .75rem; font-weight: 750; white-space: nowrap; }
.status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.status-online, .status-published, .status-succeeded { color: var(--green); background: rgba(99,221,164,.08); }
.status-rejected, .status-failed { color: var(--red); background: rgba(255,113,128,.08); }
.status-started, .status-dispatching { color: var(--orange); background: rgba(255,173,102,.08); }
.status-pending { color: var(--muted); background: rgba(147,168,187,.08); }
.empty { grid-column: 1 / -1; padding: 28px 12px; color: var(--muted); text-align: center; font-size: .875rem; }

.worker-flow { padding-bottom: 18px; }
.flow-steps { display: grid; grid-template-columns: repeat(4, 1fr); gap: 9px; }
.flow-steps article { display: flex; gap: 10px; padding: 12px; border: 1px solid var(--line); border-radius: 9px; background: #0a1624; }
.flow-steps b { display: grid; place-items: center; width: 24px; height: 24px; flex: 0 0 auto; border-radius: 7px; background: rgba(72,217,208,.1); color: var(--cyan); font-size: .78rem; }
.flow-steps strong, .flow-steps span { display: block; }
.flow-steps strong { margin-bottom: 4px; font-size: .84rem; }
.flow-steps span { color: var(--muted); font-size: .76rem; line-height: 1.45; }
.flow-steps code { color: #bdd1df; font-size: .72rem; }
.placeholder-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; overflow: hidden; margin-top: 12px; border: 1px solid var(--line); border-radius: 9px; background: var(--line); }
.placeholder-grid div { display: grid; gap: 4px; padding: 11px 12px; background: #0a1624; }
.placeholder-grid code { color: var(--cyan); font-size: .78rem; }
.placeholder-grid span { color: var(--muted); font-size: .76rem; }

.routing-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 9px; }
.route-card { padding: 13px; border: 1px solid var(--line); border-radius: 9px; background: #0a1624; }
.route-header { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.route-header strong { font-size: .875rem; }
.route-actions { display: flex; gap: 5px; }
.tag-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.tag { padding: 5px 8px; border-radius: 6px; background: rgba(75,143,255,.1); color: #b8d1ff; font-size: .75rem; }
.badge { display: inline-flex; padding: 5px 8px; border-radius: 7px; background: var(--surface-2); color: var(--muted); font-size: .75rem; font-weight: 750; white-space: nowrap; }
.badge.success { color: var(--green); background: rgba(99,221,164,.08); }
.badge.warning { color: var(--orange); background: rgba(255,173,102,.08); }

.setup-grid { display: grid; grid-template-columns: minmax(300px, .65fr) minmax(500px, 1.35fr); gap: 14px; }
.setup-grid .panel { margin: 0; }
fieldset { margin: 0; padding: 11px; border: 1px solid var(--line); border-radius: 8px; }
legend { padding: 0 5px; color: #c1cfda; font-size: .82rem; font-weight: 650; }
.group-picker { display: flex; flex-wrap: wrap; gap: 7px; }
.group-option { display: inline-flex; align-items: center; gap: 7px; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; color: var(--muted); cursor: pointer; }
.group-option input { width: 14px; height: 14px; margin: 0; accent-color: var(--cyan); }
.group-option:has(input:checked) { border-color: rgba(72,217,208,.45); background: rgba(72,217,208,.08); color: var(--text); }

dialog { width: min(820px, calc(100% - 28px)); max-height: 86vh; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 30px 90px rgba(0,0,0,.5); }
dialog::backdrop { background: rgba(2,8,14,.78); backdrop-filter: blur(4px); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.dialog-heading h2 { margin: 0; font-size: 1.12rem; }
.detail-content { overflow: auto; max-height: 68vh; margin: 0; padding: 16px; border-radius: 9px; background: #06101a; color: #c4d6e3; font-size: .78rem; line-height: 1.65; white-space: pre-wrap; word-break: break-word; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 30; transform: translateY(15px); padding: 11px 14px; border: 1px solid rgba(72,217,208,.3); border-radius: 8px; background: #112738; color: var(--text); opacity: 0; pointer-events: none; transition: .18s; font-size: .875rem; }
.toast.error { border-color: rgba(255,113,128,.45); }
.toast.show { transform: translateY(0); opacity: 1; }

@media (max-width: 1080px) {
  .app-header nav { display: none; }
  .primary-grid, .setup-grid { grid-template-columns: 1fr; }
  .flow-steps { grid-template-columns: 1fr 1fr; }
  .placeholder-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 720px) {
  .app-header { gap: 10px; padding: 9px 14px; }
  .brand { min-width: auto; }
  .brand small, .online-dot, .user-name, #refresh-button { display: none; }
  main { padding: 22px 14px 55px; }
  .page-heading { align-items: flex-start; flex-direction: column; gap: 8px; }
  .stats { grid-template-columns: 1fr 1fr; }
  .stats article { align-items: flex-start; flex-direction: column; gap: 7px; }
  .flow-steps, .placeholder-grid, .form-grid { grid-template-columns: 1fr; }
  .full-span { grid-column: auto; }
  .panel { padding: 16px; }
  .panel-heading { align-items: flex-start; flex-direction: column; }
}
