/* ===== نظام الألوان والمتغيرات ===== */
:root {
    --ink: #1e2530;
    --muted: #6b7280;
    --muted-light: #9aa3b2;
    --bg: #f4f5f7;
    --surface: #ffffff;
    --border: #e5e7eb;

    --accent: #3a5a8f;
    --accent-dark: #2c4670;
    --accent-bg: #eaf0f9;

    --success: #2f9e63;
    --success-bg: #e9f9f1;
    --danger: #d0473f;
    --danger-bg: #fbeceb;
    --gray-btn: #6b7280;

    --sidebar-bg: #1b2436;
    --sidebar-text: #aab3c5;
    --sidebar-text-active: #ffffff;
    --sidebar-border: #29334a;

    --radius: 10px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 1px 3px rgba(16, 24, 40, 0.06);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Tahoma, Arial, sans-serif;
    direction: rtl;
    background: var(--bg);
    margin: 0;
    color: var(--ink);
    font-size: 14.5px;
    line-height: 1.6;
}

h1, h2, h3 { font-weight: 600; letter-spacing: -0.01em; }
a { color: var(--accent); }

/* ===== تخطيط التطبيق: قائمة جانبية + محتوى ===== */
.app-shell {
    display: flex;
    min-height: 100vh;
    align-items: stretch;
}

.sidebar {
    width: 230px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    padding: 22px 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar .brand {
    color: #fff;
    font-size: 16px;
    font-weight: 700;
    padding: 0 10px 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar .brand small {
    display: block;
    font-weight: 400;
    font-size: 11px;
    color: var(--sidebar-text);
    margin-top: 2px;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; }

.sidebar a {
    color: var(--sidebar-text);
    text-decoration: none;
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 14px;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background .15s, color .15s;
}

.sidebar a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar a.active { background: var(--accent); color: #fff; }

.sidebar .sidebar-footer {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--sidebar-border);
    font-size: 12px;
    color: var(--muted-light);
}

.main-content { flex: 1; min-width: 0; padding: 26px 32px; }

.page-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 22px;
}

.page-head h2 { margin: 0; font-size: 20px; }
.page-head .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ===== الحاويات القديمة (مستخدمة بصفحات الطباعة/الدخول) ===== */
.container { padding: 20px; }
.container.narrow { max-width: 700px; margin: auto; }

/* ===== البطاقات ===== */
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.card {
    background: var(--surface);
    padding: 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    margin-bottom: 16px;
}

.card h3 { margin: 0; font-size: 13px; color: var(--muted); font-weight: 500; }
.card p { margin: 8px 0 0; font-size: 22px; font-weight: 700; color: var(--ink); }
.card .trend { font-size: 12px; margin-top: 4px; color: var(--muted-light); }

.chart-card { padding: 20px; }
.chart-card h3 { font-size: 14px; color: var(--ink); font-weight: 600; margin: 0 0 14px; }

/* ===== الفلاتر ===== */
.filter { background: var(--surface); padding: 16px; border-radius: var(--radius); border: 1px solid var(--border); margin-bottom: 20px; box-shadow: var(--shadow); }
.filter form { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.filter label { font-size: 13px; color: var(--muted); }

/* ===== الحقول ===== */
input, select {
    padding: 9px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    font-family: inherit;
    font-size: 14px;
    background: #fff;
    color: var(--ink);
}

input:focus, select:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }

.card input, .card select { width: 100%; margin-top: 6px; padding: 10px 12px; border-radius: 8px; }
label { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ===== الأزرار ===== */
button, .btn {
    padding: 9px 14px;
    border: none;
    background: var(--accent);
    color: #fff;
    border-radius: 8px;
    cursor: pointer;
    font-family: inherit;
    font-size: 13.5px;
    font-weight: 500;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: background .15s, opacity .15s;
}

button:hover, .btn:hover { background: var(--accent-dark); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.actions a.btn:last-child { background: var(--success); }
.actions a.btn:last-child:hover { background: #24824f; }

table .btn { padding: 6px 10px; font-size: 12.5px; }

.blue { background: var(--accent); }
.blue:hover { background: var(--accent-dark); }
.green { background: var(--success); }
.green:hover { background: #24824f; }
.gray { background: var(--gray-btn); }
.gray:hover { background: #565f6c; }
.red { background: var(--danger); }
.red:hover { background: #b23a33; }

/* ===== الجداول ===== */
.table-wrap { background: var(--surface); border-radius: var(--radius); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; }
table { width: 100%; border-collapse: collapse; }
th {
    background: #fafbfc;
    padding: 12px 10px;
    text-align: center;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .03em;
    border-bottom: 1px solid var(--border);
}
td { padding: 12px 10px; text-align: center; border-bottom: 1px solid var(--border); vertical-align: middle; font-size: 14px; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #fafbfc; }

.paid { color: var(--success); font-weight: 600; }
.unpaid { color: var(--danger); font-weight: 600; }
.badge { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.badge.paid { background: var(--success-bg); color: var(--success); }
.badge.unpaid { background: var(--danger-bg); color: var(--danger); }

.inline-form { display: inline; }

/* ===== نموذج الفاتورة ===== */
.row { display: flex; gap: 10px; }
.item { position: relative; }
.remove {
    position: absolute; left: 10px; top: 10px;
    background: var(--danger); color: #fff; border: none;
    border-radius: 50%; width: 26px; height: 26px; padding: 0; cursor: pointer;
}

.add { background: #eef0f3; color: var(--ink); width: 100%; padding: 12px; justify-content: center; }
.add:hover { background: #e2e5ea; }
.save { background: var(--accent); color: #fff; width: 100%; margin-top: 10px; padding: 12px; justify-content: center; font-size: 15px; }

.total { background: var(--accent-bg); padding: 15px; border-radius: 8px; text-align: center; font-size: 18px; }
.total-lines { background: #fafbfc; border: 1px solid var(--border); padding: 15px 18px; border-radius: var(--radius); font-size: 14.5px; }
.total-lines div { display: flex; justify-content: space-between; padding: 4px 0; }
.total-lines .grand { font-weight: 700; font-size: 17px; color: var(--ink); border-top: 1px solid var(--border); margin-top: 8px; padding-top: 10px; }

/* ===== الترقيم ===== */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 18px; flex-wrap: wrap; }
.pagination a, .pagination span {
    padding: 7px 13px; border-radius: 8px; text-decoration: none; color: var(--accent);
    border: 1px solid var(--border); font-size: 13px; background: #fff;
}
.pagination a:hover { background: var(--accent-bg); }
.pagination .current { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ===== التنبيهات ===== */
.alert { padding: 11px 15px; border-radius: 8px; margin-bottom: 15px; font-size: 14px; }
.alert-error { background: var(--danger-bg); color: #9a3630; border: 1px solid #f2c9c6; }
.alert-success { background: var(--success-bg); color: #1f7a4d; border: 1px solid #bfe9d1; }

/* ===== صفحات الدخول ===== */
.login-wrap { max-width: 380px; margin: 90px auto; padding: 0 16px; }
.login-wrap .card { text-align: center; padding: 30px 26px; }
.login-wrap h2 { margin-top: 0; }
.login-wrap input { margin-top: 10px; }
.login-wrap button { width: 100%; margin-top: 12px; justify-content: center; }

/* ===== شعار الشركة ===== */
.logo-preview { max-width: 180px; max-height: 90px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff; }
.settings-section { max-width: 520px; }

/* ===== بطاقة معلومات النشاط التجاري ===== */
.biz-card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.biz-icon {
    width: 42px; height: 42px; border-radius: 10px;
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; flex-shrink: 0;
    box-shadow: 0 2px 6px rgba(58, 90, 143, .35);
}

.invoice-preview {
    position: relative;
    margin-top: 18px;
    padding: 18px 20px;
    border-radius: 10px;
    background: repeating-linear-gradient(135deg, #fafbfd, #fafbfd 10px, #f5f7fa 10px, #f5f7fa 20px);
    border: 1.5px dashed #c7cedb;
    transition: border-color .2s, background .2s;
}
.invoice-preview:focus-within,
#bizForm:has(input:focus) .invoice-preview { border-color: var(--accent); }

.preview-badge {
    position: absolute;
    top: -11px;
    right: 14px;
    background: var(--accent);
    color: #fff;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 999px;
    letter-spacing: .02em;
}

.preview-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--ink);
    word-break: break-word;
    transition: opacity .15s;
}
.preview-sub { font-size: 12.5px; color: var(--muted); margin-top: 4px; }

.save-btn {
    margin-top: 16px;
    position: relative;
    overflow: hidden;
    transition: background .2s, transform .1s;
}
.save-btn:active { transform: scale(.97); }
.save-btn .save-icon {
    display: inline-block;
    transition: transform .3s ease;
}
.save-btn.just-saved {
    animation: save-pulse .5s ease;
}
.save-btn.just-saved .save-icon {
    animation: check-pop .5s ease;
}
@keyframes save-pulse {
    0%   { box-shadow: 0 0 0 0 rgba(47, 158, 99, .45); }
    100% { box-shadow: 0 0 0 14px rgba(47, 158, 99, 0); }
}
@keyframes check-pop {
    0%   { transform: scale(1); }
    40%  { transform: scale(1.5) rotate(-10deg); }
    100% { transform: scale(1); }
}

/* ===== طباعة ===== */
@media print {
    .header, .no-print, .sidebar { display: none; }
}

/* ===== استجابة للشاشات الصغيرة ===== */
@media (max-width: 860px) {
    .app-shell { flex-direction: column; }
    .sidebar { width: 100%; flex-direction: row; align-items: center; padding: 10px 14px; overflow-x: auto; }
    .sidebar .brand { padding: 0 10px 0 0; flex-shrink: 0; }
    .sidebar nav { flex-direction: row; }
    .sidebar .sidebar-footer { display: none; }
    .main-content { padding: 18px; }
}
