:root {
  --bg: #f4f2ee;
  --card: #ffffff;
  --ink: #1d232b;
  --muted: #69717c;
  --brand: #1f3a5f;
  --brand-ink: #ffffff;
  --ok: #2f7d4f;
  --err: #b3261e;
  --line: #e2ded6;
  --radius: 14px;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Rubik", "Arial Hebrew", Arial, sans-serif;
  font-size: 17px; line-height: 1.45;
  padding: max(12px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
  -webkit-text-size-adjust: 100%;
}
main { max-width: 640px; margin: 0 auto; }
h1 { font-size: 24px; margin: 8px 0 4px; }
h2 { font-size: 19px; margin: 20px 0 8px; }
p { margin: 6px 0; }
.muted { color: var(--muted); font-size: 15px; }
.hidden { display: none !important; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin: 10px 0; }

button, .btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 56px; width: 100%; padding: 12px 16px; margin: 8px 0;
  border: 0; border-radius: var(--radius); font: inherit; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
button.secondary { background: #e7ebf1; color: var(--brand); }
button:disabled { opacity: .5; }
button:active:not(:disabled) { transform: scale(.985); }

input[type=password], input[type=text] {
  width: 100%; min-height: 56px; font-size: 24px; text-align: center; letter-spacing: 6px;
  border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; background: #fff;
}

.cost {
  position: fixed; top: max(8px, env(safe-area-inset-top)); left: 10px; z-index: 10;
  background: var(--brand); color: #fff; border-radius: 999px; padding: 4px 10px;
  font-size: 13px; font-variant-numeric: tabular-nums; direction: ltr; opacity: .92;
}
.cost.warn { background: #a35c00; }
.cost.over { background: var(--err); }

.msg { padding: 10px 12px; border-radius: 10px; margin: 8px 0; font-size: 15px; }
.msg.err { background: #fdecea; color: var(--err); }
.msg.ok { background: #e8f4ec; color: var(--ok); }

.rooms { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.room { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; min-height: 92px; }
.room b { display: block; }
.room .dims { color: var(--muted); font-size: 13px; direction: ltr; text-align: right; }

.preview { width: 100%; border-radius: 10px; display: block; margin: 8px 0; background: #ddd; }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.pending { display: flex; gap: 10px; align-items: center; border-top: 1px solid var(--line); padding: 8px 0; }
.pending img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; }
.pending .grow { flex: 1; font-size: 14px; }
.pending button { width: auto; min-height: 48px; margin: 0; padding: 8px 14px; }

.room-thumb { height: 84px; margin: -12px -12px 8px; border-radius: var(--radius) var(--radius) 0 0; background: #ddd center/cover; }

.room-row { justify-content: flex-start; text-align: right; background: var(--card); color: var(--ink); border: 1px solid var(--line); font-weight: 400; }
.room-row.disabled { opacity: .55; }
.room-row .thumb { width: 64px; height: 64px; flex: none; border-radius: 10px; background: #e7e3dc center/cover; }
.room-row .grow { flex: 1; }

details { margin: 6px 0; }
summary { cursor: pointer; min-height: 32px; }
.preview.plan { max-height: 280px; object-fit: contain; background: #fff; }

.seg { display: flex; gap: 6px; margin: 8px 0; }
.seg button { margin: 0; min-height: 48px; background: #e7ebf1; color: var(--brand); }
.seg button.on { background: var(--brand); color: #fff; }

textarea { width: 100%; font: inherit; font-size: 15px; padding: 10px; border: 1px solid var(--line); border-radius: 10px; direction: auto; }
.fromchip { display: flex; align-items: center; justify-content: space-between; background: #fff4e0; color: #7a4a00; border-radius: 10px; padding: 4px 4px 4px 12px; margin: 6px 0; font-size: 15px; }
.fromchip .x { width: 44px; min-height: 44px; margin: 0; padding: 0; background: transparent; color: inherit; }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 12px; }
.cand { border: 2px solid transparent; border-radius: 12px; padding: 4px; background: #faf9f6; }
.cand img { width: 100%; border-radius: 8px; display: block; aspect-ratio: 3/4; object-fit: cover; background: #ddd; }
.cand.is-chosen { border-color: var(--ok); }
.cand.is-from { border-color: #d08a00; }
.cand .note { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin: 4px 2px 0; }
.cand .row button { min-height: 48px; margin: 6px 0 0; padding: 6px; font-size: 15px; }

.lightbox { position: fixed; inset: 0; z-index: 50; background: rgba(0,0,0,.92); display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 12px; overflow: auto; }
.lightbox img { max-width: 100%; max-height: calc(100vh - 100px); object-fit: contain; }
.lightbox .close { width: auto; padding: 0 28px; }

.spinner { width: 20px; height: 20px; border: 3px solid rgba(255,255,255,.4); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
