: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;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    min-height: 100%;
    font-family: "Tajawal", sans-serif;
    color: var(--ink);
    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(1180px, 100%);
    display: grid;
    grid-template-columns: 1.15fr 0.85fr;
    gap: 28px;
    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: flex;
    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: grid;
    grid-template-columns: 310px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    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;
}

.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;
}

.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;
}

.company-mini {
    margin-top: auto;
    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 {
    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;
}

.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;
}

.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 {
    overflow: auto;
}

.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;
}

@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));
    }
}

@media (max-width: 920px) {
    .app-shell {
        grid-template-columns: 1fr;
    }

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

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

    .mobile-menu-button {
        display: inline-flex;
    }

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

    .topbar-actions {
        justify-content: space-between;
    }
}

@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;
    }

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