:root {
  --bg: #f4f6fb;
  --panel: #ffffff;
  --border: #e3e7ef;
  --text: #1c2333;
  --muted: #6b7489;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --sidebar: #111827;
  --radius: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error-text { color: var(--danger); min-height: 1.2em; margin: 0; }
h1, h2, h3 { margin: 0 0 .5rem; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.1rem; }
h3 { font-size: 1rem; }
code, pre, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }

/* ── Layout ── */
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: 230px; flex-shrink: 0; background: var(--sidebar); color: #cbd5e1;
  display: flex; flex-direction: column; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: .6rem; font-weight: 600; color: #fff; padding: 0 .5rem 1.25rem; }
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center; width: 52px; height: 52px;
  border-radius: 12px; background: var(--primary); color: #fff; font-weight: 700; font-size: 1.2rem;
}
.brand-mark.small { width: 32px; height: 32px; border-radius: 8px; font-size: .8rem; }
#nav { display: flex; flex-direction: column; gap: 2px; }
#nav a {
  color: #cbd5e1; text-decoration: none; padding: .6rem .75rem; border-radius: 8px;
  display: flex; justify-content: space-between; align-items: center;
}
#nav a:hover { background: #1f2937; color: #fff; }
#nav a.active { background: var(--primary); color: #fff; }
.sidebar-footer { margin-top: auto; display: flex; flex-direction: column; gap: .5rem; padding: 0 .25rem; }
.content { flex: 1; padding: 1.75rem 2rem; max-width: 1280px; min-width: 0; }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; margin-bottom: 1.25rem; flex-wrap: wrap; }
.page-head p { margin: 0; }

/* ── Building blocks ── */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1.25rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: .75rem; flex-wrap: wrap; }
.panel-head h2 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); margin-bottom: 1.25rem; }
.two-col { grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); }
.stat { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .label { color: var(--muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 1.6rem; font-weight: 650; margin-top: .25rem; }
.stat .sub { color: var(--muted); font-size: .8rem; margin-top: .2rem; }
.stat.clickable { cursor: pointer; }
.stat.clickable:hover { border-color: var(--primary); }
.row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.btn {
  border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 8px;
  padding: .5rem .9rem; font: inherit; font-weight: 500; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { background: #f1f4f9; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover:not(:disabled) { background: var(--primary-dark); }
.btn.success { background: var(--success); border-color: var(--success); color: #fff; }
.btn.success:hover:not(:disabled) { filter: brightness(.95); }
.btn.danger { color: var(--danger); border-color: #f3c4c4; }
.btn.danger:hover:not(:disabled) { background: #fdf0f0; }
.btn.ghost { background: transparent; border-color: #374151; color: #cbd5e1; }
.btn.ghost:hover:not(:disabled) { background: #1f2937; }
.btn.small { padding: .3rem .6rem; font-size: .85rem; }

.pill, .badge, .tag {
  display: inline-flex; align-items: center; gap: .35rem; border-radius: 999px; font-size: .78rem; font-weight: 600;
}
.pill { padding: .35rem .7rem; background: #1f2937; color: #cbd5e1; }
.pill::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: #6b7280; }
.pill.on::before { background: #22c55e; box-shadow: 0 0 0 3px rgba(34,197,94,.25); }
.pill.err::before { background: var(--danger); }
.badge { background: #fff; color: var(--primary); padding: 0 .45rem; min-width: 1.4rem; justify-content: center; }
.badge.danger { background: var(--danger); color: #fff; }
.tag { padding: .15rem .55rem; background: #eef2f8; color: var(--muted); }
.tag.pending, .tag.running { background: #fff4e0; color: #b45309; }
.tag.approved, .tag.succeeded, .tag.ok { background: #e3f6e9; color: #15803d; }
.tag.rejected, .tag.failed, .tag.error, .tag.interrupted { background: #fde8e8; color: #b91c1c; }
.tag.warn { background: #fff4e0; color: #b45309; }
.tag.dry { background: #e8effd; color: var(--primary-dark); }

/* ── Toggles ── */
.toggle-group { margin-bottom: 1rem; }
.toggle-group:last-child { margin-bottom: 0; }
.toggle-group h3 { font-size: .78rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); margin-bottom: .35rem; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .6rem 0; border-top: 1px solid var(--border); }
.toggle-row:first-of-type { border-top: none; }
.toggle-row .title { font-weight: 550; }
.toggle-row .desc { color: var(--muted); font-size: .85rem; }
.switch { position: relative; width: 44px; height: 24px; flex-shrink: 0; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd2dd; border-radius: 999px; cursor: pointer; transition: .15s; }
.switch span::before { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.switch input:checked + span { background: var(--success); }
.switch input:checked + span::before { transform: translateX(20px); }
.switch input:disabled + span { opacity: .5; cursor: not-allowed; }

/* ── Forms ── */
input[type=text], input[type=password], input[type=number], input[type=date], input[type=email], input[type=search], select, textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .65rem; font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(37,99,235,.35); border-color: var(--primary); }
textarea { resize: vertical; min-height: 220px; line-height: 1.45; }
label.field { display: flex; flex-direction: column; gap: .3rem; font-weight: 500; }
label.field small { color: var(--muted); font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .85rem; margin: .85rem 0; }
.search { max-width: 280px; }

/* ── Queue ── */
.tabs { display: flex; gap: .25rem; background: #e9edf4; padding: .25rem; border-radius: 9px; }
.tabs button { border: none; background: transparent; padding: .4rem .8rem; border-radius: 7px; font: inherit; cursor: pointer; color: var(--muted); font-weight: 500; }
.tabs button.active { background: #fff; color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.draft { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; margin-bottom: .75rem; }
.draft.selected { border-color: var(--primary); box-shadow: 0 0 0 1px var(--primary); }
.draft-head { display: flex; gap: .75rem; padding: .85rem 1rem; align-items: flex-start; cursor: pointer; }
.draft-head input[type=checkbox] { margin-top: .25rem; width: 16px; height: 16px; }
.draft-main { flex: 1; min-width: 0; }
.draft-subject { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.draft-meta { color: var(--muted); font-size: .83rem; margin-top: .15rem; }
.draft-body { border-top: 1px solid var(--border); padding: 1rem; }
.draft-body pre { white-space: pre-wrap; word-wrap: break-word; margin: 0 0 1rem; background: #f8fafc; border: 1px solid var(--border); padding: .9rem; border-radius: 8px; font-family: inherit; line-height: 1.5; }
.draft-original { font-size: .85rem; color: var(--muted); margin-bottom: .75rem; }
.bulk-bar { position: sticky; top: 0; z-index: 5; background: #eef4ff; border: 1px solid #c9dafc; border-radius: var(--radius); padding: .6rem .9rem; margin-bottom: .75rem; }
.empty { text-align: center; color: var(--muted); padding: 2.5rem 1rem; }

/* ── Console / tables ── */
.console {
  background: #0f172a; color: #d1d9e6; border-radius: 8px; padding: .85rem 1rem; font-size: .8rem; line-height: 1.5;
  max-height: 460px; overflow: auto; white-space: pre-wrap; word-break: break-word; margin: 0;
}
.console .l-err { color: #fca5a5; }
.console .l-ok { color: #86efac; }
.console .l-dash { color: #93c5fd; }
.table-wrap { overflow: auto; max-height: 560px; border: 1px solid var(--border); border-radius: 8px; }
table { border-collapse: collapse; width: 100%; font-size: .85rem; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { background: #f8fafc; position: sticky; top: 0; font-weight: 600; color: var(--muted); white-space: nowrap; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f8fafc; }

.task-card { border-left: 4px solid var(--primary); }
.task-card.disabled { border-left-color: #cbd2dd; }
.notice { background: #fff8eb; border: 1px solid #f5d9a8; color: #8a5a00; padding: .6rem .8rem; border-radius: 8px; margin: .5rem 0; font-size: .88rem; }
.check-row { display: flex; gap: .8rem; align-items: flex-start; padding: .7rem 0; border-top: 1px solid var(--border); }
.check-row:first-child { border-top: none; }

/* ── Login / toasts ── */
.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #111827, #1e3a8a); }
.login-card { background: #fff; padding: 2.25rem; border-radius: 14px; width: 340px; display: flex; flex-direction: column; gap: .8rem; text-align: center; align-items: center; }
.login-card p { margin: 0; }
.login-card input, .login-card button { width: 100%; }
.toasts { position: fixed; right: 1.25rem; bottom: 1.25rem; display: flex; flex-direction: column; gap: .5rem; z-index: 50; }
.toast { background: #111827; color: #fff; padding: .7rem 1rem; border-radius: 8px; max-width: 380px; box-shadow: 0 6px 20px rgba(0,0,0,.2); font-size: .9rem; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }

@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  #nav { flex-direction: row; overflow-x: auto; }
  .sidebar-footer { flex-direction: row; margin-top: .75rem; }
  .content { padding: 1.1rem; }
  .two-col { grid-template-columns: 1fr; }
}
