:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --fg: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #707579);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-fg: var(--tg-theme-button-text-color, #ffffff);
  --card: var(--tg-theme-secondary-bg-color, #f1f1f3);
  --red: #e5484d;
  --yellow: #e5a50a;
  --green: #30a46c;
  --gray: #8b8d98;
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--fg);
  font: 15px/1.4 -apple-system, "Segoe UI", Roboto, sans-serif; }
body { padding: 0 12px 40px; max-width: 760px; margin: 0 auto; }
a { color: var(--link); }
h2 { margin: 14px 0 8px; font-size: 18px; }
h3 { margin: 16px 0 6px; font-size: 15px; }
.muted { color: var(--hint); }
.top { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; position: sticky; top: 0; background: var(--bg); z-index: 5; }
.tabs { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.tabs a { margin-right: 0; text-decoration: none; color: var(--hint); font-weight: 600; padding-bottom: 4px; }
.tabs a.active { color: var(--fg); border-bottom: 2px solid var(--btn); }
.badge { font-size: 11px; color: var(--hint); border: 1px solid var(--hint); border-radius: 8px; padding: 1px 6px; }
.toast { position: fixed; left: 12px; right: 12px; bottom: 16px; background: var(--fg); color: var(--bg);
  border-radius: 10px; padding: 10px 12px; z-index: 20; white-space: pre-wrap; }
.toast.err { background: var(--red); color: #fff; }
.filters { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0 12px; }
select, input[type=date], input[type=time] { background: var(--card); color: var(--fg); border: 1px solid transparent;
  border-radius: 8px; padding: 8px; font: inherit; max-width: 100%; }
.btn { background: var(--btn); color: var(--btn-fg); border: 0; border-radius: 8px; padding: 9px 14px; font: inherit; cursor: pointer; text-decoration: none; display: inline-block; }
.btn.secondary { background: var(--card); color: var(--fg); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; }
.row { display: flex; gap: 10px; align-items: flex-start; background: var(--card); border-radius: 12px; padding: 10px 12px; margin-bottom: 8px; cursor: pointer; }
.row .main { flex: 1; min-width: 0; }
.row .title { font-weight: 600; }
.dot { width: 12px; height: 12px; border-radius: 50%; flex: none; margin-top: 4px; background: var(--gray); }
.dot.red, .tag.red { background: var(--red); }
.dot.yellow, .tag.yellow { background: var(--yellow); }
.dot.green, .tag.green { background: var(--green); }
.dot.gray, .tag.gray { background: var(--gray); }
.tag { display: inline-block; color: #fff; border-radius: 8px; padding: 1px 8px; font-size: 12px; }
.box { background: var(--card); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 4px 8px; }
.kv div:nth-child(odd) { color: var(--hint); }
.actions { display: grid; gap: 10px; }
.actions .line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.doc, .chk { display: flex; gap: 8px; align-items: center; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid rgba(128,128,128,.2); }
.doc:last-child, .chk:last-child { border-bottom: 0; }
.chk .st { flex: none; }
.ok { color: var(--green); } .bad { color: var(--red); }
.stub { border: 1px dashed var(--hint); border-radius: 12px; padding: 10px 12px; margin: 8px 0; }
.back { margin: 6px 0; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin: 8px 0; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.grid .wd { text-align: center; color: var(--hint); font-size: 12px; }
.cell { min-height: 48px; background: var(--card); border-radius: 8px; padding: 3px; font-size: 12px; cursor: pointer; border: 2px solid transparent; }
.cell.empty { background: transparent; cursor: default; }
.cell.today { border-color: var(--btn); }
.cell.sel { border-color: var(--fg); }
.cell .dots { display: flex; flex-wrap: wrap; gap: 2px; margin-top: 2px; }
.cell .dots i { width: 8px; height: 8px; border-radius: 50%; display: block; }
.cell .dots i.hearing { border-radius: 2px; }
.cell .dots i.red { background: var(--red); } .cell .dots i.yellow { background: var(--yellow); }
.cell .dots i.green { background: var(--green); } .cell .dots i.gray { background: var(--gray); }
.ev { display: flex; gap: 8px; padding: 8px 0; border-bottom: 1px solid rgba(128,128,128,.2); cursor: pointer; }
.viewer { position: fixed; inset: 0; background: var(--bg); z-index: 30; display: flex; flex-direction: column; }
.viewer[hidden] { display: none; }
.viewer-bar { display: flex; gap: 8px; align-items: center; padding: 8px 12px; }
.viewer-bar span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1; overflow: auto; display: flex; align-items: flex-start; justify-content: center; padding: 8px; }
.viewer-body img { max-width: 100%; height: auto; }
.viewer-body iframe { width: 100%; height: 100%; border: 0; background: #fff; }
[hidden] { display: none !important; }

/* ---- CRM ---- */
.search { display: flex; gap: 8px; margin: 0 0 8px; }
.search input { flex: 1; min-width: 0; }
input[type=text], input[type=search], input[type=tel], input[type=email], input[type=number], textarea {
  background: var(--card); color: var(--fg); border: 1px solid transparent; border-radius: 8px; padding: 8px; font: inherit; max-width: 100%; }
textarea { width: 100%; min-height: 70px; resize: vertical; }
.form { display: grid; gap: 8px; }
.form .line { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.form label { display: grid; gap: 2px; color: var(--hint); font-size: 12px; }
.pre { white-space: pre-wrap; overflow-wrap: anywhere; }
.item { padding: 8px 0; border-bottom: 1px solid rgba(128,128,128,.2); }
.item:last-child { border-bottom: 0; }
.item .meta { color: var(--hint); font-size: 12px; }
.item .btns { margin-top: 4px; display: flex; flex-wrap: wrap; gap: 6px; }
.overdue { color: var(--red); font-weight: 600; }
.prio-high { color: var(--red); } .prio-low { color: var(--hint); }
.done { text-decoration: line-through; color: var(--hint); }
.link { cursor: pointer; color: var(--link); text-decoration: underline; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13px; }
table.tbl th, table.tbl td { text-align: left; padding: 4px 6px; border-bottom: 1px solid rgba(128,128,128,.2); }
table.tbl td.num, table.tbl th.num { text-align: right; }
.bar { background: rgba(128,128,128,.2); border-radius: 6px; height: 10px; }
.bar > div { background: var(--btn); height: 10px; border-radius: 6px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); gap: 8px; }
.cards .box { text-align: center; margin: 0; }
.cards .big { font-size: 22px; font-weight: 700; }
