:root {
    color-scheme: dark;
    --bg: #0b1119;
    --surface: #111a27;
    --surface-2: #162131;
    --border: #2b3a4e;
    --text: #f5f7fb;
    --muted: #9aa9bd;
    --accent: #ef3c83;
    --accent-hover: #d92f73;
    --success: #37c68a;
    --danger: #f36b72;
    --warning: #f3bd55;
    font-family: "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body { font-size: 14px; }
a { color: inherit; }
button, input, select { font: inherit; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 228px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; padding: 26px 18px; background: #0d1625; border-right: 1px solid var(--border); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; margin: 0 8px 34px; }
.brand-mark { width: 36px; height: 36px; display: inline-grid; place-items: center; border-radius: 6px; background: var(--accent); font-weight: 800; color: white; }
.brand strong { display: block; font-size: 20px; letter-spacing: 0; }
.brand small { display: block; color: var(--muted); margin-top: 1px; }
.sidebar nav { display: grid; gap: 6px; }
.nav-link { display: block; width: 100%; padding: 12px 14px; border: 1px solid transparent; border-radius: 6px; text-decoration: none; color: #cad4e2; text-align: left; background: transparent; cursor: pointer; }
.nav-link:hover { background: var(--surface-2); }
.nav-link.active { color: white; background: var(--accent); font-weight: 600; }
.logout-form { margin-top: auto; }
.nav-button { border-color: var(--border); }
.content { min-width: 0; padding: 38px 42px 64px; }

.page-header { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 28px; }
.page-header h1 { margin: 5px 0 4px; font-size: 30px; line-height: 1.2; letter-spacing: 0; }
.page-header p, .section-heading p { margin: 0; color: var(--muted); }
.back-link, .text-link { color: #7fa9ff; text-decoration: none; }
.back-link:hover, .text-link:hover, .table-link:hover { text-decoration: underline; }

.button { min-height: 40px; display: inline-flex; align-items: center; justify-content: center; padding: 0 18px; border: 1px solid var(--border); border-radius: 6px; background: #111c2c; color: var(--text); text-decoration: none; cursor: pointer; white-space: nowrap; }
.button:hover { background: #19263a; }
.button.primary { background: var(--accent); border-color: var(--accent); color: white; font-weight: 600; }
.button.primary:hover { background: var(--accent-hover); }
.button.danger { border-color: #893e48; color: #ffb8bd; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); border: 1px solid var(--border); border-radius: 8px; margin-bottom: 24px; overflow: hidden; }
.metric-grid-three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric { min-height: 120px; padding: 20px; background: var(--surface); border-right: 1px solid var(--border); }
.metric:last-child { border-right: 0; }
.metric span, .metric small { display: block; color: var(--muted); }
.metric strong { display: block; margin: 12px 0 7px; font-size: 25px; letter-spacing: 0; }
.metric-warning strong { color: var(--warning); }

.section-block { margin-top: 22px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); overflow: hidden; }
.section-block.compact { margin-top: 0; }
.section-heading { min-height: 76px; padding: 18px 20px; display: flex; align-items: center; justify-content: space-between; gap: 20px; border-bottom: 1px solid var(--border); }
.section-heading h2, .danger-zone h2 { margin: 0 0 5px; font-size: 18px; letter-spacing: 0; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 14px; color: var(--muted); background: #0d1624; text-align: left; font-size: 12px; font-weight: 600; white-space: nowrap; }
td { padding: 14px; border-top: 1px solid var(--border); vertical-align: middle; }
tbody tr:first-child td { border-top: 0; }
.clickable-row { cursor: pointer; }
.clickable-row:hover td { background: #172437; }
.cell-secondary { display: block; margin-top: 4px; color: var(--muted); font-size: 11px; }
.empty { height: 110px; text-align: center; color: var(--muted); }
.table-link { color: #98b9ff; text-decoration: none; font-weight: 600; }
.error-cell { max-width: 280px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #ffabb1; }
.model-name { display: block; }

.status { display: inline-block; padding: 5px 8px; border-radius: 4px; background: #253247; white-space: nowrap; }
.status.success, .status.completed { color: #92e9c4; background: #17382f; }
.status.danger, .status.failed { color: #ffb2b8; background: #3c2228; }
.status.processing { color: #b8d2ff; background: #203552; }
.status.cancelled { color: #d2d8e2; background: #303744; }
.progress { height: 4px; margin-top: 8px; border-radius: 2px; overflow: hidden; background: #27364a; }
.progress span { display: block; height: 100%; background: var(--accent); }
.progress.large { height: 7px; margin: -14px 0 24px; }

.form-section { padding-bottom: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(3, minmax(180px, 1fr)); gap: 18px; padding: 20px; }
.form-grid label, .form-stack label, .filter-bar label { display: grid; gap: 7px; color: #d7deea; font-weight: 600; }
input, select { width: 100%; height: 42px; padding: 0 12px; border: 1px solid #3a4b62; border-radius: 4px; background: #0d1726; color: var(--text); outline: none; }
input:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgb(239 60 131 / 16%); }
label small { color: var(--muted); font-weight: 400; }
.form-actions { display: flex; align-items: end; }
.full { grid-column: 1 / -1; }
.checkbox-label { align-self: center; grid-template-columns: 20px auto !important; align-items: center; margin-top: 20px; }
.checkbox-label input { width: 18px; height: 18px; accent-color: var(--accent); }
.validation { color: #ffabb1; }
.validation:empty { display: none; }

.filter-bar { display: flex; align-items: end; gap: 12px; padding: 16px; margin-bottom: 18px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }
.filter-bar label { min-width: 220px; }
.notice { padding: 13px 16px; margin-bottom: 18px; border: 1px solid var(--border); border-radius: 6px; }
.notice.success { color: #a7ebce; background: #15352c; border-color: #275d4d; }
.notice.danger { color: #ffb4ba; background: #3b2228; border-color: #6d343d; }
.secret-panel { display: grid; grid-template-columns: 1fr minmax(320px, auto); gap: 18px; padding: 18px; margin-bottom: 22px; border: 1px solid #9c7131; border-radius: 8px; background: #312817; }
.secret-panel p { margin: 5px 0 0; color: #d4c3a1; }
.secret-value { display: flex; align-items: center; gap: 10px; min-width: 0; }
.secret-value code { padding: 12px; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; background: #15130e; color: #ffe3a7; }
.danger-zone { display: flex; align-items: center; justify-content: space-between; gap: 22px; padding: 18px 20px; margin-top: 22px; border: 1px solid #71313a; border-radius: 8px; background: #28191d; }
.danger-zone p { margin: 0; color: #d6a7ab; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: #0b1119; }
.login-panel { width: min(430px, 100%); padding: 34px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); box-shadow: 0 24px 80px rgb(0 0 0 / 35%); }
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.login-brand strong { font-size: 20px; }
.login-panel h1 { margin: 0 0 6px; font-size: 27px; letter-spacing: 0; }
.muted { color: var(--muted); }
.form-stack { display: grid; gap: 17px; margin-top: 25px; }

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

@media (max-width: 760px) {
    .app-shell { display: block; }
    .sidebar { position: static; width: 100%; height: auto; padding: 15px; }
    .brand { margin: 0 0 14px; }
    .sidebar nav { display: flex; overflow-x: auto; }
    .nav-link { width: auto; white-space: nowrap; }
    .logout-form { position: absolute; top: 15px; right: 15px; }
    .logout-form .nav-link { padding: 9px 12px; }
    .content { padding: 24px 15px 44px; }
    .page-header { align-items: start; }
    .page-header h1 { font-size: 25px; }
    .metric-grid, .metric-grid-three { grid-template-columns: 1fr; }
    .metric { border-right: 0; border-bottom: 1px solid var(--border); }
    .metric:last-child { border-bottom: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .filter-bar { align-items: stretch; flex-direction: column; }
    .filter-bar label { min-width: 0; }
    .secret-panel { grid-template-columns: 1fr; }
    .secret-value { align-items: stretch; flex-direction: column; }
    .danger-zone { align-items: stretch; flex-direction: column; }
}
