:root {
  --bg: #f4f7f8; --card: #fff; --ink: #1d2b33; --muted: #6b7c85; --line: #e1e8eb;
  --brand: #0f5c6e; --brand2: #1a8aa3; --red: #c62828; --redbg: #fdecea; --amber: #b26a00; --amberbg: #fff4e0;
  --green: #2e7d32; --greenbg: #e8f5e9; --radius: 14px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--ink); font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
a { color: var(--brand2); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; color: inherit; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.err { color: var(--red); }

/* верх */
.top { position: sticky; top: 0; z-index: 10; background: var(--brand); color: #fff; padding: 10px 14px calc(10px); padding-top: calc(10px + env(safe-area-inset-top, 0px)); display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.brand { font-weight: 700; font-size: 17px; margin-right: auto; }
.people { display: flex; gap: 6px; }
.chip { border: 1px solid rgba(255,255,255,.5); background: transparent; color: #fff; border-radius: 20px; padding: 4px 12px; font-size: 14px; }
.chip.on { background: #fff; color: var(--brand); border-color: #fff; font-weight: 600; }

main { max-width: 860px; margin: 0 auto; padding: 14px 12px calc(90px + var(--safe-b)); }
h2 { font-size: 18px; margin: 18px 4px 10px; }
h3 { font-size: 16px; margin: 0 0 8px; }

/* нижня навігація */
.tabs { position: fixed; bottom: 0; left: 0; right: 0; z-index: 10; display: flex; background: #fff; border-top: 1px solid var(--line); padding-bottom: var(--safe-b); }
.tabs a { flex: 1; text-align: center; padding: 7px 0 6px; font-size: 20px; color: var(--muted); }
.tabs a span { display: block; font-size: 11px; margin-top: 1px; }
.tabs a.on { color: var(--brand); }
.tabs a.on span { font-weight: 600; }
@media (min-width: 900px) {
  .tabs { top: 0; bottom: auto; left: auto; right: 0; width: auto; background: transparent; border: 0; padding-top: env(safe-area-inset-top, 0px); }
  .tabs a { flex: none; white-space: nowrap; font-size: 15px; color: #cfe6ec; padding: 14px 10px; }
  .tabs a span { display: inline; font-size: 14px; margin-left: 4px; }
  .tabs a.on { color: #fff; }
  .top { padding-right: 520px; }
  main { padding-bottom: 30px; }
}

/* картки */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.person-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.person-head .name { font-size: 20px; font-weight: 700; }
.alert { border-radius: 10px; padding: 8px 12px; margin: 6px 0; }
.alert.red { background: var(--redbg); color: var(--red); }
.alert.amber { background: var(--amberbg); color: var(--amber); }
.alert.green { background: var(--greenbg); color: var(--green); }
.sec-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 12px 0 4px; }

/* списки подій */
.ev { display: flex; gap: 10px; padding: 9px 4px; border-bottom: 1px solid var(--line); cursor: pointer; }
.ev:last-child { border-bottom: 0; }
.ev .ic { font-size: 20px; width: 26px; text-align: center; flex: none; }
.ev .body { flex: 1; min-width: 0; }
.ev .t { font-weight: 600; }
.ev .meta { color: var(--muted); font-size: 13px; }
.ev .date { color: var(--muted); font-size: 13px; white-space: nowrap; }
.tag { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 10px; background: #e6f1f4; color: var(--brand); margin-right: 4px; }
.tag.red { background: var(--redbg); color: var(--red); }
.month { font-weight: 700; color: var(--muted); margin: 16px 4px 4px; font-size: 13px; text-transform: uppercase; }

/* фільтри */
.filters { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.filters input, .filters select { flex: 1; min-width: 140px; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }

/* кнопки */
.btn { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--brand); color: #fff; font-weight: 600; }
.btn.sec { background: #e6f1f4; color: var(--brand); }
.btn.danger { background: var(--redbg); color: var(--red); }
.btn.ok { background: var(--green); }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* асистент */
.chat { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.msg { max-width: 88%; padding: 9px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.msg.ai { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; box-shadow: 0 1px 2px rgba(0,0,0,.06); }
.msg .att { font-size: 12px; opacity: .85; margin-top: 4px; }
.proposal { border: 2px solid var(--brand2); }
.proposal ul { margin: 6px 0; padding-left: 18px; }
.composer { position: sticky; bottom: calc(62px + var(--safe-b)); background: var(--bg); padding: 8px 0; }
@media (min-width: 900px) { .composer { bottom: 0; } }
.composer textarea { width: 100%; min-height: 54px; max-height: 200px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 12px; resize: vertical; background: #fff; }
.composer .row { margin-top: 6px; }
.rec { background: var(--red) !important; color: #fff !important; animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .65; } }
.files-picked { font-size: 13px; color: var(--muted); }
.typing { color: var(--muted); font-style: italic; }

/* документи */
.docs { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.doc { background: #fff; border-radius: 12px; overflow: hidden; cursor: pointer; box-shadow: 0 1px 2px rgba(0,0,0,.05); }
.doc .thumb { height: 120px; background: #e9eff1 center/cover no-repeat; display: flex; align-items: center; justify-content: center; font-size: 36px; }
.doc .cap { padding: 6px 8px; font-size: 13px; }

/* модалка */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.sheet { background: #fff; width: 100%; max-width: 680px; max-height: 92vh; overflow: auto; border-radius: 18px 18px 0 0; padding: 16px 16px calc(20px + var(--safe-b)); }
@media (min-width: 700px) { .modal { align-items: center; } .sheet { border-radius: 18px; } }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 10px; font-size: 14px; margin: 8px 0; }
.kv div:nth-child(odd) { color: var(--muted); }
.form label { display: block; font-size: 13px; color: var(--muted); margin: 8px 0 2px; }
.form input, .form select, .form textarea { width: 100%; padding: 9px 10px; border: 1px solid var(--line); border-radius: 10px; }
.form textarea { min-height: 80px; }
table.labs { width: 100%; border-collapse: collapse; font-size: 14px; }
table.labs td, table.labs th { border-bottom: 1px solid var(--line); padding: 5px 6px; text-align: left; }
.hi { color: var(--red); font-weight: 600; }
.lo { color: #1565c0; font-weight: 600; }

.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(80px + var(--safe-b)); background: #263238; color: #fff; padding: 10px 16px; border-radius: 10px; z-index: 60; max-width: 90%; }
.toast[hidden] { display: none; }

/* вхід */
body.login { display: flex; min-height: 100vh; align-items: center; justify-content: center; }
.login-box { background: #fff; padding: 32px 26px; border-radius: 18px; text-align: center; max-width: 360px; box-shadow: 0 2px 12px rgba(0,0,0,.08); }
.login-box .logo { font-size: 48px; }
.login-box h1 { margin: 6px 0; }
#widget { margin: 20px 0 10px; min-height: 48px; }
.empty { text-align: center; color: var(--muted); padding: 30px 10px; }
