/* ============================================
   سيستم المشاكل (منصة عبدالمعبود)
   تصميم مبسط وواضح
   ============================================ */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #dde1e6;
  --text: #24292f;
  --muted: #6b7280;
  --main: #3a5f8a;
  --main-dark: #2c4a6e;
  --danger: #b03a3a;
  --success: #2a7a3f;
}

body {
  font-family: 'Segoe UI', Tahoma, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.6;
}
a { color: var(--main); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- الهيدر ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 10px 20px;
  display: flex;
  align-items: center;
  gap: 15px;
  flex-wrap: wrap;
}
.topbar .brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); }
.topbar .brand img { height: 36px; width: auto; }
.topbar nav { display: flex; gap: 4px; flex-wrap: wrap; margin-inline-start: 10px; }
.topbar nav a {
  padding: 6px 12px; border-radius: 6px; color: var(--text); font-size: 14px;
}
.topbar nav a:hover { background: #eef1f5; text-decoration: none; }
.topbar nav a.active { background: var(--main); color: #fff; }
.topbar .user-area { margin-inline-start: auto; display: flex; align-items: center; gap: 10px; font-size: 14px; }
.topbar .user-area .logout { color: var(--danger); }

/* ---------- الحاوية ---------- */
.container { max-width: 1100px; margin: 25px auto; padding: 0 15px; }
.container.narrow { max-width: 560px; }

.page-head { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 10px; margin-bottom: 18px; }
.page-head h1 { font-size: 20px; }

/* ---------- الكروت ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 20px; margin-bottom: 18px; }
.card h2 { font-size: 16px; margin-bottom: 12px; }

/* ---------- الفورم ---------- */
label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 14px; }
.hint { font-weight: 400; color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=url], textarea, select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: 6px;
  font-family: inherit; font-size: 14.5px; background: #fff; color: var(--text);
}
input:focus, textarea:focus, select:focus { outline: 2px solid #b9cbe0; border-color: var(--main); }
textarea { min-height: 110px; resize: vertical; }
.field { margin-bottom: 15px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 15px; }
@media (max-width: 600px) { .row2 { grid-template-columns: 1fr; } }

.btn {
  display: inline-block; padding: 9px 18px; border: none; border-radius: 6px;
  background: var(--main); color: #fff; font-size: 14.5px; font-family: inherit;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--main-dark); text-decoration: none; }
.btn-light { background: #eef1f5; color: var(--text); border: 1px solid var(--border); }
.btn-light:hover { background: #e2e6ec; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #8f2e2e; }
.btn-success { background: var(--success); }
.btn-success:hover { background: #206232; }
.btn-sm { padding: 5px 12px; font-size: 13px; }

/* ---------- رسائل الفلاش ---------- */
.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 15px; font-size: 14px; }
.flash-success { background: #e7f5ec; border: 1px solid #b7dcc4; color: #1e5c30; }
.flash-error { background: #fbeaea; border: 1px solid #e5b8b8; color: #8f2e2e; }

/* ---------- شارات الأولوية والحالة ---------- */
.badge { display: inline-block; padding: 2px 10px; border-radius: 20px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.pr-1 { background: #eef1f5; color: #5a6472; }
.pr-2 { background: #e4eef8; color: #2f5d8a; }
.pr-3 { background: #fdf3d7; color: #8a6d1a; }
.pr-4 { background: #fde8d7; color: #9c5518; }
.pr-5 { background: #fbdddd; color: #a12828; }
.st-new { background: #e4eef8; color: #2f5d8a; }
.st-in_progress { background: #fdf3d7; color: #8a6d1a; }
.st-solved { background: #e7f5ec; color: #1e5c30; }

/* ---------- جدول المشاكل ---------- */
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-bottom: 15px; }
.filters .field { margin-bottom: 0; min-width: 150px; flex: 1; }
.filters .field.grow2 { flex: 2; }

.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 14px; text-align: right; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: #f8f9fb; font-size: 13px; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
td .prob-title { font-weight: 600; color: var(--text); }
td .prob-title:hover { color: var(--main); }
.row-solved { opacity: 0.65; }

/* ---------- صفحة المشكلة ---------- */
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 15px; }
.meta-item { background: #f8f9fb; border: 1px solid var(--border); border-radius: 6px; padding: 8px 12px; font-size: 13.5px; }
.meta-item b { display: block; color: var(--muted); font-weight: 600; font-size: 12px; margin-bottom: 2px; }

.desc-box { background: #fbfcfd; border: 1px solid var(--border); border-radius: 6px; padding: 14px; white-space: pre-wrap; word-break: break-word; }

.attachments { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.attachments a.thumb img { width: 130px; height: 100px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); display: block; }
.attachments a.thumb img:hover { outline: 2px solid var(--main); }
.attachments video { max-width: 100%; width: 420px; border-radius: 6px; border: 1px solid var(--border); }
.links-list { margin-top: 8px; padding-inline-start: 0; list-style: none; }
.links-list li { margin: 4px 0; word-break: break-all; }
.links-list li::before { content: '🔗 '; }

/* ---------- التايم لاين ---------- */
.timeline { border-inline-start: 3px solid var(--border); margin: 10px 8px; padding-inline-start: 18px; }
.timeline .tl-item { position: relative; margin-bottom: 14px; font-size: 14px; }
.timeline .tl-item::before {
  content: ''; position: absolute; inset-inline-start: -26px; top: 6px;
  width: 11px; height: 11px; border-radius: 50%; background: var(--main); border: 2px solid #fff;
}
.timeline .tl-item.tl-solved::before { background: var(--success); }
.timeline .tl-time { color: var(--muted); font-size: 12.5px; }
.timeline .tl-comment { background: #f8f9fb; border: 1px solid var(--border); border-radius: 6px; padding: 6px 10px; margin-top: 4px; font-size: 13.5px; white-space: pre-wrap; }

/* ---------- الأفاتار ---------- */
.avatar { border-radius: 50%; object-fit: cover; vertical-align: middle; flex-shrink: 0; }
.avatar-letter { display: inline-flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; }

/* ---------- الكومنتات ---------- */
.comment { display: flex; gap: 10px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: none; }
.comment .c-body { flex: 1; }
.comment .c-head { display: flex; align-items: center; gap: 8px; margin-bottom: 3px; }
.comment .c-head .c-name { font-weight: 700; font-size: 14px; }
.comment .c-head .c-time { color: var(--muted); font-size: 12px; }
.comment .c-text { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; }

/* ---------- سجل النشاط ---------- */
.log-item { display: flex; gap: 10px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.log-item:last-child { border-bottom: none; }
.log-item .l-time { color: var(--muted); font-size: 12.5px; }

/* ---------- صفحة الدخول ---------- */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 15px; }
.login-box { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 32px; width: 100%; max-width: 380px; text-align: center; }
.login-box img.logo { height: 60px; margin-bottom: 10px; }
.login-box h1 { font-size: 18px; margin-bottom: 20px; }
.login-box form { text-align: right; }
.login-box .btn { width: 100%; margin-top: 5px; }

/* ---------- صلاحيات المستخدمين ---------- */
.perms { display: flex; flex-wrap: wrap; gap: 12px; }
.perms label { display: flex; align-items: center; gap: 6px; font-weight: 400; background: #f8f9fb; border: 1px solid var(--border); border-radius: 6px; padding: 6px 12px; cursor: pointer; margin: 0; }
.perms input { accent-color: var(--main); }

/* ---------- إحصائيات سريعة ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: 8px; padding: 14px; text-align: center; }
.stat .num { font-size: 26px; font-weight: 700; }
.stat .lbl { color: var(--muted); font-size: 13px; }
.stat.s-new .num { color: var(--main); }
.stat.s-prog .num { color: #8a6d1a; }
.stat.s-done .num { color: var(--success); }

.empty { text-align: center; color: var(--muted); padding: 35px 15px; }

/* ---------- الموبايل ---------- */
@media (max-width: 700px) {
  .topbar { padding: 8px 12px; }
  .topbar nav { order: 3; width: 100%; }
  th, td { padding: 8px 10px; font-size: 13px; }
  .container { margin-top: 15px; }
}

/* ============================================
   إضافات النسخة الثانية
   ============================================ */

/* ---------- اللايت بوكس ---------- */
.lightbox {
  position: fixed; inset: 0; z-index: 1000;
  background: rgba(15, 20, 28, 0.88);
  display: none; align-items: center; justify-content: center;
  padding: 30px;
}
.lightbox.show { display: flex; }
.lightbox img { max-width: 95%; max-height: 92vh; border-radius: 8px; box-shadow: 0 8px 40px rgba(0,0,0,.5); }
.lightbox .lb-close {
  position: absolute; top: 15px; inset-inline-start: 15px;
  width: 40px; height: 40px; border-radius: 50%;
  border: none; background: rgba(255,255,255,.15); color: #fff;
  font-size: 18px; cursor: pointer;
}
.lightbox .lb-close:hover { background: rgba(255,255,255,.3); }

/* ---------- بلوك الوسائط والمعاينة ---------- */
.media-block { border: 1px dashed var(--border); border-radius: 8px; padding: 12px; background: #fbfcfd; }
.media-block .mi-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.media-block .mi-hint { color: var(--muted); font-size: 12.5px; margin-top: 6px; }
.mi-rec.recording { background: var(--danger); color: #fff; border-color: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: .75; } }

.mi-previews { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 10px; }
.pv { position: relative; }
.pv-img img { width: 95px; height: 75px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; display: block; }
.pv-audio audio { height: 40px; max-width: 260px; }
.pv .pv-x {
  position: absolute; top: -7px; inset-inline-end: -7px;
  width: 22px; height: 22px; border-radius: 50%; border: none;
  background: var(--danger); color: #fff; font-size: 11px; cursor: pointer; line-height: 1;
}

/* ---------- مرفقات صغيرة (كومنتات وأحداث) ---------- */
.att-sm { margin-top: 8px; }
.att-sm a.thumb img { width: 95px; height: 75px; }
.att-sm audio { height: 38px; max-width: 280px; vertical-align: middle; }

/* ---------- التوست ---------- */
.toast {
  position: fixed; bottom: 25px; inset-inline-start: 50%; transform: translateX(50%);
  background: #24292f; color: #fff; padding: 10px 20px; border-radius: 25px;
  font-size: 14px; z-index: 1100; opacity: 0; pointer-events: none; transition: opacity .25s;
}
.toast.show { opacity: 1; }

/* ---------- شارة مخفية ---------- */
.badge-hidden { background: #ece7f5; color: #5b4a8a; }

/* ---------- زر لم يتم الحل ---------- */
.reopen-box { background: #fdf6ee; border: 1px solid #ecd9bd; border-radius: 8px; padding: 14px; margin-top: 12px; }
.reopen-box h3 { font-size: 14.5px; margin-bottom: 8px; }

/* ---------- حدث إعادة الفتح في التايم لاين ---------- */
.timeline .tl-item.tl-reopen::before { background: #b5762a; }

@media (prefers-reduced-motion: reduce) {
  .mi-rec.recording { animation: none; }
}
