/* ─── سجل الديون — Global Styles ──────────────────────────── */

body {
    font-family: 'IBM Plex Sans Arabic', sans-serif;
    background-color: #F8FAFC;
}

.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    vertical-align: middle;
}

.material-symbols-filled,
.material-symbols-outlined.fill,
.material-symbols-outlined.filled {
    font-variation-settings: 'FILL' 1, 'wght' 400, 'GRAD' 0, 'opsz' 24 !important;
}

/* ─── Scrollbar ───────────────────────────────────────────── */
.custom-scrollbar::-webkit-scrollbar {
    width: 5px;
}
.custom-scrollbar::-webkit-scrollbar-track {
    background: transparent;
}
.custom-scrollbar::-webkit-scrollbar-thumb {
    background: #becabf;
    border-radius: 10px;
}

/* ─── Form Focus & Error States ──────────────────────────── */
.form-input-focus:focus {
    outline: none;
    border-color: #1B8354;
    box-shadow: 0 0 0 2px rgba(27, 131, 84, 0.1);
}

.border-error, input.border-error, textarea.border-error, select.border-error {
    border-color: #ba1a1a !important;
    box-shadow: 0 0 0 1px #ba1a1a !important;
}

/* ─── Invoice Modal ───────────────────────────────────────── */
.invoice-modal-panel,
.invoice-modal-panel * {
    box-sizing: border-box;
}

.invoice-modal-panel {
    scrollbar-gutter: stable;
    width: 100%;
    max-height: min(94vh, 920px);
    display: flex;
    flex-direction: column;
    overflow: hidden !important;
    position: relative;
}

.invoice-modal-header {
    position: sticky;
    top: 0;
    z-index: 30;
    background: rgba(255, 255, 255, 0.97);
    backdrop-filter: blur(10px);
}

.invoice-modal-header button {
    width: 40px;
    height: 40px;
    display: grid;
    place-items: center;
    border-radius: 999px;
}

.invoice-modal-header button:hover {
    background: #f1f5f3;
}

.invoice-modal-form input:not([type="radio"]):not([type="checkbox"]),
.invoice-modal-form select {
    min-height: 42px;
}

.invoice-modal-form {
    display: flex;
    flex: 1;
    min-height: 0;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}

.invoice-modal-scroll {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding-top: 4px;
    padding-bottom: 16px;
    scrollbar-gutter: stable;
}

.invoice-purchase-card {
    border: 1px solid #dce5df;
    box-shadow: 0 1px 2px rgba(20, 27, 43, 0.03);
}

.invoice-services-card {
    border: 1px solid #dce5df;
    background: #fbfcfb;
}

.invoice-line-table-head,
.invoice-line-grid {
    display: grid;
    grid-template-columns: 88px 118px minmax(180px, 1fr) 118px 100px 36px;
    gap: 8px;
    align-items: center;
}

.invoice-line-table-head {
    padding: 0 8px 7px;
    color: #647067;
    font-size: 11px;
    font-weight: 700;
}

.invoice-line-row {
    padding: 8px;
    border: 1px solid #e1e8e3;
    border-radius: 12px;
    background: #fff;
}

.invoice-line-grid > div {
    width: auto !important;
    min-width: 0 !important;
    padding-top: 0 !important;
}

.invoice-line-grid > div > label {
    display: none;
}

.invoice-line-grid input,
.invoice-line-grid select {
    width: 100%;
}

.invoice-line-grid .line-total-text {
    display: flex;
    min-height: 42px;
    align-items: center;
    justify-content: flex-start;
    padding: 0 !important;
    font-size: 14px;
}

.invoice-line-grid button {
    margin-inline: auto;
}

.invoice-service-grid {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) 150px 40px;
    gap: 8px;
    align-items: end;
    padding: 8px;
    border: 1px solid #e1e8e3;
    border-radius: 12px;
    background: #fff;
}

.invoice-service-grid > div {
    width: auto !important;
    min-width: 0 !important;
    padding-top: 0 !important;
}

.services-subtotal-row {
    display: none !important;
}

.invoice-totals-card {
    margin-top: 14px;
    padding: 14px 16px;
    border: 1px solid #d7e1da !important;
    border-radius: 14px;
    background: #f8faf9;
}

.invoice-totals-card #itemsGrandTotalText,
.invoice-totals-card #itemsRemainingAfterPaidText {
    font-size: 18px;
}

.invoice-modal-footer {
    flex-shrink: 0;
    margin: 0;
    background: rgba(255, 255, 255, 0.98);
    backdrop-filter: blur(10px);
    box-shadow: 0 -8px 24px rgba(20, 27, 43, 0.06);
}

.invoice-modal-footer > button {
    min-height: 48px;
}

@media (max-width: 767px) {
    .invoice-modal-overlay {
        padding: 0 !important;
        align-items: stretch !important;
    }

    .invoice-modal-panel {
        height: 100vh !important;
        max-height: 100vh !important;
        border-radius: 0 !important;
    }
}

/* Tablet + mobile: stack the 6-column line grid into cards so rows
   never overflow the popup width */
@media (max-width: 1023.98px) {
    .invoice-line-table-head {
        display: none;
    }

    .invoice-line-grid {
        grid-template-columns: 1fr 1fr;
        gap: 10px 8px;
    }

    .invoice-line-grid > div > label {
        display: block;
    }

    .invoice-line-grid > div:nth-child(3) {
        grid-column: 1 / -1;
    }

    .invoice-line-grid > div:nth-child(5) {
        align-self: end;
    }

    .invoice-line-grid > div:nth-child(6) {
        align-self: end;
        justify-self: end;
    }

    .invoice-service-grid {
        grid-template-columns: 1fr 110px 40px;
    }

    .invoice-services-card,
    .invoice-purchase-card {
        padding: 12px !important;
    }
}

/* ─── Glass Card ──────────────────────────────────────────── */
.glass-card {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(10px);
    border: 1px solid #e5e7eb;
}

/* ─── Animations ──────────────────────────────────────────── */
@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeInRow {
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ─── Hide Number Input Spinners ───────────────────────────── */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
input[type="number"] {
    -moz-appearance: textfield;
}

/* ─── RTL Select Arrow & Padding Fix ────────────────────────── */
[dir="rtl"] select,
select {
    background-position: left 0.75rem center !important;
    padding-left: 2.25rem !important;
    padding-right: 0.75rem !important;
}

/* ─── Mobile Bottom-Nav Clearance ─────────────────────────── */
/* Fixed bottom-nav is h-4rem + safe-area; keep page content scrollable above it */
@media (max-width: 767.98px) {
    main,
    .flex-1.overflow-y-auto {
        scroll-padding-bottom: calc(5rem + env(safe-area-inset-bottom));
    }
    /* Safety net: any mobile main content always clears the fixed nav */
    /* (beats Tailwind pb-* utilities which would otherwise win on specificity) */
    main {
        padding-bottom: calc(6rem + env(safe-area-inset-bottom)) !important;
    }
    .flex-1.overflow-y-auto {
        padding-bottom: calc(6rem + env(safe-area-inset-bottom)) !important;
    }
    /* Pinned top bar (floating pill): stick offset matches container top padding */
    .app-topbar {
        position: sticky;
        top: 20px;
        z-index: 40;
    }
    /* client-details / status mains use pt-md (16px) instead of p-container-margin */
    main.pt-md > .app-topbar {
        top: 16px;
    }
}

/* ═════════ Design System v2 — modern UI layer ════════════════
   Single source of truth for surfaces, buttons, inputs, tables,
   chips, modals, skeletons and auth. Pages converge here instead
   of scattering one-off Tailwind chains. */
:root {
    --brand: #006840;
    --brand-deep: #005231;
    --brand-tint: #cfe9da;
    --brand-wash: #f0f8f3;
    --ink: #24362b;
    --muted: #59685e;
    --line: #dbe3dd;
    --danger: #ba1a1a;
    --radius: 14px;
    --shadow-card: 0 1px 2px rgba(20, 27, 43, 0.04), 0 4px 16px -8px rgba(20, 60, 37, 0.12);
    --shadow-pop: 0 12px 40px -8px rgba(20, 60, 37, 0.22);
}

html { scroll-behavior: smooth; }

body {
    color: var(--ink);
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeLegibility;
    font-variant-numeric: tabular-nums;
}

::selection { background: #bfe6cf; color: #002111; }

:focus-visible {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
    border-radius: 6px;
}

/* ─── Cards ─────────────────────────────────────────────────── */
.ui-card {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-card);
}

.ui-card-hover { transition: box-shadow 0.2s ease, transform 0.2s ease, border-color 0.2s ease; }
.ui-card-hover:hover { box-shadow: var(--shadow-pop); border-color: #c4d8c9; }

/* ─── Buttons (44px touch targets, one shape language) ─────── */
.ui-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    min-height: 44px;
    padding: 0 20px;
    border-radius: 999px;
    font-weight: 700;
    font-size: 14px;
    cursor: pointer;
    border: 1px solid transparent;
    transition: background 0.15s ease, transform 0.1s ease, box-shadow 0.15s ease;
    white-space: nowrap;
}
.ui-btn:active { transform: scale(0.97); }
.ui-btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; }
.ui-btn-primary { background: var(--brand); color: #fff; box-shadow: 0 2px 8px -2px rgba(0, 104, 64, 0.5); }
.ui-btn-primary:hover { background: var(--brand-deep); }
.ui-btn-secondary { background: #fff; color: var(--brand); border-color: var(--brand); }
.ui-btn-secondary:hover { background: var(--brand-wash); }
.ui-btn-danger { background: var(--danger); color: #fff; }
.ui-btn-danger:hover { filter: brightness(0.92); }
.ui-btn-ghost { background: transparent; color: var(--ink); }
.ui-btn-ghost:hover { background: #eef3ef; }
.ui-btn-sm { min-height: 36px; padding: 0 14px; font-size: 12px; }

/* ─── Inputs ────────────────────────────────────────────────── */
.ui-input {
    width: 100%;
    min-height: 44px;
    padding: 0 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fff;
    font-size: 14px;
    color: var(--ink);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.ui-input::placeholder { color: #8a978d; }
.ui-input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(0, 104, 64, 0.14); }
.ui-label { display: block; font-size: 13px; font-weight: 700; color: var(--ink); margin-bottom: 6px; }

/* ─── Chips / status pills ──────────────────────────────────── */
.ui-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 12px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 700;
    white-space: nowrap;
}
.ui-chip-green { background: var(--brand-tint); color: #002111; }
.ui-chip-red { background: #ffdad6; color: #93000a; }
.ui-chip-grey { background: #eef1ee; color: var(--muted); }
.ui-chip-amber { background: #ffedd5; color: #7c2d12; }

/* ─── Tables ────────────────────────────────────────────────── */
.ui-table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--line); background: #fff; }
.ui-table { width: 100%; border-collapse: collapse; text-align: right; white-space: nowrap; font-size: 13px; }
.ui-table thead th {
    position: sticky;
    top: 0;
    background: #f4f7f5;
    color: var(--muted);
    font-size: 11px;
    font-weight: 700;
    padding: 10px 14px;
    border-bottom: 1px solid var(--line);
    z-index: 1;
}
.ui-table tbody td { padding: 12px 14px; border-bottom: 1px solid #edf1ed; }
.ui-table tbody tr:last-child td { border-bottom: none; }
.ui-table tbody tr { transition: background 0.12s ease; }
.ui-table tbody tr:hover { background: var(--brand-wash); }
.ui-num { font-variant-numeric: tabular-nums; direction: ltr; unicode-bidi: embed; }

/* ─── Section titles ────────────────────────────────────────── */
.ui-section-title { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 700; color: var(--ink); }
.ui-section-title .material-symbols-outlined { color: var(--brand); font-size: 22px; }
.ui-page-sub { color: var(--muted); font-size: 13px; margin-top: 2px; }

/* ─── Modal motion (composes with existing modal markup) ───── */
@keyframes ui-pop-in { from { opacity: 0; transform: translateY(10px) scale(0.98); } to { opacity: 1; transform: none; } }
@keyframes ui-fade-in { from { opacity: 0; } to { opacity: 1; } }
.anim-pop { animation: ui-pop-in 0.18s ease-out; }
.anim-fade { animation: ui-fade-in 0.15s ease-out; }

/* ─── Skeleton loading shimmer ──────────────────────────────── */
.ui-skeleton {
    position: relative;
    overflow: hidden;
    background: #e8ede9;
    border-radius: 8px;
    min-height: 14px;
}
.ui-skeleton::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.7), transparent);
    animation: ui-shimmer 1.4s infinite;
}
@keyframes ui-shimmer { from { transform: translateX(100%); } to { transform: translateX(-100%); } }

/* ─── Empty state ───────────────────────────────────────────── */
.ui-empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.ui-empty .material-symbols-outlined { font-size: 44px; color: #b9c6bc; display: block; margin-bottom: 8px; }
.ui-empty p { font-weight: 700; color: var(--ink); margin-bottom: 4px; }

/* ─── Auth (login) ──────────────────────────────────────────── */
.auth-bg {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    background:
        radial-gradient(600px 300px at 85% -5%, rgba(0, 104, 64, 0.12), transparent),
        radial-gradient(500px 280px at 10% 110%, rgba(0, 104, 64, 0.1), transparent),
        #f4f7f5;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: rgba(255, 255, 255, 0.96);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(255, 255, 255, 0.6);
    border-radius: 20px;
    padding: 32px 28px;
    box-shadow: var(--shadow-pop);
    animation: ui-pop-in 0.22s ease-out;
}
.auth-logo { width: 72px; height: 72px; object-fit: contain; }

/* ─── Topbar: full-bleed sticky bar (replaces floating pill) ── */
@media (max-width: 767.98px) {
    .app-topbar { top: 0 !important; border-radius: 0 !important; border-left: none !important; border-right: none !important; border-top: none !important; margin-bottom: 16px !important; }
    main.pt-md > .app-topbar { top: 0 !important; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
    html { scroll-behavior: auto; }
}
