:root {
    --bg: #f5f7fb;
    --panel: #ffffff;
    --ink: #172033;
    --muted: #667085;
    --line: #e4e7ec;
    --primary: #155eef;
    --success: #079455;
    --danger: #d92d20;
    --warning: #dc6803;
    --shadow: 0 14px 40px rgba(16, 24, 40, .08);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
    margin: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--ink);
    background: var(--bg);
}
a { color: inherit; text-decoration: none; }
.app-shell { display: grid; grid-template-columns: 260px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
    background: #101828;
    color: white;
    padding: 22px;
    overflow: hidden;
}
.brand { display: flex; gap: 12px; align-items: center; margin-bottom: 28px; max-width: 100%; }
.brand-mark {
    width: 46px; height: 46px; border-radius: 8px;
    display: grid; place-items: center;
    background: linear-gradient(135deg, #155eef, #12b76a);
    font-weight: 800;
}
.brand-logo {
    width: 54px;
    height: 54px;
    min-width: 54px;
    max-width: 54px;
    border-radius: 8px;
    object-fit: cover;
    background: white;
    display: block;
}
.brand-logo.large {
    width: 76px;
    height: 76px;
    min-width: 76px;
    max-width: 76px;
}
.brand span { display: block; color: #98a2b3; font-size: 13px; margin-top: 4px; }
nav { display: grid; gap: 6px; }
nav a {
    padding: 12px 14px;
    border-radius: 8px;
    color: #d0d5dd;
}
nav a:hover { background: #1d2939; color: white; }
.content { padding: 26px; overflow-x: auto; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
}
h1 { margin: 0; font-size: 28px; }
.eyebrow { margin: 0 0 6px; color: var(--muted); font-size: 13px; }
.user-pill {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 10px 14px;
    box-shadow: var(--shadow);
}
.grid { display: grid; gap: 16px; }
.stats { grid-template-columns: repeat(4, minmax(160px, 1fr)); }
.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
    box-shadow: var(--shadow);
}
.stat-label { color: var(--muted); font-size: 13px; margin-bottom: 10px; }
.stat-value { font-size: 24px; font-weight: 800; }
.toolbar { display: flex; gap: 10px; justify-content: space-between; align-items: center; margin: 14px 0; flex-wrap: wrap; }
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 10px 14px;
    cursor: pointer;
    background: var(--primary);
    color: white;
    font-weight: 700;
}
.btn.secondary { background: #344054; }
.btn.light { background: #eef4ff; color: #155eef; }
.btn.danger { background: var(--danger); }
.btn.small { min-height: 32px; padding: 7px 10px; font-size: 12px; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.low-stock { background: #fff6ed; }
.print-header { display: none; }
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
}
table { min-width: 760px; }
th, td { padding: 13px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; background: #f9fafb; }
tr:last-child td { border-bottom: 0; }
.badge { display: inline-flex; padding: 5px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.paid { background: #dcfae6; color: #067647; }
.debt { background: #fef0c7; color: #b54708; }
.overdue { background: #fee4e2; color: #b42318; }
.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 14px; }
label { display: grid; gap: 7px; color: var(--muted); font-size: 13px; font-weight: 700; }
input, select, textarea {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    min-height: 42px;
    padding: 10px 12px;
    font: inherit;
    color: var(--ink);
    background: white;
    font-size: 16px;
}
textarea { min-height: 90px; resize: vertical; }
.full { grid-column: 1 / -1; }
.alert {
    border-radius: 8px;
    padding: 12px 14px;
    margin-bottom: 16px;
    background: #eef4ff;
    color: #1849a9;
}
.alert.error { background: #fee4e2; color: #b42318; }
.login-screen {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #101828, #1849a9);
}
.login-card { width: min(430px, 100%); }
.muted { color: var(--muted); }
.amount-positive { color: var(--success); font-weight: 800; }
.amount-danger { color: var(--danger); font-weight: 800; }
@media print {
    .sidebar, .topbar, .btn, .actions { display: none !important; }
    .app-shell { display: block; }
    .content { padding: 0; }
    .card, table { box-shadow: none; border-color: #111; }
    .print-header { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
    .print-header img { width: 72px; height: 72px; border-radius: 8px; }
}
html[dir="rtl"] body { font-family: Tahoma, Arial, Helvetica, sans-serif; }
html[dir="rtl"] th,
html[dir="rtl"] td { text-align: right; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.lang-switch {
    display: flex;
    gap: 4px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 4px;
    box-shadow: var(--shadow);
}
.lang-switch a {
    min-width: 38px;
    padding: 7px 9px;
    border-radius: 999px;
    text-align: center;
    color: var(--muted);
    font-weight: 800;
    font-size: 12px;
}
.lang-switch a:hover { background: #eef4ff; color: var(--primary); }

@media (max-width: 900px) {
    body { background: #f8fafc; }
    .app-shell {
        display: block;
        min-height: 100vh;
    }
    .sidebar {
        position: sticky;
        top: 0;
        z-index: 20;
        padding: 12px;
        border-bottom: 1px solid rgba(255,255,255,.08);
    }
    .brand {
        margin-bottom: 10px;
        gap: 10px;
    }
    .brand-logo {
        width: 44px !important;
        height: 44px !important;
        min-width: 44px;
        max-width: 44px !important;
    }
    .brand strong { font-size: 15px; }
    .brand span { font-size: 11px; line-height: 1.35; }
    nav {
        display: flex;
        gap: 8px;
        overflow-x: auto;
        padding: 2px 0 4px;
        scrollbar-width: none;
    }
    nav::-webkit-scrollbar { display: none; }
    nav a {
        white-space: nowrap;
        flex: 0 0 auto;
        padding: 9px 12px;
        border-radius: 999px;
        background: #1d2939;
        color: #f2f4f7;
        font-size: 13px;
    }
    .content {
        padding: 14px;
        overflow-x: hidden;
    }
    .topbar {
        align-items: flex-start;
        flex-direction: column;
        margin-bottom: 14px;
        gap: 12px;
    }
    h1 { font-size: 22px; }
    .eyebrow { font-size: 12px; }
    .top-actions {
        width: 100%;
        justify-content: space-between;
    }
    .user-pill {
        padding: 8px 12px;
        font-size: 13px;
    }
    .lang-switch {
        box-shadow: none;
        max-width: 160px;
    }
    .lang-switch a {
        min-width: 34px;
        padding: 7px 8px;
    }
    .stats {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }
    .card {
        padding: 14px;
        border-radius: 8px;
        box-shadow: 0 8px 24px rgba(16,24,40,.06);
    }
    .stat-label { font-size: 12px; }
    .stat-value { font-size: 19px; }
    .form-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }
    .toolbar {
        align-items: stretch;
        gap: 8px;
    }
    .toolbar h2 {
        width: 100%;
        margin: 6px 0;
        font-size: 18px;
    }
    .toolbar form,
    .toolbar input,
    .toolbar .btn {
        width: 100%;
    }
    .btn {
        min-height: 44px;
        padding: 11px 14px;
        border-radius: 8px;
    }
    .btn.small {
        min-height: 38px;
        padding: 8px 10px;
    }
    .actions {
        min-width: 150px;
    }
    table {
        min-width: 720px;
        font-size: 13px;
    }
    th, td {
        padding: 10px;
    }
    .content > table,
    .card table,
    .toolbar + table {
        display: block;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        border-radius: 8px;
    }
    .card table tbody,
    .card table thead,
    .content > table tbody,
    .content > table thead,
    .toolbar + table tbody,
    .toolbar + table thead {
        display: table;
        width: 100%;
    }
    .login-screen {
        padding: 14px;
        align-items: start;
        padding-top: 8vh;
    }
    .login-card {
        width: 100%;
        padding: 16px;
    }
}

@media (max-width: 420px) {
    .stats { grid-template-columns: 1fr; }
    .content { padding: 10px; }
    .card { padding: 12px; }
}
