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

:root {
    --primary:    #1a3a5c;
    --primary-lt: #2563a8;
    --accent:     #e8a020;
    --success:    #16a34a;
    --warning:    #d97706;
    --danger:     #dc2626;
    --info:       #0891b2;
    --teal:       #0d9488;
    --bg:         #f0f4f8;
    --card-bg:    #ffffff;
    --border:     #d1dbe8;
    --text:       #1e293b;
    --muted:      #64748b;
    --shadow:     0 2px 16px rgba(26,58,92,0.09);
    --shadow-md:  0 8px 32px rgba(26,58,92,0.14);
    --radius:     14px;
    --sidebar-w:  240px;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body.tas-portal {
    font-family: 'Tajawal', sans-serif;
    background: var(--bg);
    color: var(--text);
    direction: rtl;
    min-height: 100vh;
    display: flex;
}

/* ─── Sidebar ─── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--primary);
    min-height: 100vh;
    position: fixed;
    right: 0; top: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
    transition: transform 0.3s ease;
}
.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}
.brand-icon {
    width: 40px; height: 40px;
    background: var(--accent);
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px;
    color: var(--primary);
    flex-shrink: 0;
}
.brand-text strong { display: block; font-size: 14px; font-weight: 700; color: #fff; line-height: 1.2; }
.brand-text small  { font-size: 11px; color: rgba(255,255,255,0.5); }

.sidebar-nav { flex: 1; padding: 12px 10px; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 14px;
    border-radius: 10px;
    color: rgba(255,255,255,0.65);
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    margin-bottom: 4px;
    transition: all 0.2s;
}
.nav-item:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-item.active { background: var(--accent); color: var(--primary); font-weight: 700; }
.nav-icon { font-size: 18px; width: 24px; text-align: center; }

.sidebar-footer {
    padding: 16px 14px;
    border-top: 1px solid rgba(255,255,255,0.1);
}
.user-info { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.user-avatar {
    width: 36px; height: 36px;
    background: var(--accent);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 14px; font-weight: 700;
    color: var(--primary);
    flex-shrink: 0;
}
.user-meta strong { display: block; font-size: 13px; color: #fff; font-weight: 600; }
.user-meta small  { font-size: 11px; color: rgba(255,255,255,0.45); }
.btn-logout {
    width: 100%;
    padding: 8px;
    background: rgba(255,255,255,0.07);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: 8px;
    color: rgba(255,255,255,0.6);
    font-family: 'Tajawal', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}
.btn-logout:hover { background: rgba(255,255,255,0.12); color: #fff; }

/* ─── Main Content ─── */
.main-content {
    margin-right: var(--sidebar-w);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ─── Topbar ─── */
.topbar {
    background: var(--card-bg);
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border);
    position: sticky; top: 0; z-index: 50;
}
.topbar-toggle { display: none; background: none; border: none; font-size: 22px; cursor: pointer; color: var(--primary); }
.topbar-title { font-family: 'Cairo', sans-serif; font-size: 17px; font-weight: 700; color: var(--primary); }
.topbar-right { display: flex; align-items: center; gap: 8px; }
.badge-branch {
    background: #e6f1fb; color: var(--primary-lt);
    font-size: 12px; padding: 4px 12px;
    border-radius: 20px; font-weight: 600;
}
.badge-role {
    background: #fef3e2; color: #92400e;
    font-size: 12px; padding: 4px 12px;
    border-radius: 20px; font-weight: 600;
}

/* ─── Page Body ─── */
.page-body { padding: 24px; flex: 1; }
.page-header { margin-bottom: 20px; }
.page-title { font-family: 'Cairo', sans-serif; font-size: 22px; font-weight: 700; color: var(--primary); }

/* ─── Flash ─── */
.portal-flash {
    padding: 12px 18px; border-radius: 10px;
    font-size: 14px; font-weight: 600;
    margin-bottom: 16px; display: none;
}
.portal-flash--success { background: #eaf3de; color: #166534; border: 1px solid #bbf7d0; }
.portal-flash--error   { background: #fcebeb; color: #991b1b; border: 1px solid #fecaca; }

/* ─── Stats ─── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 18px 16px;
    display: flex; align-items: center; gap: 14px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.stat-icon {
    width: 46px; height: 46px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px; flex-shrink: 0;
}
.stat-card--blue   .stat-icon { background: #e6f1fb; }
.stat-card--green  .stat-icon { background: #eaf3de; }
.stat-card--orange .stat-icon { background: #faeeda; }
.stat-card--red    .stat-icon { background: #fcebeb; }
.stat-card--teal   .stat-icon { background: #e1f5ee; }
.stat-card--gold   .stat-icon { background: #faeeda; }
.stat-val { font-size: 20px; font-weight: 700; color: var(--text); line-height: 1.2; }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 3px; }

/* ─── Quick Actions ─── */
.quick-actions { margin-bottom: 22px; }
.actions-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.action-btn {
    display: flex; align-items: center; gap: 8px;
    padding: 11px 20px;
    border-radius: 10px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px; font-weight: 700;
    text-decoration: none; border: none; cursor: pointer;
    transition: all 0.2s;
}
.action-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.action-btn--primary { background: var(--primary); color: #fff; }
.action-btn--orange  { background: var(--accent);  color: var(--primary); }
.action-btn--teal    { background: var(--teal);    color: #fff; }
.action-btn--green   { background: var(--success); color: #fff; }

/* ─── Section Card ─── */
.section-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 20px;
    overflow: hidden;
}
.section-head {
    padding: 16px 20px 12px;
    display: flex; align-items: center; justify-content: space-between;
    border-bottom: 1px solid var(--border);
}
.section-title { font-size: 15px; font-weight: 700; color: var(--primary); }
.link-more { font-size: 13px; color: var(--primary-lt); text-decoration: none; }
.link-more:hover { text-decoration: underline; }

/* ─── Tables ─── */
.table-wrap { overflow-x: auto; }
.portal-table {
    width: 100%; border-collapse: collapse;
    font-size: 13px;
}
.portal-table th {
    background: #f8fafc;
    padding: 10px 14px;
    text-align: right;
    color: var(--muted);
    font-weight: 600;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.portal-table td {
    padding: 11px 14px;
    border-bottom: 1px solid #f1f5f9;
    color: var(--text);
}
.portal-table tr:last-child td { border-bottom: none; }
.portal-table tr:hover td { background: #fafbfc; }
.text-warn { color: var(--warning); font-weight: 600; }
.text-ok   { color: var(--success); font-weight: 600; }

/* ─── Badges ─── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 11px; font-weight: 700;
}
.badge-paid    { background: #eaf3de; color: #166534; }
.badge-partial { background: #faeeda; color: #92400e; }
.badge-unpaid  { background: #fcebeb; color: #991b1b; }
.badge-draft   { background: #f1f5f9; color: #64748b; }

/* ─── Buttons ─── */
.btn-primary {
    background: var(--primary); color: #fff;
    border: none; border-radius: 10px;
    padding: 10px 20px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px; font-weight: 700;
    cursor: pointer; text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
    transition: all 0.2s;
}
.btn-primary:hover { background: var(--primary-lt); }
.btn-secondary {
    background: var(--bg); color: var(--text);
    border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 20px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px; font-weight: 600;
    cursor: pointer; text-decoration: none;
    display: inline-flex; align-items: center; gap: 6px;
    transition: all 0.2s;
}
.btn-secondary:hover { background: var(--border); }
.btn-sm {
    background: #e6f1fb; color: var(--primary-lt);
    border: none; border-radius: 7px;
    padding: 5px 12px;
    font-family: 'Tajawal', sans-serif;
    font-size: 12px; font-weight: 600;
    cursor: pointer; text-decoration: none;
    transition: all 0.2s;
}
.btn-sm:hover { background: var(--primary-lt); color: #fff; }
.btn-full { width: 100%; justify-content: center; }

/* ─── Forms ─── */
.form-page-layout {
    display: grid;
    grid-template-columns: 1fr 280px;
    gap: 20px;
    align-items: start;
}
.form-page-layout > div:first-child {
    min-width: 0;
    overflow: visible;
}
.items-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}
.items-tbl {
    min-width: 900px;
}
.items-tbl td input, .items-tbl td {
    min-width: 0;
}
.form-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    margin-bottom: 16px;
    overflow: visible;
}
.form-card-title {
    font-size: 15px; font-weight: 700;
    color: var(--primary);
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 1px solid var(--border);
}
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}
.fg { display: flex; flex-direction: column; gap: 5px; }
.fg label { font-size: 13px; font-weight: 600; color: var(--muted); }
.req { color: var(--danger); }
.fi {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: 9px;
    font-family: 'Tajawal', sans-serif;
    font-size: 14px; color: var(--text);
    background: #fff;
    transition: border-color 0.2s;
    outline: none;
    width: 100%;
}
.fi:focus { border-color: var(--primary-lt); box-shadow: 0 0 0 3px rgba(37,99,168,0.1); }
.fi-sm { width: 90px; text-align: center; }

/* ─── Invoice Items Table ─── */
.items-table-wrap { overflow-x: auto; margin-bottom: 12px; }
.items-tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
.items-tbl th {
    background: var(--primary);
    color: #fff; padding: 9px 10px;
    text-align: right; font-weight: 600;
}
.items-tbl td { padding: 7px 8px; border-bottom: 1px solid #f1f5f9; }
.items-tbl tr:last-child td { border-bottom: none; }
.item-total { font-weight: 700; color: var(--primary); }
.btn-add-row {
    background: #e6f1fb; color: var(--primary-lt);
    border: none; border-radius: 8px;
    padding: 8px 16px;
    font-family: 'Tajawal', sans-serif;
    font-size: 13px; font-weight: 600;
    cursor: pointer;
}
.btn-remove {
    background: #fcebeb; color: var(--danger);
    border: none; border-radius: 6px;
    width: 26px; height: 26px;
    font-size: 13px; cursor: pointer;
    display: flex; align-items: center; justify-content: center;
}

/* ─── Summary Card ─── */
.summary-card { position: sticky; top: 76px; }
.summary-row {
    display: flex; justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    font-size: 13px;
    border-bottom: 1px solid #f1f5f9;
}
.summary-row:last-child { border-bottom: none; }
.summary-total { font-size: 16px; font-weight: 700; color: var(--primary); padding: 12px 0; }
.summary-rem   { font-size: 15px; font-weight: 700; color: var(--warning); }

/* ─── Invoice Document ─── */
.inv-doc {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border);
    overflow: hidden;
    max-width: 800px;
    margin: 0 auto;
}
.inv-doc-header {
    background: var(--primary);
    padding: 24px 28px;
    display: flex; justify-content: space-between; align-items: flex-start;
}
.inv-doc-agency h2 {
    font-family: 'Cairo', sans-serif;
    font-size: 18px; font-weight: 700;
    color: #fff; margin-bottom: 4px;
}
.inv-doc-agency p { font-size: 12px; color: rgba(255,255,255,0.6); line-height: 1.6; }
.inv-number-box { text-align: left; }
.inv-number-box small { display: block; font-size: 11px; color: rgba(255,255,255,0.5); }
.inv-number-box strong {
    font-family: 'Cairo', sans-serif;
    font-size: 22px; font-weight: 700;
    color: var(--accent);
    display: block;
}
.inv-date-box { font-size: 12px; color: rgba(255,255,255,0.6); margin-top: 4px; }
.inv-status-badge {
    display: inline-block; margin-top: 8px;
    padding: 4px 14px; border-radius: 20px;
    font-size: 12px; font-weight: 700;
}
.inv-status-badge.paid    { background: #eaf3de; color: #166534; }
.inv-status-badge.partial { background: #faeeda; color: #92400e; }

.inv-client-box {
    margin: 20px 28px;
    background: #f8fafc;
    border-radius: 10px;
    padding: 16px;
}
.inv-client-box h4 { font-size: 13px; font-weight: 700; color: var(--primary); margin-bottom: 10px; }
.inv-client-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}
.inv-client-grid span { font-size: 13px; color: var(--text); }
.inv-client-grid span b { color: var(--primary); }

.inv-items-table { width: 100%; border-collapse: collapse; margin: 0 0 20px; }
.inv-items-table th {
    background: var(--primary); color: #fff;
    padding: 10px 14px; text-align: right;
    font-size: 13px; font-weight: 600;
}
.inv-items-table td {
    padding: 10px 14px;
    border-bottom: 1px solid #f1f5f9;
    font-size: 13px;
}
.inv-items-table tr:last-child td { border-bottom: none; }

.inv-totals-box { margin: 0 28px 20px; }
.inv-totals-box table { width: 280px; margin-right: auto; font-size: 13px; }
.inv-totals-box td { padding: 6px 10px; }
.inv-totals-box tr.total-final td { font-size: 16px; font-weight: 700; color: var(--primary); border-top: 2px solid var(--border); padding-top: 10px; }
.inv-totals-box tr.remaining-row td { color: var(--warning); font-weight: 700; }
.inv-totals-box tr.ok-row td { color: var(--success); font-weight: 700; }

.inv-notes-box { margin: 0 28px 16px; font-size: 13px; color: var(--muted); }

.inv-doc-footer {
    margin: 0 28px;
    padding: 16px 0;
    border-top: 1px solid var(--border);
    text-align: center;
    font-size: 13px; color: var(--muted);
}
.inv-sigs {
    display: flex; justify-content: space-around;
    margin-top: 24px;
}
.sig-line {
    border-top: 1px solid var(--border);
    padding-top: 8px;
    font-size: 12px; color: var(--muted);
    width: 140px; text-align: center;
}

/* ─── List Page ─── */
.list-page { }
.list-toolbar {
    display: flex; align-items: center;
    justify-content: space-between;
    margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
}
.list-filters { display: flex; gap: 8px; flex-wrap: wrap; }

/* ─── Empty / Loading ─── */
.empty-msg {
    text-align: center; padding: 40px;
    color: var(--muted); font-size: 15px;
}
.empty-msg a { color: var(--primary-lt); }
.loading-msg {
    text-align: center; padding: 30px;
    color: var(--muted); font-size: 14px;
}

/* ─── Mobile Topbar ─── */
.topbar-user {
    width: 32px; height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700; color: #fff;
}
.sidebar-overlay {
    display: none; position: fixed;
    inset: 0; background: rgba(0,0,0,0.5);
    z-index: 90;
}

/* ─── Dashboard Grid ─── */
.dashboard-grid { }

/* ─── Expenses / Purchases Form ─── */
.single-form { max-width: 680px; }

/* ─── Reports ─── */
.reports-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 16px;
}

.items-tbl td input {
    background: #fff !important;
    color: #1e293b !important;
    pointer-events: auto !important;
    cursor: text !important;
    -webkit-user-select: text !important;
    user-select: text !important;
}

/* ─── Print ─── */
@media print {
    .sidebar, .topbar, .invoice-actions, .no-print { display: none !important; }
    .main-content { margin-right: 0 !important; }
    .inv-doc { box-shadow: none; border: none; }
    body { background: #fff; }
}

/* ─── Responsive ─── */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
        transition: transform 0.3s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay.show { display: block; }
    .main-content { margin-right: 0; }
    .topbar-toggle { display: block; }
    .topbar-title { font-size: 15px; }
    .stats-row { grid-template-columns: repeat(2, 1fr); }
    .form-page-layout { grid-template-columns: 1fr; }
    .form-grid { grid-template-columns: 1fr; }
    .summary-card { position: static; }
    .page-body { padding: 16px; }
    .actions-row { flex-direction: column; }
    .action-btn { justify-content: center; }
}
