:root {
    color-scheme: light;
    --bg: #f4f7fb;
    --panel: #ffffff;
    --sidebar: #111827;
    --sidebar-muted: #94a3b8;
    --text: #172033;
    --muted: #64748b;
    --border: #e2e8f0;
    --primary: #5b5bd6;
    --primary-dark: #4646ba;
    --success: #0f9f6e;
    --danger: #dc4c64;
    --warning: #d48a12;
    --radius: 14px;
    --shadow: 0 10px 30px rgba(15, 23, 42, .06);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; }
button { cursor: pointer; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; background: var(--sidebar); color: white; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 0 10px 28px; font-size: 22px; font-weight: 800; letter-spacing: -.5px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 10px; color: white; background: linear-gradient(135deg, #7777ed, #4f46e5); font-size: 18px; }
.sidebar nav { display: grid; gap: 5px; }
.nav-link { display: block; width: 100%; padding: 11px 13px; border: 0; border-radius: 9px; background: transparent; color: var(--sidebar-muted); text-align: left; transition: .15s ease; }
.nav-link:hover, .nav-link.active { background: rgba(255,255,255,.09); color: white; }
.nav-link.active { font-weight: 700; }
.logout-form { margin-top: auto; }
.nav-button { appearance: none; }

.main-wrap { min-width: 0; }
.topbar { min-height: 96px; padding: 24px 32px 18px; display: flex; align-items: center; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.78); backdrop-filter: blur(8px); }
.topbar h1 { margin: 2px 0 0; font-size: 25px; letter-spacing: -.5px; }
.eyebrow { color: var(--primary); font-size: 10px; font-weight: 800; letter-spacing: 1.3px; }
.content { padding: 26px 32px 48px; }

.alert { margin-bottom: 18px; padding: 12px 14px; border: 1px solid; border-radius: 10px; }
.alert-success { color: #086b4c; background: #eafaf4; border-color: #b9ebd8; }
.alert-error { color: #a52a41; background: #fff0f3; border-color: #fac7d1; }
.alert-warning { color: #895609; background: #fff8e8; border-color: #f6dda4; }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(150px, 1fr)); gap: 16px; margin-bottom: 22px; }
.stat-card { min-height: 120px; padding: 20px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); display: flex; flex-direction: column; justify-content: space-between; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 600; }
.stat-value { font-size: 32px; line-height: 1; letter-spacing: -1px; }
.stat-value.accent { color: var(--primary); }
.stat-value.success { color: var(--success); }
.stat-value.danger { color: var(--danger); }

.panel { margin-bottom: 22px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.panel-heading { padding: 19px 20px; display: flex; align-items: center; justify-content: space-between; gap: 16px; border-bottom: 1px solid var(--border); }
.panel-heading h2, .note-panel h2 { margin: 0 0 4px; font-size: 16px; }
.panel-heading p, .note-panel p { margin: 0; color: var(--muted); font-size: 13px; }
.text-link { color: var(--primary); font-weight: 700; }
.form-panel { overflow: visible; }
.compact-panel { padding: 18px 20px; }
.note-panel { padding: 20px; }

.form-grid { padding: 20px; display: grid; grid-template-columns: repeat(3, minmax(160px, 1fr)); gap: 16px; align-items: end; }
.api-form { grid-template-columns: repeat(3, minmax(160px, 1fr)); }
label { display: grid; gap: 7px; color: #334155; font-size: 12px; font-weight: 700; }
.hint { color: var(--muted); font-weight: 400; }
input, select { width: 100%; min-height: 41px; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 9px; outline: none; background: #fff; color: var(--text); }
input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(91,91,214,.12); }
input:disabled { background: #f1f5f9; color: #94a3b8; }
.check-label { min-height: 41px; display: flex; flex-direction: row; align-items: center; gap: 8px; }
.check-label input { width: 17px; min-height: 17px; accent-color: var(--primary); }
.form-actions { display: flex; gap: 9px; align-items: center; }

.button { min-height: 38px; padding: 9px 13px; border: 1px solid transparent; border-radius: 9px; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; white-space: nowrap; }
.button-primary { background: var(--primary); color: white; }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { border-color: var(--border); background: #fff; color: #475569; }
.button-secondary:hover { background: #f8fafc; }
.button-danger { border-color: #ffd3db; background: #fff3f5; color: var(--danger); }
.button-small { min-height: 31px; padding: 6px 9px; font-size: 12px; }
.button-wide { width: 100%; }
.button:disabled { cursor: not-allowed; opacity: .48; }
.inline-form { display: inline; }
.action-row { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }

.mode-form { padding: 20px; display: grid; grid-template-columns: 1fr 1fr 1.5fr auto; gap: 14px; align-items: end; }
.radio-card { min-height: 64px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; display: flex; grid-template-columns: auto 1fr; flex-direction: row; align-items: center; gap: 10px; }
.radio-card input { width: 17px; min-height: 17px; accent-color: var(--primary); }
.radio-card span { display: grid; gap: 3px; }
.radio-card small { color: var(--muted); font-weight: 400; }
.mode-select { min-width: 200px; }

.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 14px; background: #f8fafc; color: var(--muted); font-size: 11px; text-align: left; text-transform: uppercase; letter-spacing: .45px; white-space: nowrap; }
td { padding: 13px 14px; border-top: 1px solid var(--border); vertical-align: middle; white-space: nowrap; }
tbody tr:hover { background: #fbfcfe; }
.empty-cell { padding: 34px; color: var(--muted); text-align: center; }
.error-cell { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }
code { padding: 2px 5px; border-radius: 5px; background: #f1f5f9; color: #475569; font-size: 12px; }
.context-code { display: block; max-width: 380px; overflow: hidden; text-overflow: ellipsis; }
.raw-panel { scroll-margin-top: 20px; }
.raw-box { margin: 0; padding: 20px; max-height: 560px; overflow: auto; background: #0f172a; color: #dbeafe; font: 12px/1.6 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.badge { display: inline-flex; padding: 5px 8px; border-radius: 999px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.badge-active, .badge-info { background: #e8f8f2; color: #087553; }
.badge-paused { background: #f1f5f9; color: #64748b; }
.badge-stopped_limit, .badge-warning { background: #fff5dc; color: #946109; }
.badge-stopped_failures, .badge-error { background: #ffedf1; color: #b8324b; }

.filter-form { display: flex; gap: 12px; align-items: end; flex-wrap: wrap; }
.filter-form label { min-width: 180px; }
.pagination { padding: 16px 20px; display: flex; justify-content: flex-end; gap: 8px; border-top: 1px solid var(--border); }

.login-body { min-height: 100vh; display: grid; place-items: center; padding: 20px; background: radial-gradient(circle at top, #eef0ff, var(--bg) 50%); }
.login-card { width: min(420px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 18px; background: white; box-shadow: 0 22px 60px rgba(15,23,42,.12); }
.brand-login { padding: 0 0 24px; color: var(--text); }
.login-card h1 { margin: 0 0 8px; font-size: 25px; }
.muted { margin: 0 0 24px; color: var(--muted); }
.stack { display: grid; gap: 16px; }
.empty-state { padding: 100px 20px; text-align: center; }
.empty-state h1 { margin: 0; font-size: 64px; color: var(--primary); }

@media (max-width: 1100px) {
    .stat-grid { grid-template-columns: repeat(2, minmax(150px, 1fr)); }
    .form-grid, .api-form { grid-template-columns: repeat(2, minmax(160px, 1fr)); }
    .mode-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; height: auto; padding: 14px; }
    .brand { padding: 0 4px 14px; }
    .sidebar nav { display: flex; gap: 4px; overflow-x: auto; }
    .nav-link { width: auto; flex: 0 0 auto; }
    .logout-form { margin-top: 8px; }
    .topbar { min-height: 80px; padding: 18px 18px 14px; }
    .content { padding: 18px 14px 36px; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
    .stat-card { min-height: 105px; padding: 15px; }
    .stat-value { font-size: 27px; }
    .form-grid, .api-form, .mode-form { grid-template-columns: 1fr; }
    .form-actions { grid-column: 1; }
    .panel-heading { align-items: flex-start; }
}

@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr; }
    .login-card { padding: 26px 22px; }
}
