@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Arabic:wght@400;500;600;700;800&display=swap');

:root {
    --primary: #146cf0;
    --primary-dark: #0034ba;
    --primary-soft: #eff6ff;
    --danger: #d92d20;
    --success: #079455;
    --warning: #b54708;
    --text: #101828;
    --muted: #667085;
    --border: #e4e7ec;
    --background: #f4f7fb;
    --card: #ffffff;
    --shadow: 0 18px 50px rgba(16, 24, 40, 0.08);
    --radius: 22px;
}

* {
    box-sizing: border-box;
}

html,
body,
input,
select,
textarea,
button {
    font-family: 'IBM Plex Sans Arabic', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
}

body {
    margin: 0;
    background: var(--background);
    color: var(--text);
}

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

button,
.button,
.quick-add-grid a,
.quick-actions a {
    border: 0;
    border-radius: 14px;
    padding: 12px 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #ffffff;
    font-weight: 700;
    cursor: pointer;
    box-shadow: 0 12px 24px rgba(20, 108, 240, 0.22);
}

button:hover,
.button:hover,
.quick-add-grid a:hover,
.quick-actions a:hover {
    transform: translateY(-1px);
}

button.danger,
.danger {
    background: var(--danger) !important;
    color: #ffffff !important;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 13px 14px;
    background: #ffffff;
    color: var(--text);
    font-size: 15px;
    outline: none;
}

input:focus,
select:focus,
textarea:focus {
    border-color: rgba(20, 108, 240, 0.8);
    box-shadow: 0 0 0 4px rgba(20, 108, 240, 0.12);
}

textarea {
    min-height: 100px;
    resize: vertical;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.92);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(14px);
}

.topbar-title {
    flex: 1;
}

.topbar-title strong {
    display: block;
    color: var(--primary);
    font-size: 16px;
}

.topbar-title span,
.topbar-user span {
    color: var(--muted);
    font-size: 13px;
}

.topbar-user {
    display: none;
    align-items: center;
    gap: 12px;
}

.topbar-user a {
    display: inline-flex;
    padding: 8px 12px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 700;
}

.menu-btn {
    width: 46px;
    height: 46px;
    padding: 0;
    font-size: 22px;
}

.sidebar {
    position: fixed;
    inset: 0 0 0 auto;
    z-index: 25;
    width: 300px;
    padding: 18px 14px 26px;
    overflow-y: auto;
    background: #ffffff;
    border-left: 1px solid var(--border);
    box-shadow: 0 24px 70px rgba(16, 24, 40, 0.22);
    transform: translateX(105%);
    transition: transform 0.24s ease;
    scrollbar-width: thin;
    overscroll-behavior: contain;
}

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

.sidebar::-webkit-scrollbar {
    width: 7px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 999px;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    padding: 8px 8px 14px;
    border-bottom: 1px solid var(--border);
}

.sidebar-brand span {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    border-radius: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #ffffff;
    font-weight: 800;
}

.sidebar-brand strong {
    color: var(--text);
}

.nav-group {
    margin-bottom: 8px;
    border: 1px solid #eef2f6;
    border-radius: 18px;
    background: #ffffff;
    overflow: hidden;
}

.nav-group summary {
    list-style: none;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 13px 14px;
    color: #344054;
    font-weight: 800;
    cursor: pointer;
}

.nav-group summary::-webkit-details-marker {
    display: none;
}

.nav-group summary::after {
    content: '⌄';
    color: var(--muted);
    transition: transform 0.2s ease;
}

.nav-group[open] summary::after {
    transform: rotate(180deg);
}

.nav-group-links {
    display: grid;
    gap: 4px;
    padding: 0 8px 10px;
}

.nav-group a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 12px;
    border-radius: 14px;
    color: #344054;
    font-weight: 600;
}

.nav-group a:hover,
.nav-group a.active {
    background: var(--primary-soft);
    color: var(--primary);
}

.nav-icon {
    display: grid;
    place-items: center;
    width: 26px;
    height: 26px;
    border-radius: 10px;
    background: #f2f4f7;
    font-size: 13px;
}

.content {
    width: 100%;
    max-width: 1180px;
    margin: 0 auto;
    padding: 18px 14px 90px;
}

.page-toolbar,
.panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    margin-bottom: 16px;
}

.page-toolbar h1,
.panel-header h2 {
    margin: 0;
    color: var(--text);
}

.page-toolbar p {
    margin: 4px 0 0;
    color: var(--muted);
}

.hero {
    margin-bottom: 16px;
    padding: 24px;
    border-radius: 28px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #ffffff;
    box-shadow: 0 24px 60px rgba(20, 108, 240, 0.28);
}

.hero h1 {
    margin: 0 0 8px;
    font-size: 22px;
}

.hero strong {
    display: block;
    font-size: 36px;
}

.hero p {
    margin: 8px 0 0;
    color: #dbeafe;
    line-height: 1.8;
}

.stats-grid,
.cards-list,
.quick-actions,
.quick-add-grid {
    display: grid;
    gap: 12px;
}

.stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 16px 0;
}

.stat-card,
.panel,
.cards-list article {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.stat-card {
    position: relative;
    overflow: hidden;
    padding: 16px;
}

.stat-card::before {
    content: '';
    position: absolute;
    inset: 0 0 auto 0;
    height: 4px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}

.stat-card span,
.stat-card small,
.cards-list article small,
.hint {
    color: var(--muted);
}

.stat-card strong {
    display: block;
    margin-top: 6px;
    font-size: 22px;
}

.panel {
    margin: 16px 0;
    padding: 16px;
}

.panel > h2 {
    margin: 0 0 14px;
    font-size: 19px;
}

.cards-list article {
    padding: 16px;
}

.cards-list article strong,
.cards-list article span,
.cards-list article small {
    display: block;
}

.cards-list article span {
    margin: 6px 0;
    font-weight: 800;
}

.quick-actions,
.quick-add-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.quick-actions a,
.quick-add-grid a,
.quick-add-grid button {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 54px;
    text-align: center;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
}

.form-grid label {
    font-weight: 700;
    color: #344054;
}

.form-grid textarea,
.form-grid button {
    grid-column: 1 / -1;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted);
}

.check input {
    width: auto;
}

.filters {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 13px 12px;
    border-bottom: 1px solid var(--border);
    text-align: right;
    white-space: nowrap;
}

th {
    color: var(--muted);
    font-size: 13px;
}

.empty-cell {
    color: transparent;
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
    padding: 6px 11px;
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 12px;
    font-weight: 800;
}

.badge.danger,
.badge.error {
    background: #fef3f2;
    color: #b42318;
}

.badge.warning {
    background: #fffaeb;
    color: #b54708;
}

.badge.ok,
.badge.success {
    background: #ecfdf3;
    color: #027a48;
}

.alert {
    margin: 12px 0;
    padding: 13px 14px;
    border: 1px solid #fedf89;
    border-radius: 16px;
    background: #fffaeb;
    color: var(--warning);
}

.alert.danger,
.alert.error {
    border-color: #fecdca;
    background: #fef3f2;
    color: #b42318;
}

.alert.success {
    border-color: #abefc6;
    background: #ecfdf3;
    color: #027a48;
}

.progress {
    height: 14px;
    overflow: hidden;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: #eef2f6;
}

.progress span {
    display: block;
    height: 100%;
    border-radius: 999px;
    background: linear-gradient(90deg, var(--primary), var(--primary-dark));
}

.fab {
    position: fixed;
    left: 18px;
    bottom: 18px;
    z-index: 40;
    display: grid;
    place-items: center;
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #ffffff;
    font-size: 30px;
    font-weight: 800;
    box-shadow: 0 16px 40px rgba(20, 108, 240, 0.34);
}

.install-pwa {
    position: fixed;
    right: 18px;
    bottom: 18px;
    z-index: 50;
}

/* Login */
.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
    background:
        radial-gradient(circle at top right, rgba(20, 108, 240, 0.18), transparent 34%),
        linear-gradient(135deg, #eef5ff, #f8fbff);
}

.login-shell {
    display: grid;
    place-items: center;
    width: 100%;
}

.login-card {
    width: min(430px, 100%);
    padding: 30px;
    border: 1px solid rgba(228, 231, 236, 0.9);
    border-radius: 34px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 28px 90px rgba(16, 24, 40, 0.16);
}

.login-card h2 {
    margin: 0 0 6px;
    color: var(--text);
    font-size: 28px;
}

.login-card p {
    margin: 0 0 18px;
    color: var(--muted);
    line-height: 1.8;
}

.login-card label {
    display: block;
    margin: 13px 0 7px;
    font-weight: 700;
}

.btn-block {
    width: 100%;
    margin-top: 16px;
}

.link-muted {
    display: block;
    margin-top: 14px;
    color: var(--muted);
    text-align: center;
    font-weight: 700;
}

.security-note {
    margin-top: 14px;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #f8fafc;
    color: var(--muted);
    line-height: 1.8;
}

/* Modals */
.modal-trigger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 120px;
    white-space: nowrap;
}

.panel .form-grid.is-modalized {
    display: none;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: none;
    align-items: flex-start;
    justify-content: center;
    padding: 22px;
    overflow-y: auto;
    background: rgba(15, 23, 42, 0.58);
    backdrop-filter: blur(8px);
}

.modal-backdrop.is-open {
    display: flex;
}

.modal-card {
    width: min(860px, 100%);
    margin-top: 18px;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.5);
    border-radius: 28px;
    background: #ffffff;
    box-shadow: 0 30px 100px rgba(15, 23, 42, 0.35);
    animation: modalIn 0.18s ease-out;
}

.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px 20px;
    border-bottom: 1px solid var(--border);
    background: linear-gradient(135deg, #f8fbff, #eef6ff);
}

.modal-head h3 {
    margin: 0;
    font-size: 20px;
}

.modal-close {
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #ffffff;
    color: #344054;
    font-size: 22px;
    box-shadow: none;
}

.modal-body {
    max-height: 72vh;
    overflow-y: auto;
    padding: 20px;
}

.modal-body .form-grid {
    display: grid;
}

.modal-body button[type='submit'],
.modal-body form button:not(.modal-close) {
    position: sticky;
    bottom: 0;
}

@keyframes modalIn {
    from {
        opacity: 0;
        transform: translateY(14px) scale(0.98);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

/* SweetAlert2 compatible toast */
.swal2-toast-container {
    position: fixed;
    top: 18px;
    left: 18px;
    z-index: 3000;
    display: grid;
    gap: 10px;
    width: min(380px, calc(100vw - 36px));
}

.swal2-toast {
    display: grid;
    grid-template-columns: 14px 1fr 28px;
    align-items: center;
    gap: 10px;
    padding: 13px 14px;
    border: 1px solid var(--border);
    border-radius: 18px;
    background: #ffffff;
    box-shadow: 0 20px 60px rgba(16, 24, 40, 0.16);
    animation: toastIn 0.22s ease-out;
}

.swal2-icon-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
}

.swal2-success .swal2-icon-dot {
    background: var(--success);
}

.swal2-error .swal2-icon-dot,
.swal2-danger .swal2-icon-dot {
    background: var(--danger);
}

.swal2-warning .swal2-icon-dot {
    background: #f79009;
}

.swal2-title {
    color: var(--text);
    font-weight: 800;
    line-height: 1.6;
}

.swal2-close {
    width: 28px;
    height: 28px;
    padding: 0;
    border-radius: 10px;
    background: #f2f4f7;
    color: #344054;
    box-shadow: none;
}

.toast-leave {
    opacity: 0;
    transform: translateY(-8px);
    transition: 0.2s ease;
}

@keyframes toastIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: none;
    }
}

@media (min-width: 900px) {
    .topbar {
        padding-inline-start: 26px;
    }

    .topbar-user {
        display: flex;
    }

    .menu-btn {
        display: none;
    }

    .sidebar {
        top: 72px;
        right: 0;
        bottom: auto;
        left: 0;
        display: flex;
        align-items: center;
        gap: 8px;
        width: 100%;
        height: auto;
        max-height: none;
        padding: 10px 24px;
        overflow: visible;
        border-left: 0;
        border-bottom: 1px solid var(--border);
        box-shadow: 0 10px 30px rgba(16, 24, 40, 0.06);
        transform: none;
    }

    .sidebar-brand {
        margin: 0 0 0 6px;
        padding: 0;
        border: 0;
    }

    .sidebar-brand span {
        width: 36px;
        height: 36px;
        border-radius: 12px;
        font-size: 13px;
    }

    .sidebar-brand strong {
        display: none;
    }

    .nav-group {
        position: relative;
        margin: 0;
        overflow: visible;
        border: 0;
        background: transparent;
    }

    .nav-group summary {
        padding: 10px 12px;
        border-radius: 14px;
        background: #ffffff;
        box-shadow: inset 0 0 0 1px #eef2f6;
    }

    .nav-group-links {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        z-index: 60;
        display: none;
        min-width: 245px;
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: #ffffff;
        box-shadow: 0 24px 60px rgba(16, 24, 40, 0.16);
    }

    .nav-group[open] .nav-group-links,
    .nav-group:hover .nav-group-links {
        display: grid;
    }

    .content {
        max-width: 1280px;
        padding: 86px 24px 34px;
    }

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

    .cards-list {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }

    .quick-actions,
    .quick-add-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .form-grid {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

@media (max-width: 620px) {
    .content {
        padding-inline: 12px;
    }

    .stats-grid,
    .cards-list {
        grid-template-columns: 1fr;
    }

    .hero strong {
        font-size: 28px;
    }

    .panel {
        padding: 14px;
        border-radius: 20px;
    }

    .page-toolbar,
    .panel-header {
        align-items: center;
    }

    .panel-header h2,
    .page-toolbar h1 {
        font-size: 19px;
    }

    .modal-backdrop {
        padding: 10px;
    }

    .modal-card {
        margin-top: 8px;
        border-radius: 22px;
    }

    .modal-body {
        max-height: 76vh;
        padding: 14px;
    }

    table,
    thead,
    tbody,
    tr,
    td,
    th {
        display: block;
    }

    table tr {
        margin: 10px 0;
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: #ffffff;
    }

    table th {
        display: none;
    }

    table td {
        padding: 8px;
        border: 0;
        white-space: normal;
    }

    table td.empty-cell {
        display: none;
    }
}


/* Navigation fixes */
.nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 24;
    display: none;
    background: rgba(15, 23, 42, 0.46);
    backdrop-filter: blur(4px);
}

.nav-open .nav-backdrop {
    display: block;
}

.sidebar-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--border);
}

.sidebar-head .sidebar-brand {
    margin-bottom: 0;
    padding: 0;
    border-bottom: 0;
}

.nav-close {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #ffffff;
    color: #344054;
    font-size: 24px;
    line-height: 1;
    box-shadow: none;
}

.nav-group:not([open]) .nav-group-links {
    display: none;
}

@media (min-width: 1024px) {
    .app-shell {
        display: block;
    }

    .topbar {
        z-index: 70;
    }

    .menu-btn,
    .nav-close,
    .nav-backdrop {
        display: none !important;
    }

    .topbar-user {
        display: flex;
    }

    .sidebar {
        position: sticky;
        top: 75px;
        z-index: 60;
        display: flex;
        align-items: center;
        gap: 10px;
        width: 100%;
        height: auto;
        max-height: none;
        padding: 10px 18px;
        overflow: visible;
        border-top: 0;
        border-left: 0;
        border-bottom: 1px solid var(--border);
        background: rgba(255, 255, 255, 0.96);
        box-shadow: 0 12px 28px rgba(16, 24, 40, 0.06);
        transform: none;
        backdrop-filter: blur(14px);
    }

    .sidebar-head {
        flex: 0 0 auto;
        margin: 0 0 0 8px;
        padding: 0;
        border-bottom: 0;
    }

    .sidebar-brand strong {
        white-space: nowrap;
    }

    .nav-group {
        position: relative;
        flex: 0 0 auto;
        margin-bottom: 0;
        overflow: visible;
    }

    .nav-group summary {
        min-height: 46px;
        padding: 10px 14px;
        white-space: nowrap;
    }

    .nav-group[open] .nav-group-links {
        position: absolute;
        top: calc(100% + 8px);
        right: 0;
        z-index: 80;
        display: grid;
        min-width: 240px;
        padding: 8px;
        border: 1px solid var(--border);
        border-radius: 18px;
        background: #ffffff;
        box-shadow: 0 24px 60px rgba(16, 24, 40, 0.16);
    }

    .content {
        padding-top: 24px;
    }
}

@media (max-width: 1023px) {
    .sidebar {
        top: 0;
        height: 100dvh;
        max-height: 100dvh;
    }

    .nav-open {
        overflow: hidden;
    }
}

/* Mobile navigation layering */
.sidebar {
    z-index: 100;
}

.nav-backdrop {
    z-index: 90;
}
