:root {
    color-scheme: light;
    --ink: #172a26;
    --muted: #65756f;
    --brand: #0f5a4d;
    --brand-2: #117b67;
    --mint: #e7f4ef;
    --line: #dce7e2;
    --paper: #fff;
    --canvas: #f4f7f5;
    --warning: #a46113;
    --danger: #a83c3c;
    --soft-shadow: 0 12px 32px rgba(20, 55, 43, .07);
    font-family: Inter, Assistant, Arial, sans-serif;
}

:root:lang(ar) { font-family: Cairo, Inter, Assistant, Arial, sans-serif; }
:root:lang(he) { font-family: Rubik, Inter, Assistant, Arial, sans-serif; }

* { box-sizing: border-box; }
body { margin: 0; background: radial-gradient(ellipse at top, #eaf3ef 0, var(--canvas) 42rem); color: var(--ink); }
button, input, select, textarea { font: inherit; }
button, select { cursor: pointer; }
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar { position: sticky; inset-block-start: 0; z-index: 10; height: 72px; padding: 0 clamp(16px, 4vw, 56px); display: flex; align-items: center; justify-content: space-between; background: rgba(255,255,255,.92); border-bottom: 1px solid var(--line); box-shadow: 0 4px 18px rgba(20,55,43,.04); backdrop-filter: blur(14px); }
.brand { display: inline-flex; gap: 10px; align-items: center; color: var(--brand); text-decoration: none; font-size: 1.35rem; font-weight: 800; letter-spacing: -.04em; }
.brand img { border-radius: 14px; box-shadow: 0 4px 12px rgba(15,90,77,.18); }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.language-select, .button, input, select, textarea { border: 1px solid var(--line); border-radius: 12px; background: white; color: var(--ink); }
.language-select { padding: 10px 13px; }
#main-content { width: min(1240px, calc(100% - 40px)); margin: 28px auto; flex: 1; }
.auth-card { width: min(460px, 100%); margin: clamp(24px, 7vh, 80px) auto; padding: clamp(24px, 5vw, 42px); background: white; border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--soft-shadow); }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 10px; font-size: clamp(1.45rem, 3vw, 2rem); letter-spacing: -.04em; }
h2 { font-size: 1.15rem; }
.eyebrow { margin-bottom: 8px; color: var(--brand-2); font-weight: 700; font-size: .82rem; letter-spacing: .06em; text-transform: uppercase; }
.muted, small { color: var(--muted); }
.stack { display: grid; gap: 16px; }
label { display: grid; gap: 7px; color: #30453f; font-size: .9rem; font-weight: 600; }
input, select, textarea { width: 100%; padding: 12px 13px; outline: none; }
input:focus, select:focus, textarea:focus { border-color: #3c9280; box-shadow: 0 0 0 4px rgba(60,146,128,.14); }
button:focus-visible, a:focus-visible { outline: 3px solid rgba(17,123,103,.35); outline-offset: 2px; }
textarea { resize: vertical; }
.button { min-height: 44px; padding: 10px 16px; font-weight: 700; transition: transform .16s, background .16s, box-shadow .16s; }
.button:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(15,90,77,.12); }
.button-primary { border-color: var(--brand); background: linear-gradient(135deg, var(--brand), var(--brand-2)); color: white; }
.button-primary:hover { background: linear-gradient(135deg, #0c4d42, #0f705d); }
.button-quiet { background: transparent; }
.button-small { min-height: 34px; padding: 6px 10px; font-size: .82rem; }
.setup-link { margin: 20px 0 0; text-align: center; }
.setup-link a { color: var(--brand-2); font-weight: 600; }
.dashboard { display: grid; gap: 20px; }
.welcome-row, .panel-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.welcome-row h1 { margin: 0; }
.welcome-row .eyebrow { margin-bottom: 4px; }
.connection-chip { display: inline-flex; border-radius: 999px; padding: 8px 13px; color: var(--brand); background: var(--mint); font-weight: 700; font-size: .82rem; }
.section-nav { display: flex; gap: 7px; overflow-x: auto; padding: 5px; background: #e9f0ed; border: 1px solid rgba(220,231,226,.8); border-radius: 16px; }
.section-nav button { flex: 0 0 auto; border: 0; border-radius: 12px; background: transparent; color: #426057; padding: 11px 15px; font-weight: 700; transition: background .15s, color .15s; }
.section-nav button.selected { background: white; color: var(--brand); box-shadow: 0 3px 10px rgba(23,58,48,.09); }
.section-content { display: grid; gap: 18px; }
.panel { padding: clamp(18px, 3vw, 30px); background: rgba(255,255,255,.96); border: 1px solid var(--line); border-radius: 22px; box-shadow: var(--soft-shadow); }
.panel-heading { margin-bottom: 18px; }
.panel-heading h1, .panel-heading h2 { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { display: grid; gap: 14px; padding: 20px; border: 1px solid var(--line); border-radius: 18px; background: white; box-shadow: 0 5px 18px rgba(20,55,43,.04); }
.stat-card span { color: var(--muted); font-weight: 600; }
.stat-card strong { color: var(--brand); font-size: 1.8rem; }
.order-card { display: grid; gap: 12px; padding: 17px 0; border-top: 1px solid var(--line); }
.order-card:first-of-type { border-top: 0; }
.order-heading, .order-footer { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.order-heading > div { display: grid; gap: 5px; }
.order-heading small { font-size: .8rem; }
.badge { border-radius: 999px; padding: 6px 10px; font-size: .78rem; font-weight: 700; white-space: nowrap; background: #fff4dc; color: var(--warning); }
.status-done { color: #186541; background: #e3f4ea; }
.status-canceled { color: var(--danger); background: #fae7e7; }
.badge-local { color: #5a6062; background: #eef0f1; }
.order-lines { display: grid; gap: 7px; margin: 0; padding-inline-start: 20px; }
.order-lines li { display: flex; justify-content: space-between; gap: 10px; }
.order-note { margin: 0; padding: 10px 12px; color: var(--muted); border-inline-start: 3px solid #b6d2c8; border-radius: 8px; background: #f7faf8; }
.order-footer { align-items: center; }
.button-row { display: flex; flex-wrap: wrap; gap: 7px; }
.inline-field { display: flex; align-items: center; gap: 10px; }
.inline-field select { width: auto; min-width: 150px; padding: 8px; }
.order-builder { max-width: none; }
.form-grid, .manager-form { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.manager-form { margin-bottom: 22px; }
.manager-form-wide { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.wide { grid-column: 1 / -1; }
.check-field { display: flex; align-items: center; gap: 9px; }
.check-field input { width: auto; }
.agent-assignment { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 14px; border: 1px solid var(--line); border-radius: 10px; }
.agent-assignment legend { padding: 0 7px; color: var(--muted); }
.agent-assignment label { display: flex; align-items: center; gap: 7px; }
.agent-assignment input { width: auto; }
.item-picker { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); align-items: stretch; gap: 16px; }
.item-picker h2 { grid-column: 1 / -1; margin: 4px 0 0; }
.item-row { display: flex; min-width: 0; flex-direction: column; gap: 13px; padding: 14px; border: 1px solid var(--line); border-radius: 18px; background: linear-gradient(160deg, #fff, #fbfdfc); box-shadow: 0 5px 18px rgba(20,55,43,.045); transition: border-color .16s, box-shadow .16s, transform .16s; }
.item-row:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(20,55,43,.09); }
.item-row:focus-within, .item-row:has(.item-select input:checked) { border-color: var(--brand-2); box-shadow: 0 0 0 3px rgba(17,123,103,.1), 0 10px 24px rgba(20,55,43,.08); }
.item-choice { display: flex; min-width: 0; flex: 1; flex-direction: column; gap: 12px; }
.item-select { display: flex; min-height: 48px; align-items: flex-start; gap: 10px; }
.item-select input { width: 20px; height: 20px; flex: 0 0 20px; margin: 2px 0 0; accent-color: var(--brand-2); }
.item-select span { display: grid; min-width: 0; gap: 4px; }
.item-select strong { line-height: 1.35; }
.item-select small { overflow-wrap: anywhere; font-size: .78rem; }
.item-image-strip { display: grid; width: 100%; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; overflow: hidden; padding: 0; }
.item-image-strip img { display: block; width: 100%; height: auto; aspect-ratio: 4 / 3; border: 1px solid var(--line); border-radius: 12px; object-fit: cover; background: var(--canvas); }
.item-image-strip img:only-child { grid-column: 1 / -1; aspect-ratio: 16 / 9; max-height: 190px; }
.item-image-strip-manager { display: flex; max-width: 230px; gap: 7px; overflow-x: auto; padding: 2px 0; }
.item-image-strip-manager img { width: 48px; height: 48px; flex: 0 0 auto; aspect-ratio: auto; border-radius: 9px; }
.image-remove-button { position: relative; flex: 0 0 auto; padding: 0; border: 0; border-radius: 9px; background: transparent; }
.image-remove-button span { position: absolute; inset-block-start: 2px; inset-inline-end: 2px; display: grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; color: white; background: var(--danger); font-weight: 800; }
.item-price { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding-top: 11px; border-top: 1px solid var(--line); text-align: start; font-size: 1.04rem; font-weight: 800; }
.item-price small { color: var(--warning); font-size: .72rem; }
.quantity-control { display: flex; align-items: center; justify-content: flex-end; }
.quantity-control input { width: 96px; min-width: 0; padding: 10px; text-align: center; font-weight: 700; }
.quantity-control input:disabled { background: #f1f3f2; color: #919b97; }
.client-information { padding: 17px; border: 1px solid #d5e9e1; border-radius: 16px; background: linear-gradient(135deg, #eff9f5, #e6f3ee); }
.client-facts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px 16px; }
.client-facts > strong, .client-facts > div { grid-column: 1 / -1; }
.client-facts ul { display: flex; flex-wrap: wrap; gap: 8px 22px; margin: 8px 0 0; padding-inline-start: 20px; }
.order-submit { display: flex; align-items: center; justify-content: space-between; gap: 15px; padding-top: 14px; border-top: 1px solid var(--line); }
.table-wrap { width: 100%; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; text-align: start; }
th, td { padding: 12px 10px; border-bottom: 1px solid var(--line); text-align: start; white-space: nowrap; }
th { color: var(--muted); font-size: .82rem; }
.message-list { display: grid; gap: 12px; }
.message-card { padding: 15px; border: 1px solid var(--line); border-radius: 13px; }
.message-card.unread { border-color: #9dc8b6; background: #f2faf6; }
.message-card p { margin: 8px 0; white-space: pre-wrap; }
.message-card small { display: block; margin-bottom: 8px; }
.empty-state { padding: 24px; color: var(--muted); text-align: center; }
.hidden { display: none !important; }
.footer { display: flex; justify-content: space-between; padding: 16px clamp(16px, 4vw, 56px); color: var(--muted); font-size: .8rem; }
.connection-status.is-offline { color: var(--warning); }
.toast { position: fixed; z-index: 20; inset-inline: 16px; bottom: 20px; width: fit-content; max-width: calc(100% - 32px); margin-inline: auto; padding: 12px 18px; color: white; background: #1d332d; border-radius: 14px; box-shadow: 0 8px 25px rgba(14,32,26,.22); opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.print-sheet { display: none; }

@media (max-width: 760px) {
    #main-content { width: min(calc(100% - 20px), 720px); margin: 16px auto; }
    .topbar { height: 64px; padding-inline: 14px; }
    .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .manager-form-wide { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .item-picker { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 13px; }
    .item-row { padding: 12px; }
    .order-footer { align-items: flex-start; flex-direction: column; }
    .client-facts { grid-template-columns: 1fr; }
}

@media (max-width: 480px) {
    .form-grid, .manager-form, .manager-form-wide { grid-template-columns: 1fr; }
    .wide, .agent-assignment { grid-column: 1; }
    .order-heading { flex-wrap: wrap; }
    .section-nav button { padding: 10px 12px; }
    .item-picker { grid-template-columns: 1fr; }
    .order-submit { align-items: stretch; flex-direction: column; }
    .order-submit .button { width: 100%; }
}

@media print {
    @page { size: A4; margin: 16mm; }
    body { background: white; }
    body > * { display: none !important; }
    .print-sheet { display: block !important; color: #111; font: 12pt Arial, sans-serif; }
    .print-brand { display: flex; align-items: center; gap: 10px; font-size: 20pt; color: #123c35; }
    .print-brand img { width: 38px; height: 38px; }
    .print-sheet h1 { margin-top: 22px; }
    .print-sheet table { margin-top: 20px; }
    .print-sheet th, .print-sheet td { border: 1px solid #bbb; }
}
