/* سكن | Sakan — RTL, offline, mobile-first */
:root {
  --accent: #b45309;
  --accent-strong: #92400e;
  --accent-soft: #fef3c7;
  --hero-from: #b45309;
  --hero-to: #92400e;
  --accent-btn: #b45309;
  --bg: #faf8f5;
  --surface: #ffffff;
  --text: #1f2937;
  --text-dim: #6b7280;
  --border: #e7e2db;
  --danger: #dc2626;
  --ok: #16a34a;
  --star: #f59e0b;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 4px 14px rgba(15, 23, 42, .05);
  --radius: 14px;
}
[data-theme="dark"] {
  --accent: #fbbf24;
  --accent-strong: #fcd34d;
  --accent-soft: #451a03;
  --hero-from: #92400e;
  --hero-to: #78350f;
  --accent-btn: #b45309;
  --bg: #171310;
  --surface: #241d17;
  --text: #f5f0ea;
  --text-dim: #a39a8f;
  --border: #3d332a;
  --shadow: 0 1px 3px rgba(0, 0, 0, .35), 0 4px 14px rgba(0, 0, 0, .25);
}

* { box-sizing: border-box; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  clip: rect(0 0 0 0); clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Tahoma, "Noto Kufi Arabic", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
body.theme-ready { transition: background .25s, color .25s; }

.app-header {
  background: linear-gradient(135deg, var(--hero-from), var(--hero-to));
  color: #fff;
  padding: 18px 16px;
  position: sticky;
  top: 0;
  z-index: 20;
  box-shadow: var(--shadow);
}
.header-inner { max-width: 1000px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-name { margin: 0; font-size: 24px; font-weight: 800; }
.brand-en { font-size: 14px; font-weight: 600; opacity: .8; letter-spacing: .4px; }
.brand-sub { margin: 0; font-size: 12.5px; opacity: .92; }
.header-actions { display: flex; gap: 6px; }
.icon-btn {
  background: rgba(255, 255, 255, .16); border: none; color: #fff;
  font-size: 17px; width: 40px; height: 40px; border-radius: 10px; cursor: pointer; transition: background .2s;
  display: grid; place-content: center;
}
.icon-btn:hover { background: rgba(255, 255, 255, .3); }
.icon-btn:focus-visible { outline: 3px solid #fff; outline-offset: 2px; }

.container { max-width: 1000px; margin: 0 auto; padding: 18px 14px 60px; }
section { margin-bottom: 18px; }
h2 { font-size: 17px; margin: 0 0 10px; }

/* Stats */
.stats-bar { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat {
  background: var(--surface); border-radius: var(--radius); padding: 14px 10px;
  text-align: center; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 2px;
}
.stat-num { font-size: 20px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.stat-label { font-size: 12.5px; color: var(--text-dim); }

/* Toolbar */
.toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.filters { display: flex; gap: 6px; flex-wrap: wrap; flex: 1; }
.filter-chip {
  border: 1.5px solid var(--border); background: var(--surface); color: var(--text);
  padding: 7px 14px; border-radius: 999px; font-size: 13.5px; cursor: pointer; font-family: inherit; transition: all .18s;
}
.filter-chip.active { background: var(--accent-btn); border-color: var(--accent-btn); color: #fff; font-weight: 700; }
.filter-chip:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.view-toggle { display: flex; gap: 4px; background: var(--surface); border: 1.5px solid var(--border); border-radius: 10px; padding: 3px; }
.view-btn {
  border: none; background: none; color: var(--text-dim); font-size: 16px; cursor: pointer;
  width: 36px; height: 32px; border-radius: 8px;
}
.view-btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.view-btn svg { display: block; margin: auto; }
.view-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.apt-card {
  background: var(--surface); border-radius: var(--radius); overflow: hidden;
  box-shadow: var(--shadow); cursor: pointer; transition: transform .15s, box-shadow .15s;
  display: flex; flex-direction: column;
}
.apt-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(15, 23, 42, .12); }
.apt-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.apt-photos { position: relative; height: 150px; background: var(--accent-soft); overflow: hidden; }
.apt-photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.apt-photos .photo-count {
  position: absolute; bottom: 8px; inset-inline-start: 8px;
  background: rgba(0, 0, 0, .6); color: #fff; font-size: 11.5px;
  padding: 2px 9px; border-radius: 999px;
}
.apt-photos .no-photo {
  height: 100%; display: grid; place-content: center; color: var(--accent); font-size: 13px;
}
.apt-status-badge {
  position: absolute; top: 8px; inset-inline-end: 8px;
  font-size: 11.5px; font-weight: 700; padding: 3px 10px; border-radius: 999px; color: #fff;
}
.badge-considering { background: #0284c7; }
.badge-chosen { background: var(--ok); }
.badge-rejected { background: #6b7280; }
.apt-body { padding: 12px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; }
.apt-name { margin: 0; font-size: 15.5px; overflow-wrap: anywhere; }
.apt-price { font-size: 17px; font-weight: 800; color: var(--accent); font-variant-numeric: tabular-nums; }
.apt-meta { font-size: 12.5px; color: var(--text-dim); display: flex; flex-wrap: wrap; gap: 4px 10px; }
.apt-first { font-size: 12.5px; color: var(--text-dim); font-variant-numeric: tabular-nums; }
.apt-stars { color: var(--star); font-size: 14px; letter-spacing: 1px; }
.apt-stars .off { color: var(--border); }
.apt-pc { font-size: 12.5px; display: flex; flex-direction: column; gap: 3px; }
.apt-pc .pros::before { content: "✔ "; color: var(--ok); font-weight: 700; }
.apt-pc .cons::before { content: "✖ "; color: var(--danger); font-weight: 700; }
.apt-tel { color: var(--accent); text-decoration: none; font-weight: 700; direction: ltr; unicode-bidi: embed; }
.apt-tel:hover { text-decoration: underline; }
.apt-tel:focus-visible { outline: 2px solid var(--accent); border-radius: 4px; }
.apt-pc span { overflow-wrap: anywhere; }

/* Table */
.table-wrap { overflow-x: auto; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 8px; }
.cmp-table { width: 100%; border-collapse: collapse; font-size: 14px; min-width: 640px; }
.cmp-table th { padding: 6px 8px; text-align: start; }
.cmp-table td { padding: 10px 8px; border-top: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.cmp-table tbody tr { cursor: pointer; transition: background .15s; }
.cmp-table tbody tr:hover { background: var(--accent-soft); }
.cmp-table tbody tr:focus-visible { outline: 3px solid var(--accent); outline-offset: -2px; }
.sort-btn {
  border: none; background: none; font-family: inherit; font-size: 13.5px; font-weight: 700;
  color: var(--text); cursor: pointer; padding: 4px 2px; display: inline-flex; align-items: center; gap: 4px;
}
.sort-btn .dir { font-size: 10px; color: var(--accent); }
.sort-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
.table-hint { font-size: 12px; color: var(--text-dim); margin: 8px 4px 4px; }
.row-name { font-weight: 700; }

/* Forms */
input[type="text"], input[type="number"], input[type="tel"], select, textarea {
  font-family: inherit; font-size: 14.5px; padding: 10px 12px;
  border: 1.5px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); transition: border-color .15s;
  width: 100%;
}
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
label { display: flex; flex-direction: column; gap: 5px; font-size: 13.5px; font-weight: 600; margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.form-row { margin-bottom: 12px; }
.form-label { display: block; font-size: 13.5px; font-weight: 600; margin-bottom: 6px; }
input[type="file"] { font-size: 13px; color: var(--text-dim); }
.photo-preview { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.photo-preview .pv {
  position: relative; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--border);
}
.photo-preview .pv img { width: 100%; height: 100%; object-fit: cover; }
.photo-preview .pv button {
  position: absolute; top: 2px; inset-inline-end: 2px; width: 20px; height: 20px;
  border: none; border-radius: 50%; background: rgba(0, 0, 0, .65); color: #fff;
  font-size: 11px; cursor: pointer; line-height: 1;
}

/* Rating input */
.rating-input { display: flex; gap: 4px; direction: rtl; }
.rating-input button {
  border: none; background: none; font-size: 26px; cursor: pointer; color: var(--border);
  padding: 2px; transition: transform .12s;
}
.rating-input button:hover { transform: scale(1.15); }
.rating-input button.on { color: var(--star); }
.rating-input button:focus-visible { outline: 3px solid var(--accent); border-radius: 6px; }

/* Buttons */
.btn {
  font-family: inherit; font-size: 14px; font-weight: 700; padding: 10px 18px;
  border-radius: 10px; border: 1.5px solid transparent; cursor: pointer; transition: all .18s;
}
.btn-primary { background: var(--accent-btn); color: #fff; }
.btn-primary:hover { background: var(--hero-from); }
.btn-ghost { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-ghost:hover { background: var(--accent-soft); }
.btn-danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* Modal */
.modal {
  border: none; border-radius: var(--radius); padding: 0;
  width: min(520px, 94vw); max-height: 90vh; overflow-y: auto;
  background: var(--surface); color: var(--text);
  box-shadow: 0 20px 60px rgba(0, 0, 0, .3);
}
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal-body { padding: 22px; }
.modal-actions { display: flex; align-items: center; gap: 8px; margin-top: 6px; }
.modal-actions .spacer { flex: 1; }

/* Photo viewer */
.photo-modal {
  border: none; padding: 0; background: transparent; max-width: 92vw; max-height: 90vh;
}
.photo-modal::backdrop { background: rgba(0, 0, 0, .8); }
.photo-modal img { max-width: 92vw; max-height: 86vh; border-radius: 10px; display: block; }
.photo-close {
  position: absolute; top: -14px; inset-inline-start: -14px;
  width: 36px; height: 36px; border-radius: 50%; border: none;
  background: #fff; color: #111; font-size: 16px; cursor: pointer; box-shadow: var(--shadow);
}

/* Toast */
.toast {
  position: fixed; bottom: 22px; inset-inline-start: 50%;
  transform: translateX(50%) translateY(80px);
  background: var(--text); color: var(--bg);
  padding: 10px 22px; border-radius: 999px; font-size: 14px; font-weight: 600;
  opacity: 0; transition: all .3s; pointer-events: none; z-index: 50;
  max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(50%) translateY(0); pointer-events: auto; }
.toast-undo {
  font-family: inherit; border: none; background: none; color: #fbbf24;
  font-weight: 800; font-size: 14px; cursor: pointer; margin-inline-start: 12px;
  padding: 2px 8px; border-radius: 6px;
}
.toast-undo:hover { text-decoration: underline; }

.empty-note { text-align: center; color: var(--text-dim); padding: 34px 10px; font-size: 15px; }

@media (max-width: 560px) {
  .brand-sub { display: none; }
  .grid-2 { grid-template-columns: 1fr; }
  .stats-bar { gap: 6px; }
  .stat-num { font-size: 17px; }
}

@media print {
  .app-header, .toolbar, .toast, .apt-photos, .photo-modal { display: none !important; }
  body { background: #fff; color: #000; }
  .apt-card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; }
  .table-wrap { box-shadow: none; border: 1px solid #ccc; }
}
