:root {
  color-scheme: light;
  --bg: #f4f7f9;
  --surface: #ffffff;
  --surface-muted: #f8fafc;
  --text: #17212b;
  --muted: #5e6b78;
  --line: #dbe3ea;
  --line-strong: #c5d0da;
  --primary: #0f6b8f;
  --primary-strong: #0a5674;
  --success: #16845c;
  --warning: #b26b00;
  --danger: #b42318;
  --ink: #243447;
  --shadow: 0 14px 36px rgba(23, 33, 43, 0.08);
  --shadow-soft: 0 8px 22px rgba(23, 33, 43, 0.06);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #eef5f7 0, #f7f9fb 260px, var(--bg) 100%);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.45;
}

body.dark {
  color-scheme: dark;
  --bg: #161b22;
  --surface: #202731;
  --surface-muted: #19202a;
  --text: #edf2f7;
  --muted: #a8b3bf;
  --line: #344150;
  --line-strong: #4b5b6a;
  --primary: #4aa3c7;
  --primary-strong: #79c3df;
  --success: #45b985;
  --warning: #d99b35;
  --danger: #f06b61;
  --ink: #d7e1ea;
  --shadow: 0 14px 36px rgba(0, 0, 0, 0.28);
  --shadow-soft: 0 8px 22px rgba(0, 0, 0, 0.2);
  background:
    linear-gradient(180deg, #101820 0, #151b23 260px, var(--bg) 100%);
}

a {
  color: var(--primary);
}

h1, h2, h3 {
  color: var(--text);
  letter-spacing: 0;
}

button,
.btn,
input[type="submit"],
input[type="button"],
.menu-action,
.top-links a {
  min-height: 38px;
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 9px 13px;
  background: var(--ink);
  color: #fff;
  font: inherit;
  font-weight: 700;
  text-decoration: none;
  cursor: pointer;
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.12s ease, border-color 0.12s ease;
}

button:hover,
.btn:hover,
input[type="submit"]:hover,
input[type="button"]:hover,
.menu-action:hover,
.top-links a:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-soft);
}

button:disabled,
.btn:disabled,
input[type="submit"]:disabled,
input[type="button"]:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

input,
select,
textarea {
  min-height: 40px;
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 9px 11px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(15, 107, 143, 0.16);
  border-color: var(--primary);
}

table {
  border-collapse: collapse;
  background: var(--surface);
}

th {
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td, th {
  border-bottom: 1px solid var(--line);
}

.page-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 22px 0 34px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.page-title {
  margin: 0;
  font-size: clamp(24px, 4vw, 34px);
  line-height: 1.08;
}

.page-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.panel,
.modern-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
}

.auth-container {
  border: 1px solid var(--line);
  border-radius: 8px !important;
  box-shadow: var(--shadow) !important;
}

.auth-container h2 {
  margin-top: 0;
  color: var(--text);
}

.auth-container input,
.auth-container button,
.auth-container .submit-btn {
  width: 100%;
}

.auth-container button,
.auth-container .submit-btn {
  background: var(--primary) !important;
}

.auth-container a {
  color: var(--primary) !important;
  font-weight: 700;
}

.auth-container .password-toggle {
  position: absolute;
  right: 8px;
  top: 50%;
  width: auto !important;
  min-height: auto !important;
  padding: 3px 8px !important;
  transform: translateY(-50%);
  box-shadow: none !important;
  background: var(--surface-muted) !important;
  border: 1px solid var(--line-strong) !important;
  color: var(--muted) !important;
  font-size: 12px;
  font-weight: 600;
}

.btn-approve,
.btn-admin {
  background: var(--primary) !important;
}

.btn-deny,
.btn-danger {
  background: var(--danger) !important;
}

.btn-load.active,
.btn-filter.active {
  background: var(--primary) !important;
  color: #fff !important;
}

.toolbar-row {
  display: flex;
  align-items: end;
  gap: 12px;
  flex-wrap: wrap;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label,
label.field-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.segmented {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segmented label {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 6px;
  color: var(--text);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}

.segmented input {
  min-height: auto;
}

.notice {
  border-radius: 7px;
  border: 1px solid var(--line);
}

@media (max-width: 720px) {
  .page-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 14px;
  }

  .page-header {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar-row {
    align-items: stretch;
  }

  .toolbar-row > *,
  .toolbar-row button,
  .toolbar-row input,
  .toolbar-row select {
    width: 100%;
  }
}

/* ── Auth page layout ────────────────────────────────────── */
body.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 24px 16px;
}

.auth-container {
  background: var(--surface);
  padding: 32px;
  max-width: 420px;
  width: 100%;
}

.auth-container h2 {
  font-size: 22px;
  text-align: center;
  margin-top: 0;
  margin-bottom: 22px;
}

.password-wrap {
  position: relative;
}

.password-wrap input {
  padding-right: 64px;
}

.auth-theme-btn {
  position: fixed;
  top: 14px;
  right: 16px;
  min-height: auto !important;
  padding: 6px 14px !important;
  font-size: 13px;
  font-weight: 600;
  background: var(--surface) !important;
  border: 1px solid var(--line) !important;
  color: var(--muted) !important;
}

.auth-links {
  margin-top: 18px;
  text-align: center;
  font-size: 14px;
  color: var(--muted);
}

.auth-links a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

.auth-error {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(180, 35, 24, 0.1);
  color: var(--danger);
  font-weight: 600;
  display: none;
  text-align: center;
  border: 1px solid rgba(180, 35, 24, 0.22);
  font-size: 14px;
}

.auth-success {
  margin-top: 12px;
  padding: 10px 12px;
  border-radius: 6px;
  background: rgba(22, 132, 92, 0.1);
  color: var(--success);
  font-weight: 600;
  text-align: center;
  border: 1px solid rgba(22, 132, 92, 0.22);
  font-size: 14px;
}

/* ── Notice variants ─────────────────────────────────────── */
.notice { padding: 10px 14px; }

.notice-success {
  background: #d1e7dd;
  color: #0f5132;
  border-color: #a3cfbb;
}

.notice-error {
  background: #f8d7da;
  color: #842029;
  border-color: #f1aeb5;
}

body.dark .notice-success {
  background: #0d2618;
  color: #6dbd91;
  border-color: #1a4a2e;
}

body.dark .notice-error {
  background: #2d0e13;
  color: #e8848e;
  border-color: #5c1a23;
}

/* ── Page nav links (consistent across all pages) ────────── */
.page-nav-links {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.page-nav-links a {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 6px 13px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.12s, border-color 0.12s;
}

.page-nav-links a:hover {
  background: var(--surface-muted);
  border-color: var(--line-strong);
  transform: none;
  box-shadow: none;
}

/* ── Section panels (content cards within pages) ─────────── */
.section-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  padding: 20px 24px;
  margin-bottom: 20px;
}

.section-panel > h2 {
  margin: 0 0 16px;
  font-size: 17px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

/* ── Command status chain (shared admin + manager) ───────── */
.status-chain { display: flex; flex-wrap: wrap; gap: 6px; }

.status-step {
  padding: 2px 8px;
  border-radius: 10px;
  border: 1px solid var(--line);
  font-size: 12px;
  white-space: nowrap;
}

.status-step-inactive { color: var(--muted); border-color: var(--line); font-weight: normal; }
.status-step-active   { font-weight: bold; }
.status-queued        { color: var(--warning); font-weight: bold; }
.status-sent          { color: var(--warning); font-weight: bold; }
.status-retrying      { color: var(--warning); font-weight: bold; }
.status-received      { color: var(--primary); font-weight: bold; }
.status-ok,
.status-completed     { color: var(--success); font-weight: bold; }
.status-fail          { color: var(--danger);  font-weight: bold; }
