/* =============================================================
   إدارة العقارات — المحلات والمخازن
   ============================================================= */

:root {
  --sidebar:      #12352b;
  --sidebar-dark: #0c2620;
  --sidebar-line: #1e4a3d;
  --brass:        #a8792c;

  --ink:      #1d2321;
  --ink-soft: #4a5350;
  --muted:    #737c79;

  --line:      #dcdfdd;
  --line-soft: #e9ebea;
  --paper:     #ffffff;
  --page:      #f3f5f3;
  --raised:    #f7f8f7;

  --danger:    #9d2b21;
  --danger-bg: #fbeeec;
  --danger-ln: #eec9c4;

  --ok:    #1c6b47;
  --ok-bg: #e9f3ee;
  --ok-ln: #bcdcc9;

  --radius:    7px;
  --radius-sm: 5px;

  --shadow-btn: 0 1px 0 rgba(20, 40, 32, .10);
  --shadow-pop: 0 8px 28px rgba(15, 35, 28, .16);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; height: 100%; }

body {
  font-family: "Cairo", "Segoe UI", Tahoma, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--page);
  direction: rtl;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

/* الأرقام تحت بعضها بنفس العرض — مهم في جداول الفلوس */
table.data td,
table.data th,
.card .value,
.ltr {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: var(--sidebar); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
  border-radius: 3px;
}

.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }

/* ---------- الهيكل ---------- */

.layout { display: flex; min-height: 100vh; }

.nav-toggle { display: none; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar);
  color: #dbe6e0;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  padding: 20px 20px 17px;
  background: var(--sidebar-dark);
  position: relative;
  border-bottom: 1px solid var(--sidebar-line);
}
.sidebar .brand h1 {
  margin: 0;
  font-size: 19px;
  font-weight: 700;
  letter-spacing: -.2px;
  color: #fff;
}
.sidebar .brand span {
  display: block;
  font-size: 12px;
  color: #8fa89c;
  margin-top: 1px;
}

.nav-btn {
  display: none;
  position: absolute;
  left: 14px;
  top: 16px;
  font-size: 24px;
  line-height: 1;
  color: #fff;
  cursor: pointer;
  padding: 5px 11px;
  border: 1px solid rgba(255,255,255,.28);
  border-radius: var(--radius-sm);
}

.sidebar nav { padding: 8px 0; flex: 1; }

.sidebar nav a {
  display: block;
  padding: 9px 20px;
  color: #c3d3cb;
  font-size: 14.5px;
  border-right: 3px solid transparent;
}
.sidebar nav a:hover {
  background: var(--sidebar-dark);
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--sidebar-dark);
  color: #fff;
  border-right-color: var(--brass);
  font-weight: 600;
}

.sidebar .who {
  padding: 13px 20px;
  border-top: 1px solid var(--sidebar-line);
  font-size: 13px;
  color: #8fa89c;
}
.sidebar .who a { color: #dbe6e0; }

.main { flex: 1; min-width: 0; }

.topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 13px 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.topbar h2 { margin: 0; font-size: 18px; font-weight: 700; letter-spacing: -.2px; }

.content { padding: 24px 26px 40px; }

/* ---------- الكروت ---------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(186px, 1fr));
  gap: 12px;
  margin-bottom: 22px;
}

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 16px 15px;
}
.card .label { font-size: 12.5px; color: var(--muted); line-height: 1.5; }
.card .value {
  font-size: 25px;
  font-weight: 700;
  letter-spacing: -.4px;
  margin-top: 3px;
  line-height: 1.25;
}
.card .value small {
  font-size: 13.5px;
  font-weight: 400;
  color: var(--muted);
  letter-spacing: 0;
}

a.card { display: block; transition: border-color .12s, background .12s; }
a.card:hover { border-color: var(--sidebar); background: var(--raised); text-decoration: none; }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 20px;
  margin-bottom: 18px;
}
.panel > h3 {
  margin: 0 0 14px;
  font-size: 15.5px;
  font-weight: 700;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--line-soft);
}

/* ---------- الجداول ---------- */

table.data {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 18px;
}
table.data th,
table.data td {
  padding: 10px 12px;
  text-align: right;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data th {
  background: var(--raised);
  font-weight: 700;
  font-size: 13.5px;
  color: var(--ink-soft);
  white-space: nowrap;
  border-bottom-color: var(--line);
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafbfa; }
table.data .empty { text-align: center; color: var(--muted); padding: 34px 12px; }

table.data td:last-child { white-space: nowrap; }
table.data td:last-child .btn { margin: 2px 0 2px 5px; }

table.data th a.th-sort {
  color: inherit;
  text-decoration: none;
  display: inline-block;
  white-space: nowrap;
}
table.data th a.th-sort:hover { color: var(--sidebar); text-decoration: underline; }
table.data th a.th-sort.is-sorted { color: var(--sidebar); }

/* ---------- الفورمات ---------- */

.field { margin-bottom: 15px; }
.field label {
  display: block;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.field label .req { color: var(--danger); }

input[type=text], input[type=password], input[type=number],
input[type=date], input[type=month], input[type=file], select, textarea {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid #c9cecc;
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 15px;
  background: #fff;
  color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
input::placeholder, textarea::placeholder { color: #9aa29f; }

input[type=text]:hover, input[type=password]:hover,
select:hover, textarea:hover { border-color: #aab2af; }

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--sidebar);
  box-shadow: 0 0 0 3px rgba(18, 53, 43, .12);
}

input[type=checkbox] {
  width: 17px;
  height: 17px;
  accent-color: var(--sidebar);
  vertical-align: -3px;
  cursor: pointer;
}

textarea { min-height: 82px; resize: vertical; line-height: 1.7; }

select {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-soft) 50%),
    linear-gradient(135deg, var(--ink-soft) 50%, transparent 50%);
  background-position: 14px calc(50% + 1px), 19px calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-left: 30px;
}

.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }

.date-field { display: flex; gap: 6px; direction: ltr; align-items: center; }
.date-field select {
  width: auto;
  flex: 0 0 auto;
  padding: 9px 26px 9px 8px;
  text-align: center;
  text-align-last: center;
  background-position: 8px calc(50% + 1px), 13px calc(50% + 1px);
}
.date-field select.dm { min-width: 104px; }

/* ---------- الأزرار ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 38px;
  padding: 8px 18px;
  border: 1px solid var(--sidebar);
  border-radius: var(--radius-sm);
  background: var(--sidebar);
  color: #fff;
  font-family: inherit;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
  cursor: pointer;
  box-shadow: var(--shadow-btn);
  transition: background .12s, border-color .12s, transform .06s, box-shadow .12s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover {
  background: var(--sidebar-dark);
  border-color: var(--sidebar-dark);
  color: #fff;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); box-shadow: none; }

.btn-light {
  background: #f1f3f2;
  color: var(--ink);
  border-color: #c4cac7;
}
.btn-light:hover { background: #e4e8e6; border-color: #aab2af; color: var(--ink); }

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

.btn-sm { min-height: 31px; padding: 4px 12px; font-size: 13px; font-weight: 600; }

.btn[disabled], .btn:disabled { opacity: .55; cursor: not-allowed; }

/* ---------- الحالات والرسايل ---------- */

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
  line-height: 1.6;
}
.badge-ok     { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok-ln); }
.badge-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-ln); }
.badge-muted  { background: #eef0ef;          color: var(--muted);  border-color: var(--line); }

.msg {
  padding: 11px 15px;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
  border: 1px solid transparent;
  border-right-width: 4px;
  font-size: 14.5px;
}
.msg-ok     { background: var(--ok-bg);     color: var(--ok);     border-color: var(--ok-ln); }
.msg-danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-ln); }

/* ---------- صفحة الدخول ---------- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--sidebar);
  padding: 20px;
}
.login-box {
  background: var(--paper);
  border-radius: 10px;
  padding: 34px 32px;
  width: 356px;
  max-width: 100%;
  box-shadow: var(--shadow-pop);
}
.login-box h1 { margin: 0 0 3px; font-size: 22px; letter-spacing: -.3px; }
.login-box p.sub { margin: 0 0 22px; color: var(--muted); font-size: 14px; }
.login-box .btn { width: 100%; margin-top: 8px; }

/* ---------- معرض البطايق ---------- */

.id-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(298px, 1fr)); gap: 14px; }

.id-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.id-photo {
  background: #e7eae9;
  height: 188px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border-bottom: 1px solid var(--line);
}
.id-photo img { width: 100%; height: 100%; object-fit: cover; cursor: zoom-in; display: block; }
.id-missing { color: var(--muted); font-size: 14px; }

.id-info { padding: 12px 14px; font-size: 13.8px; line-height: 1.85; }
.id-info strong { font-size: 15.5px; }

.id-viewer {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 18, .88);
  z-index: 999;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
.id-viewer-bar {
  width: 100%;
  max-width: 1100px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: #fff;
  margin-bottom: 12px;
  font-weight: 600;
}
.id-viewer img {
  max-width: 100%;
  max-height: 84vh;
  object-fit: contain;
  background: #fff;
  border-radius: var(--radius);
}

.id-thumb {
  width: 56px;
  height: 41px;
  object-fit: cover;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  cursor: zoom-in;
  vertical-align: middle;
}

/* ---------- صف مفتوح جوه الجدول ---------- */

table.data tr[id^="wo"] td { white-space: normal; padding: 14px 12px; }
table.data tr[id^="wo"] .field label { font-size: 13px; }

/* ---------- الطباعة ---------- */

@media print {
  .sidebar, .topbar, .btn, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; font-size: 12pt; }
  .panel { border: 0; padding: 0; margin-bottom: 14px; }
  table.data { border-color: #999; }
  table.data th { background: #eee; }
  a { color: #000; text-decoration: none; }
}

/* ---------- الموبايل ---------- */

@media (max-width: 900px) {
  .layout { flex-direction: column; }

  .sidebar { width: 100%; }
  .sidebar .brand { padding: 15px 20px; }
  .sidebar .brand h1 { font-size: 17px; }

  .nav-btn { display: block; }

  .sidebar nav { display: none; padding: 6px 0 10px; }
  .sidebar .who { display: none; }
  .nav-toggle:checked ~ .sidebar nav,
  .nav-toggle:checked ~ .sidebar .who { display: block; }

  .topbar { padding: 11px 16px; }
  .topbar h2 { font-size: 16.5px; }
  .content { padding: 16px 16px 34px; }

  .panel { padding: 14px; }

  table.data {
    display: block;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
  }

  .row-2, .row-3 { grid-template-columns: 1fr; }

  input[type=text], input[type=password], input[type=number],
  input[type=date], input[type=month], select, textarea { font-size: 16px; }

  .date-field { gap: 5px; }
  .date-field select.dm { min-width: 96px; }

  .cards { grid-template-columns: repeat(auto-fit, minmax(148px, 1fr)); gap: 10px; }
  .card { padding: 12px 13px; }
  .card .value { font-size: 21px; }

  .btn { min-height: 42px; padding: 9px 16px; }
  .btn-sm { min-height: 34px; }

  .id-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .id-photo { height: 130px; }
  .id-info { padding: 10px; font-size: 13px; }

  table.data tr[id^="wo"] form { flex-direction: column; align-items: stretch; }
}

@media (max-width: 520px) {
  .cards { grid-template-columns: 1fr 1fr; }
  .card .value { font-size: 19px; }
  .id-grid { grid-template-columns: 1fr; }
  .id-photo { height: 200px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

/* ---------- النوافذ المنبثقة ---------- */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 18, .55);
  z-index: 900;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
}
.modal-box {
  background: var(--paper);
  border-radius: 9px;
  padding: 22px 24px;
  width: 520px;
  max-width: 100%;
  box-shadow: var(--shadow-pop);
}
.modal-box h3 { font-size: 17px; font-weight: 700; }

@media (max-width: 900px) {
  .modal-overlay { padding: 16px 12px; }
  .modal-box { padding: 16px; }
}

/* ---------- تحسين شكل الفلاتر ---------- */

/* سهم القايمة المنسدلة: أوضح ومش داخل في النص */
select {
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%),
    linear-gradient(to right, var(--line-soft), var(--line-soft));
  background-position:
    12px calc(50% + 1px),
    17px calc(50% + 1px),
    30px 20%;
  background-size: 5px 5px, 5px 5px, 1px 60%;
  background-repeat: no-repeat;
  padding-left: 38px;
}
select:hover  { background-color: #fbfcfb; }
select:focus  { background-color: #fff; }

/* خانة التاريخ: سهم أصغر ومساحة أنسب */
.date-field select {
  padding-left: 26px;
  background-position:
    8px calc(50% + 1px),
    13px calc(50% + 1px),
    21px 25%;
  background-size: 4px 4px, 4px 4px, 1px 50%;
}

/* "من" و"إلى" جنب بعض بمسافة واضحة وفاصل بينهم */
.filter-range {
  display: flex;
  gap: 18px;
  align-items: flex-end;
  flex-wrap: wrap;
  padding: 0 4px;
  position: relative;
}
.filter-range > .field + .field {
  padding-inline-start: 18px;
  border-inline-start: 1px solid var(--line);
}

@media (max-width: 900px) {
  .filter-range { gap: 10px; width: 100%; }
  .filter-range > .field { width: 100%; }
  .filter-range > .field + .field {
    padding-inline-start: 0;
    border-inline-start: 0;
  }
}
