:root {
    --bg: #10141c;
    --bg-panel: #171d28;
    --bg-panel-2: #1e2634;
    --line: #2a3444;
    --text: #dfe6f0;
    --text-dim: #8d9bb0;
    --accent: #4a9eff;
    --ok: #34c77b;
    --warn: #f0b429;
    --err: #ef5b5b;
}

html, body {
    height: 100%;
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    font-size: 14px;
}

a { color: var(--accent); }

h1, h2, h3, h4 { color: #fff; font-weight: 600; }
h1 { font-size: 1.4rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ---- Каркас ---- */

.app-shell { display: flex; min-height: 100vh; }

.app-nav {
    width: 224px;
    flex: 0 0 224px;
    background: var(--bg-panel);
    border-right: 1px solid var(--line);
    display: flex;
    flex-direction: column;
}

.app-nav-brand {
    padding: 18px 16px;
    font-weight: 700;
    letter-spacing: .5px;
    color: #fff;
    border-bottom: 1px solid var(--line);
}

.app-nav-list { list-style: none; margin: 0; padding: 8px 0; }

.app-nav-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: var(--text-dim);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.app-nav-link:hover { background: var(--bg-panel-2); color: var(--text); }

.app-nav-link.active {
    background: var(--bg-panel-2);
    color: #fff;
    border-left-color: var(--accent);
}

.nav-icon { width: 18px; text-align: center; opacity: .8; }

.app-main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.app-topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    height: 56px;
    background: var(--bg-panel);
    border-bottom: 1px solid var(--line);
}

.app-topbar-title { font-weight: 600; display: flex; align-items: center; gap: 10px; }

.brand-dot {
    width: 9px; height: 9px; border-radius: 50%;
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

.app-topbar-user { display: flex; align-items: center; gap: 12px; }
.user-name { color: var(--text-dim); }

.app-content { padding: 20px; flex: 1; min-width: 0; }

.page-loading {
    display: flex; align-items: center; justify-content: center;
    gap: 12px; height: 100vh; color: var(--text-dim);
}

/* ---- Карточки и таблицы ---- */

.card-panel {
    background: var(--bg-panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
    margin-bottom: 16px;
}

.card-panel h2, .card-panel h3 { margin-top: 0; }

.section-header {
    display: flex; align-items: center; justify-content: space-between;
    gap: 12px; margin-bottom: 16px; flex-wrap: wrap;
}

.table-dark-soft { width: 100%; border-collapse: collapse; }
.table-dark-soft th {
    text-align: left; font-weight: 600; color: var(--text-dim);
    border-bottom: 1px solid var(--line); padding: 8px 10px; font-size: .85rem;
    text-transform: uppercase; letter-spacing: .4px;
}
.table-dark-soft td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table-dark-soft tr:hover td { background: var(--bg-panel-2); }

.muted { color: var(--text-dim); }
.mono { font-family: "Cascadia Mono", Consolas, monospace; font-size: .85rem; }

/* ---- Состояния ---- */

.state {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 3px 9px; border-radius: 12px; font-size: .8rem; font-weight: 600;
    border: 1px solid transparent;
}
.state::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.state-connected { color: var(--ok); background: rgba(52,199,123,.12); border-color: rgba(52,199,123,.35); }
.state-pending { color: var(--warn); background: rgba(240,180,41,.12); border-color: rgba(240,180,41,.35); }
.state-failed { color: var(--err); background: rgba(239,91,91,.12); border-color: rgba(239,91,91,.35); }
.state-idle { color: var(--text-dim); background: rgba(141,155,176,.12); border-color: rgba(141,155,176,.3); }

/* ---- Формы ---- */

.form-label { color: var(--text-dim); font-size: .82rem; margin-bottom: 4px; font-weight: 600; }

.form-control, .form-select, textarea {
    background: var(--bg-panel-2) !important;
    border: 1px solid var(--line) !important;
    color: var(--text) !important;
}
.form-control:focus, .form-select:focus {
    border-color: var(--accent) !important;
    box-shadow: 0 0 0 .15rem rgba(74,158,255,.25) !important;
}
.form-control::placeholder { color: #5d6b80; }

.form-hint { color: var(--text-dim); font-size: .78rem; margin-top: 3px; }

.field-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }

.tab-strip {
    display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap;
}
.tab-strip button {
    background: none; border: none; border-bottom: 2px solid transparent;
    color: var(--text-dim); padding: 8px 14px; cursor: pointer; font-weight: 600;
}
.tab-strip button:hover { color: var(--text); }
.tab-strip button.active { color: #fff; border-bottom-color: var(--accent); }

/* ---- Журнал вывода клиента ---- */

.console {
    background: #0b0e14;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 10px 12px;
    height: 320px;
    overflow-y: auto;
    font-family: "Cascadia Mono", Consolas, monospace;
    font-size: .8rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.console .line-error { color: #ff8f8f; }
.console .line-time { color: #56637a; margin-right: 8px; }

/* ---- Окно SAML ---- */

.saml-frame {
    background: #000;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: auto;
    display: flex;
    justify-content: center;
}
.saml-frame img { max-width: 100%; cursor: crosshair; outline: none; display: block; }
.saml-frame img:focus { box-shadow: inset 0 0 0 2px var(--accent); }

.saml-toolbar { display: flex; gap: 8px; align-items: center; margin-bottom: 10px; flex-wrap: wrap; }
.saml-url { flex: 1; min-width: 240px; }

/* ---- Вход ---- */

.login-shell {
    min-height: 100vh; display: flex; align-items: center; justify-content: center;
    background: radial-gradient(circle at 30% 20%, #1b2432, var(--bg) 60%);
}
.login-card {
    width: 380px; background: var(--bg-panel); border: 1px solid var(--line);
    border-radius: 10px; padding: 28px;
}
.login-card h1 { font-size: 1.25rem; margin-bottom: 4px; }

/* ---- Мелочи ---- */

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--bg-panel); border: 1px solid var(--line); border-radius: 8px; padding: 14px 16px; }
.stat-card .value { font-size: 1.7rem; font-weight: 700; color: #fff; }
.stat-card .label { color: var(--text-dim); font-size: .82rem; }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.alert-inline {
    border-radius: 6px; padding: 9px 12px; margin-bottom: 12px; font-size: .88rem;
    border: 1px solid transparent;
}
.alert-inline.error { color: #ffb4b4; background: rgba(239,91,91,.1); border-color: rgba(239,91,91,.35); }
.alert-inline.ok { color: #a8ebc7; background: rgba(52,199,123,.1); border-color: rgba(52,199,123,.35); }
.alert-inline.warn { color: #ffdb92; background: rgba(240,180,41,.1); border-color: rgba(240,180,41,.35); }

.otp-banner {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: rgba(240,180,41,.1); border: 1px solid rgba(240,180,41,.4);
    border-radius: 8px; padding: 12px 14px; margin-bottom: 16px;
}
.otp-banner input { width: 130px; }

#blazor-error-ui {
    color-scheme: light only;
    background: lightyellow;
    bottom: 0;
    box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
    box-sizing: border-box;
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem 0.7rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    color: #000;
}
#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

/* Подсказка на случай, когда цепочка Blazor так и не установилась: без неё
   человек видит пустой серый экран и не понимает, куда смотреть. */
#tn-startup {
    max-width: 46rem;
    margin: 4rem auto;
    padding: 1.75rem 2rem;
    border: 1px solid #f85149;
    border-radius: 10px;
    background: #1b1f27;
    color: #c9d1d9;
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    line-height: 1.5;
}

#tn-startup h1 {
    margin: 0 0 .75rem;
    font-size: 1.35rem;
    color: #f85149;
}

#tn-startup pre {
    overflow-x: auto;
    padding: .9rem 1rem;
    border-radius: 8px;
    background: #0d1117;
    color: #8b949e;
    font-size: .8rem;
}

#tn-startup code {
    padding: .1rem .3rem;
    border-radius: 4px;
    background: #0d1117;
    color: #e6edf3;
}

/* Показываем только ту причину, которая относится к делу. */
#tn-startup .tn-when-assets,
#tn-startup .tn-when-circuit { display: none; }

#tn-startup[data-reason="assets"] .tn-when-assets,
#tn-startup[data-reason="circuit"] .tn-when-circuit { display: block; }
