:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --panel-2: #f8f9fb;
  --line: #e3e6eb;
  --text: #1c2230;
  --muted: #6b7385;
  --accent: #3563e9;
  --accent-soft: #e8eefd;
  --ok: #1f9d55;
  --ok-soft: #e3f5ea;
  --err: #d6443a;
  --err-soft: #fcebea;
  --warn: #b7791f;
  --warn-soft: #fdf4e3;
  --console: #12151c;
  --console-text: #d7dce5;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f1218; --panel: #171b23; --panel-2: #1c212b; --line: #2a303c; --text: #e6e9ef; --muted: #9099ab;
    --accent: #6d8dff; --accent-soft: #1e2a4d; --ok: #43c47a; --ok-soft: #15301f; --err: #ff6b61; --err-soft: #3a1b19;
    --warn: #e0a84a; --warn-soft: #382a12; --console: #0a0c10; --shadow: none; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f1218; --panel: #171b23; --panel-2: #1c212b; --line: #2a303c; --text: #e6e9ef; --muted: #9099ab;
  --accent: #6d8dff; --accent-soft: #1e2a4d; --ok: #43c47a; --ok-soft: #15301f; --err: #ff6b61; --err-soft: #3a1b19;
  --warn: #e0a84a; --warn-soft: #382a12; --console: #0a0c10; --shadow: none; color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
a { color: var(--accent); }
code, pre, textarea.code { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }

/* layout */
.layout { display: grid; grid-template-columns: 280px 1fr; height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.logo { font-weight: 700; font-size: 16px; letter-spacing: -.01em; }
.logo.big { font-size: 22px; text-align: center; }
.upload-btn { margin: 8px 12px 12px; border: 1.5px dashed var(--accent); border-radius: var(--radius); padding: 12px; text-align: center;
  cursor: pointer; background: var(--accent-soft); color: var(--accent); display: flex; flex-direction: column; gap: 2px; font-weight: 600; }
.upload-btn small { color: var(--muted); font-weight: 400; }
.upload-btn:hover { filter: brightness(.98); }
.script-list { flex: 1; overflow: auto; padding: 0 8px; }
.script-item { display: flex; gap: 10px; align-items: center; padding: 9px 10px; border-radius: 9px; color: var(--text); text-decoration: none; }
.script-item:hover { background: var(--panel-2); }
.script-item.active { background: var(--accent-soft); }
.script-item .t { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.script-item small { display: block; color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--line); flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.side-foot { border-top: 1px solid var(--line); padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.side-link { display: block; padding: 8px 10px; border-radius: 8px; color: var(--text); text-decoration: none; background: none; border: 0;
  text-align: left; font: inherit; cursor: pointer; }
.side-link:hover { background: var(--panel-2); }
.main { overflow: auto; min-width: 0; }
#view { max-width: 1180px; margin: 0 auto; padding: 24px 28px 60px; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.only-mobile { display: none; }

/* header */
.head { display: flex; gap: 16px; align-items: flex-start; justify-content: space-between; flex-wrap: wrap; margin-bottom: 6px; }
.head h1 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.desc { color: var(--muted); margin: 6px 0 0; max-width: 760px; white-space: pre-line; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.chip { background: var(--panel-2); border: 1px solid var(--line); border-radius: 99px; padding: 2px 10px; font-size: 12px; color: var(--muted); }
.chip.svc { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.chip.ok { background: var(--ok-soft); color: var(--ok); border-color: transparent; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin: 18px 0 20px; overflow-x: auto; }
.tab { padding: 10px 14px; border: 0; background: none; font: inherit; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; white-space: nowrap; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

/* cards & forms */
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; align-items: start; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card h3 { margin: 0 0 4px; font-size: 15px; }
.card .sub { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.group-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 18px 0 10px; font-weight: 600; }
.group-title:first-child { margin-top: 0; }
.field { margin-bottom: 12px; }
.field > label { display: block; font-weight: 550; margin-bottom: 4px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 3px; }
.field .tech { color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; margin-left: 6px; font-weight: 400; }
input[type=text], input[type=password], input[type=number], select, textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); font: inherit; }
textarea { min-height: 70px; resize: vertical; }
textarea.code { min-height: 60vh; font-size: 13px; line-height: 1.5; tab-size: 4; white-space: pre; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--panel); }
.row { display: flex; gap: 8px; align-items: center; }
.row > input { flex: 1; min-width: 0; }
.switch, .field > label.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.switch .knob { width: 38px; height: 22px; border-radius: 99px; background: var(--line); position: relative; transition: .15s; flex: none; }
.switch .knob::after { content: ""; position: absolute; width: 16px; height: 16px; border-radius: 50%; background: #fff; top: 3px; left: 3px; transition: .15s; }
.switch input:checked + .knob { background: var(--accent); }
.switch input:checked + .knob::after { left: 19px; }
.fstate { font-size: 12px; white-space: nowrap; }
.fstate.ok { color: var(--ok); }
.fstate.no { color: var(--warn); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: var(--panel);
  color: var(--text); padding: 8px 14px; border-radius: 9px; font: inherit; font-weight: 550; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--panel-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { filter: brightness(1.07); }
.btn.big { padding: 11px 20px; font-size: 15px; }
.btn.danger { color: var(--err); }
.btn.stop { background: var(--err); border-color: var(--err); color: #fff; }
.btn.sm { padding: 4px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: default; }
.icon-btn { border: 0; background: none; font-size: 18px; cursor: pointer; color: var(--text); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--panel-2); }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-top: 8px; }

.notice { border-radius: 10px; padding: 10px 14px; margin-bottom: 14px; font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: var(--warn); }
.notice.err { background: var(--err-soft); color: var(--err); }
.notice.info { background: var(--accent-soft); color: var(--accent); }
.notice code { background: rgba(127,127,127,.15); padding: 0 4px; border-radius: 4px; }

.func { border-top: 1px solid var(--line); padding-top: 14px; margin-top: 14px; }
.func:first-of-type { border-top: 0; margin-top: 0; padding-top: 0; }
.func-head { display: flex; justify-content: space-between; gap: 10px; align-items: flex-start; }
.func-head h4 { margin: 0; font-size: 14px; }
.func-head .tech { color: var(--muted); font-size: 11px; font-family: ui-monospace, Consolas, monospace; }
.func .params { margin-top: 10px; }

/* console */
.console { background: var(--console); color: var(--console-text); border-radius: var(--radius); overflow: hidden; position: sticky; top: 16px; }
.console-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid #252a35; flex-wrap: wrap; }
.console-head .title { flex: 1; font-weight: 600; font-size: 13px; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; padding: 2px 8px; border-radius: 99px; background: #252a35; }
.status.running { background: #1e3a8a; color: #c7d7ff; }
.status.ok { background: #14532d; color: #b8f0cd; }
.status.error, .status.interrupted { background: #5c1d19; color: #ffcbc6; }
.status.stopped { background: #3f3f46; color: #e4e4e7; }
.console pre { margin: 0; padding: 12px; height: 52vh; overflow: auto; font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; word-break: break-word; }
.console-in { display: flex; gap: 6px; padding: 8px; border-top: 1px solid #252a35; }
.console-in input { background: #1a1e27; color: var(--console-text); border-color: #2c3240; }
.console .outs { padding: 8px 12px 12px; border-top: 1px solid #252a35; font-size: 13px; }
.console .outs a { color: #9db4ff; margin-right: 12px; display: inline-block; }
.console .empty { padding: 40px 16px; text-align: center; color: #7c8496; }
.run-chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px 12px 0; }
.run-chips button { background: #1f2430; border: 1px solid #2c3240; color: var(--console-text); border-radius: 99px; padding: 2px 10px; font-size: 12px; cursor: pointer; }
.run-chips button.active { border-color: #6d8dff; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.tbl th, .tbl td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.tbl th { color: var(--muted); font-weight: 600; font-size: 12px; background: var(--panel-2); position: sticky; top: 0; }
.tbl td.num { text-align: right; white-space: nowrap; color: var(--muted); }
.tbl tr:hover td { background: var(--panel-2); }
.tbl .acts { display: flex; gap: 4px; justify-content: flex-end; flex-wrap: wrap; }
.tbl-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--line); border-radius: 10px; }
.tbl-wrap .tbl td { white-space: nowrap; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.dropzone { border: 1.5px dashed var(--line); border-radius: var(--radius); padding: 22px; text-align: center; color: var(--muted); cursor: pointer; margin-bottom: 14px; }
.dropzone:hover, .dropzone.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.empty-state { text-align: center; padding: 70px 20px; color: var(--muted); }
.empty-state h2 { color: var(--text); margin: 0 0 8px; }
.empty-state .steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; max-width: 760px; margin: 28px auto 0; text-align: left; }
.empty-state .steps div { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.empty-state .steps b { display: block; color: var(--text); margin-bottom: 4px; }

/* modal / toast */
.modal { position: fixed; inset: 0; background: rgba(10, 12, 18, .55); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-card { background: var(--panel); border-radius: 14px; width: min(1000px, 100%); max-height: 90vh; overflow: auto; padding: 20px; position: relative; }
.modal-x { position: absolute; right: 10px; top: 10px; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--panel); padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90vw; }
.toast.err { background: var(--err); color: #fff; }
.drop-overlay { position: fixed; inset: 0; background: rgba(53, 99, 233, .18); border: 3px dashed var(--accent); z-index: 70; display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; color: var(--accent); pointer-events: none; }
.login { display: flex; align-items: center; justify-content: center; height: 100vh; padding: 16px; }
.login-card { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 28px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.err { color: var(--err); font-size: 13px; min-height: 18px; }
.muted { color: var(--muted); }
.subtabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.subtabs button { border: 1px solid var(--line); background: var(--panel-2); color: var(--text); border-radius: 99px; padding: 3px 12px; cursor: pointer; font: inherit; font-size: 13px; }
.subtabs button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.label-edit { display: grid; grid-template-columns: 180px 1fr 1fr; gap: 8px; align-items: center; margin-bottom: 8px; }
.label-edit code { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }

@media (max-width: 960px) {
  .grid2 { grid-template-columns: 1fr; }
  .console { position: static; }
  .console pre { height: 40vh; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 20% 0 0; z-index: 40; transform: translateX(-102%); transition: transform .2s; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  .side.open { transform: none; }
  .only-mobile { display: flex; }
  #view { padding: 16px 16px 50px; }
  .head h1 { font-size: 20px; }
  .empty-state .steps { grid-template-columns: 1fr; }
  .label-edit { grid-template-columns: 1fr; }
  .tbl .hide-m { display: none; }
}
