/* UPL Portal — RTL-first, logical properties so English (LTR) mirrors cleanly. No inline styles (CSP). */
:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --ink: #1d2433;
  --muted: #6b7385;
  --line: #e2e5eb;
  --brand: #0f4c5c;
  --brand-ink: #ffffff;
  --accent: #c9a227;
  --danger: #b42318;
  --ok: #1a7f4b;
  --warn: #b25e09;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 10%);
  font-family: 'Segoe UI', Tahoma, 'Noto Sans Arabic', system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body { margin: 0; min-height: 100vh; line-height: 1.5; }
h1 { font-size: 1.5rem; margin: 0; }
h2 { font-size: 1.05rem; margin: 0 0 0.75rem; }
h3 { font-size: 0.95rem; margin: 1rem 0 0.5rem; }
a { color: var(--brand); }
code { font-family: Consolas, 'Courier New', monospace; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
}
button {
  border: 1px solid var(--line);
  background: var(--surface);
  border-radius: 8px;
  padding: 0.45rem 0.9rem;
  cursor: pointer;
}
button:hover:not(:disabled) { border-color: var(--brand); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, white); }
button.link { border: 0; background: none; color: var(--brand); padding: 0.25rem 0.4rem; text-decoration: underline; }
.icon-btn { border: 0; background: none; font-size: 1.15rem; padding: 0.25rem 0.5rem; position: relative; }
input, select, textarea {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  min-inline-size: 0;
}
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid color-mix(in srgb, var(--brand) 50%, white); outline-offset: 1px; }

/* ── forms ── */
.field { display: flex; flex-direction: column; gap: 0.25rem; margin-block-end: 0.8rem; flex: 1; }
.field label { font-size: 0.85rem; color: var(--muted); }
.hint { color: var(--muted); }
.row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; align-items: center; margin-block: 0.5rem; }
.inline-form { display: flex; gap: 0.5rem; align-items: flex-start; flex-wrap: wrap; margin-block-end: 0.75rem; }
.inline-form textarea, .inline-form input { flex: 1; min-inline-size: 12rem; }
.form-error { color: var(--danger); background: #fef3f2; border: 1px solid #fecdca; border-radius: 8px; padding: 0.5rem 0.75rem; margin-block: 0.5rem; }
.notice { background: #ecfdf3; border: 1px solid #abefc6; color: var(--ok); border-radius: 8px; padding: 0.5rem 0.75rem; margin-block-end: 0.75rem; }
.check { display: flex; align-items: center; gap: 0.4rem; margin-block: 0.3rem; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 0.8rem; }

/* ── auth ── */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 1rem; background: linear-gradient(135deg, var(--brand), #123b47); }
.auth-card { inline-size: min(26rem, 100%); background: var(--surface); border-radius: 14px; padding: 1.75rem; box-shadow: 0 10px 30px rgb(0 0 0 / 25%); }
.auth-card h1 { margin-block-end: 1rem; }
.auth-brand { display: flex; align-items: center; gap: 0.6rem; margin-block-end: 1.25rem; font-weight: 600; }
.auth-brand .lang-toggle { margin-inline-start: auto; }
.logo { background: var(--brand); color: var(--accent); font-weight: 800; border-radius: 8px; padding: 0.2rem 0.5rem; letter-spacing: 0.05em; }
.secret { display: block; padding: 0.5rem; background: var(--bg); border-radius: 6px; word-break: break-all; }
.codes { columns: 2; padding-inline-start: 1.2rem; }

/* ── layout ── */
.layout { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; justify-content: space-between; padding: 0.6rem 1.25rem; background: var(--surface); border-block-end: 1px solid var(--line); position: sticky; inset-block-start: 0; z-index: 10; }
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 600; }
.topbar-actions { display: flex; align-items: center; gap: 0.5rem; }
.who { color: var(--muted); }
.body { display: flex; flex: 1; }
.nav { inline-size: 13rem; background: var(--surface); border-inline-end: 1px solid var(--line); padding: 1rem 0.6rem; display: flex; flex-direction: column; gap: 0.2rem; }
.nav a { padding: 0.5rem 0.75rem; border-radius: 8px; text-decoration: none; color: var(--ink); }
.nav a:hover { background: var(--bg); }
.nav a.active { background: color-mix(in srgb, var(--brand) 12%, white); color: var(--brand); font-weight: 600; }
.main { flex: 1; padding: 1.25rem 1.5rem; min-inline-size: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-block-end: 1rem; flex-wrap: wrap; }
.page-head > div:first-child { display: flex; align-items: center; gap: 0.75rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); margin-block-end: 1rem; min-inline-size: 0; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(20rem, 1fr)); gap: 1rem; }

/* ── bell ── */
.bell-wrap { position: relative; }
.badge { position: absolute; inset-block-start: -0.2rem; inset-inline-end: -0.2rem; background: var(--danger); color: white; border-radius: 999px; font-size: 0.7rem; padding: 0 0.35rem; min-inline-size: 1.1rem; text-align: center; }
.bell-panel { position: absolute; inset-inline-end: 0; inset-block-start: 2.4rem; inline-size: min(24rem, 90vw); max-block-size: 70vh; overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 10px 30px rgb(0 0 0 / 15%); padding: 0.75rem; }
.bell-head { display: flex; justify-content: space-between; align-items: center; margin-block-end: 0.5rem; }
.bell-list { list-style: none; margin: 0; padding: 0; }
.bell-list li { border-block-end: 1px solid var(--line); }
.bell-list li.unread .bell-title { font-weight: 700; }
.bell-list li.unread { background: color-mix(in srgb, var(--accent) 8%, white); }
.bell-item { display: flex; flex-direction: column; align-items: flex-start; gap: 0.15rem; inline-size: 100%; border: 0; background: none; text-align: start; padding: 0.55rem 0.4rem; border-radius: 0; }
.bell-item small { color: var(--muted); }

/* ── tables & filters ── */
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-block-end: 1rem; }
.filters input[type='search'] { min-inline-size: 16rem; }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
.table { inline-size: 100%; border-collapse: collapse; }
.table th, .table td { padding: 0.6rem 0.75rem; text-align: start; border-block-end: 1px solid var(--line); white-space: nowrap; }
.table th { font-size: 0.8rem; color: var(--muted); font-weight: 600; background: #fafbfc; }
.table tr.clickable { cursor: pointer; }
.table tr.clickable:hover td { background: #f8fafc; }
.pager { display: flex; gap: 0.75rem; align-items: center; justify-content: center; margin-block: 1rem; }

/* ── pills & stages ── */
.pill { display: inline-block; border-radius: 999px; padding: 0.1rem 0.6rem; font-size: 0.8rem; background: var(--bg); border: 1px solid var(--line); margin-inline: 0.25rem; }
.pill.warn { background: #fffaeb; border-color: #fedf89; color: var(--warn); }
.stage-NEW_INQUIRY { background: #eff8ff; border-color: #b2ddff; }
.stage-CONTACTED { background: #f4f3ff; border-color: #d9d6fe; }
.stage-TOUR_SCHEDULED { background: #fdf2fa; border-color: #fcceee; }
.stage-OFFER_SUBMITTED { background: #fffaeb; border-color: #fedf89; }
.stage-UNDER_CONTRACT { background: #fef6ee; border-color: #f9dbaf; }
.stage-CLOSED_WON { background: #ecfdf3; border-color: #abefc6; }
.stage-CLOSED_LOST { background: #fef3f2; border-color: #fecdca; }
.stage-buttons { display: flex; flex-wrap: wrap; gap: 0.4rem; align-items: center; }
.stage-btn { border-radius: 999px; }

.facts { display: grid; grid-template-columns: max-content 1fr; gap: 0.35rem 1rem; margin: 0; }
.facts dt { color: var(--muted); font-size: 0.85rem; }
.facts dd { margin: 0; }
.plain { list-style: none; padding: 0; margin: 0; }
.plain li { padding-block: 0.35rem; border-block-end: 1px solid var(--line); display: flex; justify-content: space-between; gap: 0.5rem; align-items: center; }
.timeline { list-style: none; padding: 0; margin: 0; max-block-size: 24rem; overflow: auto; }
.timeline li { border-inline-start: 3px solid var(--line); padding: 0.25rem 0.75rem; margin-block-end: 0.5rem; }
.timeline li.system { border-color: var(--accent); }
.timeline small { color: var(--muted); }
.timeline p { margin: 0.15rem 0 0; white-space: pre-wrap; }
.hist-STAGE_CHANGE { border-color: var(--brand) !important; }

/* ── tours week ── */
.week { display: grid; grid-template-columns: repeat(7, minmax(9rem, 1fr)); gap: 0.5rem; overflow-x: auto; }
.day { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 0.5rem; min-block-size: 10rem; }
.day.today { border-color: var(--brand); }
.day h3 { margin: 0 0 0.5rem; font-size: 0.85rem; color: var(--muted); }
.tour { display: flex; flex-direction: column; align-items: flex-start; gap: 0.1rem; inline-size: 100%; text-align: start; margin-block-end: 0.4rem; border-inline-start: 4px solid var(--brand); }
.tour small { color: var(--muted); }
.tour.status-CANCELLED { opacity: 0.6; border-inline-start-color: var(--danger); text-decoration: line-through; }
.tour.status-COMPLETED { border-inline-start-color: var(--ok); }
.tour.status-NO_SHOW { border-inline-start-color: var(--warn); }

/* ── modal & toast ── */
.backdrop { position: fixed; inset: 0; background: rgb(16 24 40 / 45%); display: grid; place-items: center; padding: 1rem; z-index: 50; }
.modal { background: var(--surface); border-radius: 14px; inline-size: min(34rem, 100%); max-block-size: 90vh; overflow: auto; box-shadow: 0 20px 50px rgb(0 0 0 / 30%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 0.9rem 1.1rem; border-block-end: 1px solid var(--line); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 1rem 1.1rem; }
#toast-root { position: fixed; inset-block-end: 1rem; inset-inline-start: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 0.5rem; z-index: 60; }
.toast { background: var(--ink); color: white; border-radius: 8px; padding: 0.6rem 1rem; box-shadow: var(--shadow); }
.toast.success { background: var(--ok); }
.toast.error { background: var(--danger); }

@media (max-width: 760px) {
  .body { flex-direction: column; }
  .nav { inline-size: auto; flex-direction: row; overflow-x: auto; border-inline-end: 0; border-block-end: 1px solid var(--line); }
  .main { padding: 1rem; }
  .who { display: none; }
}

/* ── 10b: tabs, gallery, notices ── */
.tabs { display: flex; gap: 0.25rem; border-block-end: 1px solid var(--line); margin-block-end: 1rem; flex-wrap: wrap; }
.tabs a { padding: 0.5rem 0.9rem; text-decoration: none; color: var(--muted); border-block-end: 2px solid transparent; }
.tabs a.active { color: var(--brand); border-block-end-color: var(--brand); font-weight: 600; }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.75rem; margin-block-end: 0.75rem; }
.gallery figure { margin: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--bg); }
.gallery figure.cover { border-color: var(--accent); }
.gallery img { display: block; inline-size: 100%; aspect-ratio: 4 / 3; object-fit: cover; }
.gallery figcaption { display: flex; gap: 0.25rem; align-items: center; padding: 0.3rem; flex-wrap: wrap; }
.notice.warn { background: #fffaeb; border-color: #fedf89; color: var(--warn); }
.table td.wrap { white-space: normal; max-inline-size: 28rem; word-break: break-word; }
.table td.actions { margin: 0; }
button.link.danger { color: var(--danger); }
