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

* {
    box-sizing: border-box;
    font-family: "Tajawal", Tahoma, Arial, sans-serif;
}

body {
    margin: 0;
    padding: 28px 20px;
    background: #f3f6fb;
    direction: rtl;
    color: #101820;
    font-weight: 500;
}

body.login-active {
    min-height: 100vh;
    background:
        linear-gradient(rgba(255, 255, 255, .08), rgba(8, 36, 56, .12)),
        url("assets/muscat-airport-user.jpg") center center / cover fixed no-repeat;
}

body.login-active > .container > h1 {
    color: #fff;
    text-shadow: 0 2px 14px rgba(0, 0, 0, .45);
}

.container {
    max-width: 1280px;
    margin: auto;
}

h1 {
    text-align: right;
    color: #0b2239;
    margin: 0 0 20px;
    font-size: clamp(26px, 4vw, 36px);
}

/* واجهة تسجيل الدخول */
.login-shell { display:grid; grid-template-columns:minmax(280px,.9fr) minmax(340px,1.1fr); max-width:1050px; min-height:570px; margin:34px auto; overflow:hidden; border:1px solid rgba(255,255,255,.72); border-radius:28px; background:rgba(255,255,255,.04); box-shadow:0 28px 70px rgba(3,22,39,.28); }
.login-visual { position:relative; display:flex; flex-direction:column; justify-content:center; padding:clamp(34px,6vw,64px); overflow:hidden; color:#fff; background:linear-gradient(150deg,rgba(8,43,68,.34),rgba(18,92,145,.14)); text-shadow:0 2px 10px rgba(0,0,0,.5); }
.login-visual::before,.login-visual::after { content:""; position:absolute; border-radius:50%; background:rgba(255,255,255,.08); }
.login-visual::before { width:260px; height:260px; top:-90px; left:-90px; }
.login-visual::after { width:190px; height:190px; bottom:-80px; right:-55px; }
.login-visual > * { position:relative; z-index:1; }
.brand-mark { display:grid; place-items:center; width:58px; height:58px; margin-bottom:32px; border:1px solid rgba(255,255,255,.35); border-radius:18px; background:rgba(255,255,255,.14); font-weight:800; letter-spacing:1px; }
.login-eyebrow { display:block; margin-bottom:9px; color:#86d5ff; font-size:12px; font-weight:800; letter-spacing:1.4px; }
.login-visual h2 { margin:0 0 18px; font-size:clamp(29px,4vw,42px); line-height:1.35; }
.login-visual p { margin:0 0 28px; color:#d9edfa; line-height:1.9; }
.login-feature { display:flex; align-items:center; gap:10px; margin-top:12px; color:#eef9ff; font-size:14px; }
.login-feature span { display:grid; place-items:center; width:24px; height:24px; border-radius:50%; background:rgba(255,255,255,.15); color:#7ee0b3; font-weight:bold; }
.login-panel { display:flex; flex-direction:column; justify-content:center; padding:clamp(32px,6vw,70px); background:rgba(255,255,255,.76); backdrop-filter:blur(7px); -webkit-backdrop-filter:blur(7px); }
.login-heading { display:flex; align-items:center; gap:14px; }
.login-heading h2 { margin:0; color:#123557; font-size:30px; }
.login-heading .login-eyebrow { color:#1f6feb; letter-spacing:0; }
.login-lock { display:grid; place-items:center; width:52px; height:52px; border-radius:16px; background:#eaf4ff; font-size:23px; }
.login-subtitle { margin:14px 0 25px; color:#66788a; }
.login-field { margin-bottom:14px; }
.login-field label { display:block; margin-bottom:7px; color:#29445f; font-size:14px; font-weight:bold; }
.input-wrap { position:relative; }
.input-wrap input { height:52px; margin:0; padding-right:46px; padding-left:70px; background:#f9fbfd; }
.input-icon { position:absolute; z-index:1; top:50%; right:16px; transform:translateY(-50%); color:#7890a6; font-size:15px; }
.password-toggle { position:absolute; z-index:2; top:50%; left:9px; width:auto; margin:0; padding:7px 9px; transform:translateY(-50%); background:transparent; color:#1769c2; font-size:12px; font-weight:bold; box-shadow:none; }
.password-toggle:hover { transform:translateY(-50%); background:#eaf4ff; box-shadow:none; }
.login-button { display:flex; align-items:center; justify-content:space-between; width:100%; margin-top:9px; padding:14px 19px; background:linear-gradient(135deg,#1769c2,#0e87be); font-weight:bold; box-shadow:0 10px 22px rgba(23,105,194,.22); }
.auto-login-note { margin:10px 0 0; color:#718397; text-align:center; font-size:12px; }
.login-help { margin-top:20px; margin-bottom:0; font-size:12px; line-height:1.7; }
.login-panel #message { min-height:22px; margin-bottom:0; font-size:14px; font-weight:bold; }

.card {
    background: white;
    padding: clamp(18px, 3vw, 32px);
    border-radius: 18px;
    margin-bottom: 20px;
    box-shadow: 0 16px 42px rgba(21, 53, 87, 0.09);
    border: 1px solid #e7edf5;
}

.hidden {
    display: none !important;
}

.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.dashboard-header h2 {
    margin: 0;
}

.role-info {
    margin: 4px 0 0;
    font-size: 14px;
    color: #5a6c7d;
}

.scope-note {
    font-size: 14px;
    color: #5a6c7d;
    background: #f0f4f8;
    padding: 10px 12px;
    border-radius: 8px;
    border-right: 3px solid #1f6feb;
    margin-bottom: 12px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 14px;
    margin-bottom: 24px;
}

.today-overview {
    margin: 0 0 24px;
    padding: 20px;
    border: 1px solid #e2eaf3;
    border-radius: 16px;
    background: linear-gradient(135deg, #f8fbff, #f2f7fc);
}

.overview-heading {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.eyebrow {
    display: block;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: bold;
    color: #1f6feb;
}

.overview-heading h3 { margin: 0; color: #123557; }
.overview-date { margin: 0; color: #5a6c7d; font-size: 13px; }

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

.shift-overview-card {
    position: relative;
    overflow: hidden;
    min-height: 205px;
    margin: 0;
    padding: 14px;
    border: 1px solid #e1e9f1;
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 5px 14px rgba(24, 63, 103, 0.06);
    color: inherit;
    text-align: right;
    cursor: pointer;
}

.shift-overview-card::before {
    content: "";
    position: absolute;
    right: 0;
    top: 0;
    width: 100%;
    height: 5px;
    background: #1f6feb;
}

.shift-overview-card.night::before { background: #334f8d; }
.shift-overview-card.evening::before { background: #e47c30; }
.shift-overview-card.morning::before { background: #d49a19; }
.shift-overview-card.leave::before { background: #8492a6; }

.shift-overview-card:hover, .shift-overview-card.active { border-color: #79aee7; box-shadow: 0 9px 20px rgba(24, 63, 103, 0.14); transform: translateY(-2px); }
.shift-overview-card.active { background: #f5faff; }
.shift-overview-top { display: flex; align-items: center; gap: 9px; color: #52677c; font-size: 13px; }
.shift-icon { display: grid; place-items: center; width: 34px; height: 48px; border-radius: 6px; background: #edf3fa; font-size: 18px; }
.shift-period { display: block; margin: 16px 0 4px; color: #123557; font-size: 22px; font-weight: bold; }
.shift-time { display: block; min-height: 20px; color: #607286; font-size: 12px; }
.shift-staff { display: flex; justify-content: space-between; margin-top: 14px; padding-top: 10px; border-top: 1px solid #edf1f5; color: #607286; font-size: 12px; }
.shift-staff b { font-size: 14px; color: #1e8449; }
.shift-staff.shortage b { color: #c0392b; }
.shift-detail-hint { display: block; margin-top: 12px; color: #1f6feb; font-size: 12px; font-weight: bold; }

.shift-summary { margin-top: 14px; padding: 16px; border: 1px solid #dce7f1; border-radius: 10px; background: #fff; }
.shift-summary.empty { color: #607286; text-align: center; background: #f8fbfe; }
.summary-title { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid #e7edf4; }
.summary-title h4 { margin: 0; color: #123557; font-size: 18px; }
.summary-period { padding: 7px 10px; border-radius: 7px; color: #123557; background: #eaf2fb; font-size: 13px; font-weight: bold; }
.summary-details { display: grid; grid-template-columns: repeat(3, minmax(120px, 1fr)); gap: 10px; margin-top: 14px; }
.summary-details div { padding: 10px; border: 1px solid #edf1f5; border-radius: 7px; background: #fbfdff; }
.summary-details span, .summary-details b { display: block; }
.summary-details span { margin-bottom: 4px; color: #607286; font-size: 12px; }
.summary-details b { color: #123557; font-size: 15px; }
.success-text { color: #1e8449 !important; }
.warning-text { color: #c0392b !important; }

.stat-card {
    position: relative;
    overflow: hidden;
    background: rgba(255, 255, 255, .92);
    color: #17202a;
    padding: 18px 18px 18px 76px;
    border: 1px solid rgba(0, 0, 0, .07);
    border-radius: 18px;
    text-align: right;
    box-shadow: 0 8px 24px rgba(30, 43, 58, .09), inset 0 1px 0 rgba(255,255,255,.8);
}

.stat-card.warning {
    background: rgba(255, 255, 255, .94);
}

.stat-card.success {
    background: rgba(255, 255, 255, .94);
}

.stat-card .stat-value {
    font-size: 28px;
    font-weight: bold;
    margin: 4px 0;
}

.stat-card .stat-label {
    font-size: 13px;
    color: #66717d;
    opacity: 1;
}

.stat-icon { position:absolute; left:18px; top:18px; display:grid; place-items:center; width:46px; height:46px; border-radius:13px; color:#fff; font-size:22px; font-weight:800; box-shadow:0 5px 12px rgba(0,0,0,.16), inset 0 1px 0 rgba(255,255,255,.35); }
.stat-icon-total { background:linear-gradient(145deg,#168bff,#0667d8); }
.stat-icon-available { background:linear-gradient(145deg,#48d66b,#20a94a); }
.stat-icon-absence { background:linear-gradient(145deg,#ffb431,#f07813); }

.absence-stat { min-width: 260px; }
.absence-breakdown { display: grid; grid-template-columns: repeat(2, minmax(95px, 1fr)); gap: 7px; margin-top: 10px; }
.absence-breakdown span { display: flex; justify-content: space-between; gap: 6px; padding: 7px 9px; border-radius: 9px; background: #f1f3f6; color:#4d5965; font-size: 12px; }
.absence-breakdown b { color: #17202a; font-size: 14px; }

input,
select,
textarea {
    width: 100%;
    padding: 12px;
    margin: 6px 0;
    border: 1px solid #d8e1ec;
    border-radius: 10px;
    font-size: 16px;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: #1f6feb;
    box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.13);
}

textarea {
    min-height: 70px;
    resize: vertical;
}

button {
    padding: 12px 16px;
    margin: 6px 0;
    border: none;
    border-radius: 10px;
    background: #1769c2;
    color: white;
    font-size: 16px;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
}

button:hover {
    opacity: 0.9;
    transform: translateY(-1px);
    box-shadow: 0 5px 12px rgba(23, 105, 194, 0.2);
}

button.btn-secondary {
    background: #5a6c7d;
}

button.btn-danger {
    background: #c0392b;
}

button.btn-success {
    background: #1e8449;
}

button.btn-small {
    padding: 6px 12px;
    font-size: 14px;
    width: auto;
    margin: 2px;
}

.menu {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 10px;
    margin: 0 0 24px;
    padding: 0;
    background: transparent;
}

.menu button {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 12px;
    min-height: 68px;
    width: 100%;
    margin: 0;
    padding: 12px 14px;
    border: 1px solid rgba(0,0,0,.07);
    border-radius: 16px;
    background: rgba(255,255,255,.92);
    color: #17202a;
    font-weight: 700;
    box-shadow: 0 6px 18px rgba(30,43,58,.07), inset 0 1px 0 rgba(255,255,255,.9);
    font-size: 15px;
    line-height: 1.35;
}

.menu button:hover,
.menu button.active {
    color: #111820;
    border-color: rgba(0,122,255,.25);
    background: #f5f9ff;
    box-shadow: 0 10px 24px rgba(24,63,103,.13);
}

.menu-icon { flex:0 0 42px; display:grid; place-items:center; width:42px; height:42px; border-radius:11px; color:#fff; font-size:20px; line-height:1; box-shadow:0 4px 10px rgba(0,0,0,.17), inset 0 1px 0 rgba(255,255,255,.35); }
.icon-employees { background:linear-gradient(145deg,#168bff,#0874e8); }
.icon-shifts { background:linear-gradient(145deg,#7069ef,#5146cb); }
.icon-schedule { background:linear-gradient(145deg,#ff5d67,#df2735); }
.icon-alerts { background:linear-gradient(145deg,#ffb52f,#ed7d0c); }
.icon-compensation { background:linear-gradient(145deg,#36c998,#139a70); }
.icon-settings { background:linear-gradient(145deg,#8d98a5,#65717e); }

.menu button:focus-visible {
    outline: 3px solid rgba(31, 111, 235, 0.3);
    outline-offset: 3px;
}

.section {
    display: none;
}

.section.active {
    display: block;
    animation: section-enter 0.22s ease-out;
}

@keyframes section-enter {
    from { opacity: 0; transform: translateY(5px); }
    to { opacity: 1; transform: translateY(0); }
}

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

.checkbox-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 10px 0;
}

.checkbox-row input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    align-items: center;
    margin: 12px 0;
}

.toolbar input,
.toolbar select {
    width: auto;
    min-width: 160px;
    margin: 0;
}

.employee-filter-panel { margin: 14px 0; padding: 14px; border: 1px solid #dfe8f2; border-radius: 13px; background: #f8fbfe; }
.filter-panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; color: #23425f; }
.filter-panel-heading span { color: #607286; font-size: 13px; }
.advanced-filters { display: grid; grid-template-columns: repeat(3, minmax(150px, 1fr)); margin-bottom: 0; }
.advanced-filters input,.advanced-filters select,.advanced-filters button { width: 100%; min-width: 0; margin: 0; }

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    background: white;
}

th {
    background: #123557;
    color: white;
    padding: 10px;
}

td {
    padding: 10px;
    border: 1px solid #ddd;
    text-align: center;
}

tbody tr:nth-child(even) { background: #f8fbfe; }
tbody tr:hover { background: #eef6ff; }

.employee-status-row { border-right: 5px solid #e9a23b; background: #fff8e6 !important; }
.employee-status-row.status-sick { border-right-color: #d94c65; background: #fff0f3 !important; }
.employee-status-row.status-course { border-right-color: #6c63d8; background: #f2f0ff !important; }
.employee-status-row.status-other { border-right-color: #718096; background: #f2f5f8 !important; }
.employee-status-row:hover { filter: brightness(.98); }

.employee-absence-row { border-right: 5px solid #d98619; background: #fff4d8 !important; }
.employee-absence-cell { color: #8a4b00; font-size: 15px; text-align: right; }
.employee-absence-cell strong { margin: 0 7px; }
.employee-absence-cell span { display: inline-block; margin-right: 8px; color: #6e5a40; font-size: 13px; }

#statusStart:disabled,
#statusEnd:disabled { cursor: not-allowed; background: #edf1f5; color: #8a98a6; opacity: .7; }

.status-badge {
    display: inline-block;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 13px;
    background: #e8f5e9;
    color: #1e8449;
}

.status-badge.leave {
    background: #fff3e0;
    color: #e67e22;
}

.status-badge.sick {
    background: #fce4ec;
    color: #c0392b;
}

.schedule-work-row {
    background: #e8f5e9 !important;
    border-right: 4px solid #27ae60;
}

.schedule-leave-row {
    background: #fff3e0 !important;
    border-right: 4px solid #e67e22;
}

.schedule-comp-row {
    background: #fff8e1 !important;
    border-right: 4px solid #f39c12;
}

.schedule-cycle-badge {
    display: inline-block;
    margin-top: 6px;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: bold;
}

.schedule-cycle-badge.work {
    background: #27ae60;
    color: white;
}

.schedule-cycle-badge.leave {
    background: #e67e22;
    color: white;
}

.alert {
    background: #fff8e1;
    border-right: 4px solid #f39c12;
    padding: 12px 16px;
    margin: 8px 0;
    border-radius: 8px;
    text-align: right;
}

.alert.danger {
    background: #fdecea;
    border-right-color: #c0392b;
}

.alert.success {
    background: #e8f5e9;
    border-right-color: #27ae60;
}

.alert.info { background: #edf6ff; border-right-color: #3182ce; }
.alert { display: flex; flex-wrap: wrap; align-items: center; gap: 7px; }
.alert > span { color: #5b6d7f; font-size: 13px; }
.alert > span:not(.alert-priority) { flex-basis: 100%; }
.alert-priority { flex-basis: auto !important; margin-left: auto; padding: 4px 8px; border-radius: 999px; background: rgba(192,57,43,.1); color: #a92f24 !important; font-weight: bold; }
.alert-summary { display: grid; grid-template-columns: repeat(4, minmax(120px,1fr)); gap: 10px; margin: 14px 0 20px; }
.alert-summary div { padding: 14px; border: 1px solid #e0e8f1; border-radius: 12px; background: #fff; box-shadow: 0 5px 13px rgba(20,56,90,.06); }
.alert-summary b,.alert-summary span { display: block; }
.alert-summary b { margin-bottom: 4px; color: #1769c2; font-size: 25px; }
.alert-summary span { color: #607286; font-size: 12px; }
.alert-group { margin: 18px 0; }
.alert-group h4 { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; color: #29445f; }
.alert-group h4 span { display: inline-grid; place-items: center; min-width: 24px; height: 24px; padding: 0 7px; border-radius: 999px; background: #e8f1fa; color: #1769c2; font-size: 12px; }

#message {
    color: #c0392b;
    text-align: center;
    margin-top: 8px;
}

.empty-state {
    text-align: center;
    padding: 30px;
    color: #7f8c8d;
}

hr {
    border: none;
    border-top: 1px solid #ddd;
    margin: 20px 0;
}

.settings-group {
    background: #f8fbfe;
    padding: 18px;
    border-radius: 12px;
    border: 1px solid #e4ecf5;
    margin-bottom: 16px;
}

.schedule-guide {
    display: grid;
    grid-template-columns: repeat(4, minmax(130px, 1fr));
    gap: 10px;
    margin: 14px 0 18px;
}

.schedule-guide-item {
    padding: 13px;
    border-radius: 12px;
    background: #f6f9fd;
    border: 1px solid #e3ebf5;
}

.schedule-guide-item strong { display: block; margin-bottom: 4px; color: #123557; }
.schedule-guide-item span { color: #607286; font-size: 13px; }
.schedule-guide-item.night { border-right: 4px solid #4c51bf; }
.schedule-guide-item.evening { border-right: 4px solid #f59e0b; }
.schedule-guide-item.morning { border-right: 4px solid #16a34a; }
.schedule-guide-item.leave { border-right: 4px solid #e67e22; }

.daily-roster-wrap {
    margin: 22px 0;
    padding: 20px;
    background: #f8fbfe;
    border: 1px solid #dfe9f3;
    border-radius: 16px;
}

.daily-roster-heading {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    align-items: center;
    margin-bottom: 12px;
}

.daily-roster-heading h4 { margin: 0 0 4px; color: #123557; font-size: 18px; }
.daily-roster-heading p { margin: 0; color: #607286; font-size: 13px; }
.roster-block { overflow-x: auto; margin: 16px 0; }
.roster-table { min-width: 720px; margin: 0; border: 1px solid #ceddea; }
.roster-table .roster-title th { padding: 13px; font-size: 16px; background: #123557; }
.roster-table .roster-columns th { background: #eaf2fb; color: #244563; font-size: 13px; }
.roster-table td { height: 42px; background: #fff; }
.roster-table .period-cell { font-weight: bold; color: #1769c2; }
.roster-block.leave-block .roster-title th { background: #a76311; }
.roster-block.leave-block .period-cell { color: #a76311; }
.roster-period { margin: 26px 0 36px; }
.roster-period h5 { margin: 0 0 12px; padding: 10px 12px; color: #123557; background: #eaf2fb; border-radius: 9px; }
.legacy-schedule-table, .legacy-schedule-controls { display: none; }

@media print {
    .daily-roster-wrap { border: 0; padding: 0; background: white; }
    .daily-roster-heading button { display: none !important; }
    .roster-block { break-inside: avoid; }
}

.settings-group h4 {
    margin-top: 0;
}

@media (max-width: 768px) {
    .login-shell { grid-template-columns: 1fr; margin: 8px auto; }
    .login-visual { min-height: 230px; padding: 30px; }
    .login-visual h2 { font-size: 28px; }
    .login-visual p { margin-bottom: 8px; }
    .brand-mark { margin-bottom: 18px; }
    .login-feature { display: none; }
    .login-panel { padding: 32px 24px; }

    .menu {
        gap: 6px;
    }

    .advanced-filters { grid-template-columns: repeat(2, minmax(130px, 1fr)); }
    .alert-summary { grid-template-columns: repeat(2, 1fr); }

    .schedule-guide { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 600px) {
    body {
        padding: 12px;
    }

    .menu {
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .advanced-filters { grid-template-columns: 1fr; }

    table {
        font-size: 13px;
    }

    th,
    td {
        padding: 6px;
    }

    .section { overflow-x: auto; }
    table { min-width: 680px; }
    .schedule-guide { grid-template-columns: 1fr; }
    .daily-roster-heading { align-items: stretch; flex-direction: column; }

    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
    }

    .today-overview { padding: 14px; }
    .overview-heading { align-items: start; flex-direction: column; }
    .shift-overview-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
    .shift-overview-card { padding: 12px; }
    .shift-overview-card { min-height: 190px; }
    .shift-period { font-size: 19px; }
    .summary-title { align-items: start; flex-direction: column; }
    .summary-details { grid-template-columns: 1fr 1fr; }
}

@media print {
    body {
        background: white;
        padding: 0;
    }

    .menu,
    .toolbar,
    .dashboard-header button,
    .stats-grid,
    #loginBox {
        display: none !important;
    }

    .card {
        box-shadow: none;
        padding: 0;
    }

    .section {
        display: none !important;
    }

    #schedule.active {
        display: block !important;
    }
}

/* ===== بطاقات إدارة مستخدمي النظام ===== */

.system-users-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.system-user-card {
  background: #fff;
  border: 1px solid #dfe5ea;
  border-radius: 12px;
  padding: 14px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  overflow-wrap: anywhere;
}

.system-user-card-title {
  font-size: 17px;
  font-weight: 700;
  margin-bottom: 10px;
  padding-bottom: 8px;
  border-bottom: 1px solid #eee;
}

.system-user-card-row {
  margin: 7px 0;
  line-height: 1.6;
}

.system-user-card-row strong {
  font-weight: 700;
}

.system-user-protected {
  margin-top: 12px;
  padding: 8px 10px;
  border-radius: 8px;
  background: #f3f4f6;
  font-weight: 700;
  text-align: center;
}

@media (max-width: 600px) {
  .system-users-cards {
    grid-template-columns: 1fr;
  }

  .system-user-card {
    width: 100%;
    box-sizing: border-box;
  }
}

/* ===== تمرير جدول الموظفين فقط على الشاشات الصغيرة ===== */

.employee-table-scroll {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
  box-sizing: border-box;
}

.employee-data-table {
  min-width: 850px;
  width: 100%;
}

/* منع جدول الموظفين من توسيع قسم الموظفين بالكامل */
#employees {
  max-width: 100%;
  overflow-x: hidden;
  box-sizing: border-box;
}

@media (max-width: 600px) {
  .employee-table-scroll {
    width: 100%;
    max-width: 100%;
    overflow-x: auto;
    touch-action: pan-x pan-y;
  }

  .employee-data-table {
    min-width: 850px;
  }
}

/* ======================================================
   نظام المراسلات
   ====================================================== */

.chat-layout {
  display: grid;
  grid-template-columns: minmax(220px, 30%) 1fr;
  gap: 14px;
  min-height: 520px;
}

.chat-groups-panel,
.chat-conversation-panel {
  border: 1px solid #ddd;
  border-radius: 14px;
  background: #fff;
  overflow: hidden;
}

.chat-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px;
  border-bottom: 1px solid #eee;
}

#chatGroupsList {
  padding: 8px;
  max-height: 520px;
  overflow-y: auto;
}

.chat-group-item {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: right;
  padding: 12px;
  margin-bottom: 7px;
  border: 0;
  border-radius: 12px;
  cursor: pointer;
}

.chat-group-item.active {
  outline: 2px solid currentColor;
}

.chat-group-preview {
  display: block;
  margin-top: 5px;
  font-size: 0.85rem;
  opacity: 0.7;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding-left: 34px;
}

.chat-unread-badge,
#messagesUnreadBadge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: bold;
  background: #d32f2f;
  color: #fff;
}

.chat-unread-badge {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
}

#chatEmptyState {
  min-height: 420px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  opacity: 0.65;
}

#chatMessagesList {
  height: 390px;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: #f7f7f7;
}

.chat-message {
  align-self: flex-start;
  width: fit-content;
  max-width: 82%;
  padding: 10px 12px;
  border-radius: 14px;
  background: #fff;
  border: 1px solid #ddd;
  word-break: break-word;
}

.chat-message.mine {
  align-self: flex-end;
}

.chat-message-alert {
  border-right: 5px solid #f0a000;
}

.chat-message-command {
  border-right: 5px solid #1976d2;
}

.chat-message-urgent {
  border-right: 5px solid #d32f2f;
}

.chat-message-header,
.chat-message-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
}

.chat-message-header {
  margin-bottom: 6px;
}

.chat-message-type,
.chat-message-footer {
  font-size: 0.75rem;
  opacity: 0.75;
}

.chat-message-text {
  white-space: pre-wrap;
  line-height: 1.6;
}

.chat-message-reply {
  padding: 7px 9px;
  margin-bottom: 7px;
  border-right: 3px solid currentColor;
  background: rgba(0, 0, 0, 0.05);
  border-radius: 7px;
  font-size: 0.85rem;
}

.chat-reply-btn {
  border: 0;
  background: transparent;
  cursor: pointer;
  padding: 4px;
}

#chatReplyBox {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-top: 1px solid #ddd;
}

#chatReplyBox.hidden {
  display: none;
}

.chat-compose {
  display: grid;
  grid-template-columns: 150px 1fr auto;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #ddd;
  align-items: stretch;
}

.chat-compose textarea {
  resize: vertical;
  min-height: 48px;
  max-height: 160px;
}

#chatStatusMessage {
  margin: 0;
  padding: 0 12px 10px;
}

.chat-no-messages {
  margin: auto;
  opacity: 0.65;
}

/* الهاتف والآيفون */
@media (max-width: 700px) {
  .chat-layout {
    grid-template-columns: 1fr;
    min-height: auto;
  }

  #chatGroupsList {
    max-height: 210px;
  }

  #chatMessagesList {
    height: 52vh;
    min-height: 320px;
  }

  .chat-message {
    max-width: 90%;
  }

  .chat-compose {
    grid-template-columns: 1fr;
  }

  .chat-compose textarea {
    font-size: 16px;
  }

  #chatSendBtn {
    min-height: 46px;
  }
}

/* ===== مرفقات المحادثة ===== */

.chat-message-attachments {
  margin-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.chat-attachment-item {
  max-width: 100%;
}

.chat-attachment-image {
  display: block;
  width: auto;
  max-width: 100%;
  max-height: 360px;
  border-radius: 12px;
  object-fit: contain;
  cursor: pointer;
}

.chat-attachment-loading {
  padding: 8px 10px;
  font-size: 13px;
  opacity: 0.75;
}

.chat-attachment-file {
  width: 100%;
  max-width: 320px;
  padding: 10px 12px;
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.75);
  text-align: start;
  cursor: pointer;
  overflow-wrap: anywhere;
}

.chat-attachment-file:disabled {
  opacity: 0.65;
  cursor: wait;
}

@media (max-width: 600px) {
  .chat-attachment-image {
    max-height: 300px;
  }

  .chat-attachment-file {
    max-width: 100%;
  }
}

/* ===== الصوت والفيديو داخل المحادثة ===== */

.chat-attachment-audio {
  display: block;
  width: 100%;
  max-width: 320px;
  margin-top: 6px;
}

.chat-attachment-video {
  display: block;
  width: 100%;
  max-width: 420px;
  max-height: 420px;
  margin-top: 6px;
  border-radius: 12px;
  object-fit: contain;
  background: #000;
}

@media (max-width: 600px) {
  .chat-attachment-audio,
  .chat-attachment-video {
    max-width: 100%;
  }

  .chat-attachment-video {
    max-height: 360px;
  }
}
