/* Фірмовий стиль TerraLab — токени з «Статистика БОТ» (botstat/brand.py). */
@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-SemiBold.ttf") format("truetype"); font-weight: 600; font-display: swap; }
@font-face { font-family: "Montserrat"; src: url("fonts/Montserrat-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --accent: #BE1E2D; --accent-hover: #A11926; --accent-soft: #F8E6E8; --accent-line: #E9B9BE;
  --text: #111111; --grey-dark: #4A4749; --grey-light: #D5D3D4;
  --rule: #DCDCDC; --panel: #F0F2F1; --separator: #E2E2E2; --muted: #6E6B6D; --faint: #9A9A9A;
  --bg: #F0F2F1; --card: #FFFFFF;
  --ok: #2E7D4F; --ok-bg: #E4F2EA; --warn: #8A5A00; --warn-bg: #FBF1DC;
  --radius: 4px;
}
* { box-sizing: border-box; }
[x-cloak] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.5 "Montserrat", "Segoe UI", system-ui, sans-serif; background: var(--bg); color: var(--text); overflow-x: hidden; }

/* Шапка */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 20px; padding: 10px 20px; background: var(--card); border-bottom: 3px solid var(--accent); }
.brand { display: flex; align-items: center; gap: 14px; margin-right: auto; }
.brand-logo { height: 26px; width: auto; display: block; }
.brand-title { font-weight: 600; font-size: 15px; color: var(--grey-dark); padding-left: 14px; border-left: 1px solid var(--rule); }
.envsel { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 13px; color: var(--grey-dark); }
.envsel select { min-width: 220px; margin-top: 0; }
.envtag { font-size: 12px; font-weight: 600; letter-spacing: .04em; background: var(--panel); color: var(--grey-dark); padding: 3px 10px; border-radius: 12px; border: 1px solid var(--rule); }
.env-prod .topbar { border-bottom-width: 6px; }
.env-prod .envtag { background: var(--accent); border-color: var(--accent); color: #fff; }

.banner { text-align: center; padding: 6px 16px; font-weight: 600; font-size: 13px; letter-spacing: .04em; }
.banner-prod { background: var(--accent); color: #fff; text-transform: uppercase; }
.banner-ro { background: var(--warn-bg); color: var(--warn); border-bottom: 1px solid #EDD9AE; }

/* Розкладка */
.layout { display: grid; grid-template-columns: 380px minmax(0, 1fr); gap: 20px; padding: 20px; align-items: start; }
.sidebar { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); box-shadow: 0 1px 2px rgba(17,17,17,.04); max-height: calc(100vh - 110px); overflow: auto; position: sticky; top: 8px; }
.side-head { padding: 12px; display: grid; gap: 8px; border-bottom: 1px solid var(--rule); background: var(--card); position: sticky; top: 0; z-index: 1; }
.clist { list-style: none; margin: 0; padding: 0; }
.clist a { display: block; padding: 9px 12px; color: inherit; text-decoration: none; border-bottom: 1px solid var(--separator); border-left: 3px solid transparent; }
.clist a:hover { background: var(--panel); }
.clist a.active { background: var(--accent-soft); border-left-color: var(--accent); }
.cname { display: block; font-weight: 600; overflow-wrap: anywhere; }
.cmeta { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; align-items: center; }
.id { color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums; }
.badge { font-size: 11px; font-weight: 600; background: var(--panel); border: 1px solid var(--rule); border-radius: 10px; padding: 0 7px; color: var(--muted); }
.badge.warn { background: var(--warn-bg); border-color: #EDD9AE; color: var(--warn); }
.badge.off { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.pad { padding: 10px 12px; }

.main { min-width: 0; }
.card { background: var(--card); border: 1px solid var(--rule); border-radius: var(--radius); padding: 22px 24px; min-width: 0; box-shadow: 0 1px 2px rgba(17,17,17,.04); }
h2 { margin: 0 0 8px; font-size: 22px; font-weight: 700; overflow-wrap: anywhere; }
h2 .muted { font-size: 15px; font-weight: 600; color: var(--faint); margin-left: 4px; }
h3 { margin: 16px 0 8px; font-size: 15px; font-weight: 600; padding-top: 10px; border-top: 1px solid var(--separator); }
.card > h3:first-child, .botcard h3, .modal h3, .subform h3 { border-top: 0; padding-top: 0; }
.muted { color: var(--muted); }
.notice { background: var(--warn-bg); border: 1px solid #EDD9AE; color: var(--warn); padding: 8px 12px; border-radius: var(--radius); }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--rule); margin: 14px 0; }
.tabs button { border: 0; border-bottom: 3px solid transparent; border-radius: 0; background: none; padding: 9px 14px; cursor: pointer; color: var(--muted); font: inherit; font-weight: 600; }
.tabs button:hover:not(:disabled) { background: none; color: var(--text); }
.tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

/* Форми */
input, select, textarea, button { font: inherit; }
input, select, textarea { width: 100%; padding: 7px 9px; border: 1px solid var(--grey-light); border-radius: var(--radius); background: #fff; color: var(--text); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent-line); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: auto; accent-color: var(--accent); }
input.invalid, select.invalid, textarea.invalid { border-color: var(--accent); background: var(--accent-soft); }
button { padding: 7px 14px; border: 1px solid var(--grey-light); border-radius: var(--radius); background: #fff; color: var(--text); cursor: pointer; font-weight: 600; }
button:hover:not(:disabled) { background: var(--panel); }
button:disabled { cursor: not-allowed; background: var(--panel); border-color: var(--rule); color: var(--faint); }
button.primary:disabled, button.danger:disabled { background: var(--panel); border-color: var(--rule); color: var(--faint); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary:hover:not(:disabled) { background: var(--accent-hover); border-color: var(--accent-hover); }
button.danger { background: #fff; border-color: var(--accent); color: var(--accent); }
button.danger:hover:not(:disabled) { background: var(--accent-soft); }
button.mini { padding: 0 7px; font-size: 11px; }
fieldset { border: 0; margin: 0; padding: 0; min-width: 0; }
fieldset:disabled input, fieldset:disabled select, fieldset:disabled textarea { background: var(--panel); color: var(--muted); }
label, .field { display: block; font-weight: 600; font-size: 13px; color: var(--grey-dark); }
label input, label select, label textarea { margin-top: 4px; font-weight: 400; color: var(--text); }
label.inline { display: inline-flex; align-items: center; gap: 6px; font-weight: 400; margin-right: 14px; color: var(--text); }
.checks { margin-top: 4px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.grid.one { grid-template-columns: 1fr; }
.err { display: block; color: var(--accent); font-weight: 400; font-size: 12px; min-height: 0; }
.pw { display: flex; gap: 6px; margin-top: 4px; }
.pw input { margin-top: 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 14px 0; }

/* Таблиці — як у документах TerraLab: світла шапка, тонкі лінії */
.tbl { width: 100%; border-collapse: collapse; table-layout: auto; border: 1px solid var(--rule); }
.tbl th, .tbl td { text-align: left; padding: 7px 10px; border-bottom: 1px solid var(--rule); vertical-align: middle; }
.tbl th { font-size: 12px; color: var(--grey-dark); font-weight: 600; background: var(--panel); }
.tbl tbody tr:hover td { background: #FBFBFB; }
.wrap { overflow-wrap: anywhere; word-break: break-word; }
.nowrap { white-space: nowrap; }
.pre { white-space: pre-line; }
.clip { max-width: 320px; }
.thumb { width: 56px; height: 40px; object-fit: cover; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--panel); display: block; }
tr[draggable=true] { cursor: grab; }
tr.dragging { opacity: .4; }
tr.over td { border-top: 2px solid var(--accent); }
.subform { border: 1px solid var(--rule); border-radius: var(--radius); padding: 14px; margin-top: 14px; background: var(--panel); }
.two { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
pre { max-width: 520px; overflow: auto; background: var(--panel); border: 1px solid var(--rule); padding: 8px; border-radius: var(--radius); font-size: 12px; }

/* Боти */
.botgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.botcard { border: 1px solid var(--rule); border-top: 3px solid var(--accent); border-radius: var(--radius); padding: 14px; min-width: 0; background: var(--card); }
.botcard h3 { margin-top: 0; font-size: 16px; }
.statusrow { padding: 7px 12px; border-radius: var(--radius); background: var(--panel); border: 1px solid var(--rule); display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 12px; font-weight: 600; }
.statusrow.st-active { background: var(--ok-bg); border-color: #BFDDCB; color: var(--ok); }
.statusrow.st-ready { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent); }
.statusrow.st-error { background: var(--accent); border-color: var(--accent); color: #fff; }
.statusrow.st-created, .statusrow.st-checking, .statusrow.st-applying { background: var(--warn-bg); border-color: #EDD9AE; color: var(--warn); }
.tokenrow { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-bottom: 12px; }
.tokenrow code { background: var(--panel); border: 1px solid var(--rule); border-radius: var(--radius); padding: 3px 8px; font-size: 13px; }
.count { font-variant-numeric: tabular-nums; font-weight: 700; }
.reason { overflow-wrap: anywhere; font-weight: 400; }

/* Майстер */
.steps { display: flex; flex-wrap: wrap; gap: 8px; list-style: none; padding: 0; margin: 8px 0; }
.steps li { padding: 4px 14px; border: 1px solid var(--rule); border-radius: 14px; color: var(--muted); font-weight: 600; font-size: 13px; }
.steps li.cur { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.steps li.done { background: var(--ok-bg); color: var(--ok); border-color: #BFDDCB; }
.log { color: var(--ok); margin: 4px 0 12px; padding-left: 18px; }

/* Модальні вікна і сповіщення */
.overlay { position: fixed; inset: 0; background: rgba(17, 17, 17, .5); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal { background: #fff; border-radius: var(--radius); border-top: 4px solid var(--accent); padding: 20px; width: min(520px, 100%); max-height: 90vh; overflow: auto; box-shadow: 0 10px 40px rgba(0, 0, 0, .25); }
.secret { display: grid; grid-template-columns: 1fr auto; gap: 4px 8px; align-items: center; margin: 8px 0; }
.secret .muted { grid-column: 1 / -1; }
.secret code { background: var(--panel); border: 1px solid var(--rule); padding: 6px 8px; border-radius: var(--radius); overflow-wrap: anywhere; font-size: 15px; user-select: all; }

.toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 60; max-width: 380px; }
.toast { background: var(--grey-dark); color: #fff; padding: 10px 14px; border-radius: var(--radius); box-shadow: 0 4px 14px rgba(0, 0, 0, .25); overflow-wrap: anywhere; }
.toast.error { background: var(--accent); }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; padding: 12px; }
  .sidebar { position: static; max-height: 280px; }
  .brand-title { display: none; }
}
.hint { display: block; margin-top: 3px; font-weight: 400; font-size: 12px; color: var(--muted); }
.checkfield { padding-top: 26px; }
.badge.ok { background: var(--ok-bg); border-color: #BFDDCB; color: var(--ok); }
.grid > .wide { grid-column: 1 / -1; }
.pw { flex-wrap: wrap; }
.pw input { flex: 1 1 200px; min-width: 160px; }
.tbl td.nowrap button { padding: 5px 10px; font-size: 13px; }
.tbl td.wrap { min-width: 230px; overflow-wrap: break-word; word-break: normal; }
input.masked { -webkit-text-security: disc; text-security: disc; }

/* map picker for collection points */
.mapbox > span:first-child { display: block; margin-bottom: 4px; }
.mapsearch { display: flex; gap: 8px; }
.mapsearch input { flex: 1; min-width: 0; font-weight: 400; }
.georesults { list-style: none; margin: 4px 0 0; padding: 0; border: 1px solid var(--grey-light); border-radius: var(--radius); background: #fff; max-height: 180px; overflow: auto; }
.georesults li + li { border-top: 1px solid var(--separator); }
.georesults button { display: block; width: 100%; text-align: left; border: 0; border-radius: 0; font-weight: 400; padding: 7px 9px; }
.map { height: 360px; margin-top: 8px; border: 1px solid var(--grey-light); border-radius: var(--radius); z-index: 0; }
.map.invalid { border-color: var(--accent); }
.coords { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 6px; font-weight: 400; color: var(--text); font-variant-numeric: tabular-nums; }
.coords button { padding: 3px 10px; font-size: 12px; }

/* subscriber lookup */
.subsearch { max-width: 640px; }
.subsearch .mapsearch { margin-top: 4px; }
.tblwrap { overflow-x: auto; }

/* statistics */
.side-head button.active { border-color: var(--accent); color: var(--accent); }
.inline-field { display: inline-flex; align-items: center; gap: 8px; }
.inline-field input { margin-top: 0; width: auto; }
.tbl.stats th.grp { text-align: center; border-left: 1px solid var(--rule); }
.tbl.stats .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.tbl.stats td.strong, .tbl.stats .sum td { font-weight: 600; }
.tbl.stats tfoot td { font-weight: 600; background: var(--panel); border-top: 2px solid var(--grey-light); }
.tbl.stats a { color: inherit; font-weight: 600; text-decoration: none; }
.tbl.stats a:hover { color: var(--accent); }
.tbl.narrow { width: auto; min-width: 520px; }
.caveats { margin: 16px 0 0; padding-left: 18px; color: var(--muted); font-size: 13px; }
.caveats li + li { margin-top: 4px; }
.caveats b { color: var(--grey-dark); }
.tbl.stats th, .tbl.stats td { padding: 6px 7px; }
.tbl.stats td.org { min-width: 150px; }
.tbl.stats td.org .id { display: block; }

/* dashboard */
.side-nav { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.side-nav button { padding: 7px 8px; font-size: 13px; }
.side-nav button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.daypick input[type=date] { width: auto; }
.daypick > button:first-child, .daypick > input + button { min-width: 38px; font-size: 16px; line-height: 1; }
.inline-field input[type=date] { width: auto; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin: 4px 0 16px; }
.kpi { border: 1px solid var(--rule); border-left: 3px solid var(--accent); border-radius: var(--radius); padding: 10px 14px; background: #fff; }
.kpi b { display: block; font-size: 26px; line-height: 1.15; font-variant-numeric: tabular-nums; }
.kpi span { display: block; font-weight: 600; font-size: 13px; color: var(--grey-dark); }
.kpi small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.tbl td.num.muted { color: var(--muted); }

/* merged statistics page */
.pdfbtn { border-color: var(--accent); color: var(--accent); }
.showempty { display: inline-flex; margin: -4px 0 12px; }
.btnlink { color: var(--accent); font-weight: 600; text-decoration: none; }
.btnlink:hover { text-decoration: underline; }
.tbl.stats th.num { white-space: normal; min-width: 0; }
.tbl.stats td { font-size: 13px; }
.tbl.stats td.org { min-width: 130px; }

/* roles & sign-in */
.whoami { margin-left: auto; display: flex; align-items: center; gap: 8px; font-size: 13px; }
.whoami .who { font-weight: 600; color: var(--grey-dark); max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.whoami button { padding: 5px 12px; font-size: 13px; }
.banner-role { background: var(--panel); color: var(--grey-dark); border-bottom: 1px solid var(--rule); }
.side-users { width: 100%; font-size: 13px; }
.side-users.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.roles-legend td { vertical-align: top; }
.overlay.session-over { background: var(--bg); z-index: 70; }  /* непрозорий: дані після виходу не видно */
.login { max-width: 520px; margin: 60px auto; padding: 0 16px; }
.login .card { text-align: left; }
.login .brand-logo { margin-bottom: 18px; }
a.btn { display: inline-block; padding: 7px 14px; border-radius: var(--radius); text-decoration: none; font-weight: 600; border: 1px solid var(--grey-light); color: var(--text); }
a.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.badge { white-space: nowrap; }
