/* Razan CRM — premium animated UI
   Palette matches the Razan brand: navy, maroon, sky blue, cream. */

@import url('https://fonts.googleapis.com/css2?family=Sora:wght@400;600;700;800&family=Inter:wght@400;500;600;700&display=swap');

:root {
  --navy: #06065C;
  --navy-soft: #14145E;
  --navy-deep: #030330;
  --maroon: #A70007;
  --red: #ED0101;
  --sky: #5B94FF;
  --sky-soft: #9DBBFF;
  --cream: #F7F5F1;
  --ink: #14142B;
  --ink-soft: #4A4A63;
  --success: #166534;
  --font-display: 'Sora', sans-serif;
  --font-body: 'Inter', sans-serif;
  --shadow-soft: 0 12px 32px -12px rgba(6, 6, 92, 0.18);
  --shadow-strong: 0 24px 60px -20px rgba(6, 6, 92, 0.32);
  --shadow-glow: 0 0 0 4px rgba(91, 148, 255, 0.15);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--font-body);
  background: linear-gradient(160deg, var(--cream) 0%, #EFEDE6 100%);
  color: var(--ink);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { font-family: var(--font-display); color: var(--navy); margin: 0; }

/* ── Animated background orbs (subtle, premium ambiance) ────────────── */
.bg-orbs { position: fixed; inset: 0; overflow: hidden; z-index: 0; pointer-events: none; }
.bg-orbs::before, .bg-orbs::after {
  content: ''; position: absolute; border-radius: 50%; filter: blur(80px); opacity: 0.35;
  animation: float-orb 18s ease-in-out infinite;
}
.bg-orbs::before {
  width: 480px; height: 480px; background: var(--sky-soft);
  top: -120px; left: -120px; animation-delay: 0s;
}
.bg-orbs::after {
  width: 400px; height: 400px; background: var(--maroon);
  bottom: -140px; right: -100px; opacity: 0.12; animation-delay: -9s;
}
@keyframes float-orb {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50% { transform: translate(40px, -30px) scale(1.08); }
}

/* ── Layout ───────────────────────────────────────────────────────────── */
.page { position: relative; z-index: 1; min-height: 100vh; display: flex; flex-direction: column; }
.container { max-width: 640px; margin: 0 auto; padding: 0 20px; width: 100%; }

.top-bar {
  padding: 24px 0; display: flex; align-items: center; justify-content: space-between;
  animation: fade-down 0.6s ease both;
}
.logo img { height: 34px; width: auto; }
.top-phone {
  display: inline-flex; align-items: center; gap: 8px; text-decoration: none;
  color: var(--navy); font-weight: 600; font-size: 14px;
  padding: 8px 16px; border-radius: 999px; background: #fff;
  box-shadow: var(--shadow-soft); transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.top-phone:hover { transform: translateY(-2px); box-shadow: var(--shadow-strong); }

.lang-switch { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.lang-switch a { color: var(--ink-soft); text-decoration: none; padding: 4px 6px; border-radius: 6px; }
.lang-switch a.active { color: var(--navy); font-weight: 700; background: #fff; }
.lang-switch span { color: #d0cec5; }

/* ── Live notification bell ───────────────────────────────────────────── */
.notif-badge {
  position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; padding: 0 3px;
  background: var(--maroon); color: #fff; border-radius: 999px; font-size: 10px; font-weight: 700;
  display: flex; align-items: center; justify-content: center; line-height: 1;
}
.notif-panel {
  display: none; position: absolute; top: 64px; left: 16px; right: 16px; z-index: 70;
  background: #fff; border: 1px solid #EEEDE7; border-radius: 12px; box-shadow: var(--shadow-strong);
}
.notif-panel.open { display: block; }
.notif-item { display: block; padding: 10px 14px; border-bottom: 1px solid #F5F4EF; text-decoration: none; color: var(--ink); font-size: 12.5px; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: #FBF8F2; font-weight: 600; }
.notif-item .notif-time { display: block; font-size: 10.5px; color: var(--ink-soft); font-weight: 400; margin-top: 2px; }

/* ── RTL (Arabic) ─────────────────────────────────────────────────────
   Best-effort global flip: mirrors layout direction and the handful of
   properties that don't auto-flip with `direction`. Components built
   with hard-coded inline `margin-left`/`margin-right` elsewhere in the
   app won't auto-mirror — this covers the shared chrome (nav, forms,
   cards, tables) which is the vast majority of the UI. */
html[dir="rtl"] body { direction: rtl; }
html[dir="rtl"] .req { margin-right: 2px; margin-left: 0; }
html[dir="rtl"] .error-msg { text-align: right; }
html[dir="rtl"] .admin-shell { direction: rtl; }
html[dir="rtl"] .sidebar { border-right: none; border-left: 1px solid #EEEDE7; }
html[dir="rtl"] .nav-link { text-align: right; }
html[dir="rtl"] table.grid-table th, html[dir="rtl"] table.grid-table td { text-align: right; }
html[dir="rtl"] .sidebar-close-btn, html[dir="rtl"] .modal-close { right: auto; left: 18px; }
html[dir="rtl"] .sidebar.open ~ .sidebar-backdrop,
html[dir="rtl"] .sidebar { right: 0; left: auto; }

/* Force LTR reading order for values that are inherently numeric/Latin
   (phone numbers, time ranges like "08:00–10:00", booking references)
   even inside an RTL paragraph — otherwise the browser's bidi algorithm
   can visually reverse the group order (e.g. a phone number's digit
   groups, or a time range's start/end) even though the underlying text
   is correct. */
.ltr { direction: ltr; unicode-bidi: isolate; display: inline-block; }
@media (max-width: 900px) {
  html[dir="rtl"] .sidebar { transform: translateX(100%); }
  html[dir="rtl"] .sidebar.open { transform: translateX(0); }
}

/* ── Entrance animations ─────────────────────────────────────────────── */
@keyframes fade-down { from { opacity: 0; transform: translateY(-16px); } to { opacity: 1; transform: translateY(0); } }
@keyframes fade-up { from { opacity: 0; transform: translateY(24px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scale-in { from { opacity: 0; transform: scale(0.92); } to { opacity: 1; transform: scale(1); } }
@keyframes shake {
  10%, 90% { transform: translateX(-1px); }
  20%, 80% { transform: translateX(2px); }
  30%, 50%, 70% { transform: translateX(-4px); }
  40%, 60% { transform: translateX(4px); }
}
@keyframes checkmark-pop {
  0% { transform: scale(0) rotate(-45deg); opacity: 0; }
  60% { transform: scale(1.15) rotate(0deg); opacity: 1; }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse-ring {
  0% { box-shadow: 0 0 0 0 rgba(91, 148, 255, 0.5); }
  100% { box-shadow: 0 0 0 14px rgba(91, 148, 255, 0); }
}

/* ── Card ─────────────────────────────────────────────────────────────── */
.card {
  background: #ffffff; border-radius: 24px; box-shadow: var(--shadow-strong);
  padding: 40px; animation: fade-up 0.7s cubic-bezier(0.16, 1, 0.3, 1) 0.1s both;
  position: relative; overflow: hidden;
}
.card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: linear-gradient(90deg, var(--navy), var(--sky), var(--maroon));
  background-size: 200% 100%; animation: shimmer 4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

.card-header { margin-bottom: 28px; }
.card-header h1 { font-size: 26px; font-weight: 800; letter-spacing: -0.02em; }
.card-header p { margin-top: 6px; font-size: 14px; color: var(--ink-soft); }

/* ── Modals (admin panel) ─────────────────────────────────────────────
   Shared by every "+Add X" / "Edit X" dialog across clients, cleaners,
   drivers, contracts, etc. Two known flexbox bugs this fixes on
   purpose:
   1. `align-items:center` on a fixed-position flex overlay clips a
      too-tall child from the TOP with no way to scroll to it — using
      `align-items:flex-start` + top/bottom padding + `overflow-y:auto`
      on the overlay itself avoids this entirely.
   2. Without an explicit `max-height` + `overflow-y:auto` on the card,
      a long form (e.g. the cleaner form with skill tags) can exceed
      the viewport with no way to reach the Save button on short
      screens (laptops, landscape mobile, etc).
*/
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  background: rgba(6, 6, 92, 0.45);
  padding: 24px 16px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.modal-overlay.open {
  display: flex;
  align-items: flex-start;
  justify-content: center;
}
.modal-card {
  background: #ffffff;
  border-radius: 20px;
  box-shadow: var(--shadow-strong);
  width: 100%;
  max-width: 480px;
  padding: 28px;
  position: relative;
  margin: 24px auto;
  max-height: calc(100vh - 48px);
  overflow-y: auto;
  animation: scale-in 0.18s ease both;
}
.modal-card.modal-card-wide { max-width: 620px; }
.modal-card h2 {
  font-size: 18px;
  margin: 0 0 18px;
  padding-right: 32px; /* keep title clear of the close button */
}
.modal-close {
  position: absolute;
  top: 18px;
  right: 18px;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  border: none;
  background: var(--cream);
  color: var(--ink-soft);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 16px;
  line-height: 1;
  transition: background 0.15s ease, color 0.15s ease;
}
.modal-close:hover { background: #E5E3DC; color: var(--ink); }
.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 4px;
  position: sticky;
  bottom: -28px;
  background: #fff;
  padding: 14px 0 0;
  margin-bottom: -28px;
}
.modal-actions .btn { flex: 1; }

@media (max-width: 560px) {
  .modal-overlay { padding: 0; }
  .modal-card {
    max-width: 100%;
    width: 100%;
    margin: 0;
    border-radius: 16px 16px 0 0;
    max-height: 92vh;
    align-self: flex-end;
  }
  .modal-overlay.open { align-items: flex-end; }
}

/* ── Progress steps ──────────────────────────────────────────────────── */
.steps { display: flex; gap: 6px; margin-bottom: 32px; }
.step-dot {
  flex: 1; height: 4px; border-radius: 999px; background: #E5E3DC;
  overflow: hidden; position: relative;
}
.step-dot::after {
  content: ''; position: absolute; inset: 0; background: var(--navy);
  transform: scaleX(0); transform-origin: left; transition: transform 0.5s cubic-bezier(0.65, 0, 0.35, 1);
}
.step-dot.done::after, .step-dot.active::after { transform: scaleX(1); }
.step-dot.active::after { background: var(--sky); }

/* ── Form fields ──────────────────────────────────────────────────────── */
.field { margin-bottom: 20px; opacity: 0; animation: fade-up 0.5s ease forwards; }
.field:nth-child(1) { animation-delay: 0.05s; }
.field:nth-child(2) { animation-delay: 0.1s; }
.field:nth-child(3) { animation-delay: 0.15s; }
.field:nth-child(4) { animation-delay: 0.2s; }
.field:nth-child(5) { animation-delay: 0.25s; }
.field:nth-child(6) { animation-delay: 0.3s; }
.field:nth-child(7) { animation-delay: 0.35s; }

/* The staggered fade-in above is a nice touch on the public booking
   form's multi-step wizard, but it's the wrong call inside admin
   modals: every field there sits inside a form that already has a
   hidden csrf/action input as an earlier sibling, which shifts the
   :nth-child count and makes fields beyond the 5th render with zero
   delay (or fully invisible for a beat) every time a modal opens.
   Scope the entrance animation to the public site only. */
.admin-shell .field { opacity: 1; animation: none; }

/* Materials/equipment select while locked to "Yes" because products
   was chosen (equipment is bundled free with products — see main.js's
   syncMaterialWithProduct()). Dimmed + not-allowed cursor signal it's
   not interactive right now, without actually using `disabled` (which
   would stop the field from being submitted with the form). */
.locked-select { opacity: 0.6; cursor: not-allowed; background: #F5F4EF; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 560px) { .field-row { grid-template-columns: 1fr; } }
/* Building/street/zone row — 3 narrow fields instead of the usual 2. */
.field-row-3col { grid-template-columns: 1fr 1fr 1fr; }
@media (max-width: 700px) { .field-row-3col { grid-template-columns: 1fr; } }

label {
  display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600;
  color: var(--ink); margin-bottom: 7px;
}
label .req { color: var(--maroon); }

.input, select, textarea {
  width: 100%; border: 1.5px solid #E5E3DC; border-radius: 12px;
  padding: 13px 16px; font-size: 15px; font-family: var(--font-body);
  color: var(--ink); background: #FBFAF8; transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  outline: none;
}
.input:hover, select:hover, textarea:hover { border-color: #D5D2C8; }
.input:focus, select:focus, textarea:focus {
  border-color: var(--sky); background: #ffffff; box-shadow: var(--shadow-glow);
  transform: translateY(-1px);
}
.input.err, select.err, textarea.err { border-color: var(--red); animation: shake 0.4s ease; }
.error-msg {
  display: none; color: var(--maroon); font-size: 12.5px; margin-top: 6px; font-weight: 500;
}
.error-msg.show { display: block; animation: fade-up 0.2s ease; }

textarea { resize: vertical; min-height: 90px; }

/* ── Submit button ────────────────────────────────────────────────────── */
.btn-submit {
  width: 100%; padding: 16px; border: none; border-radius: 14px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-soft) 100%);
  color: #fff; font-family: var(--font-display); font-weight: 700; font-size: 15.5px;
  cursor: pointer; display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: transform 0.2s ease, box-shadow 0.2s ease; box-shadow: var(--shadow-soft);
  position: relative; overflow: hidden; margin-top: 8px;
}
.btn-submit::before {
  content: ''; position: absolute; inset: 0; background: rgba(255,255,255,0.15);
  transform: translateX(-100%); transition: transform 0.5s ease;
}
.btn-submit:hover::before { transform: translateX(0); }
.btn-submit:hover { transform: translateY(-2px); box-shadow: var(--shadow-strong); }
.btn-submit:active { transform: translateY(0) scale(0.98); }
.btn-submit:disabled { opacity: 0.7; cursor: not-allowed; transform: none; }

.spinner {
  width: 18px; height: 18px; border: 2.5px solid rgba(255,255,255,0.35);
  border-top-color: #fff; border-radius: 50%; animation: spin 0.7s linear infinite; display: none;
}
.btn-submit.loading .spinner { display: inline-block; }
.btn-submit.loading .btn-label { opacity: 0.85; }

/* ── Success state ────────────────────────────────────────────────────── */
.success-view { text-align: center; padding: 20px 0; }
.check-circle {
  width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 22px;
  background: linear-gradient(135deg, var(--sky) 0%, #4577E8 100%);
  display: flex; align-items: center; justify-content: center;
  animation: checkmark-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) both, pulse-ring 2s ease-out 0.6s infinite;
}
.check-circle svg { width: 40px; height: 40px; stroke: #fff; stroke-width: 3; fill: none; }
.success-view h2 { font-size: 22px; margin-bottom: 6px; }
.ref-badge {
  display: inline-block; margin: 14px 0 18px; padding: 10px 22px;
  background: var(--cream); border-radius: 12px; font-family: var(--font-display);
  font-size: 24px; font-weight: 800; letter-spacing: 1px; color: var(--navy);
  animation: scale-in 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.3s both;
}
.success-view p.sub { color: var(--ink-soft); font-size: 14px; max-width: 380px; margin: 0 auto; line-height: 1.6; }

/* ── Chips (contact links) ───────────────────────────────────────────── */
.chip {
  display: inline-flex; align-items: center; gap: 6px; border-radius: 999px;
  background: var(--cream); border: 1px solid #E5E3DC; padding: 7px 14px;
  font-size: 12.5px; font-weight: 600; color: var(--ink); text-decoration: none;
  transition: background 0.2s ease, transform 0.2s ease;
}
.chip:hover { background: #EFEDE6; transform: translateY(-1px); }

/* ── Alert banners ────────────────────────────────────────────────────── */
.alert {
  padding: 13px 16px; border-radius: 12px; font-size: 13.5px; margin-bottom: 18px;
  animation: fade-up 0.3s ease;
}
.alert-error { background: #FEF0F0; color: var(--maroon); border: 1px solid #FBD5D5; }
.alert-success { background: #F0FBF4; color: var(--success); border: 1px solid #C6EDD3; }

/* ── Footer note ──────────────────────────────────────────────────────── */
.footer-note { text-align: center; padding: 28px 0 12px; font-size: 12.5px; color: var(--ink-soft); opacity: 0.8; }

/* ── Admin layout ─────────────────────────────────────────────────────── */
.admin-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 260px; background: #fff; border-right: 1px solid #EEEDE7; flex-shrink: 0;
  display: flex; flex-direction: column;
  /* No entrance animation here on purpose: a completed CSS animation's
     final keyframe value keeps overriding any later plain `transform`
     declaration on the same element for the rest of the page's life —
     which silently broke the mobile off-canvas transform below. */
}
.sidebar-header { padding: 22px; border-bottom: 1px solid #EEEDE7; display: flex; align-items: center; justify-content: space-between; }
.sidebar-nav { flex: 1; padding: 14px; display: flex; flex-direction: column; gap: 3px; overflow-y: auto; }
.nav-label { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--ink-soft); padding: 14px 12px 6px; }
.nav-link {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  text-decoration: none; color: var(--ink-soft); font-size: 14px; font-weight: 500;
  transition: all 0.2s ease;
}
.nav-link:hover { background: #F5F4EF; color: var(--ink); }
.nav-link.active { background: var(--navy); color: #fff; box-shadow: var(--shadow-soft); }
.sidebar-footer { padding: 18px; border-top: 1px solid #EEEDE7; }
.admin-main { flex: 1; min-width: 0; padding: 32px 36px; overflow-x: hidden; animation: fade-up 0.4s ease 0.1s both; }

/* Mobile topbar: hidden on desktop, shown only under the breakpoint below.
   Gives mobile users a hamburger button to open the sidebar, since the
   sidebar itself is off-canvas there. */
.mobile-topbar { display: none; }
.sidebar-backdrop { display: none; }
.sidebar-close-btn { display: none; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: #fff; border-radius: 16px; padding: 18px 20px; box-shadow: var(--shadow-soft);
  transition: transform 0.2s ease; animation: scale-in 0.4s ease both;
}
.stat-card:hover { transform: translateY(-3px); }
.stat-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }
.stat-value { font-family: var(--font-display); font-size: 26px; font-weight: 800; color: var(--navy); margin-top: 4px; }

.data-card { background: #fff; border-radius: 18px; box-shadow: var(--shadow-soft); padding: 24px; animation: fade-up 0.4s ease both; }
table.grid-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.grid-table th {
  text-align: left; padding: 10px 12px; font-size: 11px; text-transform: uppercase;
  letter-spacing: 0.04em; color: var(--ink-soft); border-bottom: 1px solid #EEEDE7;
}
table.grid-table td { padding: 12px; border-bottom: 1px solid #F5F4EF; vertical-align: top; }
table.grid-table tr { transition: background 0.15s ease; }
table.grid-table tbody tr:hover { background: #FAFAF7; }

.row-action {
  display: inline-flex; align-items: center; justify-content: center;
  width: 28px; height: 28px; border-radius: 8px; background: var(--cream);
  color: var(--ink-soft); text-decoration: none; transition: all 0.15s ease;
}
.row-action:hover { background: var(--sky); color: #fff; transform: translateY(-1px); }

.badge { display: inline-block; padding: 4px 12px; border-radius: 999px; font-size: 11.5px; font-weight: 700; color: #fff; }

.btn { display: inline-flex; align-items: center; gap: 6px; padding: 10px 18px; border-radius: 10px;
  border: none; font-weight: 600; font-size: 13.5px; cursor: pointer; text-decoration: none;
  transition: transform 0.15s ease, box-shadow 0.15s ease; }
.btn-primary { background: var(--navy); color: #fff; box-shadow: var(--shadow-soft); }
.btn-primary:hover { transform: translateY(-2px); box-shadow: var(--shadow-strong); }
.btn-outline { background: #fff; border: 1.5px solid #E5E3DC; color: var(--ink); }
.btn-outline:hover { border-color: var(--sky); }

.login-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 30% 20%, var(--navy-soft), var(--navy-deep));
  position: relative;
}
.login-card { width: 100%; max-width: 380px; margin: 20px; }

@media (max-width: 900px) {
  .mobile-topbar {
    display: flex; align-items: center; gap: 14px; padding: 14px 16px;
    background: #fff; border-bottom: 1px solid #EEEDE7; position: sticky; top: 0; z-index: 40;
  }
  .mobile-topbar img { height: 28px; }
  .sidebar-toggle {
    width: 36px; height: 36px; border-radius: 10px; border: 1.5px solid #E5E3DC;
    background: #fff; display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--navy); flex-shrink: 0;
  }
  .admin-shell { flex-direction: column; }
  .sidebar {
    position: fixed; z-index: 60; top: 0; left: 0; height: 100vh; width: 84vw; max-width: 300px;
    transform: translateX(-100%); transition: transform 0.25s ease; box-shadow: var(--shadow-strong);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-close-btn { display: flex; }
  .sidebar-backdrop.open {
    display: block; position: fixed; inset: 0; z-index: 55;
    background: rgba(6, 6, 92, 0.35);
  }
  .admin-main { padding: 20px; }
}
