/* ============================================
   Sakkara EMS - Main Stylesheet
   Uses CSS logical properties for RTL support
   ============================================ */

:root {
    --sidebar-width: 260px;
    --sidebar-collapsed-width: 0px;
    --topbar-height: 56px;
    --brand-color: #0d6efd;
    --sidebar-bg: #1a1d21;
    --sidebar-text: #adb5bd;
    --sidebar-active: var(--brand-color);
    --sidebar-hover-bg: rgba(255,255,255,0.08);
}

[data-bs-theme="dark"] {
    --sidebar-bg: #0d0f12;
}

/* Base */
body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    overflow-x: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    position: fixed;
    inset-block-start: 0;
    inset-inline-start: 0;
    z-index: 1040;
    transition: transform 0.3s ease;
    overflow: hidden;
}

.sidebar-logo {
    max-width: 80px;
    max-height: 60px;
    display: block;
    margin-inline: auto;
}

.sidebar-brand {
    color: #fff;
    font-size: 0.95rem;
}

.sidebar-nav .nav-link {
    color: var(--sidebar-text);
    padding: 0.6rem 1rem;
    font-size: 0.875rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border-radius: 0.375rem;
    margin: 0.1rem 0.5rem;
    transition: all 0.2s;
}

.sidebar-nav .nav-link:hover {
    background: var(--sidebar-hover-bg);
    color: #fff;
}

.sidebar-nav .nav-link.active {
    background: var(--sidebar-active);
    color: #fff;
}

.sidebar-nav .nav-link i {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-nav .nav-group-toggle::after {
    content: '\F282';
    font-family: 'bootstrap-icons';
    margin-inline-start: auto;
    font-size: 0.7rem;
    transition: transform 0.2s;
}

.sidebar-nav .nav-group-toggle[aria-expanded="true"]::after,
.sidebar-nav .nav-group-toggle:not(.collapsed)::after {
    transform: rotate(90deg);
}

[dir="rtl"] .sidebar-nav .nav-group-toggle[aria-expanded="true"]::after,
[dir="rtl"] .sidebar-nav .nav-group-toggle:not(.collapsed)::after {
    transform: rotate(-90deg);
}

.sidebar-nav .nav-sub {
    padding-inline-start: 1rem;
}

.sidebar-nav .nav-sub .nav-link {
    font-size: 0.8125rem;
    padding: 0.4rem 1rem;
}

.sidebar-footer {
    border-block-start: 1px solid rgba(255,255,255,0.1);
}

/* Main content */
.main-content {
    margin-inline-start: var(--sidebar-width);
    transition: margin 0.3s ease;
    min-height: 100vh;
    /* Flex children default to min-width:auto, which refuses to shrink below
       their content's intrinsic width. Without this, a single wide table or
       element forces the whole page to scroll sideways. min-width:0 lets the
       column shrink to the viewport and keeps content inside. */
    min-width: 0;
    max-width: 100%;
}

/* Top navbar */
.top-navbar {
    background: var(--bs-body-bg);
    border-block-end: 1px solid var(--bs-border-color);
    padding: 0.5rem 1rem;
    z-index: 1030;
}

.navbar-title {
    font-weight: 600;
    font-size: 1.1rem;
}

.sidebar-toggle {
    text-decoration: none;
    color: var(--bs-body-color);
    padding: 0.25rem;
}

.search-box {
    min-width: 220px;
}

/* Notification dropdown */
.notification-dropdown .notification-item {
    padding: 0.5rem 0.75rem;
    border-block-end: 1px solid var(--bs-border-color);
    cursor: pointer;
    transition: background 0.15s;
}

.notification-dropdown .notification-item:hover {
    background: var(--bs-tertiary-bg);
}

.notification-dropdown .notification-item.unread {
    border-inline-start: 3px solid var(--brand-color);
}

/* Sidebar overlay (mobile) */
.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1035;
}

/* Sidebar mobile behavior */
@media (max-width: 991.98px) {
    .sidebar {
        transform: translateX(-100%);
    }

    [dir="rtl"] .sidebar {
        transform: translateX(100%);
    }

    .sidebar.show {
        transform: translateX(0);
    }

    .sidebar-overlay.show {
        display: block;
    }

    .main-content {
        margin-inline-start: 0;
    }
}

/* Cards */
.card {
    border: none;
    box-shadow: 0 0.125rem 0.25rem rgba(0,0,0,0.075);
}

/* Status badges */
.badge-status {
    padding: 0.35em 0.65em;
    font-weight: 500;
    font-size: 0.75rem;
}

/* Masked fields */
.masked {
    display: inline-block;
    padding: 0.15em 0.5em;
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
    border-radius: 0.25rem;
    font-size: 0.85em;
    cursor: default;
}

.reveal-btn {
    border: none;
    background: none;
    padding: 0;
    margin-inline-start: 0.25rem;
    cursor: pointer;
    color: var(--bs-secondary-color);
    font-size: 0.85rem;
}

.reveal-btn:hover {
    color: var(--brand-color);
}

/* Toast customization */
.toast-container {
    z-index: 9999;
}

/* Tables */
.table th {
    font-weight: 600;
    white-space: nowrap;
}

/* Wizard */
.wizard-steps {
    display: flex;
    justify-content: center;
    gap: 0;
    margin-block-end: 2rem;
}

.wizard-step {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.wizard-step-number {
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    background: var(--bs-secondary-bg);
    color: var(--bs-secondary-color);
}

.wizard-step.active .wizard-step-number {
    background: var(--brand-color);
    color: #fff;
}

.wizard-step.completed .wizard-step-number {
    background: var(--bs-success);
    color: #fff;
}

.wizard-step-line {
    width: 3rem;
    height: 2px;
    background: var(--bs-border-color);
    margin: 0 0.5rem;
}

.wizard-step.completed + .wizard-step-line,
.wizard-step-line.completed {
    background: var(--bs-success);
}

/* Permission matrix */
.permission-matrix th,
.permission-matrix td {
    text-align: center;
    vertical-align: middle;
}

.permission-matrix .module-header {
    text-align: start;
    background: var(--bs-tertiary-bg);
    font-weight: 600;
}

/* Feature toggle cards */
.feature-card {
    transition: border-color 0.2s;
}

.feature-card.enabled {
    border-color: var(--bs-success) !important;
}

.feature-card .form-check-input:checked {
    background-color: var(--bs-success);
    border-color: var(--bs-success);
}

/* Page content padding for print button */
.page-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-block-end: 1rem;
}

/* Auth pages */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--brand-color) 0%, #1a1d21 100%);
}

.auth-card {
    width: 100%;
    max-width: 420px;
    border-radius: 1rem;
}

.auth-logo {
    max-width: 120px;
    max-height: 80px;
}

/* ============================================
   Responsive hardening (site-wide)
   ============================================ */

/* Keep page content within the viewport and break long unbroken strings
   (emails, codes, URLs) instead of letting them widen the layout. */
.page-content {
    min-width: 0;
    max-width: 100%;
    overflow-wrap: break-word;
}

/* Media never exceeds its container. */
.page-content img { max-width: 100%; }

/* Smooth momentum scrolling for the auto-wrapped responsive tables. */
.table-responsive { -webkit-overflow-scrolling: touch; }

/* Grid rows shouldn't impose an intrinsic min-width on flex parents. */
.row { min-width: 0; }

/* Tablet / small-laptop: slightly tighter content padding. */
@media (max-width: 991.98px) {
    .page-content { padding: 1rem !important; }
    .navbar-title { font-size: 1rem; }
}

/* Responsive utilities */
@media (max-width: 575.98px) {
    .page-content {
        padding: 0.75rem !important;
    }

    .page-actions {
        flex-direction: column;
        gap: 0.5rem;
        align-items: stretch;
    }

    /* Tables read better a touch smaller on phones. */
    .table { font-size: 0.85rem; }

    /* Button groups wrap instead of overflowing. */
    .btn-toolbar, .page-actions .btn-group { flex-wrap: wrap; }

    /* Card padding trimmed to claw back horizontal space. */
    .card-body { padding: 1rem 0.85rem; }

    /* Modals get a little breathing room from screen edges. */
    .modal-dialog { margin: 0.5rem; }
}

/* Scrollbar (webkit) */
.sidebar-nav::-webkit-scrollbar {
    width: 4px;
}

.sidebar-nav::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-nav::-webkit-scrollbar-thumb {
    background: rgba(255,255,255,0.2);
    border-radius: 4px;
}

/* Password strength meter */
.password-strength {
    height: 4px;
    border-radius: 2px;
    margin-block-start: 0.25rem;
    transition: all 0.3s;
}

.password-strength.weak { background: var(--bs-danger); width: 33%; }
.password-strength.medium { background: var(--bs-warning); width: 66%; }
.password-strength.strong { background: var(--bs-success); width: 100%; }
