:root {
    --primary-color: #1e293b;
    --primary-dark: #0f172a;
    --accent-color: #3b82f6;
    --accent-soft: rgba(59, 130, 246, 0.15);
    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-tertiary: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #475569;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --success-color: #10b981;
    --warning-color: #f59e0b;
    --danger-color: #ef4444;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 8px 24px rgba(15, 23, 42, 0.08);
    --sidebar-width: 280px;
    --topbar-height: 68px;
    --radius-lg: 12px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
}

body.acc-admin {
    font-family: var(--acc-font-stack, "IBM Plex Sans Arabic", "Segoe UI", Tahoma, sans-serif);
    background: var(--bg-secondary);
    color: var(--text-primary);
}

html[dir="rtl"] body.acc-admin { direction: rtl; }
html[dir="ltr"] body.acc-admin { direction: ltr; }

.app-container {
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, var(--primary-dark) 0%, var(--primary-color) 100%);
    color: #fff;
    position: fixed;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 1045;
    box-shadow: -4px 0 24px rgba(15, 23, 42, 0.18);
    display: flex;
    flex-direction: column;
}

html[dir="rtl"] .sidebar { right: 0; left: auto; }
html[dir="ltr"] .sidebar { left: 0; right: auto; }

.sidebar-header {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
}

.sidebar-logo {
    width: 72px;
    height: 72px;
    object-fit: contain;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.08);
    padding: 6px;
    margin-bottom: 0.75rem;
}

.company-name {
    font-size: 0.95rem;
    font-weight: 700;
    line-height: 1.5;
    margin-bottom: 0.25rem;
}

.company-subtitle {
    font-size: 0.82rem;
    opacity: 0.85;
}

.company-version {
    font-size: 0.72rem;
    opacity: 0.65;
    margin-top: 0.35rem;
    font-family: Consolas, monospace;
}

.sidebar-nav {
    padding: 1rem 0.75rem;
    flex: 1;
}

.nav-section-title {
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    opacity: 0.55;
    padding: 0.5rem 0.85rem 0.35rem;
    font-weight: 700;
}

.nav-item-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.85rem;
    margin-bottom: 0.15rem;
    border-radius: 0 8px 8px 0;
    color: rgba(255, 255, 255, 0.88);
    text-decoration: none;
    border-right: 3px solid transparent;
    transition: all 0.2s ease;
}

.nav-item-link i {
    font-size: 1.05rem;
    width: 22px;
    text-align: center;
}

.nav-item-link:hover {
    background: var(--accent-soft);
    color: #fff;
    border-right-color: var(--accent-color);
}

html[dir="ltr"] .nav-item-link {
    border-radius: 8px 0 0 8px;
    border-right: none;
    border-left: 3px solid transparent;
}

.nav-item-link.active {
    background: rgba(59, 130, 246, 0.22);
    color: #fff;
    border-right-color: var(--accent-color);
    font-weight: 600;
}

html[dir="ltr"] .nav-item-link.active {
    border-right-color: transparent;
    border-left-color: var(--accent-color);
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
}

.sidebar-user {
    font-size: 0.82rem;
    opacity: 0.85;
    margin-bottom: 0.65rem;
}

.main-content {
    min-height: 100vh;
    background: var(--bg-secondary);
}

html[dir="rtl"] .main-content { margin-right: var(--sidebar-width); margin-left: 0; }
html[dir="ltr"] .main-content { margin-left: var(--sidebar-width); margin-right: 0; }

.topbar {
    height: var(--topbar-height);
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-toggle {
    border: 1px solid var(--border-color);
    background: var(--bg-secondary);
    border-radius: 8px;
    width: 40px;
    height: 40px;
    display: none;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}

.page-title {
    font-size: 1.35rem;
    font-weight: 700;
    margin: 0;
    color: var(--text-primary);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.topbar-search {
    display: flex;
    align-items: center;
    gap: 0.35rem;
    min-width: 14rem;
}

.topbar-search .form-control {
    min-width: 10rem;
}

.datetime-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.35rem 0.75rem;
    text-align: center;
    min-width: 110px;
}

.datetime-chip .date {
    font-size: 0.78rem;
    color: var(--text-secondary);
    font-weight: 600;
}

.datetime-chip .time {
    font-size: 0.82rem;
    color: var(--accent-color);
    font-family: Consolas, monospace;
    direction: ltr;
}

.user-chip {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 0.4rem 0.75rem;
    font-size: 0.85rem;
    font-weight: 600;
}

.page-content {
    padding: 1.25rem;
}

.page-header {
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.page-header .lead {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.92rem;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stats-card {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    padding: 1.15rem 1.2rem;
    box-shadow: var(--shadow-sm);
    position: relative;
    overflow: hidden;
}

.stats-card::before {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    width: 4px;
    height: 100%;
    background: var(--accent-color);
}

.stats-card.green::before { background: var(--success-color); }
.stats-card.purple::before { background: #8b5cf6; }
.stats-card.orange::before { background: var(--warning-color); }

.stats-card .icon {
    font-size: 1.6rem;
    margin-bottom: 0.35rem;
}

.stats-card .value {
    font-size: 1.75rem;
    font-weight: 800;
    line-height: 1.1;
}

.stats-card .label {
    color: var(--text-muted);
    font-size: 0.88rem;
    margin-top: 0.25rem;
}

.stats-card a {
    display: inline-block;
    margin-top: 0.55rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--accent-color);
    text-decoration: none;
}

.acc-panel {
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.acc-panel .panel-head {
    padding: 1rem 1.15rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    background: linear-gradient(180deg, #fff, #fafbfc);
}

.acc-panel .panel-body {
    padding: 1.15rem;
}

.acc-panel .table {
    margin-bottom: 0;
}

.acc-panel .table thead th {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 0.82rem;
    font-weight: 700;
    border-bottom-width: 1px;
    white-space: nowrap;
}

.acc-panel .table tbody tr:hover {
    background: #f8fafc;
}

.btn-acc-primary {
    background: var(--accent-color);
    border-color: var(--accent-color);
    color: #fff;
    font-weight: 600;
    border-radius: 8px;
}

.btn-acc-primary:hover {
    background: #2563eb;
    border-color: #2563eb;
    color: #fff;
}

.btn-acc-outline {
    border-radius: 8px;
    font-weight: 600;
}

.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border-color);
}

.form-control:focus, .form-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 0.2rem rgba(59, 130, 246, 0.15);
}

.alert-success {
    border-radius: 10px;
    border: 1px solid rgba(16, 185, 129, 0.25);
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.65rem;
}

.sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1040;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s ease;
}

.sidebar-backdrop.show {
    opacity: 1;
    pointer-events: all;
}

/* Auth page */
body.acc-auth {
    min-height: 100vh;
    background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 45%, #1e293b 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    font-family: "IBM Plex Sans Arabic", "Segoe UI", sans-serif;
}

.auth-card {
    width: 100%;
    max-width: 440px;
    background: #fff;
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.25);
    overflow: hidden;
}

.auth-card-header {
    background: linear-gradient(135deg, var(--primary-dark), var(--primary-color));
    color: #fff;
    text-align: center;
    padding: 1.75rem 1.5rem 1.25rem;
}

.auth-card-header img {
    width: 84px;
    height: 84px;
    object-fit: contain;
    border-radius: 14px;
    background: rgba(255,255,255,0.1);
    padding: 8px;
    margin-bottom: 0.75rem;
}

.auth-card-body {
    padding: 1.5rem;
}

.auth-card-body .input-group .form-control {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

.auth-card-body .input-group .password-toggle {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
}

/* Settings nav */
.nav-pills .nav-link {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    border-radius: 999px;
    padding: 0.45rem 1rem;
    font-size: 0.9rem;
}

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

/* Document type tabs */
.doc-type-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.doc-type-tab {
    display: inline-block;
    padding: 0.45rem 1rem;
    border-radius: 999px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

.doc-type-tab:hover {
    border-color: var(--accent-color);
    color: var(--accent-color);
}

.doc-type-tab.active {
    background: var(--accent-soft);
    border-color: var(--accent-color);
    color: var(--accent-color);
    font-weight: 600;
}

html[data-theme="dark"] body.acc-admin {
    --bg-secondary: #0f172a;
    --bg-primary: #1e293b;
    --bg-tertiary: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --border-color: #475569;
}

html[data-theme="dark"] .acc-panel,
html[data-theme="dark"] .stats-card,
html[data-theme="dark"] .topbar {
    background: var(--bg-primary);
    color: var(--text-primary);
}

@media (max-width: 991.98px) {
    html[dir="rtl"] .sidebar {
        transform: translateX(100%);
        transition: transform 0.28s ease;
    }

    html[dir="ltr"] .sidebar {
        transform: translateX(-100%);
        transition: transform 0.28s ease;
    }

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

    html[dir="rtl"] .main-content,
    html[dir="ltr"] .main-content {
        margin-right: 0;
        margin-left: 0;
    }

    .sidebar-toggle {
        display: inline-flex;
    }

    body.sidebar-open {
        overflow: hidden;
    }

    .topbar-right {
        gap: 0.35rem;
    }

    .page-title {
        font-size: 1.05rem;
        max-width: 42vw;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }
}

/* Topbar tools */
.topbar-tool-btn,
.locale-switcher .btn {
    min-width: 40px;
    min-height: 40px;
}

.locale-switcher .btn-group {
    gap: 0;
}

.auth-toolbar {
    position: fixed;
    top: 1rem;
    inset-inline-end: 1rem;
    z-index: 10;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

html[data-theme="dark"] body.acc-auth {
    background: linear-gradient(135deg, #020617 0%, #0f172a 45%, #1e293b 100%);
}

html[data-theme="dark"] .auth-card {
    background: var(--bg-primary, #1e293b);
    color: var(--text-primary, #f1f5f9);
}

html[data-theme="dark"] .auth-card-body .form-control,
html[data-theme="dark"] .auth-card-body .form-select,
html[data-theme="dark"] .auth-card-body .input-group-text {
    background: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

html[data-theme="dark"] .acc-panel .panel-head {
    background: linear-gradient(180deg, #1e293b, #0f172a);
}

html[data-theme="dark"] .form-control,
html[data-theme="dark"] .form-select,
html[data-theme="dark"] .input-group-text {
    background: #0f172a;
    border-color: #475569;
    color: #f1f5f9;
}

html[data-theme="dark"] .form-control:focus,
html[data-theme="dark"] .form-select:focus {
    background: #0f172a;
    color: #f1f5f9;
}

html[data-theme="dark"] .table {
    --bs-table-bg: transparent;
    --bs-table-color: var(--text-primary);
    --bs-table-hover-bg: rgba(255, 255, 255, 0.04);
    --bs-table-striped-bg: rgba(255, 255, 255, 0.02);
}

html[data-theme="dark"] .acc-panel .table thead th,
html[data-theme="dark"] .table-light {
    --bs-table-bg: var(--bg-tertiary);
    --bs-table-color: var(--text-secondary);
    background: var(--bg-tertiary) !important;
    color: var(--text-secondary) !important;
}

html[data-theme="dark"] .acc-panel .table tbody tr:hover {
    background: rgba(255, 255, 255, 0.04);
}

html[data-theme="dark"] .dropdown-menu {
    background: #1e293b;
    border-color: #475569;
}

html[data-theme="dark"] .dropdown-item {
    color: #e2e8f0;
}

html[data-theme="dark"] .dropdown-item:hover {
    background: #334155;
    color: #fff;
}

html[data-theme="dark"] .alert-success {
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border-color: rgba(16, 185, 129, 0.35);
}

html[data-theme="dark"] .alert-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

html[data-theme="dark"] .badge.bg-light {
    background: #334155 !important;
    color: #e2e8f0 !important;
}

html[data-theme="dark"] .btn-outline-secondary {
    color: #cbd5e1;
    border-color: #64748b;
}

html[data-theme="dark"] .btn-outline-secondary:hover {
    background: #334155;
    color: #fff;
}

html[data-theme="dark"] .nav-pills .nav-link {
    background: #334155;
    color: #cbd5e1;
}

html[data-theme="dark"] .doc-type-tab {
    background: #1e293b;
    border-color: #475569;
    color: #cbd5e1;
}

html[data-theme="dark"] .datetime-chip,
html[data-theme="dark"] .user-chip,
html[data-theme="dark"] .sidebar-toggle {
    background: #0f172a;
    border-color: #475569;
    color: var(--text-primary);
}

html[data-theme="dark"] .bg-light {
    background-color: #334155 !important;
}

.acc-table-actions-mobile .dropdown-toggle {
    min-height: 38px;
}

/* Invoice line items — mobile card rows */
@media (max-width: 575.98px) {
    .invoice-lines-table thead {
        display: none;
    }

    .invoice-lines-table tbody tr.invoice-line-row {
        display: block;
        border: 1px solid var(--border-color);
        border-radius: 10px;
        margin-bottom: 0.75rem;
        padding: 0.65rem;
        background: var(--bg-primary);
    }

    .invoice-lines-table tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        border: none;
        padding: 0.35rem 0;
    }

    .invoice-lines-table tbody td::before {
        content: attr(data-label);
        font-size: 0.78rem;
        font-weight: 600;
        color: var(--text-muted);
        flex: 0 0 38%;
    }

    .invoice-lines-table tbody td:last-child {
        justify-content: flex-end;
        padding-top: 0.5rem;
    }

    .invoice-lines-table tbody td .form-control {
        max-width: 58%;
    }

    .customer-mode-panel .form-check-label {
        width: 100%;
    }
}
