/*
|--------------------------------------------------------------------------
| Emaar Altelal CRM - Unified UI Stylesheet
| Lightweight CSS only (no Tailwind / no Vite)
|--------------------------------------------------------------------------
*/

/* =========================
   Design Tokens
   ========================= */
:root{
  --bg:#f6f8fc;
  --surface:#ffffff;
  --surface-soft:#f8fafc;
  --text:#111827;
  --muted:#6b7280;
  --border:#e5e7eb;

  --primary:#2563eb;
  --primary-hover:#1d4ed8;

  --success:#16a34a;
  --success-soft:#ecfdf5;
  --success-border:#a7f3d0;
  --success-text:#065f46;

  --warning:#f59e0b;
  --warning-soft:#fffbeb;
  --warning-border:#fde68a;
  --warning-text:#92400e;

  --danger:#dc2626;
  --danger-hover:#b91c1c;
  --danger-soft:#fef2f2;
  --danger-border:#fecaca;
  --danger-text:#991b1b;

  --dark:#111827;
  --dark-hover:#1f2937;

  --radius-sm:10px;
  --radius:14px;
  --radius-lg:20px;

  --shadow-sm:0 4px 10px rgba(15,23,42,.04);
  --shadow:0 10px 24px rgba(15,23,42,.06);
  --shadow-lg:0 18px 40px rgba(15,23,42,.10);
}

/* =========================
   Reset / Base
   ========================= */
*{ box-sizing:border-box; }

html,body{
  height:100%;
  max-width:100%;
  overflow-x:hidden;
}

body{
  margin:0;
  background:var(--bg);
  color:var(--text);
  font-family:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,Arial,"Noto Sans",sans-serif;
}

a{ color:inherit; }

img{
  max-width:100%;
  height:auto;
}

.app-shell{
  min-height:100vh;
  display:flex;
  flex-direction:column;
}


/* ===== TOPBAR ===== */

.topbar{
  position:sticky;
  top:0;
  z-index:1000;
  background:#fff;
  border-bottom:1px solid var(--border);
}

.topbar .wrap{
  max-width:1280px;
  margin:0 auto;
  padding:10px 16px;

  display:flex;
  align-items:center;
  gap:14px;

  height:60px;
}

/* LEFT */

.tb-left{
  display:flex;
  align-items:center;
}

.brand img{
  height:36px;
}

/* SEARCH */

.tb-search{
  flex:0 0 260px;
}

.tb-search input{
  width:100%;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px 12px;
  font-size:14px;
}

/* CENTER NAV */

.tb-center{
  display:flex;
  gap:8px;
  flex:1;
  justify-content:center;
}

.nav-link{
  padding:6px 10px;
  border-radius:10px;
  text-decoration:none;
  font-weight:600;
  color:#374151;
}

.nav-link:hover{
  background:#f3f4f6;
}

/* RIGHT */

.tb-right{
  display:flex;
  align-items:center;
  gap:10px;
}

/* notification badge */

.badge{
  background:#ef4444;
  color:#fff;
  border-radius:999px;
  font-size:11px;
  padding:2px 6px;
}

/* dropdown */

.dd{
  position:relative;
}

.dd-menu{
  display:none;
  position:absolute;
  top:42px;
  right:0;

  min-width:220px;

  background:#fff;
  border:1px solid var(--border);
  border-radius:14px;

  box-shadow:0 18px 40px rgba(0,0,0,.08);

  padding:8px;
}

.dd.open .dd-menu{
  display:block;
}

.dd-menu a{
  display:block;
  padding:8px 10px;
  border-radius:8px;
  text-decoration:none;
}

.dd-menu a:hover{
  background:#f3f4f6;
}

/* =========================
   Layout
   ========================= */
.page{
  max-width:1280px;
  margin:0 auto;
  padding:18px 16px 36px;
}

.container-page{
  max-width:1280px;
  margin:0 auto;
  padding:18px 16px 36px;
}

.page-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:12px;
  flex-wrap:wrap;
  background:#fff;
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:14px 16px;
  margin-bottom:14px;
  box-shadow:var(--shadow-sm);
}

.page-title,
.page-header h1,
.page-header h2,
.page-header h3{
  margin:0;
  font-size:20px;
  font-weight:900;
  color:var(--text);
}

.page-subtitle{
  margin-top:4px;
  font-size:13px;
  color:var(--muted);
}

.page-actions{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
}

.page-body{
  background:#fff;
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:var(--shadow-sm);
}

/* =========================
   Cards
   ========================= */
.card,
.card-ui,
.form-card{
  background:var(--surface);
  border:1px solid var(--border);
  border-radius:var(--radius);
  padding:16px;
  box-shadow:var(--shadow-sm);
}

.card-ui.soft{
  background:linear-gradient(180deg,#fff,#fafbfd);
}

.grid-cards{
  display:grid;
  grid-template-columns:repeat(auto-fit,minmax(260px,1fr));
  gap:16px;
}

/* =========================
   Tables
   ========================= */
.table-wrap{
  width:100%;
  max-width:100%;
  background:#fff;
  border:1px solid var(--border);
  border-radius:var(--radius);
  overflow:auto;
  box-shadow:var(--shadow-sm);
}

.table-ui,
table{
  width:100%;
  border-collapse:collapse;
  background:#fff;
}

.table-ui th,
.table-ui td,
table th,
table td{
  padding:12px 12px;
  border-bottom:1px solid #eef2f7;
  vertical-align:middle;
  font-size:14px;
}

.table-ui th,
table th{
  background:#f8fafc;
  color:#374151;
  font-weight:800;
  white-space:nowrap;
}

.table-ui tbody tr:hover td,
table tbody tr:hover td{
  background:#fcfcfd;
}

/* =========================
   Buttons
   ========================= */
.btn{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  gap:8px;
  padding:9px 14px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  color:var(--text);
  text-decoration:none;
  cursor:pointer;
  font-weight:800;
  font-size:14px;
  transition:.18s ease;
  white-space:nowrap;
}

.btn:hover{
  background:#f9fafb;
}

.btn-primary{
  background:var(--primary);
  border-color:var(--primary);
  color:#fff;
}

.btn-primary:hover{
  background:var(--primary-hover);
  border-color:var(--primary-hover);
}

.btn-dark,
.btn-secondary{
  background:var(--dark);
  border-color:var(--dark);
  color:#fff;
}

.btn-dark:hover,
.btn-secondary:hover{
  background:var(--dark-hover);
  border-color:var(--dark-hover);
  color:#fff;
}

.btn-success{
  background:var(--success);
  border-color:var(--success);
  color:#fff;
}

.btn-success:hover{
  filter:brightness(1.04);
}

.btn-warning{
  background:var(--warning);
  border-color:var(--warning);
  color:#fff;
}

.btn-warning:hover{
  filter:brightness(1.04);
}

.btn-danger{
  background:var(--danger);
  border-color:var(--danger);
  color:#fff;
}

.btn-danger:hover{
  background:var(--danger-hover);
  border-color:var(--danger-hover);
}

.btn-light,
.btn-soft{
  background:#fff;
  color:var(--text);
  border-color:var(--border);
}

.btn-light:hover,
.btn-soft:hover{
  background:#f3f4f6;
}

.btn-back{
  background:#f3f4f6;
  border-color:#e5e7eb;
  color:#111827;
}

/* =========================
   Forms
   ========================= */
label,
.label{
  display:block;
  margin-bottom:6px;
  font-size:13px;
  font-weight:800;
  color:#4b5563;
}

input,
select,
textarea,
.input,
.select,
.textarea{
  width:100%;
  max-width:100%;
  border:1px solid #d1d5db;
  border-radius:12px;
  padding:10px 12px;
  font-size:14px;
  background:#fff;
  color:var(--text);
  transition:.18s ease;
}

input:focus,
select:focus,
textarea:focus,
.input:focus,
.select:focus,
.textarea:focus{
  outline:none;
  border-color:#93c5fd;
  box-shadow:0 0 0 4px rgba(37,99,235,.10);
}

textarea,
.textarea{
  min-height:110px;
  resize:vertical;
}

input[readonly]{
  background:#f9fafb;
  color:var(--muted);
}

input[type="checkbox"]{
  width:auto;
}

.help{
  margin-top:6px;
  font-size:12px;
  color:var(--muted);
}

/* =========================
   Form Grid
   ========================= */
.form-grid{
  display:grid;
  grid-template-columns:repeat(12,1fr);
  gap:12px;
}

.col-12{ grid-column:span 12; }
.col-6{ grid-column:span 6; }
.col-4{ grid-column:span 4; }
.col-3{ grid-column:span 3; }

@media (max-width:900px){
  .col-6,.col-4,.col-3{ grid-column:span 12; }
}

/* =========================
   Alerts
   ========================= */
.alert,
.alert-ui{
  padding:12px 14px;
  border-radius:12px;
  border:1px solid var(--border);
  background:#fff;
  font-size:14px;
}

.alert-success{
  background:var(--success-soft);
  border-color:var(--success-border);
  color:var(--success-text);
}

.alert-danger{
  background:var(--danger-soft);
  border-color:var(--danger-border);
  color:var(--danger-text);
}

.alert-info{
  background:#eff6ff;
  border-color:#bfdbfe;
  color:#1d4ed8;
}

/* =========================
   Badges
   ========================= */
.badge,
.badge-ui{
  display:inline-flex;
  align-items:center;
  justify-content:center;
  padding:6px 10px;
  border-radius:999px;
  font-size:12px;
  font-weight:800;
  border:1px solid transparent;
  white-space:nowrap;
  line-height:1;
}

.badge.gray,
.badge-muted{
  background:#f3f4f6;
  color:#374151;
  border-color:#e5e7eb;
}

.badge.success,
.badge-success{
  background:var(--success-soft);
  color:var(--success-text);
  border-color:var(--success-border);
}

.badge.warning,
.badge-warning{
  background:var(--warning-soft);
  color:var(--warning-text);
  border-color:var(--warning-border);
}

.badge.danger,
.badge-danger{
  background:var(--danger-soft);
  color:var(--danger-text);
  border-color:var(--danger-border);
}

/* =========================
   Empty / Section / Stats
   ========================= */
.section-title{
  margin:0 0 10px;
  font-size:15px;
  font-weight:900;
}

.empty-state{
  text-align:center;
  padding:28px 16px;
  color:var(--muted);
  background:#fff;
  border:1px dashed #d1d5db;
  border-radius:16px;
}

.stat-tile{
  background:#fff;
  border:1px solid var(--border);
  border-radius:18px;
  padding:18px;
  box-shadow:var(--shadow-sm);
  transition:.18s ease;
}

.stat-tile:hover{
  transform:translateY(-3px);
  box-shadow:var(--shadow);
}

.stat-number{
  font-size:30px;
  font-weight:900;
  line-height:1;
  margin-bottom:8px;
}

.stat-label{
  font-size:14px;
  font-weight:700;
  color:#374151;
}

/* =========================
   Utilities
   ========================= */
.hidden{ display:none !important; }
.flex{ display:flex; }
.items-center{ align-items:center; }
.justify-between{ justify-content:space-between; }
.justify-center{ justify-content:center; }
.gap-3{ gap:12px; }
.gap-6{ gap:24px; }
.w-full{ width:100%; }
.text-right{ text-align:right; }
.whitespace-nowrap{ white-space:nowrap; }
.text-sm{ font-size:14px; }
.text-xs{ font-size:12px; }
.text-xl{ font-size:20px; }
.font-semibold{ font-weight:700; }
.rounded{ border-radius:12px; }
.shadow{ box-shadow:0 10px 25px rgba(0,0,0,.05); }
.bg-white{ background:#fff; }
.p-6{ padding:24px; }
.p-4{ padding:16px; }
.py-6{ padding-top:24px; padding-bottom:24px; }
.px-4{ padding-left:16px; padding-right:16px; }
.mx-auto{ margin-left:auto; margin-right:auto; }
.max-w-7xl{ max-width:1200px; }
.max-w-6xl{ max-width:1000px; }
.border{ border:1px solid var(--border); }
.border-b{ border-bottom:1px solid var(--border); }
.text-gray-500{ color:var(--muted); }
.text-indigo-600{ color:#4f46e5; }
.text-red-600{ color:var(--danger); }
.bg-green-100{ background:#f0fdf4; }
.bg-red-50{ background:#fef2f2; }
.border-red-300{ border-color:#fca5a5; }
.ltr{ direction:ltr; text-align:left; }
.rtl{ direction:rtl; text-align:right; }
.auto-align{ text-align:start; }

/* Tailwind-like compatibility classes */
.sm\:px-6{ padding-left:24px; padding-right:24px; }
.lg\:px-8{ padding-left:32px; padding-right:32px; }

/* =========================
   RTL / LTR smart handling
   ========================= */
html[dir="rtl"] body{ direction:rtl; }
html[dir="ltr"] body{ direction:ltr; }

html[dir="rtl"] .text-start{ text-align:right; }
html[dir="rtl"] .text-end{ text-align:left; }
html[dir="ltr"] .text-start{ text-align:left; }
html[dir="ltr"] .text-end{ text-align:right; }

html[dir="rtl"] table th,
html[dir="rtl"] table td{
  text-align:right;
}

html[dir="ltr"] table th,
html[dir="ltr"] table td{
  text-align:left;
}

/* =========================
   Select fixes (macOS / Safari / Chrome)
   ========================= */
select{
  color:var(--text);
  background-color:#fff;
  padding-right:12px;
  padding-left:34px;
}

select option{
  color:var(--text);
  background-color:#fff;
  direction:inherit;
  unicode-bidi:plaintext;
}

html[dir="rtl"] select{
  direction:ltr;
  text-align:right;
  text-align-last:right;
  white-space:nowrap;
  overflow:hidden;
  text-overflow:ellipsis;
}

html[dir="ltr"] select{
  direction:ltr;
  text-align:left;
  text-align-last:left;
}

/* =========================
   Chat / Comments Panel
   ========================= */
.chat-wrap{
  max-width:900px;
  margin:18px auto 0;
}

.chat-card{
  background:#f8fafc;
  border:1px solid var(--border);
  border-radius:16px;
  padding:14px;
  box-shadow:0 12px 26px rgba(0,0,0,.04);
}

.chat-head{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  margin-bottom:10px;
}

.chat-title{
  display:flex;
  align-items:center;
  gap:8px;
  font-weight:800;
  font-size:14px;
}

.chat-sub{
  color:var(--muted);
  font-size:12px;
}

.chat-list{
  display:flex;
  flex-direction:column;
  gap:10px;
  max-height:420px;
  overflow:auto;
  padding:6px;
  border-radius:12px;
  background:rgba(255,255,255,.65);
  border:1px dashed #e5e7eb;
}

.chat-msg{
  display:flex;
  gap:10px;
  align-items:flex-end;
}

.chat-msg .avatar{
  width:34px;
  height:34px;
  border-radius:10px;
  background:#fff;
  border:1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:center;
  font-size:16px;
  flex:0 0 auto;
}

.chat-bubble{
  max-width:78%;
  background:#fff;
  border:1px solid var(--border);
  border-radius:14px;
  padding:10px 12px;
  box-shadow:0 6px 14px rgba(0,0,0,.03);
}

.chat-meta{
  display:flex;
  gap:10px;
  align-items:center;
  justify-content:space-between;
  margin-bottom:6px;
}

.chat-name{
  font-weight:800;
  font-size:13px;
}

.chat-time{
  color:var(--muted);
  font-size:11px;
  white-space:nowrap;
}

.chat-text{
  font-size:14px;
  line-height:1.7;
  white-space:pre-wrap;
  overflow-wrap:anywhere;
  word-break:break-word;
}

.chat-msg.is-me{
  justify-content:flex-end;
}

.chat-msg.is-me .avatar{
  display:none;
}

.chat-msg.is-me .chat-bubble{
  background:#eff6ff;
  border-color:#bfdbfe;
}

html[dir="rtl"] .chat-msg{
  flex-direction:row-reverse;
}

html[dir="rtl"] .chat-msg.is-me{
  flex-direction:row-reverse;
  justify-content:flex-start;
}

html[dir="rtl"] .chat-msg:not(.is-me){
  justify-content:flex-start;
}

html[dir="ltr"] .chat-msg.is-me{
  justify-content:flex-end;
}

html[dir="ltr"] .chat-msg:not(.is-me){
  justify-content:flex-start;
}

.chat-compose{
  margin-top:10px;
  display:flex;
  gap:10px;
  align-items:flex-end;
}

.chat-compose textarea{
  min-height:42px;
  max-height:120px;
  resize:vertical;
}

.chat-compose .btn{
  height:42px;
  padding:0 14px;
  border-radius:12px;
}

/* =========================
   PR / Document Layouts
   ========================= */
.header-actions{
  display:flex;
  gap:10px;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
}

.reject-form{
  display:flex;
  gap:6px;
  align-items:center;
}

.reject-form input{
  width:220px;
  border:1px solid var(--border);
  border-radius:12px;
  padding:8px 10px;
  font-size:14px;
}

.pr-layout{
  max-width:1200px;
  margin:0 auto;
  padding:16px;
  display:grid;
  grid-template-columns:420px 1fr;
  gap:16px;
  align-items:start;
}

.pr-chat-col{
  position:sticky;
  top:90px;
  z-index:800;
}

.pr-main-col{
  min-width:0;
}

.pr-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
  flex-wrap:wrap;
}

.pr-info{
  min-width:260px;
}

.pr-meta{
  margin-top:10px;
  font-size:12px;
  color:var(--muted);
  display:flex;
  gap:12px;
  flex-wrap:wrap;
}

.pr-meta b{
  color:var(--text);
}

.sticky-actions{
  position:sticky;
  top:72px;
  z-index:900;
  background:#fff;
  padding:8px 0;
  border-bottom:1px solid var(--border);
}

.actions-row{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
  justify-content:flex-end;
}

.doc-layout{
  display:grid;
  grid-template-columns:1fr 420px;
  gap:16px;
  align-items:start;
  max-width:100%;
}

.doc-main-col,
.doc-side-col{
  min-width:0;
}

.doc-side-col{
  position:sticky;
  top:90px;
  z-index:800;
}

@media (max-width:1100px){
  .pr-layout,
  .doc-layout{
    grid-template-columns:1fr;
  }

  .pr-chat-col,
  .doc-side-col{
    position:static;
  }
}

/* =========================
   Overflow / Dropdown safety
   ========================= */
.page,
.page-header,
.page-body,
.card,
.form-grid,
.field,
.app-shell{
  overflow:visible !important;
  transform:none !important;
  filter:none !important;
}

.table-wrap{
  overflow:auto;
}

.allow-dropdown{
  overflow:visible !important;
}

/* generic dropdown support */
.dropdown{
  position:relative;
  display:inline-block;
}

.dropdown > summary{
  cursor:pointer;
  list-style:none;
}

.dropdown > summary::-webkit-details-marker{
  display:none;
}

.dropdown-menu{
  display:none;
  position:absolute;
  top:calc(100% + 8px);
  inset-inline-start:0;
  min-width:220px;
  background:#fff;
  border:1px solid var(--border);
  border-radius:14px;
  box-shadow:var(--shadow-lg);
  padding:8px;
  z-index:99999;
}

details.dropdown[open] .dropdown-menu,
details.dropdown[open] > ul,
details.dropdown[open] > div[role="menu"]{
  display:block;
}

.dropdown a,
.dropdown button{
  display:block;
  width:100%;
  padding:10px 12px;
  border-radius:12px;
  text-decoration:none;
  background:transparent;
  border:0;
  cursor:pointer;
  text-align:start;
  color:var(--text);
}

.dropdown a:hover,
.dropdown button:hover{
  background:#f3f4f6;
}