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

/* -------------------------------------------------------------
   Strict Latin Numerals Engine (Force English digits 0-9 globally)
   Intercepts ASCII 0-9 and related punctuation at the font engine
   level before any Arabic font or Windows DirectWrite substitution.
   ------------------------------------------------------------- */
@font-face {
    font-family: 'StrictLatinDigits';
    src: local('Segoe UI'), local('Roboto'), local('Arial'), local('Helvetica Neue'), sans-serif;
    unicode-range: U+0030-0039, U+002C, U+002E, U+002F, U+0025, U+002D, U+002B; /* 0-9 , . / % - + */
}

/* Globally disable OpenType localized forms (locl) to prevent Arabic digit substitution */
*, *::before, *::after {
    font-feature-settings: "locl" 0;
    -webkit-font-feature-settings: "locl" 0;
    -moz-font-feature-settings: "locl" 0;
}

:root {
    --primary-color: #1b4332;
    --primary-hover: #143527;
    --secondary-color: #2d6a4f;
    --accent-color: #d4af37;
    --bg-light: #f8faf9;
    --sidebar-width: 270px;
}

html[dir="rtl"], body[dir="rtl"], body {
    direction: rtl;
    text-align: right;
    font-family: 'StrictLatinDigits', 'Cairo', 'Tajawal', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background-color: var(--bg-light);
    color: #212529;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Ensure all typography, cards, headers, labels, and forms default to right alignment in Arabic */
h1, h2, h3, h4, h5, h6,
p, label, .form-label,
.card-header, .card-title,
.modal-title, .modal-header,
.dropdown-item, .dropdown-menu,
.alert, .form-check-label {
    text-align: right;
    font-family: inherit;
}

/* Form inputs default alignment and Latin digits font */
.form-control, .form-select, input, select, textarea, button {
    text-align: right;
    font-family: 'StrictLatinDigits', 'Cairo', 'Tajawal', sans-serif;
}

/* Native browser date, time, and number inputs */
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
input[type="week"],
input[type="number"],
.date-input {
    direction: ltr !important;
    text-align: right !important;
    font-family: 'StrictLatinDigits', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif !important;
    font-variant-numeric: tabular-nums normal !important;
    font-feature-settings: "locl" 0, "tnum" 1 !important;
    -webkit-font-feature-settings: "locl" 0, "tnum" 1 !important;
}

/* Force Chrome & Edge internal Shadow-DOM calendar controls to Latin digits */
input[type="date"]::-webkit-datetime-edit,
input[type="date"]::-webkit-datetime-edit-fields-wrapper,
input[type="date"]::-webkit-datetime-edit-text,
input[type="date"]::-webkit-datetime-edit-month-field,
input[type="date"]::-webkit-datetime-edit-day-field,
input[type="date"]::-webkit-datetime-edit-year-field,
input[type="time"]::-webkit-datetime-edit,
input[type="time"]::-webkit-datetime-edit-fields-wrapper,
input[type="time"]::-webkit-datetime-edit-text,
input[type="time"]::-webkit-datetime-edit-hour-field,
input[type="time"]::-webkit-datetime-edit-minute-field {
    font-family: 'StrictLatinDigits', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Arial, sans-serif !important;
    direction: ltr !important;
    font-feature-settings: "locl" 0 !important;
    -webkit-font-feature-settings: "locl" 0 !important;
}

/* Financial fee inputs: keep digits LTR but aligned to the right inside the input field */
.fee-input, input[inputmode="decimal"] {
    text-align: right !important;
    direction: ltr !important;
    font-family: 'StrictLatinDigits', 'Segoe UI', Roboto, Arial, sans-serif !important;
}

/* Digits strictly English */
.en-digits, .amount, .date, .id-number, input[type="number"], input.date-input {
    font-family: 'StrictLatinDigits', 'Segoe UI', Roboto, Arial, sans-serif;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "locl" 0, "tnum" 1;
}

span.en-digits, code.en-digits, strong.en-digits, b.en-digits, a.en-digits, div.en-digits, input.en-digits {
    display: inline-block;
    direction: ltr;
    unicode-bidi: embed;
}

/* Table cells and rows must NEVER collapse into inline-block */
table, .table {
    direction: rtl !important;
    text-align: right;
    width: 100% !important;
    margin-bottom: 0;
    border-collapse: separate;
    border-spacing: 0;
}

table tr:not(.collapse):not(.tree-detail-row),
.table tr:not(.collapse):not(.tree-detail-row),
tbody tr:not(.collapse):not(.tree-detail-row),
thead tr {
    display: table-row !important;
}

/* Explicit handling for collapsible table rows */
table tr.collapse:not(.show),
.table tr.collapse:not(.show),
tbody tr.collapse:not(.show),
table tr.tree-detail-row:not(.show),
.table tr.tree-detail-row:not(.show) {
    display: none !important;
}

table tr.collapse.show,
.table tr.collapse.show,
tbody tr.collapse.show,
table tr.tree-detail-row.show,
.table tr.tree-detail-row.show {
    display: table-row !important;
}

.btn-tree-toggle {
    transition: all 0.2s ease-in-out;
    cursor: pointer;
}

.btn-tree-toggle.active {
    background-color: #0dcaf0 !important;
    color: #000 !important;
    font-weight: bold;
    border-color: #0aa2c0 !important;
    box-shadow: 0 0 0 0.2rem rgba(13, 202, 240, 0.3);
}

table th, table td,
.table th, .table td,
td.en-digits, th.en-digits,
.table > :not(caption) > * > * {
    display: table-cell !important;
    vertical-align: middle;
}

/* Explicit RTL Text Alignment Classes */
body[dir="rtl"] .text-start,
[dir="rtl"] .text-start,
.text-rtl-right,
.table th.text-start,
.table td.text-start {
    text-align: right !important;
}

body[dir="rtl"] .text-end,
[dir="rtl"] .text-end,
.text-rtl-left,
.table th.text-end,
.table td.text-end {
    text-align: left !important;
}

.text-rtl-center,
.table th.text-center,
.table td.text-center {
    text-align: center !important;
}

/* Tree branch formatting for RTL */
.tree-branch-symbol {
    font-family: monospace;
    color: #6c757d;
    user-select: none;
    display: inline-block;
    direction: ltr;
}

/* Header styling */
header.navbar {
    position: sticky;
    top: 0;
    z-index: 1030;
    min-height: 65px;
}

/* Sidebar styling */
.app-wrapper {
    display: flex;
    flex: 1;
    min-height: calc(100vh - 65px);
}

.sidebar {
    width: var(--sidebar-width);
    background: #081c15;
    background: linear-gradient(180deg, #1b4332 0%, #081c15 100%);
    color: #ffffff;
    flex-shrink: 0;
    transition: all 0.3s ease;
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 65px;
    height: calc(100vh - 65px);
    z-index: 1020;
}

.sidebar-nav-container {
    flex: 1 1 auto;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
}

.sidebar-nav-container::-webkit-scrollbar {
    width: 5px;
}
.sidebar-nav-container::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-bottom-pwa {
    flex-shrink: 0;
    margin-top: auto;
    background: rgba(0, 0, 0, 0.2);
}

.sidebar .nav-link {
    color: rgba(255, 255, 255, 0.85);
    padding: 0.75rem 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 12px;
    border-radius: 8px;
    margin: 4px 10px;
    transition: all 0.2s ease;
}

.sidebar .nav-link:hover, .sidebar .nav-link.active {
    color: #ffffff;
    background-color: rgba(255, 255, 255, 0.15);
    border-right: 4px solid var(--accent-color);
}

.sidebar .nav-link i {
    font-size: 1.2rem;
}

/* Main Content Area */
.main-content {
    flex: 1;
    padding: 1.75rem;
    background-color: var(--bg-light);
    overflow-x: auto;
}

/* Cards & Widgets */
.card {
    border: none;
    border-radius: 12px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.04);
}

.card-header {
    background-color: #ffffff;
    border-bottom: 1px solid #edf2f7;
    font-weight: 700;
    padding: 1rem 1.25rem;
    border-top-left-radius: 12px !important;
    border-top-right-radius: 12px !important;
}

.btn-primary {
    background-color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-primary:hover, .btn-primary:focus {
    background-color: var(--primary-hover);
    border-color: var(--primary-hover);
}

.btn-outline-primary {
    color: var(--primary-color);
    border-color: var(--primary-color);
}

.btn-outline-primary:hover {
    background-color: var(--primary-color);
    color: #ffffff;
}

/* Table styling */
.table {
    margin-bottom: 0;
}

.table th {
    background-color: #f1f5f3;
    color: #1b4332;
    font-weight: 700;
    vertical-align: middle;
    font-size: 0.9rem;
}

.table td {
    vertical-align: middle;
    font-size: 0.92rem;
}

/* Badge styling */
.badge-status-unpaid {
    background-color: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
}

.badge-status-paid {
    background-color: #d1fae5;
    color: #065f46;
    border: 1px solid #a7f3d0;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
}

.badge-status-partial {
    background-color: #fef3c7;
    color: #92400e;
    border: 1px solid #fde68a;
    padding: 6px 12px;
    border-radius: 20px;
    font-weight: 600;
}

/* Footer Authority styling */
.app-footer {
    background-color: #ffffff;
    border-top: 1px solid #e2e8f0;
    padding: 1rem 2rem;
    font-size: 0.9rem;
    color: #4a5568;
    margin-top: auto;
}

/* Nested owner-heir tree in Personal Properties */
.owner-card {
    background-color: #fcfdfd;
    border: 1px solid #d1e7dd;
    border-radius: 10px;
    padding: 15px;
    margin-bottom: 15px;
    position: relative;
}

.heir-card {
    background-color: #ffffff;
    border: 1px solid #e2e8f0;
    border-right: 4px solid #198754;
    border-radius: 8px;
    padding: 10px 15px;
    margin-top: 10px;
}

/* Mobile responsive sidebar */
@media (max-width: 991.98px) {
    .sidebar {
        position: fixed;
        top: 65px;
        right: -280px;
        height: calc(100vh - 65px);
        z-index: 1040;
    }
    .sidebar.show {
        right: 0;
    }
}

/* Custom Searchable Usage Dropdown */
.searchable-usage-dropdown {
    position: relative;
    width: 100% !important;
}
.searchable-usage-dropdown .dropdown-menu {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
    box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15) !important;
    border: 1px solid rgba(0, 0, 0, 0.08) !important;
    border-radius: 8px !important;
}
.searchable-usage-dropdown .usage-item {
    white-space: normal !important;
    word-break: break-word !important;
    overflow-wrap: break-word !important;
    line-height: 1.45 !important;
    transition: background-color 0.15s ease;
}
.searchable-usage-dropdown .usage-item:hover {
    background-color: #f0fdf4 !important;
    color: #1b4332 !important;
}
.searchable-usage-dropdown .usage-options-list::-webkit-scrollbar {
    width: 6px;
}
.searchable-usage-dropdown .usage-options-list::-webkit-scrollbar-thumb {
    background-color: #cbd5e1;
    border-radius: 4px;
}

