:root {
  /* Tutoy palette (tutoy.naggar-and-estorgy.com): white, pink strip, sky-blue buttons, red highlights, sand */
  --brand: #111111; --brand-2: #333333; --accent: #d0473e; --bg: #f5f5f5; --panel: #ffffff;
  --pink: #f7a8c7; --pink-soft: #fde4ee; --sky: #8fd3f4; --sky-2: #6cc4ef; --sky-soft: #e3f4fd; --sand: #d8b98a; --sand-dark: #a7834c;
  --line: #ebebeb; --text: #444444; --muted: #888888; --ok: #2f855a; --warn: #b4235a; --bad: #d0473e;
  --radius: 8px; font-size: 13px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; font-family: "Segoe UI", system-ui, -apple-system, Tahoma, "Noto Sans Arabic", sans-serif; color: var(--text); background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 5px 10px; border-radius: var(--radius); }
button:hover { border-color: var(--sky-2); }
button.primary { background: var(--sky); color: #111; border-color: var(--sky); border-radius: 30px; padding-inline: 16px; font-weight: 600; }
button.primary:hover { background: var(--sky-2); border-color: var(--sky-2); }
button.danger { color: var(--bad); }
button.active { background: var(--sky); color: #111; border-color: var(--sky-2); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { border: 1px solid var(--line); border-radius: var(--radius); padding: 5px 7px; background: #fff; min-width: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--sky); border-color: var(--sky-2); }
label { display: block; color: var(--muted); font-size: 11px; margin: 6px 0 2px; }
h2 { font-size: 16px; margin: 0 0 12px; color: #111; } h3 { font-size: 13px; margin: 14px 0 6px; color: #111; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border-bottom: 1px solid var(--line); padding: 6px 8px; text-align: start; vertical-align: middle; }
th { background: #fafafa; font-weight: 600; font-size: 12px; color: var(--muted); }
.muted { color: var(--muted); } .small { font-size: 11px; } .right { text-align: end; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.badge { display: inline-block; padding: 1px 6px; border-radius: 10px; font-size: 10px; background: #e2e8f0; color: #334; white-space: nowrap; }
.badge.ok { background: #c6f6d5; color: #22543d; } .badge.warn { background: var(--pink-soft); color: #9b2c5a; } .badge.bad { background: #fed7d7; color: #742a2a; } .badge.info { background: var(--sky-soft); color: #1d6890; }

/* ---------- login ---------- */
.login-wrap { display: grid; place-items: center; height: 100%; background: linear-gradient(135deg, var(--pink), var(--sky)); }
.login-card { background: #fff; padding: 32px; border-radius: 10px; width: 340px; box-shadow: 0 20px 50px rgba(0,0,0,.15); border-top: 6px solid var(--pink); border-radius: 16px; }
.login-card h1 { font-size: 18px; margin: 0; color: var(--brand); } .login-card p { margin: 4px 0 18px; }
.login-card input { width: 100%; } .login-card button { width: 100%; margin-top: 16px; padding: 8px; }
.login-tabs { display: flex; gap: 4px; background: var(--pink-soft); border-radius: 30px; padding: 3px; margin: 0 0 6px; }
.login-tabs button { margin: 0 !important; padding: 7px 6px !important; border: 0; background: transparent; border-radius: 30px; font-weight: 600; color: var(--text); }
.login-tabs button.active { background: #fff; box-shadow: 0 1px 4px rgba(0,0,0,.12); color: #111; }
.login-card form[hidden] { display: none; }
/* client accounts: design tools only (the server refuses the rest anyway) */
body.role-client .staff-only, body.role-client #lib-photo, body.role-client #lib-3d, body.role-client .pcard .badge { display: none !important; }
body:not(.role-client) .client-only { display: none !important; }
/* visitors (not signed in): can look around; starting a design asks them to sign in */
body.guest .member-only { display: none !important; }
body:not(.guest) .guest-only { display: none !important; }
#btn-signin { white-space: nowrap; }
.guest-cta { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
/* clients list printed / saved as PDF */
#print-area { display: none; }
@media print {
  body.printing > *:not(#print-area) { display: none !important; }
  body.printing #print-area { display: block; padding: 0; }
  #print-area table { width: 100%; border-collapse: collapse; font-size: 11px; }
  #print-area th, #print-area td { border: 1px solid #ccc; padding: 4px 6px; text-align: start; }
  #print-area h1 { font-size: 16px; margin: 0 0 4px; }
}
.req-pending { background: var(--pink-soft); }
/* wall / floor colours */
.colours .colour-row { display: flex; align-items: center; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.colours .colour-row > .small { min-width: 42px; font-weight: 600; }
.swatches { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sw { width: 28px; height: 28px; padding: 0; border-radius: 50%; border: 1px solid rgba(0,0,0,.18); box-shadow: inset 0 0 0 2px #fff; cursor: pointer; }
.sw.on { outline: 3px solid var(--sky-2); outline-offset: 1px; }
.sw-custom { position: relative; width: 28px; height: 28px; border-radius: 50%; border: 1px dashed var(--muted); display: grid; place-items: center; cursor: pointer; overflow: hidden; margin: 0; }
.sw-custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; padding: 0; border: 0; }
.sw-custom span { font-size: 15px; color: var(--muted); pointer-events: none; }
@media (max-width: 900px) { .sw, .sw-custom { width: 34px; height: 34px; } }
/* client price quote */
.quote-table img, #print-area img { width: 44px; height: 44px; object-fit: cover; border-radius: 4px; }
.quote-total td { font-weight: 700; font-size: 15px; border-top: 2px solid var(--text); }
.error { color: var(--bad); min-height: 18px; margin-top: 8px; }

/* ---------- shell ---------- */
.app { display: grid; grid-template-rows: 48px 1fr; height: 100%; }
.topbar { background: var(--pink); color: #111; border-bottom: 1px solid #e990b3; display: flex; align-items: center; gap: 12px; padding: 0 12px; }
.topbar .logo { font-weight: 700; letter-spacing: .3px; white-space: nowrap; } .topbar .logo span { color: var(--accent); } .topbar .logo .small { color: var(--muted) !important; }
.topbar nav { display: flex; gap: 2px; }
.topbar nav button { background: transparent; color: #4a2a37; border: none; padding: 14px 12px; border-radius: 0; }
.topbar nav button.active { color: #111; font-weight: 600; box-shadow: inset 0 -3px 0 #111; background: transparent; }
.topbar .project-name { font-weight: 600; } .topbar .save-state { font-size: 11px; color: #5a3445; }
.topbar .logo .small { color: #5a3445 !important; }
.topbar .badge.warn { background: #fff; }
.topbar .user { margin-inline-start: auto; display: flex; gap: 8px; align-items: center; font-size: 12px; }
.topbar .user button { background: #fff; color: #111; border-color: #111; border-radius: 30px; padding-inline: 12px; }
.topbar #btn-projects { border-color: #111; border-radius: 30px; color: #111; }
.settings-btn { display: none; }
.settings-menu { position: fixed; z-index: 70; left: 8px; min-width: 200px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 12px 32px rgba(20,30,45,.25); padding: 6px; display: grid; gap: 4px; }
.settings-menu button { text-align: start; border: none; padding: 10px 12px; font-size: 14px; border-radius: 6px; }
.settings-menu button:hover, .settings-menu button:active { background: var(--sky-soft); }
.view { display: none; min-height: 0; } .view.active { display: block; }
.page { padding: 18px; overflow: auto; height: 100%; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 14px; margin-bottom: 14px; }

/* ---------- design view ---------- */
#view-design.active { display: grid; grid-template-columns: 52px 1fr 340px; height: 100%; }
.toolbar { background: #fff; border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; gap: 4px; padding: 6px; }
.toolbar button { width: 40px; height: 40px; padding: 0; font-size: 17px; display: grid; place-items: center; }
.toolbar hr { width: 100%; border: none; border-top: 1px solid var(--line); margin: 4px 0; }
.workspace { display: grid; grid-template-rows: 36px 1fr 150px; min-width: 0; min-height: 0; }
.ws-bar { display: flex; gap: 6px; align-items: center; padding: 4px 8px; background: #fff; border-bottom: 1px solid var(--line); }
.canvases { display: grid; grid-template-columns: 1fr 1fr; min-height: 0; }
/* the hidden pane leaves the grid, so the visible one is the only item: one full-width column */
.canvases.mode-2d, .canvases.mode-3d { grid-template-columns: 1fr; }
.canvases > div { position: relative; min-width: 0; overflow: hidden; }
.canvases.mode-2d > .pane3d, .canvases.mode-3d > .pane2d { display: none; }
.pane2d { background: #fff; border-inline-end: 1px solid var(--line); } .pane3d { background: #eaf6fd; }
.pane2d canvas, .pane3d canvas { display: block; width: 100%; height: 100%; }
.pane-fit { position: absolute; top: 6px; inset-inline-end: 8px; z-index: 5; width: 38px; height: 38px; padding: 0; display: grid; place-items: center; font-size: 19px; border-radius: 50%; background: #fff; border: 1px solid var(--line); box-shadow: 0 2px 8px rgba(20,30,45,.18); }
body.has-rail .pane-fit { inset-inline-end: 12px; }
.pane-label { position: absolute; top: 6px; inset-inline-start: 8px; font-size: 10px; color: var(--muted); background: rgba(255,255,255,.8); padding: 1px 6px; border-radius: 4px; pointer-events: none; }
.item-hover { position: fixed; z-index: 50; width: 220px; background: #fff; border: 1px solid var(--line); border-radius: 8px; box-shadow: 0 8px 24px rgba(20,30,45,.18); padding: 8px; pointer-events: none; font-size: 12px; }
.item-hover img, .item-hover .noimg { display: block; width: 100%; height: 160px; object-fit: contain; background: #f6f7f9; border-radius: 6px; margin-bottom: 6px; }
.item-hover .noimg { display: grid; place-items: center; color: var(--muted); }
.item-hover .name { font-weight: 600; margin-bottom: 2px; }
.item-del { position: absolute; z-index: 6; width: 36px; height: 36px; padding: 0; display: grid; place-items: center; font-size: 17px; border-radius: 50%; background: #fff; border: 2px solid var(--bad); color: var(--bad); box-shadow: 0 3px 10px rgba(20,30,45,.25); }
.item-del:hover { background: #fff5f5; border-color: var(--bad); }
.drop-hint { position: absolute; inset: 0; border: 3px dashed var(--pink); pointer-events: none; display: none; }
.drag-over .drop-hint { display: block; }
.props { background: #fff; border-top: 1px solid var(--line); padding: 8px 12px; overflow: auto; }
.props .grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 0 10px; }
.props input, .props select { width: 100%; }
.size-box { margin: 8px 0 4px; padding: 8px 10px; background: var(--sky-soft); border: 1px solid var(--sky); border-radius: 12px; }
.size-box .grid input { font-weight: 700; font-size: 14px; background: #fff; }
.size-box #it-size-reset { margin-inline-start: 8px; padding: 2px 10px; border-radius: 30px; }

/* ---------- library panel ---------- */
.library { background: #fff; border-inline-start: 1px solid var(--line); display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.lib-head { padding: 10px; border-bottom: 1px solid var(--line); display: grid; gap: 6px; }
.lib-head .title { font-weight: 700; color: #111; display: flex; justify-content: space-between; }
.lib-head .filters { display: grid; grid-template-columns: 1fr 1fr 70px; gap: 4px; }
.lib-list { overflow: auto; padding: 8px; display: grid; gap: 8px; align-content: start; }
.pcard { display: grid; grid-template-columns: 76px 1fr; gap: 8px; border: 1px solid var(--line); border-radius: 12px; padding: 6px; cursor: grab; background: #fff; }
.pcard:hover { border-color: var(--sky); box-shadow: 0 2px 10px rgba(143,211,244,.35); }
.pcard.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.pcard img, .pcard .noimg { width: 76px; height: 76px; object-fit: contain; background: #f4f5f7; border-radius: 4px; }
.pcard .noimg { display: grid; place-items: center; color: var(--muted); font-size: 10px; }
.pcard .name { font-weight: 600; font-size: 12px; line-height: 1.25; max-height: 30px; overflow: hidden; }
.pcard .dims { font-size: 11px; color: var(--muted); }
.pcard .price { font-weight: 700; color: var(--accent); }
.pcard .src { font-size: 10px; color: var(--sand-dark); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pcard .meta { display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.lib-foot { padding: 6px 10px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; }

/* ---------- modal & toast ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 50; }
.modal { background: #fff; border-radius: 16px; border-top: 5px solid var(--pink); width: min(900px, 94vw); max-height: 90vh; overflow: auto; padding: 18px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal .close { float: inline-end; }
.toast { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); background: #111; color: #fff; padding: 8px 14px; border-radius: 6px; z-index: 60; max-width: 80vw; }
.toast.err { background: var(--bad); }
.thumbs { display: flex; gap: 6px; flex-wrap: wrap; } .thumbs img { width: 90px; height: 90px; object-fit: contain; background: #f4f5f7; border: 1px solid var(--line); border-radius: 4px; }
.review-item { display: grid; grid-template-columns: 1fr 420px; gap: 14px; }
.review-viewer { height: 320px; background: #eaf6fd; border-radius: 6px; position: relative; }
.review-viewer canvas { width: 100%; height: 100%; display: block; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0 12px; }
.form-grid input, .form-grid select, .form-grid textarea { width: 100%; }
textarea.code { font-family: Consolas, monospace; font-size: 12px; width: 100%; min-height: 160px; }
.qt input { width: 90px; }

/* ---------- language ---------- */
.lang-btn { font-weight: 600; }
.login-card { position: relative; }
.login-lang { position: absolute; top: 12px; inset-inline-end: 12px; width: auto !important; margin: 0 !important; padding: 3px 10px !important; font-size: 12px; }
/* drawings and coordinates stay left-to-right in Arabic */
.canvases, input[type=number] { direction: ltr; }
[dir=rtl] input[type=number] { text-align: right; }
.pcard .place { padding: 1px 8px; font-size: 12px; }
/* product / user names keep their own direction (an English name inside Arabic text stays readable) */
.name, .src, .no-i18n, #project-name, #user-name, .modal h2, .review-item h3 { unicode-bidi: plaintext; }

/* ---------- scroll bars: wide and easy to grab ---------- */
* { scrollbar-width: auto; scrollbar-color: var(--sky-2) #f0f0f0; }
::-webkit-scrollbar { width: 14px; height: 14px; }
::-webkit-scrollbar-track { background: #f0f0f0; }
::-webkit-scrollbar-thumb { background: var(--sky); border-radius: 8px; border: 3px solid #f0f0f0; min-height: 40px; }
::-webkit-scrollbar-thumb:hover, ::-webkit-scrollbar-thumb:active { background: var(--sky-2); }
.toolbar, .topbar nav { scrollbar-width: thin; }
/* phones: our own bar on the side of the page (phone browsers hide their thin overlay bar) */
.scroll-rail { position: fixed; z-index: 40; right: 0; width: 22px; background: #f3f3f3; border-left: 1px solid var(--line); touch-action: none; }
.scroll-rail .thumb { position: absolute; left: 3px; right: 3px; min-height: 48px; background: var(--sky); border-radius: 8px; opacity: .75; box-shadow: 0 1px 4px rgba(0,0,0,.25); }
.scroll-rail.dragging .thumb, .scroll-rail .thumb:active { opacity: 1; background: var(--sky-2); }
.scroll-rail .thumb::before { content: ''; position: absolute; left: 4px; right: 4px; top: 50%; height: 7px; margin-top: -4px; border-top: 2px solid rgba(17,17,17,.45); border-bottom: 2px solid rgba(17,17,17,.45); }

/* ---------- phones ---------- */
.canvases canvas { touch-action: none; }
@media (max-width: 900px) {
  :root { font-size: 14px; }
  button { min-height: 34px; }
  .app { grid-template-rows: auto 1fr; grid-template-columns: minmax(0, 1fr); }
  .topbar, main, .view, .workspace, .library, .toolbar { min-width: 0; }
  main { overflow: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none; }
  main::-webkit-scrollbar { display: none; }
  body.has-rail main { padding-right: 22px; padding-left: 0; }
  /* design tools pinned to the bottom of the screen; gone in 3D-only mode */
  main:has(#view-design.active) { padding-bottom: 64px; }
  body[data-mode="3d"] main:has(#view-design.active) { padding-bottom: 0; }
  body[data-mode="3d"] .toolbar { display: none !important; }
  .topbar { flex-wrap: wrap; gap: 2px 6px; padding: 4px 8px 0; }
  .topbar .user { display: none; }
  .settings-btn { display: grid; place-items: center; width: 34px; height: 34px; min-height: 0; padding: 0; font-size: 19px; background: #fff; color: #111; border-color: #111; border-radius: 50%; }
  [dir=ltr] .settings-btn { order: -1; }
  [dir=rtl] .settings-btn { order: 9; margin-inline-start: auto; }
  #nav [data-view="quotes"], #nav [data-view="admin"], #nav [data-view="clients"] { display: none; }
  .ws-bar #hint { display: none; }
  .topbar .logo { font-size: 14px; } .topbar .logo .small { display: none; }
  .topbar #btn-projects { min-height: 0; padding: 4px 8px; font-size: 12px; background: #fff; color: #111; border-color: #111; }
  .topbar .project-name { font-size: 12px; max-width: 45vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .topbar .save-state { display: none; }
  .topbar .user #user-name { display: none; }
  .topbar .user { gap: 4px; } .topbar .user button { padding: 4px 8px; font-size: 12px; }
  .topbar nav { order: 10; width: 100%; overflow-x: auto; scrollbar-width: none; }
  .topbar nav button { padding: 7px 10px; white-space: nowrap; min-height: 0; font-size: 13px; }

  #view-design.active { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto auto; height: auto; }
  .toolbar { flex-direction: row; overflow-x: auto; border-inline-end: none; border-top: 1px solid var(--line); position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); box-shadow: 0 -4px 14px rgba(20,30,45,.12); }
  .toolbar button { flex: 0 0 42px; height: 42px; width: 42px; }
  .toolbar hr { width: 0; height: 28px; border: none; border-inline-start: 1px solid var(--line); margin: 0 2px; align-self: center; }
  .workspace { grid-template-rows: auto 64vh auto; }
  .ws-bar { flex-wrap: wrap; padding: 6px 8px; }
  .ws-bar #hint { order: 10; width: 100%; margin: 2px 0 0 !important; }
  .canvases.mode-split { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .pane2d { border-inline-end: none; border-bottom: 1px solid var(--line); }
  .props { overflow: visible; }
  .props .grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .library { border-inline-start: none; border-top: 4px solid var(--line); max-height: 85vh; }
  .lib-head .filters { grid-template-columns: 1fr 1fr; } .lib-head .filters select:last-child { grid-column: 1 / -1; }
  .pcard { cursor: default; }

  .view.active { height: auto; }
  .page { padding: 12px; height: auto; overflow: visible; }
  .card { overflow-x: auto; padding: 10px; }
  .two-col, .review-item { grid-template-columns: 1fr; }
  .review-viewer { height: 260px; }
  .form-grid { grid-template-columns: 1fr 1fr; }
  table { font-size: 12px; } th, td { padding: 6px 5px; }
  .modal-bg { place-items: stretch; }
  .modal { width: 100vw; max-height: 100%; border-radius: 0; padding: 14px; }
  .modal .row input[style*="width"] { max-width: 100%; }
  .item-hover { width: 180px; }
  .item-hover img, .item-hover .noimg { height: 120px; }
  .toast { bottom: 10px; max-width: 94vw; }
  .login-card { width: min(340px, 92vw); padding: 24px; }
}