:root {
  color-scheme: light;
  --ink: #17233b;
  --muted: #6c778c;
  --line: #dfe5ed;
  --line-strong: #cbd4e1;
  --canvas: #f4f7fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --nav: #13243e;
  --nav-soft: #1d3354;
  --blue: #315fec;
  --blue-dark: #2448bc;
  --blue-soft: #edf2ff;
  --teal: #18a486;
  --teal-soft: #e9f8f4;
  --amber: #c47719;
  --amber-soft: #fff5e7;
  --danger: #c94a58;
  --shadow: 0 14px 36px rgba(25, 45, 78, 0.08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: var(--canvas);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }

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

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 256px;
  display: flex;
  flex-direction: column;
  color: #eef4ff;
  background: var(--nav);
  border-right: 1px solid rgba(255,255,255,.08);
}

.brand { display: flex; gap: 12px; align-items: center; padding: 26px 22px 22px; }
.brand-mark {
  width: 42px; height: 42px; display: grid; place-items: center;
  color: #fff; background: linear-gradient(145deg, #517bff, #315fec);
  border-radius: 13px; font-size: 13px; font-weight: 800; letter-spacing: .08em;
  box-shadow: 0 8px 20px rgba(49,95,236,.32);
}
.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; letter-spacing: -.01em; }
.brand span { margin-top: 3px; color: #9fb0c7; font-size: 12px; }

.nav-list { display: grid; gap: 7px; padding: 12px; }
.nav-item {
  width: 100%; display: flex; align-items: center; gap: 12px;
  padding: 12px 13px; color: #b8c7db; background: transparent;
  border: 0; border-radius: 10px; text-align: left; transition: .18s ease;
}
.nav-item:hover { color: #fff; background: rgba(255,255,255,.06); }
.nav-item.active { color: #fff; background: var(--nav-soft); box-shadow: inset 3px 0 #668bff; }
.nav-icon { width: 23px; font-size: 19px; text-align: center; }
.nav-item span:last-child { font-size: 14px; font-weight: 650; }

.nav-list-bottom { margin-top: auto; padding-top: 12px; border-top: 1px solid rgba(255,255,255,.08); }

.sidebar-footer { padding: 18px; }
.prototype-state { display: flex; gap: 11px; padding: 13px; background: rgba(255,255,255,.055); border: 1px solid rgba(255,255,255,.08); border-radius: 12px; }
.prototype-state strong, .prototype-state span { display: block; }
.prototype-state strong { font-size: 12px; }
.prototype-state span { margin-top: 4px; color: #90a4be; font-size: 11px; }
.status-dot { flex: 0 0 auto; width: 8px; height: 8px; margin-top: 4px; border-radius: 50%; background: #ffb44c; box-shadow: 0 0 0 4px rgba(255,180,76,.12); }

.main-area { width: calc(100% - 256px); min-height: 100vh; margin-left: 256px; }
.topbar { height: 70px; display: flex; align-items: center; justify-content: space-between; padding: 0 34px; background: rgba(255,255,255,.9); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.breadcrumb { display: flex; gap: 9px; align-items: center; font-size: 13px; }
.breadcrumb span, .breadcrumb b { color: #9aa5b5; font-weight: 500; }
.breadcrumb strong { color: var(--ink); }
.topbar-actions { display: flex; align-items: center; gap: 13px; }
.preview-badge, .not-connected, .schedule-state { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.preview-badge { padding: 7px 10px; color: #94601d; background: var(--amber-soft); border: 1px solid #f0d3aa; }
.avatar { width: 35px; height: 35px; display: grid; place-items: center; color: #fff; background: var(--nav-soft); border-radius: 50%; font-size: 11px; font-weight: 800; }
.mobile-menu { display: none; border: 0; background: transparent; font-size: 21px; }

.lang-switch { display: flex; align-items: center; gap: 6px; padding: 0 6px 0 12px; height: 35px; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 999px; }
.lang-switch .lang-icon { font-size: 13px; }
.lang-switch select { height: 33px; padding: 0 6px; color: var(--ink); background: transparent; border: 0; border-radius: 999px; font-size: 12px; font-weight: 700; cursor: pointer; }
.lang-switch select:focus { box-shadow: none; }

.logout-button { padding: 9px 13px; color: #48566b; background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; font-size: 12px; font-weight: 700; }
.logout-button:hover { background: var(--surface-soft); }

.view { max-width: 1480px; margin: 0 auto; padding: 38px 34px 56px; }
.page-heading { display: flex; align-items: end; justify-content: space-between; gap: 24px; margin-bottom: 26px; }
.eyebrow { display: block; margin-bottom: 7px; color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .11em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 8px; font-size: clamp(27px, 3vw, 38px); line-height: 1.12; letter-spacing: -.035em; }
h2 { margin-bottom: 5px; font-size: 17px; letter-spacing: -.015em; }
.page-heading p, .panel-heading p { margin-bottom: 0; color: var(--muted); }
.page-heading p { font-size: 14px; }
.panel-heading p { font-size: 12px; }
.section-legend { max-width: 760px; margin: -14px 0 22px; color: var(--muted); font-size: 12px; line-height: 1.6; }

.content-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.form-column { display: grid; gap: 18px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 16px; box-shadow: 0 2px 2px rgba(21,39,67,.01); }
.form-column > .panel { padding: 22px; }
.panel-heading { display: flex; gap: 13px; align-items: flex-start; margin-bottom: 20px; }
.panel-heading-action { justify-content: space-between; align-items: center; }
.heading-group { display: flex; gap: 13px; align-items: flex-start; }
.step-number { flex: 0 0 auto; width: 28px; height: 28px; display: grid; place-items: center; color: var(--blue); background: var(--blue-soft); border-radius: 8px; font-size: 12px; font-weight: 800; }

.field-grid { display: grid; gap: 15px; }
.field-grid.one-third { grid-template-columns: minmax(150px, .45fr) 1fr; }
.field-grid.schedule-grid { grid-template-columns: repeat(3, 1fr); }
.field { min-width: 0; display: grid; gap: 7px; }
.field > span { color: #46536a; font-size: 12px; font-weight: 700; }
.field > span b { color: var(--danger); }
.field > span i { color: #929cad; font-size: 10px; font-style: normal; font-weight: 600; }
input, select, textarea {
  width: 100%; color: var(--ink); background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px; outline: none; transition: border .15s, box-shadow .15s;
}
input, select { height: 43px; padding: 0 12px; }
textarea { padding: 12px; resize: vertical; line-height: 1.55; }
input::placeholder, textarea::placeholder { color: #a2acbb; }
input:focus, select:focus, textarea:focus { border-color: #6d8df0; box-shadow: 0 0 0 3px rgba(49,95,236,.11); }

.secondary-button, .small-button, .empty-add, .icon-button, .primary-button, .token-row button { border-radius: 9px; font-weight: 700; }
.secondary-button { padding: 9px 13px; color: #48566b; background: var(--surface); border: 1px solid var(--line-strong); font-size: 12px; }
.secondary-button:hover { background: var(--surface-soft); }
.small-button { padding: 8px 11px; color: var(--blue); background: var(--blue-soft); border: 1px solid #d9e2ff; font-size: 11px; }
.small-button:hover { background: #e2e9ff; }

.repeat-list { display: grid; gap: 10px; }
.repeat-card { display: grid; grid-template-columns: 29px minmax(0, 1fr) 32px; gap: 12px; align-items: center; padding: 13px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; }
.repeat-index { width: 26px; height: 26px; display: grid; place-items: center; color: #667389; background: #fff; border: 1px solid var(--line); border-radius: 8px; font-size: 11px; font-weight: 800; }
.repeat-fields { display: grid; gap: 12px; }
.resident-fields, .vehicle-fields { grid-template-columns: 1fr 1fr; }
.icon-button { width: 31px; height: 31px; padding: 0; color: #8e99aa; background: transparent; border: 1px solid transparent; font-size: 19px; }
.icon-button:hover { color: var(--danger); background: #fff1f2; border-color: #f3d5d9; }
.empty-add { width: 100%; min-height: 96px; display: grid; place-items: center; gap: 3px; padding: 14px; color: var(--muted); background: var(--surface-soft); border: 1px dashed var(--line-strong); }
.empty-add:hover { color: var(--blue); background: var(--blue-soft); border-color: #9eb2f4; }
.empty-add span { font-size: 22px; }
.empty-add strong { color: inherit; font-size: 12px; }
.empty-add small { font-size: 10px; font-weight: 500; }

.sticky-panel { position: sticky; top: 20px; padding: 20px; box-shadow: var(--shadow); }
.preview-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; margin-bottom: 17px; }
.preview-heading h2 { font-size: 20px; }
.not-connected { padding: 6px 8px; color: #8b5a18; background: var(--amber-soft); border: 1px solid #f1d7b4; white-space: nowrap; }
.destination-card { padding: 15px; border: 1px solid var(--line); border-radius: 12px; }
.destination-card + .destination-card { margin-top: 11px; }
.accountant-destination { background: #f8faff; }
.gate-destination { background: #f5fbf9; }
.destination-title { display: flex; align-items: center; gap: 10px; margin-bottom: 13px; }
.destination-title strong, .destination-title small { display: block; }
.destination-title strong { font-size: 12px; }
.destination-title small { margin-top: 2px; color: var(--muted); font-size: 10px; }
.destination-icon { width: 31px; height: 31px; display: grid; place-items: center; color: #fff; background: var(--blue); border-radius: 8px; font-size: 11px; font-weight: 800; }
.gate-destination .destination-icon { background: var(--teal); }
dl { margin: 0; }
dl > div { display: grid; grid-template-columns: 70px 1fr; gap: 8px; padding: 7px 0; border-top: 1px solid #e5eaf2; }
dt { color: var(--muted); font-size: 10px; }
dd { margin: 0; color: #344056; font-size: 11px; font-weight: 700; text-align: right; overflow-wrap: anywhere; }
.vehicle-preview { display: grid; gap: 7px; color: #314059; font-size: 11px; }
.vehicle-preview-row { display: flex; justify-content: space-between; gap: 8px; padding-top: 7px; border-top: 1px solid #dfece8; }
.vehicle-preview-row b { color: var(--teal); }
.empty-preview { padding-top: 8px; color: var(--muted); border-top: 1px solid #dfece8; }
.privacy-note { display: flex; gap: 10px; margin: 15px 0; padding: 12px; color: #637086; background: var(--surface-soft); border-radius: 10px; }
.privacy-note span { color: var(--blue); }
.privacy-note p { margin: 0; font-size: 10px; line-height: 1.5; }
.primary-button { width: 100%; padding: 12px 16px; color: #fff; background: var(--blue); border: 0; box-shadow: 0 8px 18px rgba(49,95,236,.2); }
.primary-button:hover { background: var(--blue-dark); }
.button-caption { margin: 9px 0 0; color: #929cad; font-size: 10px; text-align: center; }

.module-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 18px; }
.module-grid.city-grid { grid-template-columns: repeat(3, 1fr); }
.module-card { min-height: 210px; display: flex; flex-direction: column; align-items: flex-start; padding: 24px; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-align: left; box-shadow: var(--shadow); }
button.module-card:hover { border-color: #9eb2f4; transform: translateY(-2px); }
.module-symbol { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 25px; color: var(--blue); background: var(--blue-soft); border-radius: 12px; font-size: 20px; }
.module-card strong { font-size: 16px; }
.module-card > span:nth-of-type(2) { margin-top: 8px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.module-card em { margin-top: auto; padding-top: 18px; color: var(--blue); font-size: 11px; font-style: normal; font-weight: 800; }
.muted-module { box-shadow: none; border-style: dashed; }

.schedule-state { padding: 8px 11px; color: #7d581e; background: var(--amber-soft); border: 1px solid #f1d7b4; }
.schedule-state span { width: 7px; height: 7px; background: #e39b32; border-radius: 50%; }
.input-suffix { position: relative; }
.input-suffix input { padding-right: 50px; }
.input-suffix em { position: absolute; top: 50%; right: 12px; color: var(--muted); font-size: 11px; font-style: normal; transform: translateY(-50%); }
.token-row { display: flex; flex-wrap: wrap; gap: 7px; align-items: center; margin-top: 11px; }
.token-row span { color: var(--muted); font-size: 10px; }
.token-row button { padding: 5px 7px; color: var(--blue); background: var(--blue-soft); border: 1px solid #dce4ff; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 10px; }
.delivery-panel { display: flex; justify-content: space-between; align-items: center; gap: 20px; }
.delivery-panel p { margin: 0; color: var(--muted); font-size: 12px; }
.switch-row { display: flex; align-items: center; gap: 8px; }
.switch-row input { position: absolute; opacity: 0; }
.switch-row span { width: 36px; height: 21px; position: relative; background: var(--blue); border-radius: 99px; }
.switch-row span::after { content: ""; position: absolute; top: 3px; right: 3px; width: 15px; height: 15px; background: #fff; border-radius: 50%; }
.switch-row em { color: var(--muted); font-size: 10px; font-style: normal; font-weight: 700; }
.phone-preview { overflow: hidden; background: #e8e3dc; border: 6px solid #202a3a; border-radius: 18px; }
.phone-top { display: flex; justify-content: space-between; padding: 11px 13px; color: #fff; background: #235d52; font-size: 10px; font-weight: 700; }
.chat-area { min-height: 250px; padding: 22px 12px; background-color: #ebe6df; background-image: radial-gradient(rgba(61,80,72,.07) .7px, transparent .7px); background-size: 11px 11px; }
.message-bubble { max-width: 91%; margin-left: auto; padding: 11px 12px 18px; white-space: pre-wrap; color: #273237; background: #d7f7c8; border-radius: 10px 10px 2px 10px; box-shadow: 0 1px 2px rgba(20,30,35,.12); font-size: 11px; line-height: 1.5; }
.message-time { display: block; margin: -15px 6px 0 0; color: #658071; font-size: 8px; text-align: right; }
.schedule-summary { margin: 13px 0; padding: 10px; color: #58657a; background: var(--surface-soft); border-radius: 9px; font-size: 10px; text-align: center; }

.placeholder-panel { max-width: 760px; padding: 60px 30px; text-align: center; }
.placeholder-icon { width: 54px; height: 54px; display: grid; place-items: center; margin: 0 auto 18px; color: var(--blue); background: var(--blue-soft); border-radius: 16px; font-size: 24px; }
.placeholder-panel p { max-width: 560px; margin: 0 auto; color: var(--muted); font-size: 13px; line-height: 1.6; }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; background: rgba(11,22,40,.58); backdrop-filter: blur(5px); }
.modal-backdrop[hidden] { display: none; }
.modal { position: relative; width: min(470px, 100%); padding: 30px; background: var(--surface); border-radius: 18px; box-shadow: 0 25px 70px rgba(8,20,40,.25); text-align: center; }
.modal-close { position: absolute; top: 13px; right: 14px; width: 31px; height: 31px; color: var(--muted); background: var(--surface-soft); border: 0; border-radius: 50%; font-size: 20px; }
.modal-check { width: 46px; height: 46px; display: grid; place-items: center; margin: 0 auto 16px; color: var(--teal); background: var(--teal-soft); border-radius: 50%; font-weight: 800; }
.modal > p { color: var(--muted); font-size: 12px; line-height: 1.55; }
.modal-summary { margin: 18px 0; padding: 14px; white-space: pre-line; color: #435069; background: var(--surface-soft); border-radius: 11px; font-size: 11px; line-height: 1.6; text-align: left; }
.modal-done { width: auto; min-width: 130px; }
.toast { position: fixed; right: 22px; bottom: 22px; z-index: 120; padding: 12px 16px; color: #fff; background: var(--nav); border-radius: 10px; box-shadow: var(--shadow); font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(12px); transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

/* ---------------- Login screen ---------------- */
.login-screen { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--nav); }
.login-card { width: min(360px, 100%); display: grid; gap: 14px; padding: 32px 28px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); text-align: center; }
.login-card .login-mark { justify-self: center; margin-bottom: 4px; }
.login-card h1 { font-size: 22px; }
.login-card p { color: var(--muted); font-size: 13px; }
.login-card .field { text-align: left; }
.login-card .primary-button { margin-top: 4px; }
.login-error { margin: 0; padding: 10px; color: #9c2f3d; background: #fdeeef; border: 1px solid #f3d5d9; border-radius: 9px; font-size: 12px; }
.login-lang-switch { justify-self: center; margin-top: 6px; }
[dir="rtl"] .login-card .field { text-align: right; }

/* ---------------- Log tables (camera logs, debt, messaging log) ---------------- */
.log-panel + .log-panel { margin-top: 18px; }
.log-panel .panel-heading { margin-bottom: 16px; }
.log-table { --log-cols: 5; display: grid; gap: 2px; }
.log-row { display: grid; grid-template-columns: repeat(var(--log-cols), 1fr); gap: 12px; align-items: center; padding: 12px 14px; border-radius: 10px; font-size: 12px; }
.log-row:not(.log-head) { background: var(--surface-soft); }
.log-row:not(.log-head) + .log-row:not(.log-head) { margin-top: 6px; }
.log-head { color: var(--muted); font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; padding: 0 14px 8px; }
.log-table.debt-table, .debt-table.log-table { --log-cols: 4; }
.log-row b { font-weight: 800; }
.status-badge { justify-self: start; padding: 4px 9px; border-radius: 999px; font-size: 10px; font-weight: 800; }
.status-good { color: #146c53; background: var(--teal-soft); }
.status-bad { color: #9c2f3d; background: #fdeeef; }
[dir="rtl"] .status-badge { justify-self: end; }

.debt-owing-table .log-row { grid-template-columns: 80px 1.6fr 1fr 110px auto; }
.log-actions { display: flex; gap: 6px; justify-self: start; }
.log-actions .small-button { white-space: nowrap; }
.log-actions .paid-button { color: #146c53; background: var(--teal-soft); border-color: #bfe6da; }
.log-actions .paid-button:hover { background: #d9f2ea; }
[dir="rtl"] .log-actions { justify-self: end; }

/* ---------------- Accounts (settings) ---------------- */
.accounts-panel { padding: 22px; }
.accounts-list { display: grid; gap: 8px; margin-bottom: 16px; }
.account-row { display: flex; align-items: center; gap: 12px; padding: 11px 13px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 10px; font-size: 12px; font-weight: 700; }
.account-row .account-dots { flex: 1; color: var(--muted); font-weight: 400; letter-spacing: .04em; }
.account-form { display: grid; grid-template-columns: 1fr 1fr 1fr auto; gap: 12px; align-items: end; }
.accounts-security-note { margin: 14px 0 0; padding: 11px; color: var(--muted); background: var(--surface-soft); border-radius: 9px; font-size: 11px; line-height: 1.5; }

@media (max-width: 1050px) {
  .content-grid { grid-template-columns: 1fr; }
  .sticky-panel { position: static; }
  .module-grid { grid-template-columns: 1fr 1fr; }
  .module-grid.city-grid { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 900px) {
  .debt-owing-table .log-row { grid-template-columns: 1fr; }
  .account-form { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 760px) {
  .sidebar { width: 240px; transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .main-area { width: 100%; margin-left: 0; }
  .topbar { padding: 0 18px; }
  .mobile-menu { display: block; }
  .breadcrumb { display: none; }
  .view { padding: 28px 17px 42px; }
  .page-heading { align-items: flex-start; }
  .field-grid.one-third, .field-grid.schedule-grid, .resident-fields, .vehicle-fields { grid-template-columns: 1fr; }
  .repeat-card { align-items: start; }
  .module-grid, .module-grid.city-grid { grid-template-columns: 1fr; }
  .delivery-panel { align-items: flex-start; flex-direction: column; }
  .account-form { grid-template-columns: 1fr; }
  .log-row { grid-template-columns: 1fr; gap: 4px; }
  .log-head { display: none; }
  .log-row:not(.log-head) { display: grid; }
}

@media (max-width: 480px) {
  .page-heading { flex-direction: column; }
  .topbar-actions .preview-badge { display: none; }
  .panel-heading-action { align-items: flex-start; flex-direction: column; }
  .small-button { margin-left: 41px; }
  .repeat-card { grid-template-columns: 1fr 30px; }
  .repeat-index { display: none; }
}

/* Right-to-left layout (Arabic, Kurdish Sorani) */
[dir="rtl"] body { font-family: "Segoe UI", Tahoma, "Noto Sans Arabic", "Noto Naskh Arabic", Inter, ui-sans-serif, Arial, sans-serif; }

[dir="rtl"] .sidebar { inset: 0 0 0 auto; border-right: 0; border-left: 1px solid rgba(255,255,255,.08); }
[dir="rtl"] .main-area { margin-left: 0; margin-right: 256px; }
[dir="rtl"] .nav-item.active { box-shadow: inset -3px 0 #668bff; }
[dir="rtl"] dd { text-align: left; }
[dir="rtl"] .modal-close { right: auto; left: 14px; }
[dir="rtl"] .input-suffix input { padding-right: 12px; padding-left: 50px; }
[dir="rtl"] .input-suffix em { right: auto; left: 12px; }
[dir="rtl"] .toast { right: auto; left: 22px; }
[dir="rtl"] .message-bubble { margin-left: 0; margin-right: auto; border-radius: 10px 10px 10px 2px; }
[dir="rtl"] .message-time { text-align: left; margin: -15px 0 0 6px; }

@media (max-width: 760px) {
  [dir="rtl"] .sidebar { transform: translateX(100%); }
  [dir="rtl"] body.sidebar-open .sidebar { transform: translateX(0); }
  [dir="rtl"] .main-area { margin-right: 0; }
}

@media (max-width: 480px) {
  [dir="rtl"] .small-button { margin-left: 0; margin-right: 41px; }
}
