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

/* هوية بصرية مشتقة من شعار الإدارة: أخضر عسكري داكن + ذهبي رملي */
:root {
  --bg: #f6f5f1;
  --card: #ffffff;
  --border: #e3e1d8;
  --text: #1d251f;
  --muted: #6f7a70;
  --green-950: #1c2921;
  --green-900: #22322a;
  --green-800: #2c4136;
  --green-700: #3a5546;
  --gold: #b3a269;
  --gold-dark: #98894f;
  --gold-tint: #f3efe2;
  --primary: var(--green-800);
  --primary-hover: var(--green-900);
  --danger: #b3362b;
  --success: #3d7a4e;
  --warning: #a8762e;
  --radius: 6px;
  --shadow: 0 1px 2px rgba(29,37,31,.06);
  --sidebar-w: 240px;
}

html, body { height: 100%; }

body {
  font-family: "IBM Plex Sans Arabic", "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.65;
}

button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }

/* أيقونات SVG الموحدة */
.ic {
  width: 18px;
  height: 18px;
  flex: none;
  vertical-align: -3px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ic.lg { width: 22px; height: 22px; }
.ic.sm { width: 15px; height: 15px; vertical-align: -2px; }

/* ===== تسجيل الدخول ===== */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(1100px 550px at 50% -10%, rgba(179,162,105,.14), transparent 60%),
    var(--green-950);
  padding: 16px;
}
.login-card {
  background: var(--card);
  border-radius: 10px;
  border-top: 4px solid var(--gold);
  padding: 34px 32px 30px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 60px rgba(0,0,0,.45);
}
.login-card h1 { font-size: 1.15rem; text-align: center; margin-bottom: 2px; color: var(--green-900); }
.login-card .sub { text-align: center; color: var(--muted); font-size: .82rem; margin-bottom: 22px; }
.login-logo { text-align: center; margin-bottom: 10px; }

/* ===== الهيكل العام ===== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--green-900) 0%, var(--green-950) 100%);
  color: #cfd6cf;
  display: flex;
  flex-direction: column;
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  z-index: 20;
}
.sidebar .brand {
  padding: 16px 16px 14px;
  color: #fff;
  border-bottom: 1px solid rgba(179,162,105,.25);
  display: flex;
  align-items: center;
  gap: 10px;
}
.sidebar .brand .brand-logo {
  background: #fff;
  border-radius: 8px;
  padding: 4px;
  width: 46px;
  height: 46px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
}
.sidebar .brand .brand-logo img { max-width: 100%; max-height: 100%; display: block; }
.sidebar .brand .brand-text { font-weight: 700; font-size: .92rem; line-height: 1.35; }
.sidebar .brand small { display: block; font-weight: 500; color: var(--gold); font-size: .72rem; }
.sidebar nav { flex: 1; padding: 10px 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #cfd6cf;
  text-decoration: none;
  padding: 9px 12px;
  border-radius: var(--radius);
  font-size: .88rem;
  margin-bottom: 2px;
  border-inline-start: 3px solid transparent;
}
.sidebar nav a .ic { opacity: .8; }
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active {
  background: rgba(179,162,105,.16);
  color: #fff;
  border-inline-start-color: var(--gold);
}
.sidebar nav a.active .ic { opacity: 1; stroke: var(--gold); }
.sidebar .user-box {
  padding: 14px 16px;
  border-top: 1px solid rgba(179,162,105,.25);
  font-size: .82rem;
}
.sidebar .user-box .name { color: #fff; font-weight: 600; }
.sidebar .user-box .role { color: var(--gold); font-size: .76rem; }
.sidebar .user-box button {
  margin-top: 8px;
  width: 100%;
  background: rgba(255,255,255,.07);
  color: #e5e9e5;
  border: 1px solid rgba(255,255,255,.12);
  border-radius: var(--radius);
  padding: 7px;
  font-size: .8rem;
}
.sidebar .user-box button:hover { background: rgba(255,255,255,.14); }

.main {
  flex: 1;
  margin-inline-start: var(--sidebar-w);
  padding: 26px 30px 60px;
  max-width: 1200px;
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h2 { font-size: 1.25rem; color: var(--green-900); display: flex; align-items: center; gap: 8px; }
.page-head h2 .ic { stroke: var(--gold-dark); }
.page-head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ===== البطاقات والإحصاءات ===== */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.card h3 { font-size: .98rem; margin-bottom: 12px; color: var(--green-900); }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat {
  background: var(--card);
  border: 1px solid var(--border);
  border-inline-start: 3px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.stat .num { font-size: 1.6rem; font-weight: 700; color: var(--green-900); }
.stat .lbl { color: var(--muted); font-size: .8rem; }
.stat.blue { border-inline-start-color: var(--green-700); }
.stat.blue .num { color: var(--green-800); }
.stat.green { border-inline-start-color: var(--gold); }
.stat.green .num { color: var(--gold-dark); }
.stat.orange { border-inline-start-color: var(--warning); }
.stat.orange .num { color: var(--warning); }

/* ===== الجداول ===== */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .87rem; }
th, td { text-align: right; padding: 10px 12px; border-bottom: 1px solid var(--border); }
th {
  color: var(--green-800);
  font-weight: 600;
  font-size: .76rem;
  white-space: nowrap;
  background: #f4f3ec;
  border-bottom: 2px solid #e0ddcf;
}
tbody tr:hover { background: #faf9f5; }
td.actions { white-space: nowrap; }

.badge {
  display: inline-block;
  padding: 1px 10px;
  border-radius: 4px;
  font-size: .74rem;
  font-weight: 600;
  border: 1px solid transparent;
}
.badge.work { background: #eaf0eb; color: var(--green-800); border-color: #cfdbd2; }
.badge.training { background: var(--gold-tint); color: #7c6c33; border-color: #e0d7b8; }
.badge.gray { background: #f1f1ec; color: #616b62; border-color: #e0e0d8; }
.badge.green { background: #e9f2ea; color: var(--success); border-color: #cfe2d3; }
.badge.red { background: #f9e9e7; color: var(--danger); border-color: #eccfcb; }

/* ===== الأزرار والنماذج ===== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-size: .86rem;
  font-weight: 600;
  background: var(--primary);
  color: #fff;
}
.btn:hover { background: var(--primary-hover); }
.btn.secondary { background: var(--card); color: var(--green-900); border-color: var(--border); }
.btn.secondary:hover { background: var(--gold-tint); border-color: #d8d0b4; }
.btn.danger { background: #fff; color: var(--danger); border-color: #e5c5c1; }
.btn.danger:hover { background: #faf0ef; }
.btn.sm { padding: 4px 10px; font-size: .78rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: .82rem; font-weight: 600; margin-bottom: 5px; color: var(--green-900); }
.field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  background: #fff;
  font-size: .9rem;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid rgba(179,162,105,.35);
  border-color: var(--gold);
}
.field .hint { color: var(--muted); font-size: .75rem; margin-top: 3px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checkbox-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--green-800); }

/* ===== الطلعات داخل نموذج المهمة ===== */
.sortie-box {
  border: 1px dashed #d5d2c4;
  border-radius: var(--radius);
  padding: 12px;
  margin-bottom: 10px;
  background: #faf9f4;
}
.sortie-box .sortie-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-size: .82rem; font-weight: 700; color: var(--green-800); }
.sortie-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ===== النوافذ المنبثقة ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(28,41,33,.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  z-index: 50;
  overflow-y: auto;
}
.modal {
  background: var(--card);
  border-radius: 8px;
  border-top: 3px solid var(--gold);
  padding: 24px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}
.modal h3 { margin-bottom: 16px; font-size: 1.02rem; color: var(--green-900); }
.modal .modal-actions { display: flex; gap: 8px; justify-content: flex-start; margin-top: 18px; }

/* ===== التنبيهات ===== */
#toast {
  position: fixed;
  bottom: 24px;
  inset-inline-start: 50%;
  transform: translateX(50%);
  background: var(--green-900);
  color: #fff;
  border-inline-start: 3px solid var(--gold);
  padding: 11px 22px;
  border-radius: var(--radius);
  font-size: .87rem;
  box-shadow: 0 10px 30px rgba(0,0,0,.3);
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--danger); border-inline-start-color: #7c1f16; }

.empty { text-align: center; color: var(--muted); padding: 30px 10px; font-size: .9rem; }
.error-text { color: var(--danger); font-size: .84rem; margin-top: 8px; min-height: 1.2em; }

/* ===== القسم اللوجستي ===== */
.badge.p-low { background: #f1f1ec; color: #616b62; border-color: #e0e0d8; }
.badge.p-normal { background: #eaf0eb; color: var(--green-800); border-color: #cfdbd2; }
.badge.p-high { background: #f7efdd; color: var(--warning); border-color: #e7d7b3; }
.badge.p-urgent { background: #f9e9e7; color: var(--danger); border-color: #eccfcb; }

.badge.st-pending { background: var(--gold-tint); color: #7c6c33; border-color: #e0d7b8; }
.badge.st-approved { background: #eaf0eb; color: var(--green-800); border-color: #cfdbd2; }
.badge.st-purchased { background: #e8ecf4; color: #40527e; border-color: #ccd5e6; }
.badge.st-prepared { background: #e5f0f0; color: #2f6b6b; border-color: #c8e0e0; }
.badge.st-shipped { background: #e9f2ea; color: var(--success); border-color: #cfe2d3; }
.badge.st-delivered { background: #e9f2ea; color: var(--success); border-color: #cfe2d3; }
.badge.st-rejected { background: #f9e9e7; color: var(--danger); border-color: #eccfcb; }
.badge.st-new { background: #f1f1ec; color: #616b62; border-color: #e0e0d8; }
.badge.st-in_progress { background: #eaf0eb; color: var(--green-800); border-color: #cfdbd2; }
.badge.st-review { background: var(--gold-tint); color: #7c6c33; border-color: #e0d7b8; }
.badge.st-done { background: #e9f2ea; color: var(--success); border-color: #cfe2d3; }
.badge.st-cancelled { background: #f1f1ec; color: #8a938b; border-color: #e0e0d8; }
.badge.st-at_workshop { background: #e8ecf4; color: #40527e; border-color: #ccd5e6; }
.badge.st-repaired { background: #e5f0f0; color: #2f6b6b; border-color: #c8e0e0; }
.badge.st-irreparable { background: #f9e9e7; color: var(--danger); border-color: #eccfcb; }
.badge.late { background: #f9e9e7; color: var(--danger); border-color: #eccfcb; }

.progress { background: #e8e6dc; border-radius: 999px; height: 7px; overflow: hidden; min-width: 70px; }
.progress > i { display: block; height: 100%; background: var(--gold); border-radius: 999px; transition: width .3s; }
.progress.done > i { background: var(--success); }
.progress-wrap { display: flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); }

.filters-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.filters-bar select, .filters-bar input {
  border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px;
  background: #fff; font-size: .84rem;
}

.modal.lg { max-width: 720px; }

.info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 8px 16px; margin-bottom: 14px; font-size: .88rem; }
.info-grid .lbl { color: var(--muted); font-size: .75rem; }

.timeline { list-style: none; margin: 8px 0; }
.timeline li { border-inline-start: 2px solid var(--border); padding: 4px 14px 12px; margin-inline-start: 6px; position: relative; font-size: .84rem; }
.timeline li::before { content: ""; position: absolute; inset-inline-start: -6px; top: 9px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); border: 2px solid #fff; }
.timeline li .meta { color: var(--muted); font-size: .74rem; }

.item-row { display: grid; grid-template-columns: 2fr 80px 100px 36px; gap: 8px; margin-bottom: 8px; }
.item-row input { border: 1px solid var(--border); border-radius: var(--radius); padding: 8px 10px; font-size: .88rem; width: 100%; }
.item-row button { border: 1px solid #e5c5c1; background: #fff; color: var(--danger); border-radius: var(--radius); }

.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.attach-list a {
  display: inline-flex; gap: 5px; align-items: center; text-decoration: none;
  background: #f1f1ec; color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 4px 10px; font-size: .8rem;
}
.attach-list a:hover { background: var(--gold-tint); }

.bell { position: relative; background: rgba(255,255,255,.07); color: #e5e9e5; border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius); padding: 7px 10px; cursor: pointer; }
.bell:hover { background: rgba(255,255,255,.14); }
.bell-badge {
  position: absolute; top: -6px; inset-inline-start: -6px;
  background: var(--danger); color: #fff; border-radius: 999px;
  font-size: .68rem; font-weight: 700; padding: 1px 6px; min-width: 18px; text-align: center;
}
.notif-item { padding: 10px 4px; border-bottom: 1px solid var(--border); font-size: .86rem; cursor: pointer; }
.notif-item:hover { background: #faf9f5; }
.notif-item.unread { font-weight: 600; }
.notif-item .meta { color: var(--muted); font-size: .74rem; font-weight: 400; }

.section-title { font-size: 1.02rem; margin: 22px 0 12px; color: var(--green-900); }

/* ===== الطباعة الرسمية ===== */
.print-header { display: none; }
@media print {
  .sidebar, .page-head .tools, .btn, #toast, .bell { display: none !important; }
  .main { margin: 0; padding: 0; max-width: none; }
  body { background: #fff; font-size: 12px; }
  .card, .stat { box-shadow: none; break-inside: avoid; }
  .print-header {
    display: flex; align-items: center; gap: 14px;
    border-bottom: 2px solid var(--green-900); padding-bottom: 10px; margin-bottom: 16px;
  }
  .print-header img { height: 64px; }
  .print-header .t1 { font-weight: 700; font-size: 15px; color: var(--green-900); }
  .print-header .t2 { font-size: 12px; color: #555; }
}

/* ===== الجوال ===== */
@media (max-width: 820px) {
  .sidebar { position: static; width: 100%; flex-direction: row; flex-wrap: wrap; inset: auto; }
  .sidebar .brand { width: 100%; padding: 12px 14px 10px; }
  .sidebar nav { display: flex; flex-wrap: wrap; padding: 6px; }
  .sidebar nav a { margin: 2px; padding: 7px 10px; border-inline-start: none; }
  .sidebar nav a.active { border: 1px solid rgba(179,162,105,.5); }
  .sidebar .user-box { width: 100%; display: flex; align-items: center; gap: 10px; justify-content: space-between; }
  .sidebar .user-box button { width: auto; margin: 0; }
  .layout { flex-direction: column; }
  .main { margin-inline-start: 0; padding: 16px 14px 50px; }
  .field-row, .sortie-grid { grid-template-columns: 1fr; }
  .item-row { grid-template-columns: 1fr 64px 76px 32px; }
  .filters-bar select, .filters-bar input { font-size: .8rem; padding: 7px 8px; }
}
