:root {
    --app-header-height: 68px;
    --bm-login-primary: #0F3057;
}

* {
    box-sizing: border-box;
}

body.bm-app {
    margin: 0;
    font-family: 'Readex Pro', var(--ds-font-base);
    color: var(--ds-color-text);
    background: var(--ds-color-bg-page);
    -webkit-font-smoothing: antialiased;
}

.bm-dashboard-wrapper {
    display: flex;
    min-height: 100vh;
}

.bm-sidebar {
    position: fixed;
    right: 0;
    top: 0;
    width: 260px;
    height: 100vh;
    background: var(--ds-color-bg-page);
    border-left: 1px solid var(--ds-color-border);
    z-index: 1000;
    overflow-y: auto;
}

.bm-sidebar-header {
    height: var(--app-header-height);
    display: flex;
    align-items: stretch;
    border-bottom: 1px solid var(--ds-primary-a12);
    box-shadow: 0 1px 6px var(--ds-primary-a06);
}

.bm-sidebar-header img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    padding: 8px 12px;
}

.bm-sidebar-menu {
    list-style: none;
    margin: 0;
    padding: 16px 12px;
}

.bm-sidebar-menu li {
    margin-bottom: 4px;
}

.bm-sidebar-menu a {
    display: block;
    padding: 10px 16px;
    border-radius: 6px;
    text-decoration: none;
    color: var(--ds-color-text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    border-right: 3px solid transparent;
    transition: background 0.15s ease, color 0.15s ease;
}

.bm-sidebar-menu a:hover {
    background: var(--ds-primary-a08);
    color: var(--ds-color-primary);
    border-right-color: var(--ds-color-primary-3);
}

.bm-sidebar-menu a.active {
    background: var(--ds-color-primary-soft);
    color: var(--ds-color-primary-2);
    border-right-color: var(--ds-color-primary-2);
    font-weight: 600;
}

.bm-sidebar-badge {
    display: inline-block;
    margin-top: 12px;
    margin-inline: 16px;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--ds-color-primary);
    background: var(--ds-color-primary-soft);
    border: 1px solid var(--ds-color-border);
}

.bm-main {
    flex: 1;
    margin-right: 260px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.bm-header {
    min-height: var(--app-header-height);
    padding: 14px 24px;
    border-bottom: 1px solid var(--ds-color-border);
    background: var(--ds-color-bg-page);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.bm-header h1 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--ds-color-text-strong);
}

.bm-header-sub {
    margin: 4px 0 0;
    font-size: 0.85rem;
    color: var(--ds-color-muted);
}

.bm-header-user {
    font-size: 0.9rem;
    color: var(--ds-color-text-secondary);
}

.bm-header-user a {
    color: var(--ds-color-primary-2);
    text-decoration: none;
    font-weight: 600;
    margin-inline-start: 8px;
}

.bm-content {
    padding: 24px;
    flex: 1;
}

.bm-footer {
    padding: 14px 24px;
    border-top: 1px solid var(--ds-color-border);
    color: var(--ds-color-muted);
    font-size: 0.82rem;
    background: var(--ds-color-bg-subtle);
}

.bm-card {
    background: var(--ds-color-surface);
    border: 1px solid var(--ds-color-border);
    border-radius: var(--ds-radius-md, 10px);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--ds-shadow-sm);
}

.bm-stats {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.bm-stat {
    background: var(--ds-color-surface);
    border: 1px solid var(--ds-color-border);
    border-radius: 10px;
    padding: 16px;
    box-shadow: var(--ds-shadow-sm);
}

.bm-stat__n {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--ds-color-primary-2);
    line-height: 1.1;
}

.bm-stat__l {
    margin-top: 6px;
    font-size: 0.85rem;
    color: var(--ds-color-muted);
}

.bm-table-wrap {
    overflow: auto;
    border-radius: 10px;
    border: 1px solid var(--ds-color-border);
    background: var(--ds-color-surface);
    box-shadow: var(--ds-shadow-sm);
}

.bm-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.92rem;
}

.bm-table th,
.bm-table td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--ds-color-border-soft);
    text-align: right;
}

.bm-table th {
    background: var(--ds-color-bg-subtle);
    color: var(--ds-color-text-secondary);
    font-weight: 600;
}

.bm-table tr:last-child td {
    border-bottom: none;
}

.bm-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
}

.bm-badge--ok {
    background: var(--ds-color-success-soft);
    color: var(--ds-color-success-text);
}

.bm-badge--off {
    background: var(--ds-color-bg-2);
    color: var(--ds-color-muted);
}

.bm-badge--api {
    background: var(--ds-color-warning-soft);
    color: var(--ds-color-warning-text);
}

.bm-form-page {
    max-width: 920px;
    margin: 0 auto;
}

.bm-form-page .bm-form-shell {
    background: var(--ds-color-surface);
    border: 1px solid var(--ds-color-border);
    border-radius: 12px;
    box-shadow: var(--ds-shadow-sm);
    overflow: hidden;
}

.bm-form-section {
    padding: 22px 24px;
    border-bottom: 1px solid var(--ds-color-border-soft);
}

.bm-form-section:last-of-type {
    border-bottom: none;
}

.bm-form-section__head {
    margin-bottom: 18px;
}

.bm-form-section__title {
    margin: 0 0 6px;
    font-size: 1rem;
    font-weight: 700;
    color: var(--ds-color-text-strong);
}

.bm-form-section__desc {
    margin: 0;
    font-size: 0.85rem;
    color: var(--ds-color-muted);
    line-height: 1.5;
}

.bm-form-grid {
    display: grid;
    gap: 16px;
}

.bm-form-row-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

@media (max-width: 720px) {
    .bm-form-row-2 {
        grid-template-columns: 1fr;
    }
}

.bm-form-panel {
    background: var(--ds-color-bg-subtle);
    border: 1px solid var(--ds-color-border);
    border-radius: 10px;
    padding: 18px 18px 6px;
    margin-top: 4px;
}

.bm-form-panel__title {
    margin: 0 0 14px;
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--ds-color-primary);
    letter-spacing: 0.02em;
}

.bm-form-actions {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    flex-wrap: wrap;
    padding: 16px 24px;
    background: var(--ds-color-bg-subtle);
    border-top: 1px solid var(--ds-color-border);
    position: sticky;
    bottom: 0;
    z-index: 2;
}

.bm-page-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.bm-page-toolbar .bm-hint {
    margin: 0;
}

.bm-form-grid label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--ds-color-text-secondary);
}

.bm-form-grid input,
.bm-form-grid select,
.bm-form-grid textarea {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--ds-color-border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 0.95rem;
    background: var(--ds-color-bg-subtle);
    color: var(--ds-color-text);
}

.bm-form-grid input:focus,
.bm-form-grid select:focus,
.bm-form-grid textarea:focus {
    outline: none;
    border-color: var(--ds-color-primary-2);
    box-shadow: 0 0 0 3px var(--ds-primary-2-a10);
    background: #fff;
}

.bm-hint {
    font-size: 0.85rem;
    color: var(--ds-color-muted);
    line-height: 1.55;
}

.bm-alert {
    padding: 12px 14px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.bm-alert--success {
    background: var(--ds-alert-success-bg);
    color: var(--ds-alert-success-text);
    border: 1px solid var(--ds-alert-success-border);
}

.bm-alert--error {
    background: var(--ds-alert-error-bg);
    color: var(--ds-alert-error-text);
    border: 1px solid var(--ds-alert-error-border);
}

/* ——— Login / Setup (هوية بوليصة) ——— */
.bm-login-shell {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    min-height: 100vh;
    width: 100%;
}

.bm-brand-panel {
    position: relative;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 72px 64px;
    background: linear-gradient(165deg, #ffffff 0%, #f8fafc 55%, #eef6fa 100%);
}

.bm-brand-blob {
    position: absolute;
    width: min(49vw, 364px);
    height: min(49vw, 364px);
    border-radius: 50%;
    background: var(--ds-color-primary-2);
    opacity: 0.06;
    bottom: -32%;
    left: -26%;
    pointer-events: none;
}

.bm-brand-inner {
    position: relative;
    z-index: 1;
    max-width: 400px;
    text-align: center;
}

.bm-brand-logo {
    width: min(100%, 240px);
    height: auto;
    margin: 0 auto 20px;
    display: block;
}

.bm-brand-title {
    font-size: clamp(20px, 2.2vw, 28px);
    font-weight: 700;
    color: var(--bm-login-primary);
    margin: 0 0 12px;
    line-height: 1.45;
}

.bm-brand-text {
    font-size: 0.95rem;
    color: #64748b;
    line-height: 1.75;
    margin: 0;
}

.bm-form-panel {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 64px 56px;
    background: #fff;
}

.bm-form-wrap {
    width: 100%;
    max-width: 400px;
}

.bm-form-card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 44px 40px;
    box-shadow: 0 8px 24px rgba(15, 48, 87, 0.08);
}

.bm-form-card h1 {
    font-size: 1.45rem;
    font-weight: 700;
    color: var(--bm-login-primary);
    margin: 0 0 8px;
}

.bm-form-card .sub {
    font-size: 0.9rem;
    color: #64748b;
    margin: 0 0 28px;
    line-height: 1.55;
}

.bm-field {
    margin-bottom: 20px;
}

.bm-field label {
    display: block;
    margin-bottom: 8px;
    font-size: 0.8125rem;
    font-weight: 500;
    color: #64748b;
}

.bm-field input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 0.95rem;
    background: #f8fafc;
    color: #1e293b;
}

.bm-field input:focus {
    outline: none;
    border-color: #0aa8e0;
    box-shadow: 0 0 0 3px rgba(10, 168, 224, 0.15);
    background: #fff;
}

.bm-btn-login {
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: 0.5rem;
    font-family: inherit;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    color: #fff;
    background: var(--ds-color-primary-2);
    box-shadow: var(--ds-shadow-accent);
    transition: background 0.2s ease, transform 0.2s ease;
}

.bm-btn-login:hover {
    background: var(--ds-color-primary-2-hover);
    transform: translateY(-1px);
}

@media (max-width: 960px) {
    .bm-login-shell {
        grid-template-columns: 1fr;
    }
    .bm-brand-panel {
        padding: 40px 24px 24px;
    }
    .bm-form-panel {
        padding: 32px 20px 48px;
    }
    .bm-main {
        margin-right: 0;
    }
    .bm-sidebar {
        transform: translateX(100%);
    }
}
