:root {
  --bg: #EEF3F2;
  --surface: #FFFFFF;
  --surface-2: #F6F9F8;
  --ink: #15232A;
  --muted: #586A72;
  --line: #D5DFDD;
  --primary: #0B6E61;
  --primary-hover: #095A50;
  --primary-ink: #FFFFFF;
  --primary-soft: #DDEFEA;
  --ok: #2B7A4B;
  --risk: #B26B00;
  --bad: #C0392B;
  --pause: #687B86;
  --note: #FFF4CC;
  --note-line: #E3C55C;
  --focus: #1D8CF0;
  --shadow: 0 1px 2px rgba(21, 35, 42, .06), 0 8px 24px rgba(21, 35, 42, .08);
  --font: "IBM Plex Sans Hebrew", "Segoe UI", Arial, sans-serif;
  --display: "Fredoka", "IBM Plex Sans Hebrew", "Segoe UI", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0E1618;
    --surface: #152024;
    --surface-2: #1A272B;
    --ink: #E4EDEB;
    --muted: #94A7AC;
    --line: #27383C;
    --primary: #36B3A0;
    --primary-hover: #4CC5B2;
    --primary-ink: #06201C;
    --primary-soft: #143430;
    --ok: #5CC488;
    --risk: #E5A33A;
    --bad: #F07563;
    --pause: #8FA2AC;
    --note: #2F2A12;
    --note-line: #7C6A22;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg); color: var(--ink); font: 15px/1.55 var(--font);
  padding: env(safe-area-inset-top, 0) env(safe-area-inset-right, 0) env(safe-area-inset-bottom, 0) env(safe-area-inset-left, 0);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { font-family: var(--display); font-weight: 600; line-height: 1.2; margin: 0; letter-spacing: 0; }
h1 { font-size: 1.9rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--primary); }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.hidden { display: none !important; }
.boot { padding: 4rem; text-align: center; color: var(--muted); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: 500 .95rem/1 var(--font); padding: .7rem 1.1rem; border-radius: 10px; border: 1px solid transparent;
  background: var(--primary); color: var(--primary-ink); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--primary-hover); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.quiet { background: transparent; color: var(--primary); padding: .45rem .6rem; }
.btn.quiet:hover { background: var(--primary-soft); }
.btn.danger { background: transparent; color: var(--bad); border-color: var(--line); }
.btn.big { padding: 1rem 1.5rem; font-size: 1.05rem; border-radius: 14px; }
.btn.sm { padding: .45rem .7rem; font-size: .85rem; border-radius: 8px; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.spread { justify-content: space-between; }
.grow { flex: 1; }
label.field { display: grid; gap: .3rem; font-weight: 500; font-size: .9rem; }
label.field > span.hint { font-weight: 400; color: var(--muted); font-size: .82rem; }
input, select, textarea {
  font: 400 .95rem/1.4 var(--font); color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 9px; padding: .62rem .75rem; width: 100%; min-width: 0;
}
textarea { resize: vertical; min-height: 6rem; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: 0 0 0 3px var(--primary-soft); }
input[type=checkbox] { width: auto; accent-color: var(--primary); }
.check { display: inline-flex; gap: .45rem; align-items: center; font-size: .9rem; cursor: pointer; }
.form { display: grid; gap: .9rem; }
.form-grid { display: grid; gap: .9rem; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

/* ---------- chips ---------- */
.chip { display: inline-flex; align-items: center; gap: .3rem; font-size: .78rem; font-weight: 500; padding: .18rem .6rem; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); color: var(--ink); white-space: nowrap; }
.chip.status-פתוח { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
.chip.status-בטיפול { background: #E3EEFB; border-color: transparent; color: #1F5FA6; }
.chip.status-ממתין { background: #F3EBDD; border-color: transparent; color: #8A5A00; }
.chip.status-נסגר { color: var(--muted); }
.chip.p-דחוף { background: var(--bad); color: #fff; border-color: transparent; }
.chip.p-גבוה { color: var(--bad); border-color: currentColor; }
.chip.brand-קיווי::before, .chip.brand-הוניגמן::before, .chip.brand-אידישקייט::before, .chip.brand-מטה::before { content: ""; width: .5rem; height: .5rem; border-radius: 50%; background: var(--b); }
.chip.brand-קיווי { --b: #5BAA3C; }
.chip.brand-הוניגמן { --b: #8B4C8F; }
.chip.brand-אידישקייט { --b: #2F6DB5; }
.chip.brand-מטה { --b: var(--pause); }
@media (prefers-color-scheme: dark) {
  .chip.status-בטיפול { background: #172C44; color: #8EBBEF; }
  .chip.status-ממתין { background: #33291A; color: #E5B865; }
}

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; background: var(--surface); border-bottom: 1px solid var(--line); }
.topbar-in { display: flex; align-items: center; gap: 1rem; padding: .6rem 1.2rem; max-width: 1500px; margin: 0 auto; }
.logo { display: flex; align-items: center; gap: .55rem; font-family: var(--display); font-weight: 600; font-size: 1.25rem; color: var(--ink); text-decoration: none; }
.logo img { width: 30px; height: 30px; }
.who { margin-inline-start: auto; display: flex; align-items: center; gap: .5rem; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); font-weight: 600; font-family: var(--display); }
.menu { position: relative; }
.menu-list { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); background: var(--surface); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); min-width: 220px; padding: .35rem; z-index: 30; }
.menu-list button { display: block; width: 100%; text-align: start; background: none; border: 0; padding: .6rem .75rem; border-radius: 8px; font: inherit; color: var(--ink); cursor: pointer; }
.menu-list button:hover { background: var(--surface-2); }
.menu-list .sep { border-top: 1px solid var(--line); margin: .3rem 0; }

/* ---------- auth ---------- */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; }
.auth-card { width: min(420px, 100%); background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 2rem; display: grid; gap: 1.2rem; }
.auth-card .logo { font-size: 1.5rem; }
.auth-card .logo img { width: 40px; height: 40px; }
.alert { padding: .75rem 1rem; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--line); font-size: .92rem; }
.alert.bad { border-color: var(--bad); color: var(--bad); background: transparent; }
.alert.warn { background: #FFF1D6; border-color: #E9C27A; color: #6B4700; }
@media (prefers-color-scheme: dark) { .alert.warn { background: #33281A; border-color: #6E5420; color: #F0C987; } }

/* ---------- agent layout ---------- */
.desk { display: grid; grid-template-columns: 236px 1fr; gap: 1.2rem; max-width: 1500px; margin: 0 auto; padding: 1.2rem; align-items: start; }
.nav { position: sticky; top: 72px; display: grid; gap: .15rem; }
.nav button { display: flex; justify-content: space-between; align-items: center; gap: .5rem; width: 100%; background: none; border: 0; padding: .6rem .8rem; border-radius: 10px; font: 500 .95rem var(--font); color: var(--ink); cursor: pointer; text-align: start; }
.nav button:hover { background: var(--surface); }
.nav button[aria-current=true] { background: var(--surface); box-shadow: inset -3px 0 0 var(--primary); color: var(--primary); }
.nav .count { font-size: .8rem; font-weight: 600; min-width: 1.6rem; text-align: center; padding: .05rem .45rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); }
.nav .count.alarm { background: var(--bad); color: #fff; }
.nav .count.warn { background: var(--risk); color: #fff; }
.nav hr { border: 0; border-top: 1px solid var(--line); margin: .6rem .4rem; }
.pulse { display: grid; gap: .55rem; margin-top: .8rem; padding: .9rem; border-radius: 14px; background: var(--surface); }
.pulse div { display: flex; justify-content: space-between; align-items: baseline; font-size: .86rem; color: var(--muted); }
.pulse strong { font-family: var(--display); font-size: 1.15rem; color: var(--ink); font-weight: 600; }

.board { background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); min-width: 0; }
.board-head { display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; padding: 1rem 1.1rem; border-bottom: 1px solid var(--line); }
.board-head h2 { margin-inline-end: auto; }
.board-head input[type=search] { width: 230px; }
.board-head select { width: auto; }
.queue { list-style: none; margin: 0; padding: 0; }
.qrow { display: grid; grid-template-columns: 4.2rem minmax(0, 1fr) 9rem 8rem 10.5rem; gap: .9rem; align-items: center; padding: .85rem 1.1rem; border-bottom: 1px solid var(--line); cursor: pointer; position: relative; }
.qrow:hover { background: var(--surface-2); }
.qrow[aria-selected=true] { background: var(--primary-soft); }
.qrow.urgent::before { content: ""; position: absolute; inset-inline-start: 0; top: .5rem; bottom: .5rem; width: 4px; border-radius: 0 4px 4px 0; background: var(--bad); }
.qid { font-family: var(--display); font-weight: 500; color: var(--muted); }
.qsubj { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.qmeta { display: flex; gap: .35rem; flex-wrap: wrap; margin-top: .25rem; align-items: center; }
.qcell { font-size: .88rem; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.empty { padding: 3rem 1.5rem; text-align: center; color: var(--muted); display: grid; gap: .8rem; justify-items: center; }
.more { padding: 1rem; text-align: center; }

/* ---------- SLA fuse (the signature element) ---------- */
.fuse { display: grid; gap: .3rem; }
.fuse-label { font-size: .8rem; font-weight: 600; display: flex; justify-content: space-between; gap: .4rem; }
.fuse-track { height: 6px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.fuse-fill { height: 100%; border-radius: 6px; background: var(--ok); transition: width .4s ease; margin-inline-start: auto; }
.fuse.ok .fuse-label { color: var(--ok); }
.fuse.risk .fuse-label { color: var(--risk); } .fuse.risk .fuse-fill { background: var(--risk); }
.fuse.breached .fuse-label, .fuse.missed .fuse-label { color: var(--bad); } .fuse.breached .fuse-fill, .fuse.missed .fuse-fill { background: var(--bad); }
.fuse.breached .fuse-track { background: repeating-linear-gradient(-45deg, transparent 0 5px, color-mix(in srgb, var(--bad) 22%, transparent) 5px 10px); }
.fuse.paused .fuse-label { color: var(--pause); } .fuse.paused .fuse-fill { background: var(--pause); }
.fuse.met .fuse-label { color: var(--muted); } .fuse.met .fuse-fill { background: var(--line); }
.fuse.big .fuse-track { height: 10px; }
.fuse.big .fuse-label { font-size: .9rem; }

/* ---------- drawer & dialogs ---------- */
.scrim { position: fixed; inset: 0; background: rgba(8, 18, 20, .35); z-index: 40; }
.drawer { position: fixed; top: 0; bottom: 0; inset-inline-end: 0; width: min(760px, 100%); background: var(--bg); z-index: 41; display: flex; flex-direction: column; box-shadow: var(--shadow); animation: slide .22s ease-out; }
@keyframes slide { from { transform: translateX(-24px); opacity: .4; } to { transform: none; opacity: 1; } }
.drawer-head { background: var(--surface); padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); display: grid; gap: .6rem; padding-top: max(1rem, env(safe-area-inset-top)); }
.drawer-body { flex: 1; overflow: auto; padding: 1.1rem 1.25rem 2rem; display: grid; gap: 1rem; align-content: start; }
.panel { background: var(--surface); border-radius: 14px; padding: 1rem 1.1rem; display: grid; gap: .8rem; border: 1px solid var(--line); }
.controls { display: grid; gap: .7rem; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
dialog { border: 0; border-radius: 18px; padding: 0; width: min(560px, calc(100% - 2rem)); background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(8, 18, 20, .45); }
.dlg { padding: 1.4rem; display: grid; gap: 1rem; }
.dlg.wide { width: min(860px, 100%); }

/* ---------- thread ---------- */
.thread { display: grid; gap: .75rem; }
.msg { padding: .8rem 1rem; border-radius: 14px; background: var(--surface); border: 1px solid var(--line); max-width: 92%; }
.msg.it { background: var(--primary-soft); border-color: transparent; justify-self: end; }
.msg.mine { justify-self: start; }
.msg.note { background: var(--note); border: 1px dashed var(--note-line); justify-self: end; }
.msg-head { display: flex; gap: .5rem; align-items: baseline; font-size: .82rem; color: var(--muted); margin-bottom: .3rem; flex-wrap: wrap; }
.msg-head strong { color: var(--ink); font-weight: 600; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; }
.event { font-size: .82rem; color: var(--muted); text-align: center; display: flex; align-items: center; gap: .6rem; }
.event::before, .event::after { content: ""; flex: 1; border-top: 1px dashed var(--line); }
.composer { display: grid; gap: .6rem; }

/* ---------- requester home ---------- */
.home { max-width: 820px; margin: 0 auto; padding: 1.6rem 1.2rem 3rem; display: grid; gap: 1.4rem; }
.hello { display: grid; gap: .9rem; padding: 1.6rem; border-radius: 20px; background: var(--surface); box-shadow: var(--shadow); }
.hello h1 { font-size: 2rem; }
.tabs { display: flex; gap: .3rem; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: 0; padding: .6rem .9rem; font: 500 .95rem var(--font); color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button[aria-selected=true] { color: var(--primary); border-bottom-color: var(--primary); }
.cards { display: grid; gap: .8rem; }
.tcard { background: var(--surface); border-radius: 16px; padding: 1rem 1.1rem; border: 1px solid var(--line); display: grid; gap: .6rem; cursor: pointer; text-align: start; font: inherit; color: inherit; width: 100%; }
.tcard:hover { border-color: var(--primary); }
.tcard.attention { border-color: var(--risk); box-shadow: inset 4px 0 0 var(--risk); }
.steps { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }
.steps span { font-size: .78rem; color: var(--muted); padding-top: .4rem; border-top: 4px solid var(--line); }
.steps span.on { color: var(--primary); border-top-color: var(--primary); font-weight: 600; }

/* ---------- new ticket ---------- */
.tiles { display: grid; gap: .6rem; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.tile { display: grid; gap: .4rem; justify-items: start; text-align: start; padding: .9rem; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); cursor: pointer; font: inherit; color: var(--ink); }
.tile svg { width: 26px; height: 26px; color: var(--primary); }
.tile b { font-weight: 600; font-size: .95rem; }
.tile small { color: var(--muted); font-size: .78rem; line-height: 1.35; }
.tile[aria-pressed=true] { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 2px var(--primary); }
.urg { display: grid; gap: .5rem; }
.urg label { display: grid; grid-template-columns: auto 1fr auto; gap: .7rem; align-items: center; padding: .7rem .9rem; border-radius: 12px; border: 1px solid var(--line); cursor: pointer; }
.urg label:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.urg input { width: auto; accent-color: var(--primary); }
.urg .promise { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.tip { padding: .8rem 1rem; border-radius: 12px; background: var(--surface-2); border-inline-start: 4px solid var(--primary); font-size: .9rem; }

/* ---------- rating ---------- */
.stars { display: flex; gap: .2rem; direction: ltr; justify-content: flex-end; }
.stars button { background: none; border: 0; font-size: 2rem; line-height: 1; cursor: pointer; color: var(--line); padding: .1rem; }
.stars button.on { color: #E3A008; }

/* ---------- admin ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: start; padding: .6rem .7rem; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-weight: 600; color: var(--muted); font-size: .82rem; }
tr.off td { color: var(--muted); }

/* ---------- toasts ---------- */
#toasts { position: fixed; bottom: max(1rem, env(safe-area-inset-bottom)); inset-inline-start: 50%; transform: translateX(50%); display: grid; gap: .5rem; z-index: 60; width: min(440px, calc(100% - 2rem)); }
.toast { padding: .8rem 1rem; border-radius: 12px; background: var(--ink); color: var(--bg); box-shadow: var(--shadow); font-weight: 500; }
.toast.bad { background: var(--bad); color: #fff; }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .qrow { grid-template-columns: 3.6rem minmax(0, 1fr) 9.5rem; }
  .qrow .qcell.store, .qrow .qcell.assignee { display: none; }
}
@media (max-width: 820px) {
  .desk { grid-template-columns: 1fr; padding: .7rem; }
  .nav { position: static; display: flex; overflow-x: auto; gap: .3rem; padding-bottom: .2rem; }
  .nav button { width: auto; white-space: nowrap; background: var(--surface); }
  .nav hr, .pulse { display: none; }
  .board-head input[type=search] { width: 100%; }
  .qrow { grid-template-columns: 1fr; gap: .45rem; }
  .qrow .qid { font-size: .85rem; }
  .hello h1 { font-size: 1.6rem; }
  .topbar-in { padding: .55rem .8rem; }
  .who .name { display: none; }
}
textarea.note { background: var(--note); border-color: var(--note-line); }

/* Mobile-first ticket creation: full usable viewport and touch controls. */
.ticket-mobile { max-width:100%; }
.ticket-mobile .tile, .ticket-mobile .urg label { min-height:56px; }
.ticket-mobile button[type="submit"] { min-height:48px; }
@media (max-width: 650px) {
  dialog:has(.ticket-mobile) {
    position:fixed; inset:0; margin:0; padding:0; width:100%; max-width:100%;
    height:100dvh; max-height:100dvh; border:0; border-radius:0;
    overflow-y:auto; overscroll-behavior:contain;
    padding-top:env(safe-area-inset-top); padding-bottom:env(safe-area-inset-bottom);
  }
  dialog:has(.ticket-mobile) .ticket-mobile { padding:1rem .85rem 1.4rem; gap:.75rem; }
  .ticket-mobile h2 { font-size:1.45rem; margin:0; }
  .ticket-mobile h3 { font-size:1.08rem; margin:.3rem 0 0; }
  .ticket-mobile .tiles { grid-template-columns:repeat(2,minmax(0,1fr)); gap:.55rem; }
  .ticket-mobile .tile { padding:.75rem; min-height:104px; gap:.25rem; }
  .ticket-mobile .tile svg { width:24px; height:24px; }
  .ticket-mobile .tile b { font-size:.9rem; line-height:1.35; }
  .ticket-mobile .tile small { font-size:.75rem; }
  .ticket-mobile .urg label { grid-template-columns:auto minmax(0,1fr); gap:.5rem; }
  .ticket-mobile .urg .promise { grid-column:2; white-space:normal; }
  .ticket-mobile .form-grid { grid-template-columns:1fr; }
  .ticket-mobile input, .ticket-mobile textarea, .ticket-mobile select { font-size:16px; min-height:48px; }
  .ticket-mobile textarea { min-height:125px; }
  .ticket-mobile .form > .row:last-child { position:sticky; bottom:0; background:var(--surface); padding:.8rem 0 max(.65rem,env(safe-area-inset-bottom)); margin-bottom:-.5rem; border-top:1px solid var(--line); z-index:2; }
  .ticket-mobile .form > .row:last-child button { flex:1; min-height:50px; }
}

/* Mobile ticket detail: usable controls instead of a narrow desktop drawer. */
@media (max-width: 650px) {
  .drawer { width: 100vw; max-width: 100vw; inset-inline: 0; }
  .drawer-head { padding: .75rem .85rem; }
  .drawer-body { padding: .8rem .7rem 5rem; }
  .drawer .panel { padding: .8rem; }
  .drawer .controls { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .drawer .controls .field { min-width: 0; }
  .drawer .composer .row { flex-wrap: wrap; }
  .drawer .composer button, .drawer .panel > div > button { min-height: 44px; }
  .drawer .composer input[type=file] { font-size: 16px; }
}

.store-multi-list { max-height: 260px; overflow-y: auto; padding: .65rem; border: 1px solid var(--line); border-radius: 12px; display: grid; gap: .35rem; }
.store-multi-list .check { padding: .35rem; }
