/* ================================================================
   Cabinet (LK) — terminal-themed Bootstrap layer
   ----------------------------------------------------------------
   Loaded after terminal.css on every authenticated cabinet page
   (_Layout.cshtml). The cabinet retains its existing Bootstrap
   markup (cards, rows, forms, tables) — this file maps Bootstrap
   tokens to the terminal palette and restyles the cabinet chrome
   (top-navbar, sidebar, main-content, footer) so the cabinet and
   the trading terminal share one visual language.

   Strategy:
   - Override the `--bs-*` CSS custom properties Bootstrap 5.3 uses
     under `data-bs-theme="dark"`, mapping them to terminal colours
     (var(--t-bg) / var(--t-panel) / var(--t-accent) etc.).
   - Restyle the cabinet's bespoke chrome (top-navbar, sidebar) to
     match the terminal-topbar aesthetic (compact, dark, yellow
     accent).
   - Avoid touching individual cabinet page markup — layout
     patches alone should be enough for visual unity.
   ================================================================ */

/* The `:root[data-bs-theme="light"]` block that overrides --t-* lives
   in terminal.css now (next to the dark defaults that own the palette
   tokens), so both terminal and cabinet pick up the same light values
   when the theme flips. */

/* ---------- Bootstrap palette → terminal palette ----------
   Theme-agnostic mapping: `--t-*` already changes per theme via the
   block above + the dark defaults in terminal.css, so binding `--bs-*`
   once on :root works for both. */
:root {
    --bs-body-bg: var(--t-bg);
    --bs-body-color: var(--t-text);
    --bs-emphasis-color: var(--t-text-bright);
    --bs-secondary-color: var(--t-text-dim);
    --bs-tertiary-color: var(--t-text-dim);
    --bs-secondary-bg: var(--t-panel);
    --bs-tertiary-bg: var(--t-surface);
    --bs-border-color: var(--t-border);
    --bs-border-color-translucent: var(--t-border);
    --bs-primary: var(--t-accent);
    --bs-success: var(--t-green);
    --bs-danger: var(--t-red);
    --bs-warning: var(--t-accent);
    --bs-info: #5fb1ff;
    --bs-link-color: var(--t-accent);
    --bs-link-hover-color: var(--t-accent-hover);
    --bs-card-bg: var(--t-panel);
    --bs-card-border-color: var(--t-border);
    --bs-card-cap-bg: var(--t-header);
    --bs-table-bg: transparent;
    --bs-table-color: var(--t-text);
    --bs-table-border-color: var(--t-border);
    --bs-table-hover-bg: var(--t-hover);
    --bs-form-control-bg: var(--t-surface);
    --bs-modal-bg: var(--t-panel);
    --bs-dropdown-bg: var(--t-panel);
    --bs-dropdown-link-color: var(--t-text);
    --bs-dropdown-link-hover-bg: var(--t-hover);
    --bs-dropdown-link-hover-color: var(--t-text-bright);
    --bs-dropdown-border-color: var(--t-border);
}
[data-bs-theme="dark"] { --bs-primary-rgb: 252, 213, 53; --bs-success-rgb: 14, 203, 129; --bs-danger-rgb: 246, 70, 93; --bs-table-striped-bg: rgba(255, 255, 255, 0.02); }
[data-bs-theme="light"] { --bs-primary-rgb: 217, 119, 6; --bs-success-rgb: 22, 163, 74; --bs-danger-rgb: 220, 38, 38; --bs-table-striped-bg: rgba(0, 0, 0, 0.02); }

body {
    font-family: var(--t-font);
    background: var(--t-bg);
    color: var(--t-text);
}

a { color: var(--t-accent); text-decoration: none; }
a:hover { color: var(--t-accent-hover); }

/* ---------- Top nav ---------- */
.top-navbar {
    background: var(--t-header);
    border-bottom: 1px solid var(--t-border);
    height: 44px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    color: var(--t-text);
    font-size: 12px;
    box-shadow: none;
    position: sticky;
    top: 0;
    z-index: 1020;
}
.top-navbar .navbar-brand {
    color: var(--t-text-bright);
    font-weight: 700;
    letter-spacing: -0.3px;
    font-size: 14px;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}
.top-navbar .navbar-brand .brand-icon {
    color: var(--t-accent);
    font-size: 16px;
}

.top-navbar .nav-main-links .nav-link,
.top-navbar .navbar-nav > li > .nav-link {
    color: var(--t-text-dim);
    padding: 6px 10px;
    border-radius: var(--t-radius);
    font-weight: 500;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background var(--t-transition), color var(--t-transition);
    font-size: 12px;
}
.top-navbar .nav-main-links .nav-link:hover,
.top-navbar .navbar-nav > li > .nav-link:hover { background: var(--t-hover); color: var(--t-text); }
.top-navbar .nav-main-links .nav-link.active { color: var(--t-accent); background: rgba(252, 213, 53, 0.08); }

.top-navbar .navbar-search {
    background: var(--t-surface);
    border: 1px solid var(--t-border);
    border-radius: var(--t-radius);
    position: relative;
    padding: 0 8px;
    min-width: 240px;
    max-width: 320px;
}
.top-navbar .navbar-search .search-icon {
    position: absolute;
    left: 8px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--t-text-dim);
    font-size: 12px;
    pointer-events: none;
}
.top-navbar .navbar-search .form-control {
    background: transparent !important;
    border: none !important;
    color: var(--t-text);
    font-size: 12px;
    padding: 4px 4px 4px 22px;
    box-shadow: none !important;
    height: 28px;
}
.top-navbar .navbar-search .form-control::placeholder { color: var(--t-text-dim); }

.top-navbar .nav-notification .nav-link { position: relative; padding: 6px 8px !important; }
.top-navbar .notification-badge {
    position: absolute;
    top: 2px;
    right: 0;
    background: var(--t-red);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 5px;
    border-radius: 8px;
    line-height: 1;
}

.top-navbar .user-dropdown .nav-link {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
    background: var(--t-surface);
    border: 1px solid var(--t-border);
    border-radius: var(--t-radius);
}
.top-navbar .user-dropdown .nav-link:hover { background: var(--t-hover); border-color: var(--t-text-dim); }
.top-navbar .user-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--t-accent);
    color: var(--t-accent-text);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 11px;
    flex-shrink: 0;
}
.top-navbar .user-avatar.user-avatar-lg { width: 36px; height: 36px; font-size: 16px; }
.top-navbar .user-name { color: var(--t-text); font-size: 12px; max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Dropdown menus (uniform with terminal) ---------- */
.dropdown-menu {
    background: var(--t-panel);
    border: 1px solid var(--t-border);
    border-radius: var(--t-radius);
    padding: 4px 0;
    font-size: 12px;
    color: var(--t-text);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.dropdown-menu .dropdown-header {
    padding: 8px 14px;
    color: var(--t-text-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.dropdown-menu .dropdown-item {
    color: var(--t-text);
    padding: 6px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: background var(--t-transition), color var(--t-transition);
}
.dropdown-menu .dropdown-item i { color: var(--t-text-dim); width: 14px; text-align: center; }
.dropdown-menu .dropdown-item:hover,
.dropdown-menu .dropdown-item:focus { background: var(--t-hover); color: var(--t-text-bright); }
.dropdown-menu .dropdown-item:hover i { color: var(--t-accent); }
.dropdown-menu .dropdown-item.active,
.dropdown-menu .dropdown-item:active { background: rgba(252, 213, 53, 0.12); color: var(--t-accent); }
.dropdown-menu .dropdown-item.text-danger { color: var(--t-red); }
.dropdown-menu .dropdown-item.text-danger:hover { background: var(--t-red-bg); color: var(--t-red); }
.dropdown-menu .dropdown-divider { border-top-color: var(--t-border); margin: 4px 0; opacity: 1; }

/* ---------- Sidebar ---------- */
/* Desktop "hide sidebar" toggle (hamburger button in topbar). On
   mobile the same button drives the existing overlay slide-in; on
   >=lg the body class flip swaps the aside's `display: flex` (from
   Bootstrap's d-lg-flex) for none so the main content claims the
   freed space. State persists in localStorage — see _Layout.cshtml. */
@media (min-width: 992px) {
    body.sidebar-collapsed .sidebar {
        display: none !important;
    }
}

.sidebar {
    background: var(--t-panel);
    border-right: 1px solid var(--t-border);
    width: 220px;
    flex-shrink: 0;
    min-height: calc(100vh - 44px);
    padding: 16px 0;
    display: flex;
    flex-direction: column;
}
.sidebar-section { padding: 0 12px; margin-bottom: 16px; }
.sidebar-section-title {
    color: var(--t-text-dim);
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin: 0 0 6px 8px;
    font-weight: 600;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 1px; }
.sidebar-link {
    color: var(--t-text-dim);
    padding: 7px 10px;
    border-radius: var(--t-radius);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    transition: background var(--t-transition), color var(--t-transition);
    background: none;
    border: none;
    width: 100%;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
}
.sidebar-link i { color: var(--t-text-dim); font-size: 13px; width: 16px; text-align: center; }
.sidebar-link:hover { background: var(--t-hover); color: var(--t-text); }
.sidebar-link:hover i { color: var(--t-text-bright); }
.sidebar-link.active {
    background: rgba(252, 213, 53, 0.10);
    color: var(--t-accent);
}
.sidebar-link.active i { color: var(--t-accent); }
/* Vertical breathing room around the divider — without it the next
   section's title (e.g. "СЧЁТ") sat one px under the line and looked
   visually crammed against it. */
.sidebar-divider { height: 1px; background: var(--t-border); margin: 12px 12px; }
.sidebar-badge {
    margin-left: auto;
    background: var(--t-red);
    color: #fff;
    font-size: 9px;
    font-weight: 700;
    padding: 1px 6px;
    border-radius: 8px;
    line-height: 1.4;
}
.sidebar-footer {
    margin-top: auto;
    padding: 8px 12px;
    border-top: 1px solid var(--t-border);
}
.sidebar-footer .sidebar-link.text-danger { color: var(--t-red); }
.sidebar-footer .sidebar-link.text-danger:hover { background: var(--t-red-bg); }
.sidebar-overlay {
    position: fixed;
    inset: 44px 0 0 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 1010;
}

/* ---------- Main content ---------- */
.main-content {
    flex: 1;
    padding: 20px 24px;
    background: var(--t-bg);
    min-width: 0;
}

/* ---------- Cards / panels ---------- */
.card {
    background: var(--t-panel);
    border: 1px solid var(--t-border);
    border-radius: var(--t-radius);
    color: var(--t-text);
    box-shadow: none;
}
.card-header {
    background: var(--t-header) !important;
    border-bottom: 1px solid var(--t-border) !important;
    color: var(--t-text);
    padding: 10px 14px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    font-weight: 600;
}
.card-header.bg-white { background: var(--t-header) !important; }
.card-body { padding: 14px; color: var(--t-text); }

/* ---------- Tables ---------- */
.table {
    color: var(--t-text);
    border-color: var(--t-border);
    margin-bottom: 0;
}
.table > :not(caption) > * > * {
    background-color: transparent;
    color: var(--t-text);
    border-bottom-color: var(--t-border);
    padding: 8px 12px;
}
.table thead th {
    color: var(--t-text-dim);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    font-weight: 600;
    background: var(--t-header) !important;
}
.table-hover > tbody > tr:hover > * { background-color: var(--t-hover) !important; }

/* ---------- Forms ---------- */
.form-control,
.form-select {
    background: var(--t-surface);
    border-color: var(--t-border);
    color: var(--t-text);
    border-radius: var(--t-radius);
    transition: border-color var(--t-transition), box-shadow var(--t-transition);
}
.form-control:focus,
.form-select:focus {
    background: var(--t-surface);
    border-color: var(--t-accent);
    color: var(--t-text);
    box-shadow: 0 0 0 2px var(--t-accent-glow-soft);
}
.form-control::placeholder { color: var(--t-text-dim); }
.form-control-plaintext { color: var(--t-text); }
.form-label { color: var(--t-text-dim); font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.form-text { color: var(--t-text-dim); }

/* ---------- Buttons ---------- */
.btn-primary {
    background: var(--t-accent);
    border-color: var(--t-accent);
    color: var(--t-accent-text);
    font-weight: 600;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active {
    background: var(--t-accent-hover);
    border-color: var(--t-accent-hover);
    color: var(--t-accent-text);
}
.btn-success { background: var(--t-green); border-color: var(--t-green); color: #06291b; }
.btn-success:hover { background: var(--t-green-hover); border-color: var(--t-green-hover); color: #06291b; }
.btn-danger { background: var(--t-red); border-color: var(--t-red); color: #fff; }
.btn-danger:hover { background: var(--t-red-hover); border-color: var(--t-red-hover); color: #fff; }
.btn-secondary,
.btn-outline-secondary {
    background: var(--t-surface);
    border-color: var(--t-border);
    color: var(--t-text);
}
.btn-secondary:hover,
.btn-outline-secondary:hover { background: var(--t-hover); border-color: var(--t-text-dim); color: var(--t-text-bright); }

/* Outline-primary on the cabinet (e.g. /Profile → "Изм" next to
   Password). The Bootstrap default uses `--bs-primary` (yellow accent)
   for both border and text, which goes near-invisible at the 0.65
   opacity Bootstrap stamps on disabled buttons — exactly the case the
   user flagged. Explicit colours + a non-opacity disabled cue (dim
   text, dashed border) keeps the button readable on both themes. */
.btn-outline-primary {
    background: var(--t-surface);
    border-color: var(--t-accent);
    color: var(--t-accent);
    font-weight: 600;
}
.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background: var(--t-accent);
    border-color: var(--t-accent);
    color: var(--t-accent-text);
}
.btn-outline-primary:disabled,
.btn-outline-primary.disabled {
    opacity: 1;
    background: var(--t-surface);
    border-style: dashed;
    border-color: var(--t-text-dim);
    color: var(--t-text-dim);
}
.btn-ghost {
    background: transparent;
    border: 1px solid transparent;
    color: var(--t-text-dim);
}
.btn-ghost:hover { background: var(--t-hover); color: var(--t-text); }

/* ---------- Alerts ---------- */
.alert {
    background: var(--t-panel);
    border: 1px solid var(--t-border);
    color: var(--t-text);
    border-radius: var(--t-radius);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.alert-success { border-left: 3px solid var(--t-green); }
.alert-danger { border-left: 3px solid var(--t-red); }
.alert-warning { border-left: 3px solid var(--t-accent); }
.alert-info { border-left: 3px solid #5fb1ff; }
.alert-success i { color: var(--t-green); }
.alert-danger i { color: var(--t-red); }
.alert-warning i { color: var(--t-accent); }
.alert-info i { color: #5fb1ff; }

/* ---------- Dashboard summary icons ----------
   `.rounded-circle` gives a 50% radius but doesn't enforce a square box.
   The dashboard tiles wrap a single Bootstrap icon in `p-2` — content
   width is ~1em while content height inherits Bootstrap's 1.5 line-
   height, so the parent ends up taller than wide and renders as an
   ellipse instead of a circle. Pin the box to a 40×40 square + flex-
   centre the glyph so all four cards (Total / Available / Locked /
   Portfolios) match. */
.dashboard-icon {
    width: 40px;
    height: 40px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

/* ---------- Badges ---------- */
/* Color is `!important` because pages historically pair `bg-warning`
   with `text-dark` (Bootstrap pattern for dark text on yellow), but
   our `.text-dark { color: var(--t-text) !important }` remap flips
   that to light text on dark theme — `bg-warning text-dark` then
   read as illegible yellow-on-yellow until the badge rule wins
   back the colour. Same defensive `!important` on every variant
   for symmetry. */
.badge.bg-success { background-color: var(--t-green) !important; color: #06291b !important; }
.badge.bg-danger { background-color: var(--t-red) !important; color: #fff !important; }
.badge.bg-warning { background-color: var(--t-accent) !important; color: var(--t-accent-text) !important; }
.badge.bg-secondary { background-color: var(--t-surface) !important; color: var(--t-text) !important; border: 1px solid var(--t-border); }
.badge.bg-primary { background-color: var(--t-accent) !important; color: var(--t-accent-text) !important; }
.badge.bg-light { background-color: var(--t-surface) !important; color: var(--t-text) !important; }

/* ---------- Footer ---------- */
.site-footer {
    background: var(--t-header);
    border-top: 1px solid var(--t-border);
    color: var(--t-text-dim);
    padding: 10px 24px;
    font-size: 11px;
}
.site-footer a { color: var(--t-text-dim); }
.site-footer a:hover { color: var(--t-accent); }
.footer-links {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 14px;
}

/* ---------- Misc Bootstrap utility overrides for dark theme ---------- */
.text-muted { color: var(--t-text-dim) !important; }
.text-dark { color: var(--t-text) !important; }
.bg-white { background: var(--t-panel) !important; color: var(--t-text); }
.bg-light { background: var(--t-surface) !important; color: var(--t-text); }
.border, .border-bottom, .border-top { border-color: var(--t-border) !important; }
.shadow-sm, .shadow, .shadow-lg { box-shadow: none !important; }
hr { border-color: var(--t-border); opacity: 1; }

/* ---------- Card body row patches ----------
   Cabinet pages use the Bootstrap pattern
       <div class="d-flex justify-content-between align-items-center">
           <div>label + description</div>
           <span class="badge ...">status</span>
       </div>
   On a narrow viewport the label wraps to two lines and the badge,
   pinned to the right by `justify-content: space-between`, ends up
   visually on top of the wrapped second line (Profile → Security →
   2FA was the noisy case the user flagged). Let the row wrap so the
   badge drops naturally; force vertical stacking on phone-width
   viewports so the wrap is unambiguous. */
.card-body .d-flex.justify-content-between {
    flex-wrap: wrap;
    gap: 6px 12px;
}
.card-body .d-flex.justify-content-between > div { min-width: 0; flex: 1 1 auto; }
.card-body .d-flex.justify-content-between > .badge,
.card-body .d-flex.justify-content-between > .btn {
    flex-shrink: 0;
    align-self: center;
    margin-left: auto;
}
@media (max-width: 480px) {
    .card-body .d-flex.justify-content-between {
        flex-direction: column;
        align-items: flex-start !important;
    }
    .card-body .d-flex.justify-content-between > .badge,
    .card-body .d-flex.justify-content-between > .btn {
        margin-left: 0;
        align-self: flex-start;
    }
}

/* ---------- /Logs page — narrow-viewport responsiveness ----------
   Six columns (Time / Level / Source / Trace / Category / Message)
   don't fit on a phone, so .table-responsive falls back to horizontal
   scroll and the Message column ends up off-screen — exactly the
   thing the user opens /Logs to read. Hide Source + Trace + Category
   below 768px so Time / Level / Message stay visible without
   horizontal swipe. The dropped columns are still searchable via the
   filter form above. */
@media (max-width: 768px) {
    .logs-table .logs-col-source,
    .logs-table .logs-col-trace,
    .logs-table .logs-col-category { display: none; }
}

/* ---------- Mobile ---------- */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 44px;
        bottom: 0;
        z-index: 1020;
        width: 240px;
        transform: translateX(-100%);
        transition: transform var(--t-transition);
    }
    .sidebar.show { transform: translateX(0); }
}
@media (max-width: 768px) {
    /* Mobile cabinet: drop main-content side padding so cards span the
       full viewport (the topbar already does — the cards looked
       artificially boxed-in next to it). Vertical breathing room kept. */
    .main-content { padding: 12px 0; }
    .main-content > .card,
    .main-content > .row,
    .main-content > div > .card {
        border-radius: 0;
        border-left: none;
        border-right: none;
    }
    .main-content > .d-flex,
    .main-content > h1,
    .main-content > h2,
    .main-content > h3,
    .main-content > h4,
    .main-content > h5 { padding-left: 12px; padding-right: 12px; }
    /* Keep the page's own narrow padding inside Bootstrap rows so the
       columns don't ride straight to the edge inside multi-card rows. */
    .main-content > .row { margin-left: 0; margin-right: 0; }
    .main-content > .row > [class*="col-"] { padding-left: 0; padding-right: 0; }
    /* Footer keeps its own padding — it's a single horizontal strip and
       text-to-edge looks worse than the bordered cards. */
}
