:root {
  --bg: #0f1115;
  --bg-soft: #161a21;
  --bg-card: #1b2029;
  --border: #262c38;
  --text: #e6e9ef;
  --text-dim: #98a1b3;
  --accent: #4f8cff;
  --accent-soft: rgba(79, 140, 255, 0.12);
  --ok: #3ecf8e;
  --warn: #f5a623;
  --err: #ff5c5c;
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6fa; --bg-soft: #ffffff; --bg-card: #ffffff; --border: #dfe4ee;
    --text: #1a1f2b; --text-dim: #64708a; --accent-soft: rgba(79, 140, 255, 0.1);
  }
}

* { box-sizing: border-box; }

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

a { color: var(--accent); text-decoration: none; }
h1, h2, h3 { margin: 0 0 12px; font-weight: 600; }
h1 { font-size: 20px; }
h2 { font-size: 17px; }
h3 { font-size: 14px; color: var(--text-dim); text-transform: uppercase; letter-spacing: .04em; }

/* ── Каркас ─────────────────────────────── */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.sidebar { background: var(--bg-soft); border-right: 1px solid var(--border); padding: 20px 14px; }
.brand { font-weight: 700; font-size: 16px; margin-bottom: 22px; display: flex; align-items: center; gap: 8px; }
.brand span { color: var(--accent); }
.nav a {
  display: block; padding: 9px 12px; border-radius: 8px; color: var(--text-dim);
  margin-bottom: 2px; font-weight: 500;
}
.nav a:hover { background: var(--bg-card); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.sidebar-footer { position: sticky; top: 100vh; padding-top: 20px; color: var(--text-dim); font-size: 12px; }
.main { padding: 24px 28px 60px; max-width: 1400px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }

/* ── Елементи ───────────────────────────── */
.card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.stat-value { font-size: 26px; font-weight: 700; }
.stat-label { color: var(--text-dim); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }

button, .btn {
  font: inherit; font-weight: 500; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-card); color: var(--text);
  padding: 8px 14px; transition: .15s;
}
button:hover { border-color: var(--accent); color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover { filter: brightness(1.1); color: #fff; }
button.danger:hover { border-color: var(--err); color: var(--err); }
button.small { padding: 5px 10px; font-size: 13px; }
button:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  font: inherit; width: 100%; padding: 8px 11px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg); color: var(--text);
}
textarea { font-family: var(--mono); font-size: 12.5px; resize: vertical; min-height: 70px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
label { display: block; margin-bottom: 12px; }
label .lbl { display: block; font-size: 12px; color: var(--text-dim); margin-bottom: 4px; }
label .hint { display: block; font-size: 11.5px; color: var(--text-dim); margin-top: 4px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { text-align: left; color: var(--text-dim); font-weight: 500; font-size: 12px; padding: 8px 10px; border-bottom: 1px solid var(--border); }
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--bg-soft); }

.tag { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11.5px; font-weight: 500; background: var(--bg-soft); border: 1px solid var(--border); color: var(--text-dim); }
.tag.ok { color: var(--ok); border-color: rgba(62, 207, 142, .4); }
.tag.err { color: var(--err); border-color: rgba(255, 92, 92, .4); }
.tag.warn { color: var(--warn); border-color: rgba(245, 166, 35, .4); }
.tag.accent { color: var(--accent); border-color: rgba(79, 140, 255, .4); }

.mono { font-family: var(--mono); font-size: 12.5px; }
.dim { color: var(--text-dim); }
.pre {
  font-family: var(--mono); font-size: 12px; white-space: pre-wrap; word-break: break-word;
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px; max-height: 420px; overflow: auto;
}
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar input[type=search] { max-width: 280px; }
.toolbar select { max-width: 200px; }
.spacer { flex: 1; }

/* Панель масових дій над списком посилок — зʼявляється, коли щось вибрано */
.bulkbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 12px; padding: 9px 14px;
  background: var(--accent-soft, rgba(93, 135, 255, .1));
  border: 1px solid var(--border); border-radius: 10px;
}
.bulkbar[hidden] { display: none; }

/* Кнопки в рядку таблиці тримаємо праворуч і не даємо їм переноситись */
td.row-actions { text-align: right; white-space: nowrap; }
td.row-actions button + button { margin-left: 6px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tabs button { border: none; background: none; border-radius: 0; border-bottom: 2px solid transparent; color: var(--text-dim); padding: 9px 14px; }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.switch { position: relative; display: inline-block; width: 38px; height: 21px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: var(--border); border-radius: 20px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 15px; height: 15px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(17px); }

.split { display: grid; grid-template-columns: 1fr 420px; gap: 18px; align-items: start; }
/* Без цього широка таблиця всередині розпирає колонку й витісняє сусідню */
.split > * { min-width: 0; }
.grid > * { min-width: 0; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } .app { grid-template-columns: 1fr; } .sidebar { display: none; } }

.step { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; background: var(--bg-soft); }
.step-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.step-head .num { width: 22px; height: 22px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-size: 12px; font-weight: 600; }

.paths { max-height: 320px; overflow: auto; font-family: var(--mono); font-size: 12px; }
.paths div { padding: 4px 6px; border-radius: 5px; cursor: pointer; display: flex; justify-content: space-between; gap: 10px; }
.paths div:hover { background: var(--accent-soft); }
.paths .p { color: var(--accent); }
.paths .v { color: var(--text-dim); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 45%; }

.toast {
  position: fixed; right: 20px; bottom: 20px; padding: 12px 16px; border-radius: 10px;
  background: var(--bg-card); border: 1px solid var(--border); box-shadow: 0 10px 30px rgba(0,0,0,.35);
  max-width: 400px; z-index: 50;
}
.toast.err { border-color: var(--err); }
.toast.ok { border-color: var(--ok); }

.login { display: grid; place-items: center; min-height: 100vh; }
.login .card { width: 340px; }
.empty { text-align: center; color: var(--text-dim); padding: 40px 20px; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: 10px 0 10px 18px; border-left: 2px solid var(--border); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 15px; width: 8px; height: 8px; border-radius: 50%; background: var(--border); }
.timeline li.delivered::before { background: var(--ok); }
.timeline li.exception::before { background: var(--err); }
