/* =========================================================
   نظام إدارة مكاتب المحاماة - التصميم الرئيسي
   ========================================================= */

:root {
  --primary: #0f2942;
  --primary-dark: #081a2c;
  --primary-light: #eaeff4;
  --gold: #c9a227;
  --gold-light: #faf3e0;
  --success: #21c17c;
  --danger: #ef4444;
  --warning: #f5a623;
  --info: #3b82f6;
  --dark: #1f2937;
  --gray: #6b7280;
  --light-bg: #f5f6fb;
  --card-radius: 16px;
  --sidebar-width: 270px;
  --transition: all .25s ease;
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }
img, svg, video { max-width: 100%; height: auto; }
canvas { max-width: 100%; }
.card-body canvas { width: 100% !important; }
.table td, .table th, .card-body { word-break: break-word; overflow-wrap: break-word; }
.table-responsive { -webkit-overflow-scrolling: touch; }

body {
  font-family: 'Cairo', 'Segoe UI', Tahoma, sans-serif;
  background: var(--light-bg);
  color: var(--dark);
}

a { text-decoration: none; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ================= Auth Pages ================= */
.auth-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f2942 0%, #081a2c 100%);
  padding: 20px; position: relative; overflow: hidden;
}
.auth-wrapper::before, .auth-wrapper::after {
  content: ''; position: absolute; border-radius: 50%;
  background: rgba(201,162,39,.08);
}
.auth-wrapper::before { width: 500px; height: 500px; top: -200px; right: -150px; }
.auth-wrapper::after { width: 350px; height: 350px; bottom: -150px; left: -100px; }

.auth-card {
  background: #fff; border-radius: 22px;
  box-shadow: 0 25px 60px rgba(0,0,0,.3);
  overflow: hidden; max-width: 960px; width: 100%; position: relative; z-index: 2;
}
.auth-side {
  background: linear-gradient(160deg, var(--primary), var(--primary-dark));
  color: #fff; padding: 50px 40px;
  display: flex; flex-direction: column; justify-content: center;
  height: 100%; min-height: 560px;
}
.auth-side .icon-badge {
  width: 70px; height: 70px; background: rgba(201,162,39,.18);
  border-radius: 18px; display: flex; align-items: center; justify-content: center;
  font-size: 32px; margin-bottom: 25px; color: var(--gold);
}
.auth-form-side { padding: 50px 45px; }
.form-label { font-weight: 600; color: var(--dark); font-size: .92rem; }
.form-control, .form-select {
  border-radius: 10px; padding: 12px 16px; border: 1.5px solid #e5e7eb; font-size: .95rem;
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-light);
}
.input-group-text { border-radius: 10px; background: #f9fafb; border: 1.5px solid #e5e7eb; }

.btn-primary {
  background: var(--primary); border-color: var(--primary);
  border-radius: 10px; padding: 12px 20px; font-weight: 700; transition: var(--transition);
}
.btn-primary:hover, .btn-primary:focus { background: var(--primary-dark); border-color: var(--primary-dark); transform: translateY(-1px); }
.btn-gold { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 700; }
.btn-gold:hover { background: #b08e1f; color: #fff; }

/* ================= App Shell ================= */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-width); background: #fff; border-left: 1px solid #eef0f4;
  position: fixed; top: 0; right: 0; bottom: 0; overflow-y: auto; z-index: 1030; transition: var(--transition);
}
.sidebar-brand { display: flex; align-items: center; gap: 12px; padding: 22px 20px; border-bottom: 1px solid #f1f2f6; }
.sidebar-brand .logo-box {
  width: 44px; height: 44px; background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  border-radius: 12px; display: flex; align-items: center; justify-content: center; color: var(--gold); font-size: 20px;
}
.sidebar-brand h5 { margin: 0; font-weight: 800; font-size: .98rem; }
.sidebar-brand small { color: var(--gray); font-size: .74rem; }

.sidebar-nav { padding: 14px 12px; }
.sidebar-nav .nav-section-title {
  font-size: .7rem; text-transform: uppercase; color: #b0b3c1; font-weight: 700; margin: 16px 10px 6px; letter-spacing: .5px;
}
.sidebar-nav .nav-link {
  color: #4b5563; border-radius: 10px; padding: 10px 14px; display: flex; align-items: center; gap: 12px;
  font-weight: 600; font-size: .88rem; margin-bottom: 3px; transition: var(--transition);
}
.sidebar-nav .nav-link i { font-size: 1.1rem; width: 22px; text-align: center; }
.sidebar-nav .nav-link:hover { background: var(--primary-light); color: var(--primary); }
.sidebar-nav .nav-link.active {
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
  box-shadow: 0 6px 16px rgba(15,41,66,.35);
}
.sidebar-nav .nav-link .badge-count {
  margin-right: auto; background: var(--gold); color: #fff; font-size: .68rem; padding: 2px 7px; border-radius: 10px;
}

.main-content { margin-right: var(--sidebar-width); flex: 1; min-height: 100vh; transition: var(--transition); }

.topbar {
  background: #fff; border-bottom: 1px solid #eef0f4; padding: 14px 26px;
  display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; z-index: 1020;
}
.icon-btn {
  width: 42px; height: 42px; border-radius: 10px; background: #f5f6fb;
  display: flex; align-items: center; justify-content: center; position: relative; color: var(--dark); border: none; transition: var(--transition);
}
.icon-btn:hover { background: var(--primary-light); color: var(--primary); }
.icon-btn .badge-dot {
  position: absolute; top: 6px; left: 6px; width: 9px; height: 9px; border-radius: 50%;
  background: var(--danger); border: 2px solid #fff;
}

.page-body { padding: 26px; }

.stat-card {
  background: #fff; border-radius: var(--card-radius); padding: 20px 22px;
  box-shadow: 0 4px 20px rgba(17,24,39,.05); border: 1px solid #f1f2f6; height: 100%; transition: var(--transition);
}
.stat-card:hover { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(17,24,39,.09); }
.stat-card .stat-icon { width: 50px; height: 50px; border-radius: 13px; display: flex; align-items: center; justify-content: center; font-size: 21px; }
.stat-card h3 { font-weight: 800; margin: 10px 0 2px; }
.stat-card .stat-label { color: var(--gray); font-size: .85rem; font-weight: 600; }

.card { border-radius: var(--card-radius); border: 1px solid #f1f2f6; box-shadow: 0 4px 20px rgba(17,24,39,.05); }
.card-header { background: transparent; border-bottom: 1px solid #f1f2f6; padding: 16px 20px; font-weight: 800; }
.card-body { padding: 18px 20px; }

.insight-item { display: flex; align-items: flex-start; gap: 12px; padding: 12px 14px; border-radius: 12px; margin-bottom: 9px; font-size: .86rem; font-weight: 600; }
.insight-item.success { background: #e9fbf3; color: #0f9d63; }
.insight-item.warning { background: #fff8e8; color: #b9790a; }
.insight-item.danger { background: #fef0f0; color: #d63b3b; }
.insight-item.info { background: #eaf2ff; color: #2563eb; }

.table { font-size: .88rem; }
.table thead th { border-bottom: 2px solid #f1f2f6; color: var(--gray); font-weight: 700; font-size: .76rem; text-transform: uppercase; letter-spacing: .3px; }
.table td { vertical-align: middle; padding: 13px 12px; }
.table tbody tr { border-bottom: 1px solid #f5f6fa; }

.badge-soft { padding: 5px 11px; border-radius: 20px; font-size: .74rem; font-weight: 700; }
.badge-status-open { background: #eaf2ff; color: #2563eb; }
.badge-status-in_progress { background: #fff8e8; color: #b9790a; }
.badge-status-postponed { background: #f3f0ff; color: #6c63ff; }
.badge-status-closed_won { background: #e9fbf3; color: #0f9d63; }
.badge-status-closed_lost { background: #fef0f0; color: #d63b3b; }
.badge-status-closed { background: #f1f2f6; color: #6b7280; }
.badge-status-scheduled { background: #eaf2ff; color: #2563eb; }
.badge-status-done { background: #e9fbf3; color: #0f9d63; }
.badge-status-cancelled { background: #fef0f0; color: #d63b3b; }
.badge-status-pending { background: #fff8e8; color: #b9790a; }
.badge-status-new { background: #eaf2ff; color: #2563eb; }
.badge-status-reviewing { background: #fff8e8; color: #b9790a; }
.badge-status-accepted { background: #e9fbf3; color: #0f9d63; }
.badge-status-rejected { background: #fef0f0; color: #d63b3b; }
.badge-status-converted { background: var(--gold-light); color: #9c7d1a; }

.badge-priority-low { background: #f1f2f6; color: #6b7280; }
.badge-priority-medium { background: #fff8e8; color: #b9790a; }
.badge-priority-high { background: #fef0f0; color: #d63b3b; }

.btn-soft-primary { background: var(--primary-light); color: var(--primary); border: none; font-weight: 700; }
.btn-soft-primary:hover { background: var(--primary); color: #fff; }
.btn-soft-danger { background: #fef0f0; color: var(--danger); border: none; }
.btn-soft-danger:hover { background: var(--danger); color: #fff; }
.btn-soft-gold { background: var(--gold-light); color: #9c7d1a; border: none; font-weight: 700; }
.btn-soft-gold:hover { background: var(--gold); color: #fff; }

.empty-state { text-align: center; padding: 55px 20px; color: var(--gray); }
.empty-state i { font-size: 3rem; color: #d1d5db; margin-bottom: 12px; display: block; }

.fab-add {
  position: fixed; bottom: 26px; left: 26px; width: 56px; height: 56px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 25px;
  box-shadow: 0 10px 25px rgba(15,41,66,.45); border: none; z-index: 1040; transition: var(--transition);
}
.fab-add:hover { transform: scale(1.08) rotate(90deg); color: #fff; }

.avatar-circle {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark)); color: var(--gold);
  display: flex; align-items: center; justify-content: center; font-weight: 700;
}

.notif-item { padding: 13px 15px; border-radius: 12px; margin-bottom: 8px; display: flex; gap: 12px; }
.notif-item.unread { background: var(--primary-light); }
.notif-item .notif-icon { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }

.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 1025; }

@media (max-width: 991.98px) {
  .sidebar { transform: translateX(100%); max-width: 85vw; }
  .sidebar.show { transform: translateX(0); }
  .main-content { margin-right: 0; }
  .sidebar-overlay.show { display: block; }
  .topbar .search-box { display: none; }
  .page-body { padding: 18px 14px 90px; }
}
@media (max-width: 575.98px) {
  .page-body { padding: 14px 10px 90px; }
  .card-body { padding: 15px 14px; }
  .table { font-size: .8rem; }
  .table td, .table th { padding: 10px 8px; }
}

.modal-content { border-radius: 18px; border: none; }
.modal-header { border-bottom: 1px solid #f1f2f6; padding: 18px 22px; }
.modal-body { padding: 22px; }
.modal-footer { border-top: 1px solid #f1f2f6; padding: 14px 22px; }

.nav-tabs .nav-link { border: none; font-weight: 700; color: var(--gray); border-radius: 10px 10px 0 0; }
.nav-tabs .nav-link.active { color: var(--primary); border-bottom: 3px solid var(--gold); background: transparent; }

.perm-matrix th, .perm-matrix td { text-align: center; vertical-align: middle; }
.perm-matrix .module-label { text-align: right; font-weight: 700; }
.form-check-input:checked { background-color: var(--primary); border-color: var(--primary); }

.timeline { position: relative; padding-right: 26px; }
.timeline::before { content: ''; position: absolute; right: 8px; top: 4px; bottom: 4px; width: 2px; background: #eef0f4; }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item::before {
  content: ''; position: absolute; right: -22px; top: 3px; width: 12px; height: 12px; border-radius: 50%;
  background: var(--primary); border: 3px solid #fff; box-shadow: 0 0 0 1px #eef0f4;
}

.icon-color-swatch { width: 28px; height: 28px; border-radius: 8px; cursor: pointer; border: 2px solid transparent; }
.icon-color-swatch.selected { border-color: var(--dark); }
