:root {
    --bg: #f4f6f9;
    --sidebar: #1b2a41;
    --sidebar-hover: #263b5a;
    --accent: #2563eb;
    --accent-dark: #1d4ed8;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #e3e8ef;
    --card: #ffffff;
    --pos: #16a34a;
    --neg: #dc2626;
    --warn: #d97706;
    --danger: #dc2626;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--sidebar);
    color: #cbd5e1;
    flex-shrink: 0;
    padding-bottom: 20px;
}
.brand { padding: 20px 18px; border-bottom: 1px solid rgba(255,255,255,.08); }
.brand-name { color: #fff; font-size: 18px; font-weight: 700; }
.brand-sub { color: #93a4bd; font-size: 12px; margin-top: 4px; }
.sidebar nav { padding: 10px 0; }
.nav-group {
    padding: 12px 18px 6px;
    font-size: 11px;
    color: #7c8ba5;
    text-transform: uppercase;
    letter-spacing: .5px;
}
.nav-link {
    display: block;
    padding: 10px 18px;
    color: #cbd5e1;
    border-right: 3px solid transparent;
}
.nav-link:hover { background: var(--sidebar-hover); color: #fff; text-decoration: none; }
.nav-link.active { background: var(--sidebar-hover); color: #fff; border-right-color: var(--accent); }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 22px;
    height: 60px;
    display: flex;
    align-items: center;
    gap: 14px;
}
.topbar h2 { margin: 0; font-size: 18px; flex: 1; }
.topbar-user { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.role-badge {
    background: #eef2ff;
    color: var(--accent-dark);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
}
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; }

.content { padding: 22px; flex: 1; }
.footer { padding: 14px 22px; color: var(--muted); font-size: 12px; border-top: 1px solid var(--border); }

.panel {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 18px;
    margin-bottom: 18px;
}
.panel h3 { margin: 0 0 14px; font-size: 15px; }

.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
    gap: 14px;
    margin-bottom: 18px;
}
.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
}
.stat-label { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.stat-value { font-size: 20px; font-weight: 700; }
.stat-value small { font-size: 12px; color: var(--muted); font-weight: 400; }

.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { padding: 9px 10px; border-bottom: 1px solid var(--border); text-align: right; }
.table thead th { background: #f8fafc; color: var(--muted); font-weight: 600; white-space: nowrap; }
.table tbody tr:hover { background: #f9fbfd; }
.table tfoot th { background: #f8fafc; }
.mono { font-family: Consolas, monospace; font-size: 12px; direction: ltr; text-align: right; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; background: #e5e7eb; color: #4b5563; }
.tag-on { background: #dcfce7; color: #15803d; }
.tag-warn { background: #fef3c7; color: #b45309; }

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }
.center { text-align: center; }
.sum-row { margin: 10px 0; font-size: 14px; }

.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    cursor: pointer;
    font-size: 13px;
    font-family: inherit;
}
.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { opacity: .9; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; }

.actions { white-space: nowrap; }
.inline { display: inline-block; }
form.inline select, form.inline input { padding: 4px 6px; font-size: 12px; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid label, .filters label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: #374151; }
.form-grid .check { flex-direction: row; align-items: center; gap: 7px; }
.form-actions { grid-column: span 2; display: flex; gap: 10px; }
@media (max-width: 700px) { .form-grid { grid-template-columns: 1fr; } .form-grid .span-2, .form-actions { grid-column: span 1; } }

input, select, textarea {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-family: inherit;
    font-size: 13px;
    background: #fff;
    color: var(--text);
    width: 100%;
}
input:focus, select:focus { outline: none; border-color: var(--accent); }

.filters { display: flex; gap: 12px; align-items: flex-end; margin-bottom: 14px; flex-wrap: wrap; }
.filters label { min-width: 150px; }
.form-inline { display: flex; gap: 10px; align-items: center; margin-top: 10px; flex-wrap: wrap; }
.form-inline input { max-width: 240px; }

.card-picker { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; }
.picker-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; gap: 10px; }
#cardSel { min-height: 120px; }

.ledger-head { display: flex; justify-content: space-between; align-items: center; gap: 16px; flex-wrap: wrap; }
.ledger-head h3 { margin: 0 0 6px; }
.ledger-balance { text-align: center; }
.ledger-balance span { display: block; color: var(--muted); font-size: 12px; }
.ledger-balance strong { font-size: 22px; }

.alert { padding: 11px 14px; border-radius: 8px; margin-bottom: 14px; font-size: 13px; }
.alert-success { background: #dcfce7; color: #15803d; }
.alert-error { background: #fee2e2; color: #b91c1c; }
.alert-warn { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }
tr.row-warn td { background: #fffbeb; }

.pager { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1b2a41, #2563eb);
}
.login-card {
    background: #fff;
    padding: 34px 30px;
    border-radius: 14px;
    width: 340px;
    box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { margin: 0 0 4px; font-size: 22px; text-align: center; }
.login-card .muted { text-align: center; margin: 0 0 22px; }
.login-card label { display: block; margin-bottom: 14px; font-size: 13px; }
.login-card input { margin-top: 6px; }

.print-header { display: none; }

@media print {
    .sidebar, .topbar, .footer, .no-print, .filters { display: none !important; }
    .content { padding: 0; }
    .print-header { display: block; margin-bottom: 16px; }
    .panel { border: none; }
}

@media (max-width: 900px) {
    .sidebar {
        position: fixed;
        top: 0; right: -260px;
        height: 100%;
        z-index: 50;
        transition: right .2s;
    }
    .sidebar.open { right: 0; }
    .menu-toggle { display: block; }
}

.add-inv-bar { display: flex; justify-content: flex-end; margin-bottom: 14px; }
.add-inv-bar .btn { font-size: 15px; padding: 10px 20px; }
.modal-overlay {
    position: fixed; inset: 0; z-index: 100;
    background: rgba(15, 23, 42, .55);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
    background: #fff; border-radius: 14px; width: 100%; max-width: 640px;
    max-height: 92vh; display: flex; flex-direction: column;
    box-shadow: 0 24px 60px rgba(0,0,0,.35); overflow: hidden;
}
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-close { background: none; border: 0; font-size: 24px; line-height: 1; cursor: pointer; color: var(--muted); }
.modal-body { overflow-y: auto; padding: 0; }
.modal-body .inv-view { padding: 18px 20px 22px; }
.modal-options { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-options .option {
    display: block; width: 100%; text-align: right; padding: 14px 16px; border: 1px solid var(--border); border-radius: 10px;
    text-decoration: none; color: inherit; background: #fff; cursor: pointer; font: inherit;
    transition: border-color .15s, background .15s;
}
.modal-options .option:hover { border-color: #2563eb; background: #f1f5ff; }
.modal-options .option b { display: block; font-size: 15px; margin-bottom: 4px; }
.modal-options .option span { font-size: 12px; color: var(--muted); }
.modal-body .card-picker { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; }
.modal-body .sum-row { text-align: left; }
@media (max-width: 520px) { .modal-options { grid-template-columns: 1fr; } }

/* ===== نظام الكهرباء ===== */
.row-credit td { background: #f0fdf4; }
.amount-box { font-weight: 700; color: #1d4ed8; background: #f8fafc; }
.print-header h2 { margin: 0 0 4px; }
.print-header hr { border: none; border-top: 1px solid #cbd5e1; margin: 10px 0 16px; }
.ledger-balance strong.neg, .ledger-balance strong.pos { font-size: 24px; }
@media print {
    body { background: #fff; }
    .cards-grid { grid-template-columns: repeat(3, 1fr); }
    .stat { border: 1px solid #ddd; }
    .table th, .table td { padding: 6px 8px; }
}

/* ===== إدارة الشركات (المنصة) ===== */
.company-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    background: #eef2ff;
    color: #3730a3;
    font-size: 12px;
    font-weight: 600;
}

/* ===== فاتورة الاشتراك (قابلة للطباعة) ===== */
.invoice-wrap { max-width: 900px; margin: 0 auto; padding: 24px 18px 40px; }
.invoice-toolbar { display: flex; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.invoice-doc {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 30px;
    box-shadow: 0 8px 30px rgba(15, 23, 42, .06);
}
.invoice-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; flex-wrap: wrap; border-bottom: 2px solid var(--border); padding-bottom: 16px; margin-bottom: 18px; }
.invoice-head h1 { margin: 0 0 4px; font-size: 22px; }
.invoice-title { text-align: left; }
.invoice-title h2 { margin: 0 0 4px; font-size: 18px; color: #1d4ed8; }
.invoice-meta { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; margin-bottom: 20px; }
.invoice-box { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 13px; line-height: 1.7; }
.invoice-box .box-label { color: var(--muted); font-size: 11px; margin-bottom: 4px; }
.invoice-box .box-name { font-weight: 700; font-size: 15px; margin-bottom: 2px; }
.table-plain th, .table-plain td { border-bottom: 1px dashed var(--border); }
.table-plain th { background: transparent; width: 45%; }
.invoice-items { margin-bottom: 18px; }
.invoice-total th { font-size: 15px; }
.invoice-foot { margin-top: 26px; border-top: 1px solid var(--border); padding-top: 16px; }
.signature { display: flex; justify-content: space-between; gap: 20px; margin-top: 30px; font-size: 13px; flex-wrap: wrap; }
@media (max-width: 700px) {
    .invoice-meta { grid-template-columns: 1fr; }
    .invoice-doc { padding: 20px 16px; }
    .invoice-title { text-align: right; }
}
@media print {
    .invoice-wrap { max-width: none; padding: 0; }
    .invoice-doc { border: none; box-shadow: none; padding: 0; }
}

/* ===== تسجيل الدخول باسم المستخدم فقط ===== */
.login-card .login-hint {
    margin: 14px 0 0;
    font-size: 12px;
    line-height: 1.6;
    text-align: center;
}
