/* ============================================================
   ACIM System - Complete Stylesheet
   Afghanistan Chamber of Industries & Mines
   RTL Support | Modern UI | Print Styles
   ============================================================ */

/* ---- CSS Variables ---- */
:root {
    --primary: #1a3a5c;
    --primary-light: #2a5a8c;
    --primary-dark: #0f2236;
    --accent: #c8a84e;
    --accent-light: #e0c872;
    --bg-body: #f0f2f5;
    --bg-card: #ffffff;
    --bg-sidebar: #0f2236;
    --bg-sidebar-hover: #1a3a5c;
    --bg-sidebar-active: #c8a84e;
    --text-primary: #1a1a2e;
    --text-secondary: #6b7280;
    --text-sidebar: #b0bec5;
    --text-sidebar-active: #0f2236;
    --border: #e2e8f0;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 30px rgba(0,0,0,0.15);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --sidebar-width: 280px;
    --header-height: 64px;
    --transition: 0.25s ease;
}

/* ---- Reset & Base ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 14px; direction: rtl; }
html[dir="ltr"] { direction: ltr; }
html[dir="rtl"] { direction: rtl; }

body {
    font-family: 'Noto Sans Arabic', 'Segoe UI', Tahoma, sans-serif;
    background: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* ---- Scrollbar ---- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #c1c1c1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #999; }

/* ============================================================
   LOGIN PAGE
   ============================================================ */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--primary-dark) 0%, var(--primary) 50%, var(--primary-light) 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 420px;
    text-align: center;
}

.login-logo {
    width: 90px;
    height: 90px;
    object-fit: contain;
    margin-bottom: 16px;
    border-radius: 12px;
}

.login-card h1 {
    font-size: 1.5rem;
    color: var(--primary);
    margin-bottom: 4px;
}

.login-card .subtitle {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 32px;
}

.login-message {
    margin: 4px 0 14px;
    padding: 10px 12px;
    border: 1px solid #fecaca;
    border-radius: var(--radius-sm);
    background: #fef2f2;
    color: #991b1b;
    font-size: 0.88rem;
    font-weight: 600;
    text-align: right;
}

/* ---- Form Controls ---- */
.form-group {
    margin-bottom: 20px;
    text-align: right;
}

.form-group label {
    display: block;
    font-size: 0.9rem;
    font-weight: 600;
    margin-bottom: 6px;
    color: var(--text-primary);
}

.form-control {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-family: inherit;
    transition: border-color var(--transition), box-shadow var(--transition);
    background: #fff;
    direction: rtl;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(42,90,140,0.15);
}

.form-control::placeholder { color: #adb5bd; }

.form-help {
    display: block;
    margin-top: 6px;
    color: var(--text-muted);
    font-size: 12px;
    line-height: 1.6;
}

select.form-control { cursor: pointer; }

textarea.form-control { resize: vertical; min-height: 80px; }

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

.afghan-date-selects {
    display: grid;
    grid-template-columns: minmax(90px, 1fr) auto minmax(150px, 1.4fr) auto minmax(80px, 0.8fr);
    align-items: center;
    gap: 8px;
}

.afghan-date-selects span {
    color: var(--text-secondary);
    font-weight: 700;
}

.material-entry {
    padding: 14px;
    margin-bottom: 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
}

.material-entry-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
    cursor: pointer;
}

.material-entry-summary {
    color: var(--text-secondary);
    font-size: 0.78rem;
    font-weight: 600;
    margin-inline-start: auto;
}

.material-entry.collapsed {
    padding: 8px 12px;
    background: var(--bg-body);
}

.material-entry.collapsed .material-entry-header {
    margin-bottom: 0;
}

.material-entry.collapsed .material-entry-fields {
    display: none;
}

.record-detail-list {
    display: grid;
    gap: 14px;
}

.record-detail-card {
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    overflow: hidden;
}

.record-detail-title {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-body);
    color: var(--primary);
}

.record-detail-title span:last-child {
    color: var(--text-secondary);
}

.record-detail-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0;
}

.detail-section {
    padding: 14px;
    border-inline-end: 1px solid var(--border);
}

.detail-section:last-child {
    border-inline-end: 0;
}

.detail-section h4 {
    margin: 0 0 10px;
    font-size: 0.9rem;
    color: var(--primary);
}

.detail-section div {
    display: grid;
    grid-template-columns: 110px 1fr;
    gap: 10px;
    padding: 7px 0;
    border-top: 1px dashed var(--border);
}

.detail-section span {
    color: var(--text-secondary);
    font-size: 0.8rem;
}

.detail-section strong {
    font-weight: 700;
    color: var(--text-primary);
    overflow-wrap: anywhere;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover { text-decoration: none; }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }

.btn-accent { background: var(--accent); color: #fff; }
.btn-accent:hover { background: var(--accent-light); color: var(--primary-dark); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #059669; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }

.btn-outline {
    background: transparent;
    border: 1.5px solid var(--border);
    color: var(--text-primary);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: rgba(26,58,92,0.04); }

.btn-sm { padding: 6px 12px; font-size: 0.82rem; }

.btn-block { width: 100%; }

.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ============================================================
   APP LAYOUT
   ============================================================ */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ---- Sidebar ---- */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    color: var(--text-sidebar);
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    z-index: 100;
    display: flex;
    flex-direction: column;
    transition: transform var(--transition);
    overflow-y: auto;
}

html[dir="ltr"] .sidebar {
    left: 0;
    right: auto;
}

html[dir="rtl"] .sidebar {
    right: 0;
    left: auto;
}

.sidebar-brand {
    padding: 20px;
    text-align: center;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand img {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 10px;
    margin-bottom: 8px;
}

.sidebar-brand h2 {
    font-size: 0.95rem;
    color: #fff;
    font-weight: 700;
    line-height: 1.4;
}

.sidebar-brand .brand-sub {
    font-size: 0.75rem;
    color: var(--accent);
    margin-top: 2px;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 0;
}

.nav-section-title {
    padding: 12px 24px 6px;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: rgba(176,190,197,0.6);
    font-weight: 700;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 24px;
    color: var(--text-sidebar);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all var(--transition);
    border-right: 3px solid transparent;
}

html[dir="ltr"] .nav-item {
    border-right: 0;
    border-left: 3px solid transparent;
}

.nav-item:hover {
    background: var(--bg-sidebar-hover);
    color: #fff;
}

.nav-item.active {
    background: rgba(200,168,78,0.15);
    color: var(--accent);
    border-right-color: var(--accent);
    font-weight: 700;
}

html[dir="ltr"] .nav-item.active {
    border-right-color: transparent;
    border-left-color: var(--accent);
}

.nav-item .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

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

html[dir="ltr"] .main-content {
    margin-right: 0;
    margin-left: var(--sidebar-width);
}

html[dir="rtl"] .main-content {
    margin-right: var(--sidebar-width);
    margin-left: 0;
}

/* ---- Top Header ---- */
.top-header {
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 28px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-sm);
}

.top-header .page-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.kabul-clock {
    padding: 7px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    color: var(--primary);
    font-size: 0.84rem;
    font-weight: 700;
    direction: ltr;
    white-space: nowrap;
}

.global-search {
    position: relative;
    flex: 1;
    max-width: 720px;
    min-width: 260px;
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 120px auto;
    align-items: center;
    gap: 8px;
}

.global-search input {
    width: 100%;
    padding: 9px 14px 9px 38px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
}

.global-search-year {
    width: 100%;
    padding: 9px 10px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.9rem;
    background: #fff;
}

html[dir="rtl"] .global-search input {
    padding: 9px 38px 9px 14px;
}

.global-search .search-icon {
    position: absolute;
    left: 13px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    z-index: 1;
}

html[dir="rtl"] .global-search .search-icon {
    left: auto;
    right: 13px;
}

.global-search-results {
    display: none;
    position: absolute;
    top: calc(100% + 8px);
    left: 0;
    right: 0;
    z-index: 200;
    max-height: 420px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
}

.global-search-section {
    padding: 10px;
    border-bottom: 1px solid var(--border);
}

.global-search-section:last-child {
    border-bottom: 0;
}

.global-search-section h4 {
    margin: 0 0 8px;
    font-size: 0.78rem;
    color: var(--text-secondary);
    text-transform: uppercase;
}

.global-result {
    display: block;
    width: 100%;
    padding: 9px 10px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    text-align: inherit;
    font-family: inherit;
    cursor: pointer;
}

.global-result:hover {
    background: var(--bg-body);
}

.global-result strong,
.global-result span {
    display: block;
}

.global-result strong {
    color: var(--primary);
    margin-bottom: 3px;
}

.global-result span,
.global-search-empty,
.global-search-loading {
    color: var(--text-secondary);
    font-size: 0.84rem;
}

.global-search-empty,
.global-search-loading {
    padding: 14px;
    text-align: center;
}

.user-badge {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 6px 14px;
    background: var(--bg-body);
    border-radius: 50px;
    font-size: 0.85rem;
}

.user-badge .avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.8rem;
}

/* ---- Page Content ---- */
.page-content {
    flex: 1;
    padding: 28px;
}

/* ============================================================
   CARDS
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    overflow: hidden;
}

.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
}

.card-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--primary);
}

.card-body {
    padding: 20px;
}

.embedded-section {
    margin-top: 28px;
    padding-top: 22px;
    border-top: 1px solid var(--border);
}

.embedded-panel .card-header {
    padding-right: 0;
    padding-left: 0;
}

.embedded-panel .card-body {
    padding-right: 0;
    padding-left: 0;
    padding-bottom: 0;
}

.inline-form-panel {
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fff;
    box-shadow: var(--shadow-sm);
    overflow: hidden;
}

.inline-form-header {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
}

.inline-form-header h3 {
    margin: 0;
    color: var(--primary);
    font-size: 1.05rem;
}

.inline-form-body {
    padding: 12px 14px;
}

.inline-form-panel .form-group {
    margin-bottom: 10px;
}

.inline-form-panel .form-group label {
    font-size: 0.78rem;
    margin-bottom: 3px;
}

.inline-form-panel .form-control {
    padding: 7px 10px;
    font-size: 0.84rem;
}

.inline-form-panel textarea.form-control {
    min-height: 50px;
}

.inline-form-panel .form-row {
    gap: 10px;
}

.inline-form-panel .company-contact-row {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.inline-form-panel .afghan-date-selects {
    gap: 6px;
}

.inline-form-panel .material-entry {
    padding: 10px;
    margin-bottom: 8px;
}

.inline-form-panel .material-entry-header {
    margin-bottom: 8px;
}

.inline-form-footer {
    display: flex;
    gap: 10px;
    justify-content: flex-start;
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    background: var(--bg-body);
}

/* ============================================================
   STAT CARDS (Dashboard)
   ============================================================ */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px;
    margin-bottom: 28px;
}

.stat-card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 16px;
    transition: transform var(--transition), box-shadow var(--transition);
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.stat-icon {
    width: 52px;
    height: 52px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    flex-shrink: 0;
}

.stat-icon.blue   { background: rgba(59,130,246,0.12); color: var(--info); }
.stat-icon.green  { background: rgba(16,185,129,0.12); color: var(--success); }
.stat-icon.amber  { background: rgba(245,158,11,0.12); color: var(--warning); }
.stat-icon.purple { background: rgba(139,92,246,0.12); color: #8b5cf6; }

.stat-info h4 {
    font-size: 1.6rem;
    font-weight: 800;
    line-height: 1.2;
}

.stat-info p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

/* ============================================================
   TABLES
   ============================================================ */
.table-wrapper {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.88rem;
}

.data-table {
    table-layout: fixed;
}

thead th {
    background: var(--primary);
    color: #fff;
    padding: 12px 14px;
    text-align: right;
    font-weight: 600;
    white-space: nowrap;
    position: sticky;
    top: 0;
}

tbody td {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

.data-table th,
.data-table td {
    text-align: center;
}

.data-table td[data-label]::before {
    display: none;
}

.latest-records-table {
    table-layout: fixed;
}

.latest-records-table th,
.latest-records-table td {
    text-align: center;
    vertical-align: middle;
}

.latest-records-table th:nth-child(1),
.latest-records-table td:nth-child(1) {
    width: 70px;
}

.latest-records-table th:nth-child(2),
.latest-records-table td:nth-child(2),
.latest-records-table th:nth-child(3),
.latest-records-table td:nth-child(3) {
    text-align: start;
}

.latest-records-table th:nth-child(4),
.latest-records-table td:nth-child(4) {
    width: 140px;
}

.latest-records-table th:nth-child(5),
.latest-records-table td:nth-child(5) {
    width: 150px;
}

.company-list-table {
    table-layout: fixed;
}

.company-list-table th:nth-child(1),
.company-list-table td:nth-child(1) { width: 58px; }
.company-list-table th:nth-child(2),
.company-list-table td:nth-child(2) { width: 130px; }
.company-list-table th:nth-child(4),
.company-list-table td:nth-child(4) { width: 135px; }
.company-list-table th:nth-child(6),
.company-list-table td:nth-child(6) { width: 150px; }
.company-list-table th:nth-child(7),
.company-list-table td:nth-child(7) { width: 150px; }

.company-list-table .company-row {
    cursor: pointer;
}

tbody tr:hover { background: rgba(26,58,92,0.03); }

tbody tr:last-child td { border-bottom: none; }

.table-actions {
    display: flex;
    gap: 6px;
    white-space: nowrap;
    justify-content: center;
}

.company-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.company-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    cursor: pointer;
    transition: border-color var(--transition), box-shadow var(--transition), transform var(--transition);
}

.company-card:hover,
.company-card:focus {
    border-color: var(--primary);
    box-shadow: var(--shadow-md);
    outline: none;
    transform: translateY(-2px);
}

.company-card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 12px;
}

.company-card-index {
    width: 30px;
    height: 30px;
    border-radius: 50%;
    background: var(--bg-body);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.78rem;
    font-weight: 700;
}

.company-card h4 {
    color: var(--primary);
    font-size: 1rem;
    line-height: 1.45;
    margin-bottom: 12px;
    overflow-wrap: anywhere;
}

.company-card-meta {
    display: grid;
    gap: 9px;
}

.company-card-meta span,
.detail-grid span {
    display: block;
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-bottom: 2px;
}

.company-card-meta strong,
.detail-grid strong {
    color: var(--text-primary);
    font-size: 0.88rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.company-card-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
}

.detail-grid > div {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    background: var(--bg-body);
}

.record-company-summary {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 10px;
    margin-top: 14px;
}

.record-company-summary > div {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    background: var(--bg-body);
}

.record-company-summary span {
    display: block;
    color: var(--text-secondary);
    font-size: 0.74rem;
    margin-bottom: 3px;
}

.record-company-summary strong {
    font-size: 0.88rem;
    overflow-wrap: anywhere;
}

.company-material-table {
    font-size: 0.84rem;
    table-layout: fixed;
}

.company-material-table thead th {
    position: static;
    text-align: center;
}

.company-material-table th,
.company-material-table td {
    text-align: center;
    vertical-align: middle;
}

.company-material-table th:nth-child(1),
.company-material-table td:nth-child(1) {
    width: 72px;
}

.company-material-table th:nth-child(2),
.company-material-table td:nth-child(2) {
    width: 32%;
}

.company-material-table th:nth-child(3),
.company-material-table td:nth-child(3),
.company-material-table th:nth-child(4),
.company-material-table td:nth-child(4) {
    width: 16%;
}

.company-material-table th:nth-child(5),
.company-material-table td:nth-child(5) {
    width: 22%;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

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

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    overflow-y: auto;
    animation: slideUp 0.25s ease;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.05rem;
    font-weight: 700;
    color: var(--primary);
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-secondary);
    padding: 4px 8px;
    border-radius: 4px;
    line-height: 1;
}
.modal-close:hover { background: var(--bg-body); color: var(--danger); }

.modal-body { padding: 24px; }

.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-start;
    gap: 10px;
}

.a4-modal {
    max-width: 900px;
}

.a4-modal .modal-body {
    background: #eef2f7;
    padding: 18px;
}

.report-view-actions {
    display: flex;
    justify-content: flex-start;
    gap: 10px;
    margin-bottom: 16px;
}

.profile-report-view {
    background: #eef2f7;
    padding: 18px;
    border-radius: 8px;
}

.a4-sheet {
    box-sizing: border-box;
    width: min(100%, 794px);
    min-height: 1123px;
    margin: 0 auto;
    background: #fff;
    color: var(--text-primary);
    border: 1px solid #d8e0ea;
    box-shadow: var(--shadow-md);
    padding: 26px 34px;
    overflow: hidden;
}

.company-profile-doc {
    display: flex;
    flex-direction: column;
    gap: 14px;
    direction: rtl;
}

.profile-doc-header {
    display: grid;
    grid-template-columns: 140px 1fr 140px;
    align-items: start;
    gap: 14px;
    padding-bottom: 12px;
    border-bottom: 2px solid var(--primary);
}

.profile-brand {
    display: flex;
    grid-column: 2;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    min-width: 0;
    text-align: center;
}

.profile-brand img {
    width: 68px;
    height: 68px;
    object-fit: contain;
    flex-shrink: 0;
}

.profile-brand p {
    color: var(--primary);
    font-size: 0.95rem;
    font-weight: 700;
    margin-bottom: 0;
}

.profile-brand h2 {
    color: var(--primary);
    font-size: 1.28rem;
    line-height: 1.25;
    font-weight: 800;
}

.profile-doc-meta {
    grid-column: 1;
    grid-row: 1;
    border: 1px solid #dbe4ef;
    border-radius: 8px;
    padding: 10px 12px;
    text-align: center;
    min-width: 132px;
}

.profile-doc-meta span,
.profile-doc-meta small,
.profile-info-grid span,
.profile-doc-footer span {
    display: block;
    color: var(--text-secondary);
    font-size: 0.72rem;
}

.profile-doc-meta strong {
    display: block;
    color: #1d4ed8;
    font-size: 0.92rem;
    margin: 4px 0;
}

.profile-section {
    margin-top: 0;
}

.profile-section-heading {
    display: flex;
    align-items: center;
    gap: 9px;
    margin-bottom: 8px;
    justify-content: flex-start;
}

.profile-section-heading > span {
    width: 28px;
    height: 28px;
    border-radius: 6px;
    background: var(--primary);
    color: #fff;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.72rem;
    font-weight: 800;
}

.profile-section-heading h3 {
    color: var(--primary);
    font-size: 1rem;
}

.profile-info-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 10px 18px;
    text-align: right;
}

.profile-info-grid > div {
    min-width: 0;
    padding: 0;
}

.profile-info-grid strong {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.profile-table-wrap {
    border: 1px solid #dbe4ef;
    overflow: hidden;
}

.profile-material-table {
    width: 100%;
    min-width: 0;
    table-layout: fixed;
    border-collapse: collapse;
    font-size: 0.7rem;
}

.profile-material-table thead th {
    position: static;
    background: var(--primary);
    color: #fff;
    padding: 8px 6px;
    text-align: center;
}

.profile-material-table td {
    padding: 7px 6px;
    border-bottom: 1px solid #e5ecf3;
    text-align: center;
    vertical-align: top;
    overflow-wrap: anywhere;
    word-break: break-word;
}

.profile-material-table th:nth-child(1),
.profile-material-table td:nth-child(1) { width: 32px; }
.profile-material-table th:nth-child(2),
.profile-material-table td:nth-child(2) { width: 160px; }
.profile-material-table th:nth-child(3),
.profile-material-table td:nth-child(3) { width: auto; }
.profile-material-table th:nth-child(4),
.profile-material-table td:nth-child(4) { width: 130px; }
.profile-material-table th:nth-child(5),
.profile-material-table td:nth-child(5) { width: 105px; }

.companies-report-table th:nth-child(1),
.companies-report-table td:nth-child(1) { width: 42px; }
.companies-report-table th:nth-child(2),
.companies-report-table td:nth-child(2) { width: 105px; }
.companies-report-table th:nth-child(3),
.companies-report-table td:nth-child(3) { width: 180px; }
.companies-report-table th:nth-child(4),
.companies-report-table td:nth-child(4) { width: 120px; }
.companies-report-table th:nth-child(5),
.companies-report-table td:nth-child(5) { width: auto; }

.profile-doc-footer {
    margin-top: auto;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 18px;
    padding-top: 26px;
}

.profile-doc-footer div {
    border-top: 1px solid var(--primary);
    padding-top: 8px;
    min-height: 42px;
}

.profile-doc-footer strong {
    display: block;
    margin-top: 4px;
    font-size: 0.82rem;
}

.profile-contact-footer {
    margin-top: auto;
    padding-top: 10px;
    border-top: 1px solid #dbe4ef;
    color: var(--primary);
    text-align: center;
}

.profile-contact-footer h4 {
    margin: 0 0 6px;
    font-size: 0.82rem;
    font-weight: 800;
}

.profile-contact-footer div {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    color: var(--text-secondary);
    font-size: 0.68rem;
}

@media print {
    @page {
        size: A4 portrait;
        margin: 0;
    }

    html,
    body {
        width: 210mm;
        height: 297mm;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: hidden !important;
    }

    body.print-profile-report > *:not(#app) {
        display: none !important;
    }

    body.print-profile-report #app,
    body.print-profile-report .app-layout,
    body.print-profile-report .main-content,
    body.print-profile-report .page-content,
    body.print-profile-report #reportOutput,
    body.print-profile-report .profile-report-view {
        display: block !important;
        position: static !important;
        width: 210mm !important;
        height: 297mm !important;
        margin: 0 !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: hidden !important;
    }

    body.print-profile-report .sidebar,
    body.print-profile-report .top-header,
    body.print-profile-report .report-view-actions {
        display: none !important;
    }

    body.print-profile-report .page-content > *:not(.profile-report-view):not(#reportOutput),
    body.print-profile-report #reportOutput > *:not(.profile-report-view) {
        display: none !important;
    }

    body.print-profile-report .a4-sheet {
        position: static !important;
        box-sizing: border-box;
        width: 210mm !important;
        height: 297mm !important;
        min-height: 0 !important;
        box-shadow: none;
        border: none;
        padding: 11mm 13mm !important;
        overflow: hidden !important;
        page-break-after: avoid;
        break-after: avoid;
    }

    body:not(.print-profile-report) .modal-overlay {
        position: static !important;
        display: block !important;
        width: 210mm !important;
        height: 297mm !important;
        padding: 0 !important;
        background: #fff !important;
        overflow: hidden !important;
    }

    .a4-modal {
        width: 210mm !important;
        max-width: none !important;
        height: 297mm !important;
        max-height: none !important;
        margin: 0 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        overflow: hidden !important;
    }

    .a4-modal .modal-header,
    .a4-modal .modal-footer {
        display: none !important;
    }

    .a4-modal .modal-body {
        display: block !important;
        width: 210mm !important;
        height: 297mm !important;
        padding: 0 !important;
        margin: 0 !important;
        background: #fff !important;
        overflow: hidden !important;
    }

    .a4-sheet {
        position: static !important;
        box-sizing: border-box;
        width: 210mm !important;
        height: 297mm !important;
        min-height: 0 !important;
        box-shadow: none;
        border: none;
        padding: 11mm 13mm !important;
        overflow: hidden !important;
        page-break-after: avoid;
        break-after: avoid;
    }

    .profile-material-table {
        font-size: 7.5pt;
    }
}
/* ============================================================
   TOOLBAR / FILTER BAR
   ============================================================ */
.toolbar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.search-box {
    position: relative;
    flex: 1;
    min-width: 200px;
    max-width: 320px;
}

.search-box input {
    width: 100%;
    padding: 8px 14px 8px 36px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: inherit;
    direction: rtl;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(42,90,140,0.12);
}

.search-box .search-icon {
    position: absolute;
    left: 12px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.dashboard-company-search {
    flex: 0 1 320px;
    margin-inline-start: auto;
}

.filter-select {
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    font-family: inherit;
    direction: rtl;
    background: #fff;
    cursor: pointer;
}

.filter-select:focus {
    outline: none;
    border-color: var(--primary-light);
}

.searchable-filter {
    width: 220px;
}

.searchable-filter .form-control {
    height: 38px;
    font-size: 0.85rem;
}

/* ============================================================
   PAGINATION
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 0 0;
}

.pagination button {
    padding: 7px 13px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fff;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all var(--transition);
}

.pagination button:hover { border-color: var(--primary); color: var(--primary); }
.pagination button.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.pagination button:disabled { opacity: 0.4; cursor: not-allowed; }

.pagination .page-info {
    font-size: 0.82rem;
    color: var(--text-secondary);
    padding: 0 8px;
}

/* ============================================================
   ALERTS / TOAST
   ============================================================ */
.toast-container {
    position: fixed;
    top: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.toast {
    padding: 14px 20px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: 0.9rem;
    box-shadow: var(--shadow-md);
    animation: slideUp 0.3s ease;
    min-width: 280px;
    max-width: 420px;
}

.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.warning { background: var(--warning); color: #1a1a2e; }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 50px;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-success { background: rgba(16,185,129,0.12); color: #059669; }
.badge-danger  { background: rgba(239,68,68,0.12); color: #dc2626; }
.badge-info    { background: rgba(59,130,246,0.12); color: #2563eb; }
.badge-warning { background: rgba(245,158,11,0.12); color: #d97706; }

/* ============================================================
   LOADING
   ============================================================ */
.loading-spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2.5px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-secondary);
}

.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { font-size: 0.95rem; }

/* ============================================================
   CONFIRM DIALOG
   ============================================================ */
.confirm-body {
    text-align: center;
    padding: 20px 0;
}

.confirm-body .confirm-icon {
    font-size: 3rem;
    color: var(--danger);
    margin-bottom: 12px;
}

.confirm-body p {
    font-size: 1rem;
    color: var(--text-primary);
}

/* ============================================================
   ROLE PERMISSIONS GRID
   ============================================================ */
.permissions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 8px;
    max-height: 400px;
    overflow-y: auto;
    padding: 8px 0;
}

.perm-check {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    border-radius: var(--radius-sm);
    background: var(--bg-body);
    cursor: pointer;
    font-size: 0.82rem;
    transition: background var(--transition);
}

.perm-check:hover { background: var(--border); }
.perm-check input[type="checkbox"] { accent-color: var(--primary); }

/* ============================================================
   REPORT - LANDSCAPE PRINT
   ============================================================ */
@media print {
    body { background: #fff !important; }
    .sidebar, .top-header, .no-print { display: none !important; }
    .main-content { margin-right: 0 !important; margin-left: 0 !important; }
    .page-content { padding: 0 !important; }
    .report-container { box-shadow: none !important; border: none !important; }
}

.report-container {
    background: #fff;
    padding: 30px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
}

.report-header {
    text-align: center;
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 3px double var(--primary);
}

.report-header img {
    width: 70px;
    height: 70px;
    object-fit: contain;
    margin-bottom: 8px;
}

.report-header h1 {
    font-size: 1.2rem;
    color: var(--primary);
    margin-bottom: 4px;
}

.report-header .report-subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
}

.report-header .report-date {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

.report-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.8rem;
    margin-bottom: 16px;
}

.report-table thead th {
    background: var(--primary) !important;
    color: #fff !important;
    padding: 8px 10px !important;
    text-align: right;
    font-weight: 600;
    print-color-adjust: exact;
    -webkit-print-color-adjust: exact;
}

.report-table tbody td {
    padding: 7px 10px;
    border-bottom: 1px solid #ddd;
}

.report-table tfoot td {
    background: var(--bg-body);
    font-weight: 700;
    padding: 10px;
    border-top: 2px solid var(--primary);
}

.report-summary {
    display: flex;
    justify-content: space-around;
    gap: 24px;
    margin-top: 20px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.report-summary-item {
    text-align: center;
}

.report-summary-item .val {
    display: inline-block;
    margin-inline-end: 6px;
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--primary);
}

.report-summary-item .lbl {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(100%);
    }
    html[dir="ltr"] .sidebar {
        transform: translateX(-100%);
    }
    .sidebar.open {
        transform: translateX(0);
    }
    .main-content {
        margin-right: 0;
        margin-left: 0;
    }
    .top-header {
        height: auto;
        min-height: var(--header-height);
        flex-wrap: wrap;
        gap: 12px;
        padding: 12px 16px;
    }
    .header-actions {
        flex-wrap: wrap;
        gap: 8px;
    }
    .kabul-clock {
        font-size: 0.8rem;
        padding: 6px 10px;
    }
    .global-search {
        order: 3;
        max-width: none;
        min-width: 100%;
        grid-template-columns: 1fr 110px auto;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .inline-form-panel .company-contact-row {
        grid-template-columns: 1fr;
    }
    .afghan-date-selects {
        grid-template-columns: 1fr;
    }
    .afghan-date-selects span {
        display: none;
    }
    .record-detail-grid {
        grid-template-columns: 1fr;
    }
    .detail-section {
        border-inline-end: 0;
        border-bottom: 1px solid var(--border);
    }
    .detail-section:last-child {
        border-bottom: 0;
    }
    .detail-section div {
        grid-template-columns: 1fr;
        gap: 4px;
    }
    .stat-grid {
        grid-template-columns: 1fr 1fr;
    }
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    .search-box { max-width: 100%; }

    .data-table,
    .data-table thead,
    .data-table tbody,
    .data-table tr,
    .data-table th,
    .data-table td {
        display: block;
        width: 100%;
    }

    .data-table thead {
        display: none;
    }

    .data-table tbody tr {
        padding: 12px;
        border-bottom: 1px solid var(--border);
    }

    .data-table tbody tr:last-child {
        border-bottom: 0;
    }

    .data-table tbody td {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
        padding: 9px 4px;
        text-align: left;
        border-bottom: 1px dashed var(--border);
    }

    html[dir="rtl"] .data-table tbody td {
        text-align: right;
    }

    .data-table tbody td:last-child {
        border-bottom: 0;
    }

    .data-table td[data-label]::before {
        content: attr(data-label);
        display: inline-block;
        color: var(--text-secondary);
        font-size: 0.78rem;
        font-weight: 700;
        flex: 0 0 42%;
        text-align: inherit;
    }

    .data-table .table-actions {
        justify-content: flex-end;
    }

    html[dir="rtl"] .data-table .table-actions {
        justify-content: flex-start;
    }
}

/* ============================================================
   DATE INPUT RTL FIX
   ============================================================ */
input[type="date"],
input[type="month"] {
    direction: ltr;
    text-align: right;
}

/* Checkbox styling */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.88rem;
    cursor: pointer;
    padding: 6px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition);
}

.checkbox-label:hover { border-color: var(--primary-light); background: rgba(26,58,92,0.04); }
.checkbox-label input { accent-color: var(--primary); }

/* Settings page */
.settings-logo-preview {
    width: 120px;
    height: 120px;
    object-fit: contain;
    border: 2px dashed var(--border);
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-body);
    margin-bottom: 12px;
}

.settings-logo-preview img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}
