/* نظام تذاكر الدعم الفني — تصميم متجاوب من اليمين لليسار */
:root {
  --primary: #1d4f91;
  --primary-600: #173f74;
  --primary-50: #eef3fb;
  --bg: #f3f5f9;
  --surface: #ffffff;
  --text: #1c2333;
  --muted: #6b7385;
  --border: #e1e6ef;
  --success: #16794a;
  --success-50: #e8f6ee;
  --danger: #c0352b;
  --danger-50: #fdecea;
  --warn: #b25e00;
  --warn-50: #fff4e5;
  --info-50: #eaf2fd;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 1px 3px rgba(16, 24, 40, .06);
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: "Tajawal", Tahoma, "Segoe UI", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: var(--text);
  background: var(--bg);
  direction: rtl;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3 { line-height: 1.35; margin: 0 0 .4em; }
h1 { font-size: 1.6rem; font-weight: 800; }
code { font-family: Consolas, Menlo, monospace; background: var(--primary-50); padding: 1px 6px; border-radius: 6px; }
img { max-width: 100%; }

.container { width: 100%; max-width: 1180px; margin: 0 auto; padding: 0 16px; }
.main { flex: 1; padding-top: 24px; padding-bottom: 40px; }
.narrow { max-width: 640px; margin-inline: auto; }
.is-public .main { max-width: 860px; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger); }
.hint { display: block; color: var(--muted); font-size: .85rem; margin: 4px 0 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.center { justify-content: center; text-align: center; }
ul.plain { margin: 0; padding-inline-start: 18px; }

/* ===== الشريط العلوي ===== */
.topbar { background: var(--primary); color: #fff; position: sticky; top: 0; z-index: 50; box-shadow: 0 2px 8px rgba(0,0,0,.08); }
.topbar-inner { display: flex; align-items: center; justify-content: space-between; min-height: 60px; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 700; font-size: 1.05rem; }
.brand:hover { text-decoration: none; }
.brand-mark { width: 36px; height: 36px; border-radius: 10px; background: rgba(255,255,255,.15); display: grid; place-items: center; flex-shrink: 0; }
.brand-text small { font-weight: 400; opacity: .75; font-size: .8rem; margin-inline-start: 6px; }
.nav { display: flex; gap: 4px; align-items: center; }
.nav a { color: rgba(255,255,255,.88); padding: 8px 12px; border-radius: 8px; font-size: .95rem; white-space: nowrap; }
.nav a:hover { background: rgba(255,255,255,.12); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.18); color: #fff; font-weight: 700; }
.nav-toggle { display: none; background: none; border: 0; padding: 10px; cursor: pointer; }
.nav-toggle span { display: block; width: 22px; height: 2px; background: #fff; margin: 5px 0; border-radius: 2px; transition: .2s; }

.footer { color: var(--muted); font-size: .85rem; padding: 18px 0; text-align: center; border-top: 1px solid var(--border); background: var(--surface); }

/* ===== البطاقات والعناوين ===== */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; box-shadow: var(--shadow); margin-bottom: 18px; }
.card-title { font-size: 1.1rem; font-weight: 700; margin-bottom: 14px; }
.page-head { margin-bottom: 18px; }
.page-head p { margin: 0; }
.section-title { font-size: 1.1rem; margin: 26px 0 12px; }
.empty { text-align: center; padding: 32px 20px; }
.back-link { display: inline-block; margin-bottom: 12px; font-size: .95rem; }

/* ===== الصفحة الرئيسية ===== */
.hero { text-align: center; padding: 26px 0 10px; }
.hero h1 { font-size: 2rem; }
.hero p { color: var(--muted); font-size: 1.05rem; max-width: 620px; margin: 0 auto; }
.choice-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; margin-top: 24px; }
.choice-card { display: flex; flex-direction: column; gap: 8px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 26px; color: var(--text); box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s, border-color .15s; }
.choice-card:hover { text-decoration: none; transform: translateY(-2px); border-color: var(--primary); box-shadow: 0 8px 24px rgba(29,79,145,.12); }
.choice-card strong { font-size: 1.2rem; }
.choice-card span:last-child { color: var(--muted); font-size: .95rem; }
.choice-icon { width: 52px; height: 52px; border-radius: 14px; background: var(--primary-50); color: var(--primary); display: grid; place-items: center; }
.choice-icon.alt { background: var(--success-50); color: var(--success); }

/* ===== النماذج ===== */
.form .field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 500; margin-bottom: 6px; font-size: .95rem; }
.req { color: var(--danger); font-weight: 700; }
input[type=text], input[type=email], input[type=password], input[type=tel], input[type=number], input[type=search], input:not([type]), select, textarea {
  width: 100%; font: inherit; color: var(--text); background: #fff;
  border: 1px solid #cdd4e0; border-radius: 10px; padding: 10px 12px; min-height: 46px;
  transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 110px; line-height: 1.7; }
select { appearance: none; -webkit-appearance: none; padding-left: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%236b7385' d='M6 8 0 0h12z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: left 14px center; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,79,145,.15); }
input[type=file] { width: 100%; font: inherit; font-size: .9rem; padding: 10px; border: 1px dashed #b9c2d3; border-radius: 10px; background: #fafbfd; }
input[readonly] { background: #f7f8fb; }
input[dir=ltr], textarea[dir=ltr] { text-align: left; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); background: #fffafa; }
.field-error { color: var(--danger); font-size: .85rem; margin-top: 5px; }
.grid-2, .grid-3 { display: grid; gap: 0 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-1 { display: block; }
.compact { align-items: center; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.field.inline { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.field.inline > span { margin: 0; }
.field.inline input { width: 90px; }

/* ===== الأزرار ===== */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font: inherit; font-weight: 700; font-size: .95rem; border: 1px solid transparent; border-radius: 10px; padding: 10px 20px; min-height: 46px; cursor: pointer; text-decoration: none !important; transition: background .15s, opacity .15s; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-light { background: #fff; color: var(--primary); border-color: #cdd4e0; }
.btn-light:hover { background: var(--primary-50); }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { color: var(--success); border-color: var(--success); }
.btn-danger { background: #fff; color: var(--danger); border-color: #f0c2bd; }
.btn-danger:hover { background: var(--danger-50); }
.btn-block { width: 100%; }
.btn-sm { min-height: 36px; padding: 6px 12px; font-size: .85rem; }
.btn[disabled], .btn.is-loading { opacity: .6; cursor: not-allowed; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ===== التنبيهات ===== */
.alert { border-radius: 10px; padding: 12px 16px; margin-bottom: 16px; font-size: .95rem; border: 1px solid transparent; }
.alert-success { background: var(--success-50); color: var(--success); border-color: #bfe5cf; }
.alert-error { background: var(--danger-50); color: var(--danger); border-color: #f5c6c1; }
.alert-warning { background: var(--warn-50); color: var(--warn); border-color: #fbd9a8; }
.alert-info { background: var(--info-50); color: #1f4f8a; border-color: #c9dcf5; }

.spam-note { display: flex; gap: 8px; align-items: flex-start; background: var(--warn-50); color: #8a4a00; border: 1px solid #fbd9a8; border-radius: 8px; padding: 7px 10px; font-size: .82rem; line-height: 1.6; margin: 8px 0 0; }
.spam-icon { flex-shrink: 0; width: 18px; height: 18px; border-radius: 50%; background: #e08a00; color: #fff; font-weight: 800; font-size: .75rem; display: grid; place-items: center; margin-top: 2px; }
.success-card .spam-note { text-align: right; max-width: 520px; margin: 12px auto 0; }

.checklist { list-style: none; margin: 0; padding: 0; }
.checklist li { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.checklist li:last-child { border: 0; }
.checklist .ok span { color: var(--success); font-weight: 800; }
.checklist .bad { color: var(--danger); }

/* ===== نجاح الإرسال ===== */
.success-card { text-align: center; padding: 30px 20px; border-color: #bfe5cf; }
.success-icon { width: 64px; height: 64px; margin: 0 auto 12px; border-radius: 50%; background: var(--success-50); color: var(--success); font-size: 2rem; font-weight: 800; display: grid; place-items: center; }
.ticket-number { display: inline-flex; align-items: center; gap: 10px; flex-wrap: wrap; justify-content: center; margin-bottom: 10px; }
.ticket-number code { font-size: 1.4rem; font-weight: 800; color: var(--primary); padding: 6px 14px; letter-spacing: .5px; }

/* ===== التذكرة ===== */
.ticket-head-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; flex-wrap: wrap; }
.ticket-no { color: var(--primary); font-weight: 700; font-size: .95rem; text-align: right; }
.ticket-subject { font-size: 1.3rem; margin: 2px 0 0; word-break: break-word; }
.head-badges { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.meta { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px 18px; margin: 16px 0 0; padding-top: 14px; border-top: 1px solid var(--border); }
.meta dt { color: var(--muted); font-size: .8rem; }
.meta dd { margin: 0; font-weight: 500; word-break: break-word; }
.meta-stack { grid-template-columns: 1fr; margin: 0; padding: 0; border: 0; gap: 10px; }

.badge { display: inline-block; padding: 3px 12px; border-radius: 999px; font-size: .8rem; font-weight: 700; white-space: nowrap; }
.st-new { background: #e7efff; color: #2457b8; }
.st-open { background: #e6f6ef; color: #16794a; }
.st-waiting_customer { background: #fff4e5; color: #a35400; }
.st-resolved { background: #eef0ff; color: #5146b8; }
.st-closed { background: #eef0f3; color: #5e6676; }

.sla { display: inline-block; font-size: .8rem; font-weight: 700; padding: 2px 10px; border-radius: 999px; white-space: nowrap; }
.sla-ok { background: #eef3fb; color: var(--primary); }
.sla-warn { background: var(--warn-50); color: var(--warn); }
.sla-late { background: var(--danger-50); color: var(--danger); }
.sla-none { color: var(--muted); }

.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 18px; }
.msg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; max-width: 88%; box-shadow: var(--shadow); }
.msg-customer { align-self: flex-start; border-inline-start: 4px solid #9aa6bb; }
.msg-agent { align-self: flex-end; background: var(--primary-50); border-color: #cfdcf0; border-inline-start: 4px solid var(--primary); }
.msg-internal { align-self: flex-end; background: #fffbea; border-color: #f1e3a6; border-inline-start: 4px solid #d6a700; }
.msg-head { display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap; font-size: .85rem; margin-bottom: 6px; }
.msg-head span { color: var(--muted); }
.msg-body { word-break: break-word; white-space: normal; }
.msg-system { align-self: center; font-size: .8rem; color: var(--muted); background: #eceff4; padding: 4px 14px; border-radius: 999px; text-align: center; }
.msg-system span { opacity: .7; margin-inline-start: 6px; }
.tag { font-style: normal; font-size: .72rem; background: #f6e7a8; color: #6b5300; padding: 1px 8px; border-radius: 999px; margin-inline-start: 6px; }
.attachments { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.attachment { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; font-size: .85rem; max-width: 100%; }
.attachment span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 220px; }
.attachment small { color: var(--muted); }
.close-ticket { text-align: center; margin-bottom: 20px; }
.copy-row { display: flex; gap: 8px; }
.copy-row input { font-size: .8rem; min-height: 38px; }

.ticket-layout { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 20px; align-items: start; }
.ticket-side .card { padding: 16px; }

/* ===== لوحة التحكم ===== */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 8px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; color: var(--text); box-shadow: var(--shadow); display: flex; flex-direction: column; }
a.stat:hover { text-decoration: none; border-color: var(--primary); }
.stat span { color: var(--muted); font-size: .85rem; }
.stat strong { font-size: 1.8rem; font-weight: 800; line-height: 1.2; }
.stat-warn strong { color: var(--warn); }
.stat-late strong { color: var(--danger); }

.table-card { padding: 0; overflow: hidden; }
.table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.table th { background: #f7f8fb; color: var(--muted); font-weight: 500; text-align: right; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr:hover { background: #fafbfe; }
.table tr.row-late td:first-child { box-shadow: inset -4px 0 0 var(--danger); }
.table tr.row-warn td:first-child { box-shadow: inset -4px 0 0 #e08a00; }
.ticket-link { font-weight: 700; white-space: nowrap; }

.filters { display: grid; grid-template-columns: 2fr repeat(3, 1fr); gap: 10px; padding: 14px; }
.filters-actions { display: flex; gap: 8px; }
.filters-actions .btn { flex: 1; }
.pagination { display: flex; justify-content: center; align-items: center; gap: 14px; margin-top: 10px; }
.pagination a { background: #fff; border: 1px solid var(--border); padding: 6px 14px; border-radius: 8px; }

.split { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 20px; align-items: start; }

.login-wrap { min-height: 60vh; display: grid; place-items: center; }
.login-card { width: 100%; max-width: 400px; }
.login-card h1 { font-size: 1.4rem; margin-bottom: 0; }
.login-card .muted { margin-top: 0; }

/* ===== حقول النموذج ===== */
.fields-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.field-card { margin-bottom: 0; transition: opacity .2s; }
.field-card.is-off { opacity: .65; }
.field-card.has-error { border-color: var(--danger); }
.preview { background: #f7f9fd; border: 1px dashed #c9d3e4; border-radius: 10px; padding: 12px; margin-top: 4px; }
.preview .field { margin-bottom: 0; }
.preview-title { display: block; font-size: .78rem; color: var(--muted); margin-bottom: 6px; }
.fields-grid + .alert { margin-top: 16px; }

/* مفتاح التشغيل */
.switch { position: relative; display: inline-flex; align-items: center; gap: 8px; cursor: pointer; flex-shrink: 0; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.slider { width: 46px; height: 26px; background: #cdd4e0; border-radius: 999px; position: relative; transition: background .2s; flex-shrink: 0; }
.slider::after { content: ""; position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.2); transition: transform .2s; }
.switch input:checked + .slider { background: var(--success); }
.switch input:checked + .slider::after { transform: translateX(-20px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(29,79,145,.25); }
.switch-label { font-size: .85rem; color: var(--muted); }

.toggle-row { display: flex; gap: 14px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-of-type { border-bottom: 0; }
.toggle-row .switch { margin-top: 2px; }
.toggle-text { flex: 1; }
.toggle-text strong { display: block; font-weight: 700; }
.toggle-text small { color: var(--muted); font-size: .85rem; }
.inline-input { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.inline-input input { width: 80px; min-height: 36px; padding: 4px 8px; display: inline-block; text-align: center; margin: 0 4px; }
.inline-input.is-disabled { opacity: .5; }
.sticky-save { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 35%); padding: 18px 0 10px; z-index: 5; }

/* ===== الجوال ===== */
@media (max-width: 1000px) {
  .fields-grid { grid-template-columns: 1fr; }
  .ticket-layout, .split { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .filters { grid-template-columns: 1fr 1fr; }
  .filters input[type=search] { grid-column: 1 / -1; }
}

@media (max-width: 760px) {
  body { font-size: 15px; }
  h1 { font-size: 1.35rem; }
  .hero h1 { font-size: 1.6rem; }
  .card { padding: 16px; border-radius: 10px; }
  .main { padding-top: 16px; }
  .choice-grid, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .msg { max-width: 100%; }
  .filters { grid-template-columns: 1fr; }
  .filters-actions { grid-column: auto; }

  /* قائمة لوحة التحكم المنسدلة */
  .is-admin .nav-toggle { display: block; }
  .is-admin .nav { display: none; position: absolute; top: 60px; left: 0; right: 0; background: var(--primary-600); flex-direction: column; align-items: stretch; padding: 8px 16px 14px; box-shadow: 0 8px 20px rgba(0,0,0,.15); }
  .is-admin .nav.open { display: flex; }
  .is-admin .nav a { padding: 12px; }
  .nav-toggle[aria-expanded=true] span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
  .nav-toggle[aria-expanded=true] span:nth-child(2) { opacity: 0; }
  .nav-toggle[aria-expanded=true] span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

  .nav-public a { padding: 6px 8px; font-size: .85rem; }
  .brand-text small { display: none; }

  /* الجداول تتحول إلى بطاقات */
  .table thead { display: none; }
  .table, .table tbody, .table tr, .table td { display: block; width: 100%; }
  .table tr { padding: 12px 14px; border-bottom: 1px solid var(--border); }
  .table td { border: 0; padding: 3px 0; display: flex; justify-content: space-between; gap: 12px; text-align: left; }
  .table td::before { content: attr(data-label); color: var(--muted); font-size: .82rem; text-align: right; flex-shrink: 0; }
  .table td[data-label=""]::before { content: none; }
  .table tr.row-late { box-shadow: inset -4px 0 0 var(--danger); }
  .table tr.row-warn { box-shadow: inset -4px 0 0 #e08a00; }
  .table tr.row-late td:first-child, .table tr.row-warn td:first-child { box-shadow: none; }
}

@media (max-width: 400px) {
  .stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat strong { font-size: 1.5rem; }
  .brand-text { font-size: .95rem; }
}
