:root {
    --ks-primary: #2563eb;
    --ks-primary-hover: #1d4ed8;
    --ks-accent: #0f766e;
    --ks-success: #15803d;
    --ks-danger: #b91c1c;
    --ks-warning: #b45309;
    --ks-border: #d7dee8;
    --ks-border-strong: #aeb9c8;
    --ks-bg: #eef2f6;
    --ks-surface: #ffffff;
    --ks-surface-muted: #f7f9fc;
    --ks-text: #172033;
    --ks-muted: #627084;
    --ks-sidebar-width: 224px;
    --ks-sidebar-bg: #f8fafc;
    --ks-sidebar-bg-soft: #eef2f7;
    --ks-sidebar-text: #263241;
    --ks-sidebar-muted: #69778a;
    --ks-focus: rgba(37, 99, 235, 0.22);
    --ks-shadow-sm: 0 8px 18px rgba(23, 32, 51, 0.06);
    --ks-shadow-md: 0 16px 34px rgba(23, 32, 51, 0.12);
    --ks-fs-main: 13px;
    --bs-body-font-size: var(--ks-fs-main);
    --ks-table-cell-padding: 6px 8px;
    --ks-table-border-width: 1px;
    --ks-table-row-height: 38px;
}

html {
    height: 100%;
}

body {
    min-height: 100%;
    margin: 0;
    background: var(--ks-bg);
    color: var(--ks-text);
    font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    font-size: var(--ks-fs-main);
    letter-spacing: 0;
}

a {
    color: var(--ks-primary);
}

a:hover {
    color: var(--ks-primary-hover);
}

code,
.ks-code-reset {
    color: var(--ks-text) !important;
    background-color: transparent !important;
    padding: 0 !important;
    font-family: inherit !important;
    font-size: var(--ks-fs-main);
}

.ks-app-shell {
    min-height: 100vh;
    background: var(--ks-bg);
}

.ks-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: var(--ks-sidebar-width);
    min-width: var(--ks-sidebar-width);
    max-width: var(--ks-sidebar-width);
    display: flex;
    flex-direction: column;
    background: var(--ks-sidebar-bg);
    border-right: 1px solid var(--ks-border);
    box-shadow: 10px 0 24px rgba(23, 32, 51, 0.08);
    z-index: 1030;
}

.ks-sidebar-brand {
    padding: 14px;
    border-bottom: 1px solid var(--ks-border);
}

.ks-brand-link {
    display: flex;
    flex-direction: column;
    gap: 9px;
    line-height: 1;
    text-decoration: none;
}

.ks-brand-logo-frame {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 48px;
    padding: 8px 10px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 8px;
}

.ks-brand-logo {
    display: block;
    max-width: 100%;
    height: auto;
    object-fit: contain;
}

.ks-brand-logo-frame .ks-brand-logo {
    max-height: 30px;
}

.ks-sidebar-nav {
    gap: 6px;
    padding: 14px 12px;
}

.ks-nav-section {
    padding: 2px 8px 4px;
    color: var(--ks-sidebar-muted);
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.ks-main-nav .nav-link {
    min-height: 40px;
    color: var(--ks-sidebar-text);
    font-size: var(--ks-fs-main);
    font-weight: 650;
    padding: 6px 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    transition: background-color 0.16s ease, color 0.16s ease, border-color 0.16s ease;
}

.ks-nav-link {
    display: flex;
    align-items: center;
    gap: 9px;
}

.ks-nav-icon {
    width: 28px;
    height: 28px;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    background: #e9eef5;
    color: #64748b;
}

.ks-nav-icon .bi {
    line-height: 1;
}

.ks-nav-text {
    line-height: 1.2;
}

.ks-main-nav .nav-link:hover {
    color: #111827;
    background: var(--ks-sidebar-bg-soft);
    border-color: #d8e0eb;
}

.ks-main-nav .nav-link.active {
    color: #1f2937;
    background: #ffffff;
    border-color: #ccd6e3;
    box-shadow: 0 8px 18px rgba(23, 32, 51, 0.08);
}

.ks-main-nav .nav-link.active .ks-nav-icon {
    background: #dbe4ef;
    color: #334155;
}

.ks-sidebar-footer {
    margin-top: auto;
    padding: 12px;
    border-top: 1px solid var(--ks-border);
}

.ks-logout-btn {
    height: 34px;
    border: 1px solid #d2dae6;
    border-radius: 8px;
    background-color: #ffffff;
    color: #475569;
    font-size: var(--ks-fs-main);
    font-weight: 700;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease;
}

.ks-logout-btn:hover {
    background-color: #f8fafc;
    color: #b91c1c;
    border-color: #f1b5b5;
}

.ks-logout-btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 0.2rem rgba(248, 113, 113, 0.24);
}

.ks-content {
    margin-left: var(--ks-sidebar-width);
    width: calc(100% - var(--ks-sidebar-width));
    min-height: 100vh;
    padding: 14px;
}

.ks-content .container-fluid {
    padding-left: 0;
    padding-right: 0;
}

.ks-search-group,
.orders-toolbar,
.trading-account-toolbar {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 12px;
    background: var(--ks-surface);
    border: 1px solid var(--ks-border);
    border-radius: 8px;
    box-shadow: var(--ks-shadow-sm);
}

.ks-search-group h4,
h4.fw-bold,
h4.mb-2,
.orders-title,
.trading-account-title {
    margin: 0 !important;
    color: var(--ks-text);
    font-size: 14px !important;
    font-weight: 750;
    line-height: 1.25;
    text-transform: uppercase;
}

.ks-search-group > .d-flex,
.orders-filter-bar,
.ks-filter-bar,
.trading-account-filter-bar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 8px;
    width: 100%;
    flex-wrap: wrap;
}

.ks-search-input,
.form-control.ks-search-input,
.form-select.ks-search-input {
    min-height: 34px;
    border: 1px solid var(--ks-border);
    border-radius: 7px;
    background-color: #ffffff;
    color: var(--ks-text);
    font-size: var(--ks-fs-main);
    box-shadow: none;
}

.ks-search-input::placeholder {
    color: #8a96a8;
}

.ks-search-input:hover {
    border-color: #c0cad8;
}

.ks-search-input:focus {
    border-color: var(--ks-primary);
    box-shadow: 0 0 0 0.18rem var(--ks-focus);
}

.btn-ks-primary {
    min-height: 34px;
    padding: 0 14px;
    border: 1px solid var(--ks-primary);
    border-radius: 7px;
    background-color: var(--ks-primary);
    color: white;
    font-size: var(--ks-fs-main);
    font-weight: 700;
    transition: background-color 0.15s ease, border-color 0.15s ease;
}

.btn-ks-primary:hover {
    background-color: var(--ks-primary-hover);
    border-color: var(--ks-primary-hover);
    color: white;
}

.ks-pdf-btn,
.order-logs-pdf-btn {
    min-height: 34px;
    padding: 0 13px;
    border: 1px solid #f3b5b5 !important;
    border-radius: 7px;
    background-color: #fff5f5 !important;
    color: var(--ks-danger) !important;
    font-size: var(--ks-fs-main);
    font-weight: 700;
}

.ks-pdf-btn:hover,
.order-logs-pdf-btn:hover {
    border-color: var(--ks-danger) !important;
    background-color: var(--ks-danger) !important;
    color: #ffffff !important;
}

.ks-table-container {
    width: 100%;
    height: clamp(420px, calc(100vh - 142px), 86vh);
    max-height: 86vh;
    overflow: auto;
    position: relative;
    background: var(--ks-surface);
    border: 1px solid var(--ks-border);
    border-radius: 8px;
    box-shadow: var(--ks-shadow-sm);
    font-size: var(--ks-fs-main);
}

.ks-table-container:has(.ks-empty-state-row) {
    width: auto;
    height: auto;
    min-height: 110px;
    max-height: none;
}

.ks-table-master {
    width: max-content;
    min-width: 100%;
    margin-bottom: 0 !important;
    border-collapse: separate;
    border-spacing: 0;
    table-layout: auto;
    color: var(--ks-text);
    font-size: var(--ks-fs-main);
}

.ks-table-master > :not(caption) > * > * {
    border-color: var(--ks-border) !important;
    border-bottom-width: var(--ks-table-border-width) !important;
}

table th,
table td,
.ks-table-master th,
.ks-table-master td {
    padding: var(--ks-table-cell-padding) !important;
}

.ks-table-master th {
    position: sticky;
    top: 0;
    z-index: 10;
    min-height: 36px;
    background: #f1f5f9 !important;
    border-bottom: 1px solid var(--ks-border-strong) !important;
    color: #334155;
    font-size: 12px;
    font-weight: 750;
    line-height: 1.2;
    white-space: nowrap;
}

.ks-table-master td,
.ks-table-master td span,
.ks-table-master td a,
.ks-table-master td .badge {
    vertical-align: middle;
    font-size: var(--ks-fs-main);
    line-height: 1.35;
}

.ks-table-master tbody tr:not(.ks-empty-state-row) > td:not(.td-edge-to-edge) {
    height: var(--ks-table-row-height);
    white-space: nowrap;
}

.orders-table tbody tr:not(.ks-empty-state-row),
.order-log-table tbody tr:not(.ks-empty-state-row),
.trading-account-table tbody tr:not(.ks-empty-state-row) {
    height: var(--ks-table-row-height);
}

.orders-table tbody tr:not(.ks-empty-state-row) > td,
.order-log-table tbody tr:not(.ks-empty-state-row) > td,
.trading-account-table tbody tr:not(.ks-empty-state-row) > td {
    height: var(--ks-table-row-height);
    vertical-align: middle;
}

.table-hover > tbody > tr:hover > * {
    background-color: #f8fbff !important;
}

.ks-table-master tbody tr:nth-child(even):not(.ks-empty-state-row) > td {
    background-color: #fbfcfe;
}

.ks-table-master tbody tr:nth-child(even):not(.ks-empty-state-row):hover > td {
    background-color: #f3f8ff !important;
}

.ks-blank-placeholder {
    display: inline-flex;
    justify-content: center;
    min-width: 3ch;
    color: #94a3b8;
    text-align: center;
}

.ks-table-master td:has(.ks-blank-placeholder) {
    text-align: center !important;
}

.td-edge-to-edge,
.ks-table-master tbody tr td.td-edge-to-edge {
    padding: 0 !important;
    font-size: var(--ks-fs-main);
}

.order-log-side-text,
.badge-buy,
.badge-sell {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: calc(var(--ks-table-row-height) - 1px);
    margin: 0 !important;
    border-radius: 0 !important;
    font-size: 12px;
    font-weight: 800;
    line-height: 1;
    text-transform: uppercase;
}

.order-log-side-text {
    background: #f1f5f9;
    color: #334155 !important;
}

.badge-buy {
    background: #dcfce7 !important;
    color: #166534 !important;
    border-left: 3px solid #22c55e;
}

.badge-sell {
    background: #fee2e2 !important;
    color: #991b1b !important;
    border-left: 3px solid #ef4444;
}

.orders-side-plain {
    background: #f1f5f9;
    color: #334155 !important;
}

.badge-status {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 23px;
    min-width: 72px;
    padding: 0 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 800;
}

.badge-status.bg-success {
    background-color: #dcfce7 !important;
    color: #166534 !important;
}

.badge-status.bg-secondary {
    background-color: #f1f5f9 !important;
    color: #64748b !important;
}

.ks-empty-state-row {
    height: 86px;
}

.ks-table-master tbody tr.ks-empty-state-row td.ks-empty-state-cell {
    padding: 20px !important;
    background-color: #f8fafc;
    color: var(--ks-muted) !important;
    line-height: 1.35 !important;
    text-align: center;
    vertical-align: middle;
    white-space: normal !important;
}

.ks-table-master tbody tr.ks-empty-state-row td.ks-empty-state-cell i {
    color: #8a96a8;
    line-height: 1;
}

.order-log-table th:nth-child(1),
.order-log-table td:nth-child(1) { min-width: 122px; }
.order-log-table th:nth-child(2),
.order-log-table td:nth-child(2) { min-width: 128px; }
.order-log-table th:nth-child(3),
.order-log-table td:nth-child(3) { min-width: 96px; }
.order-log-table th:nth-child(4),
.order-log-table td:nth-child(4) { min-width: 118px; }
.order-log-table th:nth-child(5),
.order-log-table td:nth-child(5) { min-width: 86px; }
.order-log-table th:nth-child(6),
.order-log-table td:nth-child(6) { min-width: 104px; }
.order-log-table th:nth-child(7),
.order-log-table td:nth-child(7) { min-width: 104px; }
.order-log-table th:nth-child(8),
.order-log-table td:nth-child(8) { min-width: 156px; }
.order-log-table th:nth-child(9),
.order-log-table td:nth-child(9) { min-width: 102px; }

.trading-account-table th:nth-child(1),
.trading-account-table td:nth-child(1) { min-width: 118px; }
.trading-account-table th:nth-child(2),
.trading-account-table td:nth-child(2) { min-width: 220px; }
.trading-account-table th:nth-child(3),
.trading-account-table td:nth-child(3) { min-width: 108px; }
.trading-account-table th:nth-child(4),
.trading-account-table td:nth-child(4) { min-width: 96px; }
.trading-account-table th:nth-child(5),
.trading-account-table td:nth-child(5) { min-width: 92px; }
.trading-account-table th:nth-child(6),
.trading-account-table td:nth-child(6) { min-width: 96px; }
.trading-account-table th:nth-child(7),
.trading-account-table td:nth-child(7) { min-width: 96px; }
.trading-account-table th:nth-child(8),
.trading-account-table td:nth-child(8) { min-width: 136px; }
.trading-account-table th:nth-child(9),
.trading-account-table td:nth-child(9) { min-width: 86px; }
.trading-account-table th:nth-child(10),
.trading-account-table td:nth-child(10) { min-width: 92px; }
.trading-account-table th:nth-child(11),
.trading-account-table td:nth-child(11) { min-width: 78px; }
.trading-account-table th:nth-child(12),
.trading-account-table td:nth-child(12) { min-width: 72px; }
.trading-account-table th:nth-child(13),
.trading-account-table td:nth-child(13) { min-width: 120px; }

.ks-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1050;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.56);
    font-size: var(--ks-fs-main);
}

.ks-modal-card {
    width: min(320px, 100%);
    padding: 20px;
    background: #ffffff;
    border: 1px solid var(--ks-border);
    border-radius: 8px;
    box-shadow: var(--ks-shadow-md);
    font-size: var(--ks-fs-main);
}

.ks-form-card {
    max-width: 900px;
    margin: 2rem auto;
    padding: 20px;
    background: #fff;
    border: 1px solid var(--ks-border);
    border-radius: 8px;
    box-shadow: var(--ks-shadow-sm);
    font-size: var(--ks-fs-main);
}

.ks-section-header {
    margin: 25px 0 15px;
    border-bottom: 1px solid var(--ks-border);
    color: var(--ks-primary);
    font-size: var(--ks-fs-main);
    font-weight: 800;
    text-transform: uppercase;
}

.ks-label {
    color: #334155;
    font-size: var(--ks-fs-main);
    font-weight: 700;
}

@media (max-width: 991.98px) {
    .ks-sidebar {
        position: static;
        width: 100%;
        min-width: 100%;
        max-width: 100%;
        border-right: 0;
        border-bottom: 1px solid var(--ks-border);
        box-shadow: none;
    }

    .ks-content {
        margin-left: 0;
        width: 100%;
        padding: 10px;
    }

    .ks-sidebar-brand {
        padding: 10px;
    }

    .ks-brand-link {
        max-width: 260px;
    }

    .ks-sidebar-nav {
        display: grid;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        gap: 8px;
        padding: 10px;
    }

    .ks-nav-section {
        grid-column: 1 / -1;
        padding-left: 2px;
    }

    .ks-nav-link {
        justify-content: center;
    }

    .ks-main-nav .nav-link {
        white-space: nowrap;
        padding: 6px 8px;
    }

    .ks-sidebar-footer {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
        gap: 8px;
        padding: 10px;
    }

    .ks-search-group,
    .orders-toolbar,
    .trading-account-toolbar {
        padding: 10px;
    }
}

@media (max-width: 575.98px) {
    .ks-content {
        padding: 8px;
    }

    .ks-sidebar-nav,
    .ks-sidebar-footer {
        grid-template-columns: 1fr;
    }

    .ks-main-nav .nav-link {
        justify-content: flex-start;
    }

    .ks-brand-logo-frame {
        height: 42px;
    }

    .ks-brand-logo-frame .ks-brand-logo {
        max-height: 26px;
    }

    .ks-search-group > .d-flex,
    .orders-filter-bar,
    .ks-filter-bar,
    .trading-account-filter-bar {
        align-items: stretch;
        flex-direction: column;
    }

    .ks-search-input,
    .form-control.ks-search-input,
    .form-select.ks-search-input {
        width: 100%;
    }
}
