:root {
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --text: #172033;
    --muted: #667085;
    --line: #dfe4ea;
    --brand: #176b52;
    --brand-hover: #105440;
    --blue: #2463a7;
    --amber: #9a6700;
    --red: #b42318;
    --green: #147a55;
    --sidebar: #172129;
    --sidebar-muted: #9daab2;
}

* { box-sizing: border-box; }
html { font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif; color: var(--text); background: var(--bg); }
body { margin: 0; min-width: 320px; font-size: 14px; line-height: 1.5; }
a { color: inherit; text-decoration: none; }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }

.app { min-height: 100vh; display: grid; grid-template-columns: 224px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; background: var(--sidebar); color: #fff; display: flex; flex-direction: column; padding: 20px 14px 14px; }
.brand { display: flex; align-items: center; gap: 11px; min-height: 44px; padding: 0 9px 18px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-mark { width: 34px; height: 34px; display: grid; place-items: center; background: #fff; color: var(--brand); border-radius: 6px; font-weight: 800; font-size: 17px; }
.brand-copy { display: block; }
.brand-copy strong { display: block; font-size: 15px; letter-spacing: 0; }
.brand-copy span { display: block; color: var(--sidebar-muted); font-size: 11px; margin-top: 1px; }
.nav { display: grid; gap: 4px; padding: 18px 0; }
.nav a { display: flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 6px; color: #d7dfe3; font-weight: 600; }
.nav a:hover { background: rgba(255,255,255,.07); }
.nav a.active { color: #fff; background: #285348; box-shadow: inset 3px 0 #62c29d; }
.sidebar-user { margin-top: auto; border-top: 1px solid rgba(255,255,255,.1); padding: 14px 8px 0; }
.sidebar-user strong { display: block; font-size: 13px; }
.sidebar-user span { display: block; color: var(--sidebar-muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
.logout { margin-top: 9px; padding: 0; border: 0; background: none; color: #c7d0d5; font-size: 12px; }

.main { min-width: 0; }
.topbar { height: 64px; background: var(--surface); border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 28px; }
.topbar h1 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: 0; }
.topbar-meta { color: var(--muted); font-size: 12px; }
.topbar-account { display: none; color: var(--blue); margin-left: 12px; font-weight: 600; }
.page { width: min(1440px, 100%); margin: 0 auto; padding: 24px 28px 48px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
.page-head h2 { margin: 0 0 3px; font-size: 20px; letter-spacing: 0; }
.page-head p { margin: 0; color: var(--muted); }
.actions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }

.btn { min-height: 36px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 0 13px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font-weight: 600; white-space: nowrap; }
.btn:hover { background: var(--surface-muted); }
.btn-primary { background: var(--brand); color: #fff; border-color: var(--brand); }
.btn-primary:hover { background: var(--brand-hover); }
.btn-danger { color: var(--red); border-color: #f1b8b4; }
.btn-small { min-height: 30px; padding: 0 10px; font-size: 12px; }

.metrics { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); border: 1px solid var(--line); background: var(--surface); margin-bottom: 20px; }
.metric { min-width: 0; padding: 18px 20px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 12px; }
.metric strong { display: block; margin-top: 5px; font-size: 25px; line-height: 1.1; letter-spacing: 0; }
.metric em { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; font-style: normal; }

.panel { background: var(--surface); border: 1px solid var(--line); margin-bottom: 20px; }
.panel-head { min-height: 52px; display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 0 18px; border-bottom: 1px solid var(--line); }
.panel-head h3 { margin: 0; font-size: 15px; letter-spacing: 0; }
.panel-body { padding: 18px; }
.panel-empty { padding: 40px 18px; text-align: center; color: var(--muted); }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; border-bottom: 1px solid #edf0f3; text-align: left; vertical-align: middle; }
th { color: #596579; background: var(--surface-muted); font-size: 12px; font-weight: 700; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
.primary-link { color: var(--blue); font-weight: 700; }
.secondary { color: var(--muted); font-size: 12px; }
.mono { font-family: "SFMono-Regular", Consolas, monospace; font-size: 12px; }

.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; white-space: nowrap; }
.badge-normal, .badge-succeeded, .badge-validated { background: #e7f6ef; color: var(--green); }
.badge-attention, .badge-scheduled, .badge-candidate { background: #fff4d8; color: var(--amber); }
.badge-running, .badge-queued { background: #eaf2fc; color: var(--blue); }
.badge-failed, .badge-auth_error, .badge-application_error, .badge-unreachable { background: #feeceb; color: var(--red); }
.badge-unknown, .badge-pending, .badge-blocked { background: #edf0f3; color: #596579; }
.dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; margin-right: 6px; }

.form { max-width: 920px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 18px; }
.field { min-width: 0; }
.field-full { grid-column: 1 / -1; }
.field label { display: block; margin-bottom: 6px; color: #344054; font-size: 12px; font-weight: 700; }
.input { width: 100%; min-height: 40px; border: 1px solid #cfd6df; border-radius: 6px; background: #fff; padding: 8px 10px; color: var(--text); }
textarea.input { min-height: 110px; resize: vertical; }
.input:focus { outline: 2px solid rgba(23,107,82,.18); border-color: var(--brand); }
.help { display: block; margin-top: 5px; color: var(--muted); font-size: 11px; }
.form-actions { display: flex; gap: 8px; margin-top: 20px; padding-top: 18px; border-top: 1px solid var(--line); }
.field-spaced { margin-top: 18px; }
.choice-list { display: grid; gap: 8px; }
.choice { display: flex; align-items: center; gap: 10px; min-height: 42px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; }
.choice input { width: 16px; height: 16px; accent-color: var(--brand); }

.flash { margin-bottom: 18px; padding: 11px 13px; border: 1px solid; border-radius: 6px; }
.flash-success { background: #edf9f3; border-color: #a9ddc7; color: #0f6043; }
.flash-error { background: #fff0ef; border-color: #f1b8b4; color: #8d2118; }
.flash-info { background: #eef5fc; border-color: #bbd3ed; color: #194f86; }
.panel-flash { margin: 16px; }

.detail-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); border-top: 1px solid var(--line); border-left: 1px solid var(--line); }
.detail-item { min-width: 0; padding: 14px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); }
.detail-item span { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.detail-item strong { display: block; overflow-wrap: anywhere; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); }
.stat { background: var(--surface); padding: 15px; }
.stat span { display: block; color: var(--muted); font-size: 11px; }
.stat strong { display: block; font-size: 20px; margin-top: 3px; }

.timeline { position: relative; margin: 0; padding: 0; list-style: none; }
.timeline li { position: relative; padding: 0 0 18px 20px; border-left: 1px solid var(--line); }
.timeline li:last-child { padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -5px; top: 5px; width: 9px; height: 9px; border-radius: 50%; background: var(--blue); }
.timeline time { color: var(--muted); font-size: 11px; }
.timeline p { margin: 3px 0 0; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #eef1f4; }
.login { width: min(400px, 100%); background: #fff; border: 1px solid var(--line); padding: 28px; }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 25px; }
.login-brand .brand-mark { background: var(--brand); color: #fff; }
.login h1 { margin: 0; font-size: 19px; letter-spacing: 0; }
.login p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }
.login .field { margin-bottom: 15px; }
.login .btn { width: 100%; margin-top: 4px; }
.error-page { min-height: 100vh; display: grid; place-items: center; padding: 30px; }
.error-page main { width: min(560px, 100%); }

@media (max-width: 1050px) {
    .metrics { grid-template-columns: repeat(3, minmax(0,1fr)); }
    .metric:nth-child(3) { border-right: 0; }
    .metric:nth-child(-n+3) { border-bottom: 1px solid var(--line); }
    .detail-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}

@media (max-width: 760px) {
    .app { display: block; }
    .sidebar { position: static; width: 100%; height: auto; padding: 10px 12px; }
    .brand { padding: 0 2px 10px; }
    .nav { grid-template-columns: repeat(4, minmax(0,1fr)); padding: 10px 0 0; }
    .nav a { justify-content: center; padding: 0 5px; font-size: 12px; }
    .sidebar-user { display: none; }
    .topbar { height: 54px; padding: 0 16px; }
    .topbar-account { display: inline; }
    .page { padding: 18px 14px 36px; }
    .page-head { align-items: stretch; flex-direction: column; }
    .metrics { grid-template-columns: repeat(2, minmax(0,1fr)); }
    .metric { border-bottom: 1px solid var(--line); }
    .metric:nth-child(odd) { border-right: 1px solid var(--line); }
    .metric:nth-child(even) { border-right: 0; }
    .metric:last-child { grid-column: 1 / -1; border-bottom: 0; }
    .form-grid, .detail-grid { grid-template-columns: 1fr; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
}
