:root {
  --bg: #f6f7f5;
  --surface: #ffffff;
  --surface-2: #f0f2ef;
  --border: #d9ded6;
  --text: #1d211c;
  --muted: #626b5e;
  --accent: #2f6f4f;
  --accent-text: #ffffff;
  --danger: #a3372f;
  --danger-bg: #fbeceb;
  --warn: #8a6100;
  --warn-bg: #fdf3dd;
  --ok: #2f6f4f;
  --log-bg: #12150f;
  --log-text: #dfe6d6;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(20, 25, 18, .06), 0 4px 12px rgba(20, 25, 18, .05);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14170f;
    --surface: #1c2018;
    --surface-2: #232820;
    --border: #343a2e;
    --text: #e6eade;
    --muted: #97a08c;
    --accent: #6fbf8e;
    --accent-text: #10170f;
    --danger: #e98d84;
    --danger-bg: #351f1d;
    --warn: #e0b45c;
    --warn-bg: #33291333;
    --ok: #6fbf8e;
    --log-bg: #0c0e09;
    --log-text: #d6dfca;
    --shadow: none;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

h1, h2, h3 { line-height: 1.25; }
h2 { font-size: 16px; margin: 0 0 4px; }
h3 { font-size: 13px; margin: 16px 0 6px; text-transform: uppercase;
     letter-spacing: .06em; color: var(--muted); }
code { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .92em; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* --- Вхід ---------------------------------------------------------------- */
.login-page { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card {
  width: min(380px, 100%); background: var(--surface); padding: 28px;
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; }
.login-card form { margin-top: 20px; display: grid; gap: 6px; }
.login-card label { font-size: 13px; font-weight: 600; margin-top: 10px; }
.secondary-form { margin-top: 12px; }
.hint { font-size: 13px; color: var(--muted); margin: 8px 0 0; }

input[type="text"], input[type="password"], input:not([type]), select, textarea {
  width: 100%; padding: 9px 11px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px;
}
input:focus-visible, select:focus-visible, button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

button, .button {
  font: inherit; font-weight: 600; cursor: pointer; padding: 9px 16px;
  border-radius: 8px; border: 1px solid transparent;
  background: var(--accent); color: var(--accent-text);
}
button:disabled, .button:disabled { opacity: .5; cursor: not-allowed; }
.button.ghost, button.ghost {
  background: var(--surface); color: var(--text); border-color: var(--border);
}
.button.danger, button.danger { background: var(--danger); color: #fff; }
.button.small, button.small { padding: 5px 10px; font-size: 13px; }
.link-button {
  background: none; border: none; color: var(--muted); padding: 0;
  text-decoration: underline; font-weight: 400;
}
.link { color: var(--accent); text-decoration: none; font-weight: 600; }

.alert {
  background: var(--danger-bg); color: var(--danger); border-radius: 8px;
  padding: 9px 12px; margin: 14px 0 0; font-size: 14px;
}

/* --- Каркас -------------------------------------------------------------- */
.topbar {
  display: flex; justify-content: space-between; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; flex-wrap: wrap;
}
.topbar-title { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.topbar-actions { display: flex; align-items: center; gap: 14px; }
.topbar-actions form { margin: 0; }

.layout {
  display: grid; grid-template-columns: 190px minmax(0, 1fr) minmax(0, 420px);
  gap: 20px; padding: 20px; align-items: start; max-width: 1700px; margin: 0 auto;
}
.sidebar { position: sticky; top: 74px; display: grid; gap: 2px; }
.sidebar a {
  color: var(--muted); text-decoration: none; padding: 7px 10px;
  border-radius: 8px; font-size: 14px;
}
.sidebar a:hover { background: var(--surface-2); color: var(--text); }
.content { display: grid; gap: 18px; min-width: 0; }

.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}

/* --- Команди ------------------------------------------------------------- */
.group { margin-bottom: 26px; }
.group > h2 {
  font-size: 13px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); margin: 0 0 10px;
}
.cards { display: grid; gap: 12px; }

.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
}
.card-head { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.card-title { font-weight: 650; }
.card-summary { color: var(--muted); font-size: 14px; margin: 5px 0 0; }
.card-script { font-size: 12px; color: var(--muted); margin-top: 6px; }
.card-note {
  margin-top: 10px; font-size: 13px; padding: 8px 11px; border-radius: 8px;
  background: var(--warn-bg); color: var(--warn);
}
.card-missing {
  margin-top: 10px; font-size: 13px; padding: 8px 11px; border-radius: 8px;
  background: var(--danger-bg); color: var(--danger);
}

.badge {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em;
  padding: 3px 8px; border-radius: 999px; white-space: nowrap;
}
.badge-read { background: var(--surface-2); color: var(--muted); }
.badge-write { background: var(--warn-bg); color: var(--warn); }
.badge-destructive { background: var(--danger-bg); color: var(--danger); }
.badge-idle { background: var(--surface-2); color: var(--muted); }
.badge-busy { background: var(--warn-bg); color: var(--warn); }

.params { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
          gap: 10px 14px; margin-top: 14px; }
.param label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 3px; }
.param .help { font-size: 12px; color: var(--muted); margin-top: 3px; }
.checkbox { display: flex; align-items: center; gap: 7px; font-size: 14px; }
.checkbox input { width: auto; }

.card-actions {
  display: flex; align-items: center; gap: 14px; margin-top: 14px;
  padding-top: 13px; border-top: 1px solid var(--border); flex-wrap: wrap;
}
.mode-live { color: var(--danger); font-weight: 600; }
.card-error { color: var(--danger); font-size: 13px; }

/* --- Файли --------------------------------------------------------------- */
.upload-row { display: flex; align-items: center; gap: 14px; margin: 12px 0; flex-wrap: wrap; }
.file-columns { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.file-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.file-list li {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  font-size: 13px; padding: 5px 8px; background: var(--surface-2); border-radius: 7px;
}
.file-list .fname { overflow-wrap: anywhere; }
.file-list .fmeta { color: var(--muted); white-space: nowrap; }
.file-list a { color: var(--accent); text-decoration: none; }

/* --- Журнал -------------------------------------------------------------- */
.joblog {
  position: sticky; top: 74px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow);
  max-height: calc(100vh - 100px); overflow: auto;
}
.joblog-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.log {
  background: var(--log-bg); color: var(--log-text); border-radius: 8px;
  padding: 12px 14px; margin: 12px 0 0; min-height: 220px; max-height: 46vh;
  overflow: auto; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 12.5px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere;
}
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 4px; }
.history li {
  display: flex; justify-content: space-between; gap: 10px; align-items: baseline;
  font-size: 13px; padding: 6px 8px; border-radius: 7px; cursor: pointer;
}
.history li:hover { background: var(--surface-2); }
.history .st { font-weight: 700; font-size: 11px; text-transform: uppercase; }
.st-done { color: var(--ok); }
.st-failed, .st-timeout { color: var(--danger); }
.st-running { color: var(--warn); }
.st-cancelled { color: var(--muted); }

/* --- Модалка ------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 14, 8, .55);
  display: grid; place-items: center; padding: 16px; z-index: 20;
}
/* display:grid перебиває атрибут hidden — без цього невидиме тло
   перехоплює всі кліки по сторінці. */
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius); padding: 22px 24px;
  width: min(460px, 100%); border: 1px solid var(--border);
}
.modal h2 { font-size: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal label { display: block; font-size: 13px; margin: 14px 0 5px; }

@media (max-width: 1150px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar { position: static; grid-auto-flow: column; overflow-x: auto; }
  .joblog { position: static; max-height: none; }
}
@media (max-width: 560px) {
  .layout { padding: 16px; gap: 16px; }
  .topbar { padding: 12px 16px; }
}
