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

:root {
    --bg: #f6f0fb;
    --panel: #ffffff;
    --text: #152033;
    --muted: #667085;
    --line: #e6eaf2;
    --primary: #a855f7;
    --primary-dark: #7c3aed;
    --success: #0f9f6e;
    --warning: #b7791f;
    --danger: #d92d20;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Cairo, Arial, sans-serif;
    direction: rtl;
}

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

.app {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 260px 1fr;
}

.sidebar {
    background: rgba(255,255,255,.92);
    color: #667085;
    padding: 28px 18px;
    position: sticky;
    top: 0;
    height: 100vh;
    border-left: 1px solid rgba(168,85,247,.13);
    box-shadow: 22px 0 55px rgba(88,28,135,.06);
}

.brand {
    font-weight: 800;
    font-size: 23px;
    margin-bottom: 30px;
    color: #8b5cf6;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand span {
    color: #0ea5e9;
}

.brand::after {
    content: "";
    width: 26px;
    height: 26px;
    border-radius: 8px;
    background: linear-gradient(135deg, #a855f7, #7dd3fc);
    box-shadow: 0 10px 25px rgba(168,85,247,.35);
}

.nav a {
    display: block;
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 7px;
    color: #64748b;
    font-weight: 800;
}

.nav a:hover,
.nav a.active {
    background: #f1e4ff;
    color: #9333ea;
    box-shadow: inset -4px 0 0 #a855f7;
}

.main {
    padding: 34px;
    min-width: 0;
    background:
        radial-gradient(circle at 10% 0%, rgba(168,85,247,.12), transparent 30%),
        linear-gradient(180deg, #fbf7ff 0%, #f6f0fb 100%);
}

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

.title h1 {
    margin: 0 0 4px;
    font-size: 26px;
}

.title p {
    margin: 0;
    color: var(--muted);
}

.panel {
    background: var(--panel);
    border: 1px solid rgba(168,85,247,.12);
    border-radius: 8px;
    padding: 22px;
    margin-bottom: 20px;
    box-shadow: 0 18px 45px rgba(88,28,135,.06);
}

.grid {
    display: grid;
    gap: 16px;
}

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

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

.stat {
    background: var(--panel);
    border: 0;
    border-radius: 8px;
    padding: 22px;
    color: #fff;
    min-height: 142px;
    position: relative;
    overflow: hidden;
    box-shadow: 0 18px 40px rgba(88,28,135,.12);
}

.stat::after {
    content: "";
    position: absolute;
    width: 170px;
    height: 170px;
    border-radius: 50%;
    background: rgba(255,255,255,.17);
    left: -52px;
    bottom: -68px;
}

.stat.gradient-one {
    background: linear-gradient(135deg, #f7b267, #ef5da8);
}

.stat.gradient-two {
    background: linear-gradient(135deg, #67c7f7, #2587e8);
}

.stat.gradient-three {
    background: linear-gradient(135deg, #62d6c4, #35c7a1);
}

.stat.gradient-four {
    background: linear-gradient(135deg, #a855f7, #7c3aed);
}

.stat small {
    display: block;
    color: rgba(255,255,255,.88);
    margin-bottom: 8px;
    font-weight: 800;
}

.stat strong {
    font-size: 30px;
    position: relative;
    z-index: 1;
}

.stat span {
    display: block;
    margin-top: 14px;
    color: rgba(255,255,255,.88);
    font-weight: 700;
    position: relative;
    z-index: 1;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border-radius: var(--radius);
    overflow: hidden;
}

th,
td {
    padding: 12px 11px;
    border-bottom: 1px solid var(--line);
    text-align: right;
    vertical-align: top;
}

th {
    background: #f8fafc;
    color: #475467;
    font-size: 13px;
}

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

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

label {
    display: block;
    font-weight: 700;
    margin-bottom: 6px;
}

.checkline {
    display: flex;
    align-items: center;
    gap: 9px;
    margin: 4px 0;
}

.checkline input {
    width: auto;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid #dac7f4;
    border-radius: var(--radius);
    padding: 11px 12px;
    font: inherit;
    background: #fff;
}

input:focus,
select:focus,
textarea:focus {
    outline: 0;
    border-color: #a855f7;
    box-shadow: 0 0 0 4px rgba(168,85,247,.12);
}

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

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 0;
    border-radius: var(--radius);
    background: linear-gradient(135deg, #a855f7, #7c3aed);
    color: #fff;
    padding: 10px 14px;
    font: inherit;
    font-weight: 800;
    cursor: pointer;
}

.btn:hover {
    background: linear-gradient(135deg, #9333ea, #6d28d9);
}

.btn.secondary {
    background: #eef2ff;
    color: #1d4ed8;
}

.btn.danger {
    background: var(--danger);
}

.btn.small {
    padding: 6px 9px;
    font-size: 13px;
}

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

.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 9px;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.badge.ok {
    color: #057647;
    background: #dcfae6;
}

.badge.warn {
    color: #92400e;
    background: #fef3c7;
}

.badge.danger {
    color: #b42318;
    background: #fee4e2;
}

.badge.info {
    color: #175cd3;
    background: #dbeafe;
}

.badge.muted {
    color: #475467;
    background: #f2f4f7;
}

.flash {
    padding: 12px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
    background: #dcfae6;
    color: #067647;
    font-weight: 700;
}

.dashboard-stats {
    margin-bottom: 22px;
}

.dashboard-panels .panel {
    min-height: 150px;
}

.integration-divider {
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px dashed #dac7f4;
}

.saved-chip {
    display: inline-flex;
    align-items: center;
    margin-right: 8px;
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 12px;
    color: #057647;
    background: #dcfae6;
}

.flash.error {
    background: #fee4e2;
    color: #b42318;
}

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
}

.login-card {
    width: min(440px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 28px;
}

.login-card h1 {
    margin: 0 0 6px;
}

.login-card p {
    color: var(--muted);
    margin-top: 0;
}

.ai-box {
    border-right: 4px solid var(--primary);
    background: #f8fbff;
    padding: 14px;
    border-radius: var(--radius);
    line-height: 1.9;
}

.messages {
    display: grid;
    gap: 12px;
}

.message {
    max-width: 76%;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 12px 14px;
    line-height: 1.8;
}

.message.in {
    background: #f8fafc;
    justify-self: start;
}

.message.out {
    background: #e8f1ff;
    border-color: #bfd7ff;
    justify-self: end;
}

.message-meta {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 5px;
}

.muted {
    color: var(--muted);
}

.print-page {
    background: #fff;
    direction: rtl;
}

.print-doc {
    width: min(920px, 100%);
    margin: 28px auto;
    padding: 28px;
    background: #fff;
}

.print-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    border-bottom: 2px solid var(--line);
    padding-bottom: 18px;
    margin-bottom: 18px;
}

.print-head h1 {
    margin: 0;
    font-size: 34px;
}

.print-company {
    display: grid;
    justify-items: end;
    gap: 5px;
}

.print-company img {
    max-width: 120px;
    max-height: 70px;
    object-fit: contain;
}

.print-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 18px;
}

.totals {
    width: min(360px, 100%);
    margin: 18px 0 18px auto;
    display: grid;
    gap: 8px;
    background: #f8fafc;
    border: 1px solid var(--line);
    padding: 14px;
    border-radius: var(--radius);
}

@media print {
    .no-print {
        display: none !important;
    }

    body,
    .print-page {
        background: #fff;
    }

    .print-doc {
        margin: 0;
        width: 100%;
        padding: 0;
    }
}

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

    .sidebar {
        height: auto;
        position: relative;
    }

    .grid.cols-4,
    .grid.cols-2,
    .form-row {
        grid-template-columns: 1fr;
    }
}
