:root {
    --primary: #073caa;
    --primary-strong: #03228f;
    --secondary: #0e73e4;
    --accent: #08d9ff;
    --success: #117a55;
    --warning: #b9770e;
    --danger: #c0392b;
    --ink: #0f1b2d;
    --muted: #5c6f8c;
    --line: #dbe8fb;
    --panel: rgba(255, 255, 255, 0.92);
    --background: #eef5ff;
    --shadow: 0 18px 45px rgba(8, 34, 95, 0.12);
    --radius-lg: 24px;
    --radius-md: 18px;
    --radius-sm: 12px;
    --sidebar-width: 310px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    width: 100%;
    font-family: "Tajawal", sans-serif;
    color: var(--ink);
    overflow-x: hidden;
    background:
        radial-gradient(circle at top left, rgba(8, 217, 255, 0.12), transparent 28%),
        radial-gradient(circle at top right, rgba(14, 115, 228, 0.16), transparent 24%),
        linear-gradient(180deg, #f7fbff 0%, #ecf4ff 44%, #e8f1ff 100%);
}

a {
    color: inherit;
    text-decoration: none;
}

img {
    max-width: 100%;
    display: block;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    cursor: pointer;
}

.auth-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 32px;
    background:
        radial-gradient(circle at 20% 20%, rgba(8, 217, 255, 0.2), transparent 25%),
        linear-gradient(135deg, #041a63 0%, #073caa 42%, #0e73e4 100%);
}

.auth-grid {
    width: min(560px, 100%);
    display: grid;
    grid-template-columns: 1fr;
    gap: 0;
    align-items: stretch;
}

.auth-brand-panel,
.auth-card,
.panel-card,
.stat-card {
    border: 1px solid rgba(219, 232, 251, 0.8);
    box-shadow: var(--shadow);
}

.auth-brand-panel {
    padding: 42px;
    border-radius: 32px;
    background:
        linear-gradient(160deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04)),
        radial-gradient(circle at top right, rgba(8, 217, 255, 0.3), transparent 20%);
    color: #fff;
    display: none;
    flex-direction: column;
    justify-content: space-between;
}

.brand-chip {
    width: fit-content;
    padding: 8px 14px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    font-family: "Saira", sans-serif;
    font-size: 0.95rem;
}

.auth-brand-panel h1 {
    font-size: clamp(2rem, 3vw, 3.45rem);
    line-height: 1.25;
    margin: 28px 0 16px;
}

.auth-brand-panel p {
    max-width: 46ch;
    font-size: 1.08rem;
    line-height: 1.9;
    color: rgba(255, 255, 255, 0.88);
}

.auth-brand-footer {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    color: rgba(255, 255, 255, 0.78);
}

.auth-card {
    padding: 34px;
    border-radius: 30px;
    background: rgba(255, 255, 255, 0.98);
}

.auth-card-header {
    display: flex;
    align-items: center;
    gap: 18px;
    margin-bottom: 20px;
}

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

.auth-title-wrap h2 {
    margin: 0;
    font-size: 1.85rem;
}

.auth-title-wrap p {
    margin: 6px 0 0;
    color: var(--muted);
}

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

.auth-helper {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px dashed var(--line);
    color: var(--muted);
    display: grid;
    gap: 8px;
}

.app-shell {
    display: block;
    min-height: 100vh;
    min-height: 100dvh;
    background:
        linear-gradient(
            to left,
            rgba(7, 60, 170, 0.98) 0 var(--sidebar-width),
            transparent var(--sidebar-width) 100%
        );
}

.app-shell,
.app-shell > *,
.content-shell,
.page-content,
.stats-grid,
.alert-grid,
.grid-two,
.grid-sidebar,
.panel-card,
.panel-head,
.panel-head > *,
.topbar,
.topbar > *,
.topbar-actions,
.header-actions,
.summary-inline,
.summary-chip,
.table-wrap,
.stack-form,
.filters-grid,
.field,
.field-row,
.form-actions {
    min-width: 0;
}

.sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 40;
    width: var(--sidebar-width);
    height: 100vh;
    height: 100dvh;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 24px;
    background:
        linear-gradient(180deg, rgba(6, 31, 93, 0.98) 0%, rgba(7, 60, 170, 0.98) 55%, rgba(14, 115, 228, 0.96) 100%);
    color: #fff;
    display: flex;
    flex-direction: column;
    gap: 28px;
    overflow: hidden;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 18px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(14px);
}

.brand-logo {
    width: 78px;
    height: auto;
}

.brand-title {
    font-family: "Saira", sans-serif;
    font-size: 1.55rem;
}

.brand-subtitle {
    color: rgba(255, 255, 255, 0.72);
    font-size: 0.92rem;
}

.sidebar-nav {
    display: grid;
    gap: 8px;
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-inline-end: 6px;
    align-content: start;
}

.nav-link {
    padding: 14px 16px;
    border-radius: 16px;
    color: rgba(255, 255, 255, 0.82);
    transition: 180ms ease;
}

.nav-link:hover,
.nav-link.active {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

.sidebar-nav::-webkit-scrollbar {
    width: 8px;
}

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

.sidebar-footer {
    flex: 0 0 auto;
}

.company-mini {
    padding: 18px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.08);
}

.company-mini-title {
    font-weight: 700;
}

.company-mini-meta {
    margin-top: 6px;
    color: rgba(255, 255, 255, 0.68);
    font-size: 0.92rem;
}

.content-shell {
    width: 100%;
    margin-inline-start: var(--sidebar-width);
    width: calc(100% - var(--sidebar-width));
    min-height: 100vh;
    min-height: 100dvh;
    padding: 26px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 24px;
}

.page-title {
    margin: 0;
    font-size: clamp(1.7rem, 2vw, 2.4rem);
}

.page-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
}

.topbar-actions,
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.topbar-actions form,
.header-actions form {
    margin: 0;
}

.admin-box {
    padding: 12px 16px;
    border-radius: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
}

.admin-box-label {
    color: var(--muted);
    font-size: 0.88rem;
}

.admin-box-name {
    font-family: "Saira", sans-serif;
    margin-top: 4px;
}

.page-content {
    display: grid;
    gap: 24px;
}

.flash-stack {
    display: grid;
    gap: 12px;
    margin-bottom: 18px;
}

.flash {
    padding: 14px 18px;
    border-radius: 16px;
    font-weight: 600;
}

.flash-success { background: rgba(17, 122, 85, 0.1); color: var(--success); }
.flash-error { background: rgba(192, 57, 43, 0.1); color: var(--danger); }
.flash-warning { background: rgba(185, 119, 14, 0.1); color: var(--warning); }
.flash-info { background: rgba(14, 115, 228, 0.12); color: var(--secondary); }

.stats-grid,
.alert-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 18px;
}

.mini-stats-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat-card {
    padding: 22px 20px;
    border-radius: var(--radius-lg);
    background:
        linear-gradient(135deg, rgba(255, 255, 255, 0.98), rgba(244, 249, 255, 0.94));
}

.stat-card span {
    display: block;
    color: var(--muted);
    margin-bottom: 10px;
}

.stat-card strong {
    display: block;
    font-size: 1.75rem;
    font-family: "Saira", sans-serif;
}

.alert-card {
    padding: 20px;
    border-radius: var(--radius-md);
    color: #fff;
}

.alert-card h3 {
    margin: 0 0 8px;
}

.alert-card p {
    margin: 0;
}

.alert-info { background: linear-gradient(135deg, #0e73e4, #08d9ff); }
.alert-warning { background: linear-gradient(135deg, #c0850b, #f6b93b); }
.alert-danger { background: linear-gradient(135deg, #a82315, #e74c3c); }

.grid-two {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 24px;
}

.grid-sidebar {
    display: grid;
    grid-template-columns: minmax(320px, 380px) minmax(0, 1fr);
    gap: 24px;
}

.panel-card {
    padding: 22px;
    border-radius: var(--radius-lg);
    background: var(--panel);
    backdrop-filter: blur(20px);
}

.panel-head {
    display: flex;
    align-items: start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 18px;
}

.panel-head h2 {
    margin: 0 0 6px;
    font-size: 1.32rem;
}

.panel-head span {
    color: var(--muted);
}

.with-form {
    flex-wrap: wrap;
}

.filters-grid,
.stack-form {
    display: grid;
    gap: 14px;
}

.inline-filters {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    align-items: end;
}

.report-filters {
    grid-template-columns: repeat(5, minmax(0, 1fr));
    align-items: end;
}

.field {
    display: grid;
    gap: 8px;
}

.field span {
    font-weight: 700;
    color: #173864;
}

.field input,
.field select,
.field textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 14px 16px;
    background: #fff;
    color: var(--ink);
    transition: 180ms ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--secondary);
    box-shadow: 0 0 0 4px rgba(14, 115, 228, 0.12);
}

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

.side-stack {
    display: grid;
    gap: 24px;
    align-content: start;
}

.form-note,
.muted-text {
    margin: 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.switch-list {
    display: grid;
    gap: 10px;
}

.switch-row,
.check-card {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #173864;
    font-weight: 700;
}

.switch-row input,
.check-card input {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

.permissions-box {
    display: grid;
    gap: 12px;
}

.permissions-title {
    color: #173864;
    font-weight: 800;
}

.checkbox-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.check-card {
    align-items: flex-start;
    min-height: 48px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #fff;
}

.permissions-summary {
    max-width: 360px;
    color: #173864;
}

.employee-profile-panel {
    margin-bottom: 24px;
}

.profile-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin: -6px 0 18px;
}

.profile-meta span {
    padding: 8px 12px;
    border-radius: 999px;
    background: rgba(14, 115, 228, 0.08);
    color: #173864;
    font-weight: 700;
}

.form-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-top: 4px;
}

.primary-button,
.secondary-button,
.ghost-button,
.danger-outline-button,
.icon-button {
    border: 0;
    border-radius: 14px;
    padding: 13px 18px;
    font-weight: 700;
    transition: 180ms ease;
}

.primary-button {
    color: #fff;
    background: linear-gradient(135deg, var(--primary-strong), var(--secondary));
}

.secondary-button {
    color: #fff;
    background: linear-gradient(135deg, var(--secondary), var(--accent));
}

.ghost-button,
.icon-button {
    color: var(--primary);
    background: rgba(14, 115, 228, 0.1);
}

.danger-outline-button {
    color: var(--danger);
    background: rgba(192, 57, 43, 0.1);
}

.primary-button:hover,
.secondary-button:hover,
.ghost-button:hover,
.danger-outline-button:hover,
.icon-button:hover,
.nav-link:hover {
    transform: translateY(-1px);
}

.table-wrap {
    max-width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
    overscroll-behavior-x: contain;
}

.data-table {
    width: 100%;
    min-width: 720px;
    border-collapse: collapse;
}

.compact-table {
    min-width: 0;
}

.data-table th,
.data-table td {
    padding: 14px 12px;
    border-bottom: 1px solid #edf3fd;
    text-align: right;
    vertical-align: top;
}

.data-table th {
    color: var(--muted);
    font-weight: 700;
    white-space: nowrap;
}

.data-table tbody tr:hover {
    background: rgba(14, 115, 228, 0.04);
}

.actions-cell {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

.table-link {
    border: 0;
    background: transparent;
    padding: 0;
    color: var(--primary);
    font-weight: 700;
}

.danger-link {
    color: var(--danger);
}

.success-link {
    color: var(--success);
}

.attachment-link {
    color: var(--secondary);
    font-weight: 700;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 12px;
    border-radius: 999px;
    font-size: 0.88rem;
    font-weight: 700;
}

.status-paid,
.status-active {
    background: rgba(17, 122, 85, 0.12);
    color: var(--success);
}

.status-unpaid,
.status-inactive,
.status-overdue {
    background: rgba(192, 57, 43, 0.12);
    color: var(--danger);
}

.status-due_soon,
.status-due_today {
    background: rgba(185, 119, 14, 0.12);
    color: var(--warning);
}

.status-not_due {
    background: rgba(14, 115, 228, 0.12);
    color: var(--secondary);
}

.activity-list {
    display: grid;
    gap: 14px;
}

.activity-item {
    display: flex;
    justify-content: space-between;
    gap: 14px;
    padding-bottom: 14px;
    border-bottom: 1px dashed var(--line);
}

.activity-item:last-child {
    border-bottom: 0;
    padding-bottom: 0;
}

.activity-item p {
    margin: 6px 0 0;
    color: var(--muted);
}

.activity-item time {
    color: var(--muted);
    white-space: nowrap;
}

.empty-cell,
.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 28px;
}

.divider {
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--line), transparent);
    margin: 26px 0;
}

.logo-preview-card {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 180px;
    border: 1px dashed var(--line);
    border-radius: 20px;
    background: #f8fbff;
    padding: 24px;
}

.logo-preview-card img {
    max-width: 240px;
}

.summary-inline {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.summary-chip {
    min-width: 170px;
    padding: 12px 14px;
    border-radius: 16px;
    background: #f5f9ff;
    border: 1px solid var(--line);
}

.summary-chip span {
    display: block;
    color: var(--muted);
    margin-bottom: 6px;
}

.summary-chip strong {
    font-family: "Saira", sans-serif;
}

.chart-canvas {
    width: 100%;
    min-height: 320px;
    max-height: 360px;
}

.mobile-menu-button {
    display: none;
}

.sidebar-overlay {
    position: fixed;
    inset: 0;
    border: 0;
    padding: 0;
    background: rgba(4, 26, 99, 0.34);
    opacity: 0;
    pointer-events: none;
    transition: opacity 180ms ease;
    z-index: 45;
}

.mono {
    font-family: "Saira", sans-serif;
}

.checkbox-row {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--muted);
}

.table-hint {
    display: inline-block;
    margin-inline-start: 8px;
    padding: 4px 10px;
    border-radius: 999px;
    background: rgba(14, 115, 228, 0.12);
    color: var(--secondary);
    font-size: 0.84rem;
    font-weight: 700;
}

.line-items-table input,
.line-items-table textarea,
.line-items-table select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: #fff;
}

.status-issued,
.status-partial,
.status-draft,
.status-cancelled {
    color: var(--ink);
}

.status-issued {
    background: rgba(14, 115, 228, 0.12);
    color: var(--secondary);
}

.status-partial {
    background: rgba(185, 119, 14, 0.12);
    color: var(--warning);
}

.status-draft {
    background: rgba(92, 111, 140, 0.12);
    color: var(--muted);
}

.status-cancelled {
    background: rgba(192, 57, 43, 0.12);
    color: var(--danger);
}

@media (max-width: 1180px) {
    .stats-grid,
    .alert-grid,
    .mini-stats-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .grid-two,
    .grid-sidebar,
    .auth-grid {
        grid-template-columns: 1fr;
    }

    .report-filters,
    .inline-filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .checkbox-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 920px) {
    body.menu-open {
        overflow: hidden;
    }

    .app-shell {
        grid-template-columns: 1fr;
        background: transparent;
    }

    .sidebar {
        position: fixed;
        inset: 0 0 0 auto;
        width: min(86vw, 320px);
        max-width: calc(100vw - 36px);
        height: 100dvh;
        transform: translateX(105%);
        transition: transform 220ms ease;
        z-index: 50;
        overflow-y: auto;
    }

    body.menu-open .sidebar {
        transform: translateX(0);
    }

    body.menu-open .sidebar-overlay {
        opacity: 1;
        pointer-events: auto;
    }

    .content-shell {
        width: 100%;
        margin-inline-start: 0;
        padding: 20px 16px 28px;
    }

    .mobile-menu-button {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        width: fit-content;
    }

    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .topbar-actions,
    .header-actions {
        width: 100%;
        align-items: stretch;
        justify-content: stretch;
    }

    .topbar-actions > *,
    .header-actions > * {
        width: 100%;
    }

    .admin-box,
    .topbar-actions form,
    .topbar-actions .danger-outline-button,
    .header-actions .primary-button,
    .header-actions .secondary-button,
    .header-actions .ghost-button,
    .header-actions .danger-outline-button {
        width: 100%;
    }
}

@media (max-width: 640px) {
    .content-shell,
    .auth-card,
    .auth-brand-panel,
    .panel-card {
        padding: 18px;
    }

    .stats-grid,
    .alert-grid,
    .mini-stats-grid,
    .field-row,
    .report-filters,
    .inline-filters {
        grid-template-columns: 1fr;
    }

    .actions-cell {
        flex-direction: column;
        align-items: flex-start;
    }

    .panel-head,
    .activity-item,
    .form-actions {
        flex-direction: column;
        align-items: stretch;
    }

    .auth-card-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .summary-chip {
        width: 100%;
        min-width: 0;
    }

    .auth-body {
        padding: 18px;
    }
}
