:root {
  --bg: #F3F6F5; --surface: #FFFFFF; --sunk: #E9EFED; --ink: #14302C; --muted: #5A6F6B; --line: #D8E2DF;
  --accent: #1E7A64; --accent-ink: #FFFFFF; --accent-soft: #DFF0EA;
  --t1: #7A5BA6; --t1-soft: #EEE7F7; --t2: #1E7A64; --t2-soft: #DFF0EA; --t3: #B5651D; --t3-soft: #F8EBDD;
  --ok: #2D7A4B; --ok-soft: #E2F2E8; --warn: #A86A12; --warn-soft: #FBEFD9; --bad: #B83A33; --bad-soft: #F9E3E1;
  --closed: repeating-linear-gradient(135deg, #E3E9E7 0 8px, #EDF2F0 8px 16px);
  --display: "Rubik", "Segoe UI", system-ui, sans-serif; --body: "Assistant", "Rubik", system-ui, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) { :root {
  --bg: #0E1917; --surface: #15231F; --sunk: #1B2C28; --ink: #E2EEEA; --muted: #92A9A3; --line: #27403A;
  --accent: #4CC3A2; --accent-ink: #072019; --accent-soft: #1A3A32;
  --t1: #B79BE0; --t1-soft: #2C2340; --t2: #4CC3A2; --t2-soft: #1A3A32; --t3: #E5A066; --t3-soft: #3A2A1A;
  --ok: #6CCB8F; --ok-soft: #173325; --warn: #E5B25A; --warn-soft: #3A2C12; --bad: #F08A82; --bad-soft: #3D1C1A;
  --closed: repeating-linear-gradient(135deg, #182824 0 8px, #1C2E2A 8px 16px);
  color-scheme: dark } }
* { box-sizing: border-box }
html, body { margin: 0 }
body { background: var(--bg); color: var(--ink); font-family: var(--body); font-size: 15px; line-height: 1.45 }
[hidden] { display: none !important }
h1, h2, h3 { font-family: var(--display); font-weight: 600; margin: 0; text-wrap: balance }
h1 { font-size: 1.45rem } h2 { font-size: 1.1rem } h3 { font-size: .95rem }
.num, td { font-variant-numeric: tabular-nums }
button { font: inherit; cursor: pointer }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px }
.note { color: var(--muted); font-size: .86rem; margin: 0 }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 14px }
.brand { display: flex; flex-direction: column; gap: 2px }
.brand b { font-family: var(--display); font-size: 1.2rem; font-weight: 700 }
.brand span { color: var(--muted); font-size: .8rem }
.app { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh }
.rail { background: var(--surface); border-right: 1px solid var(--line); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh }
.rail .brand { padding: 4px 10px 18px }
.rail a { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; font-size: .92rem }
.rail a:hover { background: var(--sunk) }
.rail a[aria-current="page"] { background: var(--accent-soft); color: var(--accent) }
.count { background: var(--bad); color: #fff; border-radius: 999px; font-size: .72rem; padding: 1px 7px }
main { padding: 20px max(24px, env(safe-area-inset-right, 0px)) 48px max(24px, env(safe-area-inset-left, 0px)); min-width: 0 }
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; flex-wrap: wrap; margin-bottom: 16px }
.row-btns { display: flex; gap: 6px; flex-wrap: wrap }
.head { display: flex; flex-wrap: wrap; gap: 8px 16px; align-items: baseline; justify-content: space-between; margin-bottom: 16px }
.head p { margin: 0; color: var(--muted) }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 16px; min-width: 0 }
.grid { display: grid; gap: 16px }
.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)) }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 2px }
.stat span { color: var(--muted); font-size: .78rem; font-weight: 600; letter-spacing: .03em; text-transform: uppercase }
.stat b { font-family: var(--display); font-size: 1.55rem; font-weight: 600; font-variant-numeric: tabular-nums }
.stat small { color: var(--muted) }
.pill { display: inline-flex; align-items: center; border-radius: 999px; padding: 2px 9px; font-size: .78rem; font-weight: 600; white-space: nowrap }
.pill.ok { background: var(--ok-soft); color: var(--ok) } .pill.warn { background: var(--warn-soft); color: var(--warn) }
.pill.bad { background: var(--bad-soft); color: var(--bad) } .pill.muted { background: var(--sunk); color: var(--muted) }
.pill.t1 { background: var(--t1-soft); color: var(--t1) } .pill.t2 { background: var(--t2-soft); color: var(--t2) } .pill.t3 { background: var(--t3-soft); color: var(--t3) }
.list { display: flex; flex-direction: column }
.row { display: flex; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--line); flex-wrap: wrap }
.row:first-child { border-top: 0 }
.row .time { font-family: var(--display); font-weight: 600; min-width: 52px }
.row .main { flex: 1; min-width: 180px }
.row .main div:last-child { color: var(--muted); font-size: .86rem }
.alert { display: flex; gap: 12px; align-items: flex-start; justify-content: space-between; padding: 12px; border-radius: 10px; border-left: 4px solid var(--bad); background: var(--bad-soft) }
.alert.warn { border-left-color: var(--warn); background: var(--warn-soft) }
.alert p { margin: 2px 0 0; font-size: .88rem }
.empty { color: var(--muted); padding: 12px 0 }
.btn { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px; padding: 7px 12px; font-weight: 600; font-size: .88rem }
.btn:hover { background: var(--sunk) }
.btn:disabled { opacity: .5; cursor: not-allowed }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink) }
.btn.danger { color: var(--bad) }
.btn.small { padding: 4px 9px; font-size: .8rem }
.table-wrap { overflow-x: auto }
table { border-collapse: collapse; width: 100%; min-width: 640px }
th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line) }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle }
td.r, th.r { text-align: right }
.field { display: flex; flex-direction: column; gap: 4px; font-size: .85rem; font-weight: 600 }
.field input, .field select, .field textarea { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; background: var(--surface); color: var(--ink); font: inherit; font-weight: 400 }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px }
.counts { border: 1px solid var(--line); border-radius: 10px; padding: 12px; margin: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px }
.counts legend { font-weight: 600; font-size: .85rem; padding: 0 4px }
.counts #visit-total { grid-column: 1 / -1; font-weight: 600; color: var(--ink) }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden }
.seg button { border: 0; background: var(--surface); color: var(--ink); padding: 7px 12px; font-weight: 600; font-size: .86rem }
.seg button[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink) }
/* inbox */
.inbox { display: grid; grid-template-columns: 300px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--surface); min-height: 560px }
.threads { border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; overflow-y: auto; max-height: 75vh }
.thread { display: flex; flex-direction: column; gap: 3px; padding: 12px 14px; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink); text-align: left }
.thread:hover { background: var(--sunk) }
.thread[aria-selected="true"] { background: var(--accent-soft) }
.thread .top { display: flex; justify-content: space-between; gap: 8px; font-weight: 600 }
.thread .top small { color: var(--muted); font-weight: 400 }
.thread .prev { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis }
.convo { display: flex; flex-direction: column; min-width: 0; background: var(--bg) }
.convo-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 8px; align-items: center; padding: 12px 16px; background: var(--surface); border-bottom: 1px solid var(--line) }
.msgs { flex: 1; padding: 16px; display: flex; flex-direction: column; gap: 8px; overflow-y: auto; max-height: 60vh }
.msg { max-width: min(78%, 520px); padding: 8px 11px; border-radius: 10px; font-size: .93rem; white-space: pre-wrap; unicode-bidi: plaintext; text-align: start }
.msg .who { display: block; font-size: .72rem; font-weight: 600; margin-bottom: 2px }
.msg .at { display: block; font-size: .7rem; color: var(--muted); margin-top: 3px }
.msg.parent { align-self: flex-start; background: var(--surface); border: 1px solid var(--line) }
.msg.bot { align-self: flex-end; background: var(--accent-soft) } .msg.bot .who { color: var(--accent) }
.msg.staff { align-self: flex-end; background: var(--t1-soft) } .msg.staff .who { color: var(--t1) }
.msg.system { align-self: center; background: none; color: var(--muted); font-size: .8rem }
.compose { display: flex; gap: 8px; padding: 12px 16px; background: var(--surface); border-top: 1px solid var(--line); flex-wrap: wrap }
.compose input { flex: 1; min-width: 180px; border: 1px solid var(--line); border-radius: 8px; padding: 9px 11px; background: var(--bg); color: var(--ink); font: inherit }
/* calendar */
.cal-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--surface) }
.cal { display: grid; grid-template-columns: 52px repeat(7, minmax(120px, 1fr)); min-width: 920px }
.cal .dh { padding: 10px 8px; border-bottom: 1px solid var(--line); border-left: 1px solid var(--line); font-weight: 600; font-family: var(--display); font-size: .9rem }
.cal .dh small { display: block; color: var(--muted); font-family: var(--body); font-weight: 400; font-size: .76rem }
.cal .dh.today { color: var(--accent) }
.hours div { height: 48px; font-size: .72rem; color: var(--muted); text-align: right; padding-right: 6px; transform: translateY(-7px) }
.day { position: relative; border-left: 1px solid var(--line); height: 480px; background-image: linear-gradient(var(--line) 1px, transparent 1px); background-size: 100% 48px }
.closed { position: absolute; left: 0; right: 0; background: var(--closed); display: flex; justify-content: center; padding-top: 8px; color: var(--muted); font-size: .76rem; font-weight: 600; text-align: center }
.ev { position: absolute; left: 4px; right: 4px; border-radius: 7px; padding: 4px 7px; font-size: .76rem; line-height: 1.25; overflow: hidden; border-left: 3px solid; color: var(--ink); background: var(--sunk); border-color: var(--muted); cursor: pointer; text-align: left; font-family: inherit }
.ev b { display: block; font-size: .78rem }
.ev.t1 { background: var(--t1-soft); border-color: var(--t1) } .ev.t2 { background: var(--t2-soft); border-color: var(--t2) } .ev.t3 { background: var(--t3-soft); border-color: var(--t3) }
.ev.open { background: var(--warn-soft); border-color: var(--warn) }
.ev.block { background: var(--closed); border-color: var(--line); color: var(--muted); cursor: default }
/* tech app */
.tech { max-width: 560px; margin: 0 auto; display: flex; flex-direction: column; gap: 12px }
.job { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 6px }
.job .t { display: flex; justify-content: space-between; align-items: center; gap: 8px; font-family: var(--display); font-weight: 600 }
.job .acts { display: flex; gap: 6px; flex-wrap: wrap }
.job.open { border: 2px dashed var(--warn) }
[dir="rtl"] .rail a, [dir="rtl"] th, [dir="rtl"] .thread { text-align: right }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 0; background: var(--surface); color: var(--ink); width: min(520px, calc(100vw - 32px)) }
dialog::backdrop { background: rgba(10, 25, 22, .45) }
.dialog-body { padding: 20px; display: flex; flex-direction: column; gap: 14px }
.dialog-body .acts { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap }
.toast { position: fixed; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 10px; font-weight: 600; font-size: .9rem; z-index: 20; max-width: calc(100vw - 32px) }
.toast.bad { background: var(--bad); color: #fff }
@media (max-width: 860px) {
  .app { grid-template-columns: 1fr }
  .rail { position: sticky; top: 0; height: auto; flex-direction: row; overflow-x: auto; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--line); z-index: 5 }
  .rail .brand { display: none }
  .rail a { flex: none }
  main { padding: 16px max(16px, env(safe-area-inset-right, 0px)) 40px max(16px, env(safe-area-inset-left, 0px)) }
  .inbox { grid-template-columns: 1fr }
  .threads { border-right: 0; border-bottom: 1px solid var(--line); max-height: 240px }
}
