*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0f1014; color: #e7e9ec; margin: 0;
}
a { color: #60a5fa; text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- LAYOUT: sidebar слева, content справа ---- */
body.layout {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  min-height: 100vh;
}
.content { padding: 24px 28px; min-width: 0; }

.sidebar {
  background: #12141a;
  border-right: 1px solid #23262e;
  padding: 20px 0;
  position: sticky; top: 0; align-self: start;
  height: 100vh;
  display: flex; flex-direction: column;
}
.sidebar-brand {
  padding: 0 20px 16px;
  font-weight: 700; font-size: 15px; letter-spacing: 0.5px;
  color: #e7e9ec;
  border-bottom: 1px solid #23262e;
  margin-bottom: 12px;
}
.sidebar-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }
.sidebar-nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 14px; border-radius: 8px;
  color: #a0a4ad; font-size: 13px; font-weight: 500;
}
.sidebar-nav a:hover { color: #fff; text-decoration: none; background: rgba(255,255,255,0.03); }
.sidebar-nav a.active { color: #60a5fa; background: rgba(37,99,235,0.12); }
.sidebar-nav a.disabled { color: #575a62; cursor: not-allowed; }
.sidebar-nav a.disabled:hover { background: transparent; color: #575a62; }
.sidebar-nav .icon { width: 18px; text-align: center; font-size: 13px; opacity: 0.85; }
.nav-sep {
  margin: 16px 14px 6px;
  font-size: 10px; text-transform: uppercase;
  letter-spacing: .8px; color: #575a62;
}

h1 { margin: 0 0 16px; font-size: 22px; font-weight: 700; }
.hint { color: #8a8f98; font-size: 13px; margin-bottom: 20px; }

.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert.ok { background: rgba(74,222,128,0.12); color: #4ade80; border: 1px solid rgba(74,222,128,0.3); }
.alert.err { background: rgba(248,113,113,0.14); color: #f87171; border: 1px solid rgba(248,113,113,0.3); }

/* ============ INPUTS (shared polished style) ============ */
input[type="text"], input[type="number"], input[type="date"],
input[type="email"], input[type="password"], textarea, select {
  background: #0f1014;
  border: 1px solid #2a2d35;
  border-radius: 8px;
  color: #e7e9ec;
  font-size: 13px;
  padding: 10px 14px;
  font-family: inherit;
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
  outline: none;
}
input[type="text"]::placeholder,
input[type="number"]::placeholder,
textarea::placeholder {
  color: #575a62;
}
input[type="text"]:hover, input[type="number"]:hover, input[type="date"]:hover,
textarea:hover, select:hover {
  border-color: #3a3d45;
}
input[type="text"]:focus, input[type="number"]:focus, input[type="date"]:focus,
input[type="email"]:focus, input[type="password"]:focus,
textarea:focus, select:focus {
  border-color: #2563eb;
  background: #12141a;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea { resize: vertical; line-height: 1.5; font-family: ui-monospace, "SF Mono", monospace; }
select {
  cursor: pointer;
  padding-right: 32px;
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path fill='%238a8f98' d='M2 4l4 4 4-4z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

/* ---- FORM (/add-token legacy form) ---- */
.form {
  max-width: 640px;
  background: #181a20;
  border: 1px solid #23262e;
  border-radius: 12px;
  padding: 28px;
}
.form label {
  display: block;
  margin-bottom: 18px;
  font-size: 12px;
  color: #8a8f98;
  text-transform: uppercase;
  letter-spacing: .5px;
  font-weight: 600;
}
.form .req { color: #f87171; margin-left: 2px; }
.form input, .form textarea {
  display: block;
  width: 100%;
  margin-top: 8px;
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 13px;
}
.form small {
  display: block;
  margin-top: 6px;
  color: #575a62;
  font-size: 11px;
  font-family: -apple-system, sans-serif;
  text-transform: none;
  letter-spacing: 0;
  font-weight: 400;
}
.form code {
  background: #0f1014;
  padding: 2px 6px;
  border-radius: 4px;
  color: #fbbf24;
  font-size: 11px;
}
.form button[type="submit"] {
  background: #2563eb;
  border: 1px solid #2563eb;
  color: #fff;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 13px;
  cursor: pointer;
  font-weight: 600;
  transition: all .15s ease;
  margin-top: 8px;
}
.form button[type="submit"]:hover {
  background: #1d4ed8;
  border-color: #1d4ed8;
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* ---- BM LIST ---- */
.bm-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 24px; }
.bm-card {
  background: #181a20;
  border: 1px solid #23262e;
  border-radius: 10px;
  padding: 14px 16px;
}
.bm-head { display: flex; justify-content: space-between; align-items: center; }
.bm-head small { display: block; color: #8a8f98; font-size: 11px; margin-top: 2px; }
.bm-actions { display: flex; gap: 8px; align-items: center; }
.scrape-status { font-size: 11px; padding: 3px 10px; border-radius: 12px; }
.btn-sm {
  background: transparent; color: #c7cad1; border: 1px solid #2a2d35;
  padding: 4px 10px; border-radius: 6px; font-size: 12px; cursor: pointer;
}
.btn-sm:hover { border-color: #3a3d45; color: #fff; }
.btn-sm.btn-danger { color: #f87171; border-color: rgba(248,113,113,0.3); }
.btn-sm.btn-danger:hover { border-color: #f87171; color: #fff; }
.bm-status-select {
  padding: 4px 24px 4px 8px !important;
  font-size: 11px !important;
  border-radius: 6px !important;
}

.budget-value {
  font-family: ui-monospace, monospace; font-size: 12px;
  color: #4ade80; margin-right: 6px;
  font-variant-numeric: tabular-nums;
}
.budget-value.muted { color: #575a62; }
.btn-edit {
  background: transparent; border: 1px solid #2a2d35;
  color: #8a8f98; cursor: pointer;
  padding: 2px 8px; border-radius: 4px;
  font-size: 11px;
  transition: all .15s ease;
}
.btn-edit:hover { border-color: #60a5fa; color: #60a5fa; }

/* Toast-уведомление (крупное, заметное) */
.toast {
  position: fixed; top: 16px; left: 50%;
  transform: translateX(-50%) translateY(-200px);
  z-index: 10000;
  padding: 16px 28px;
  border-radius: 10px;
  font-size: 15px; font-weight: 600;
  box-shadow: 0 12px 40px rgba(0,0,0,0.6);
  opacity: 0;
  transition: opacity .25s, transform .25s;
  max-width: 80vw;
  min-width: 300px;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.info { background: #1e3a8a; color: #bfdbfe; border: 2px solid #2563eb; }
.toast.ok   { background: #14532d; color: #4ade80; border: 2px solid #4ade80; }
.toast.err  { background: #7f1d1d; color: #fca5a5; border: 2px solid #f87171; }

/* === Красивая форма добавления токена === */
.add-token-form {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
}
.add-token-form label {
  display: flex; flex-direction: column; gap: 6px;
  font-size: 11px; color: #8a8f98;
  text-transform: uppercase; letter-spacing: .5px; font-weight: 600;
}
.add-token-form label .req { color: #f87171; margin-left: 2px; }
.add-token-form label input,
.add-token-form label textarea {
  width: 100%;
  margin-top: 0;
  font-family: ui-monospace, "SF Mono", monospace;
}
.add-token-form label.full { grid-column: 1 / -1; }
.add-token-form label.full textarea { resize: vertical; min-height: 54px; }
.add-token-form .form-actions {
  grid-column: 1 / -1;
  display: flex; justify-content: flex-end; margin-top: 4px;
}
.btn-primary-solid {
  background: #2563eb; border: 1px solid #2563eb; color: #fff;
  padding: 10px 22px; border-radius: 8px;
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: all .15s ease;
}
.btn-primary-solid:hover {
  background: #1d4ed8; border-color: #1d4ed8;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3);
}

/* ---- TABS ---- */
.tabs { display: flex; gap: 6px; margin-bottom: 20px; }
.tab {
  background: #181a20; border: 1px solid #23262e; color: #a0a4ad;
  padding: 8px 16px; border-radius: 8px; font-size: 13px;
  cursor: pointer; transition: .1s;
}
.tab:hover { background: #1f222a; color: #e7e9ec; }
.tab.active { background: transparent; border-color: #60a5fa; color: #60a5fa; }

/* ---- CARDS (legacy) ---- */
.cards { display: grid; grid-template-columns: repeat(5, 1fr); gap: 12px; margin-bottom: 24px; }
.card {
  background: #181a20; border: 1px solid #23262e;
  border-radius: 10px; padding: 16px;
}
.card .l { color: #8a8f98; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.card .v { font-size: 24px; font-weight: 600; margin-top: 6px; color: #4ade80; }
.card .v.n { color: #e7e9ec; }

/* ---- KPI ROWS (FBTool Killer style) ---- */
.page-head {
  display: flex; align-items: baseline; justify-content: flex-start;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 16px;
}
.page-head h1 { margin: 0; }
.page-head .hint { margin: 0; }
.section-block {
  margin-bottom: 14px;
  background: #14161c;
  border: 1px solid #23262e;
  border-radius: 10px;
  padding: 10px 10px 2px;
}
.section-block-title {
  font-size: 11px; font-weight: 700; color: #8a8f98;
  letter-spacing: .5px; margin: 0 4px 8px;
  text-transform: uppercase;
}
.kpi-row {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-bottom: 8px;
}
.kpi {
  background: #181a20;
  border: 1px solid #23262e;
  border-radius: 8px;
  padding: 10px 12px;
  position: relative;
  overflow: hidden;
}
.kpi::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
}
.kpi.green::before  { background: #4ade80; }
.kpi.blue::before   { background: #60a5fa; }
.kpi.orange::before { background: #fb923c; }
.kpi.lime::before   { background: #a3e635; }
.kpi.purple::before { background: #c084fc; }
.kpi .l {
  color: #8a8f98; font-size: 10px; text-transform: uppercase; letter-spacing: .4px;
  margin-bottom: 4px;
}
.kpi .v {
  font-size: 18px; font-weight: 700; font-variant-numeric: tabular-nums;
  color: #e7e9ec;
  line-height: 1.2;
}
.kpi.green   .v { color: #4ade80; }
.kpi.blue    .v { color: #60a5fa; }
.kpi.orange  .v { color: #fb923c; }
.kpi.lime    .v { color: #a3e635; }
.kpi.purple  .v { color: #c084fc; }
.kpi .sub {
  margin-top: 4px; color: #575a62; font-size: 10px;
}

/* ---- SECTION HEAD ---- */
.section-head {
  display: flex; justify-content: space-between; align-items: center;
  margin: 24px 0 12px;
}
.section-head h2 { margin: 0; font-size: 16px; font-weight: 600; color: #c7cad1; }
.btn-primary {
  background: transparent; color: #60a5fa; padding: 8px 14px;
  border: 1px solid #2563eb;
  border-radius: 6px; font-size: 13px; text-decoration: none;
  display: inline-block;
}
.btn-primary:hover { border-color: #60a5fa; color: #93c5fd; text-decoration: none; }

/* ---- period tabs — теперь inline с заголовком ---- */
.period-wrap { }
.td.money { font-weight: 600; color: #4ade80; }
.t td.money { font-weight: 600; color: #4ade80; }

/* ---- TABLE ---- */
/* Обёртка для горизонтального скролла широких таблиц */
.t-wrap { overflow-x: auto; border-radius: 10px; border: 1px solid #23262e; }
.t-wrap .t { border: none; border-radius: 0; min-width: 1100px; }

.t {
  width: 100%; border-collapse: collapse;
  background: #181a20; border: 1px solid #23262e;
  border-radius: 10px; overflow: hidden;
}
.t th {
  background: #12141a; padding: 8px 10px;
  font-size: 10px; color: #8a8f98; text-transform: uppercase; letter-spacing: .3px;
  border-bottom: 1px solid #23262e;
  text-align: left; white-space: nowrap;
}
.t th.num { text-align: right; }
.t th.ctr { text-align: center; }
.t td {
  padding: 8px 10px; border-bottom: 1px solid #23262e;
  font-size: 12px; vertical-align: middle;
}
.t td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.t td.ctr { text-align: center; }
.t td small { color: #8a8f98; font-size: 11px; }
.t tr.bm-row td { background: #0f1014; color: #8a8f98; font-size: 11px; padding: 8px 12px; }
.t tr.bm-row small { margin-left: 8px; }
.t .empty-row { text-align: center; color: #8a8f98; padding: 32px; }
.t tfoot td {
  font-weight: 600; background: #12141a;
  border-top: 2px solid #2a2d35; border-bottom: none; color: #e7e9ec;
}

/* Компактный режим для широких таблиц (дашборд) */
.t-compact th {
  padding: 6px 6px;
  font-size: 9px;
  letter-spacing: 0;
  white-space: nowrap;
}
.t-compact td {
  padding: 5px 6px;
  font-size: 11px;
}
.t-compact td small { font-size: 10px; }
.t-compact .status-pill { font-size: 9px; padding: 1px 5px; }
.t-compact .buyer-badge { font-size: 10px; padding: 1px 6px; margin-left: 3px; }
.t-compact tr.bm-row td { padding: 5px 8px; font-size: 10px; }
.t-wrap .t-compact { min-width: 1200px; }

/* Режим "компактно" — скрывает дополнительные колонки (.col-extra) */
.t.compact-view .col-extra { display: none; }
.t-wrap .t-compact.compact-view { min-width: 0; }

/* ---- STATUS PILL ---- */
.status-pill {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600; letter-spacing: .3px;
}
.st-ok { background: rgba(74,222,128,0.12); color: #4ade80; }
.st-bad { background: rgba(248,113,113,0.14); color: #f87171; }
.st-warn { background: rgba(251,191,36,0.14); color: #fbbf24; }
.st-unk { background: rgba(138,143,152,0.15); color: #8a8f98; }

.empty {
  padding: 40px; text-align: center;
  background: #181a20; border: 1px solid #23262e;
  border-radius: 10px; color: #8a8f98;
}

/* ---- FILTERS (reports/stats page) ---- */
.filters {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: #181a20; border: 1px solid #23262e;
  border-radius: 10px; padding: 12px 16px; margin-bottom: 18px;
}
.filters label {
  display: flex; align-items: center; gap: 8px;
  color: #8a8f98; font-size: 11px;
  text-transform: uppercase; letter-spacing: .4px; font-weight: 600;
}
.filters select, .filters input {
  padding: 7px 12px; font-size: 12px;
  font-weight: normal; text-transform: none; letter-spacing: 0;
  color: #e7e9ec;
}

.badge {
  display: inline-block;
  padding: 2px 6px; margin: 0 2px;
  background: rgba(96,165,250,0.12); color: #60a5fa;
  border-radius: 3px; font-size: 11px; font-weight: 600;
}

.issue-item {
  background: rgba(248,113,113,0.08);
  border-left: 2px solid #f87171;
  padding: 2px 8px; margin: 2px 0;
  font-size: 11px; color: #fca5a5;
  border-radius: 3px;
}

.level-tabs {
  display: flex; gap: 4px;
  background: #181a20; border: 1px solid #23262e;
  border-radius: 10px; padding: 4px;
  margin-bottom: 18px; width: fit-content;
}
.level-tabs .tab {
  padding: 8px 18px; border-radius: 6px;
  border: none; background: transparent;
  color: #a0a4ad; font-size: 13px;
  text-decoration: none;
}
.level-tabs .tab:hover { color: #fff; text-decoration: none; }
.level-tabs .tab.active { background: rgba(37,99,235,0.18); color: #60a5fa; }

.ad-thumb {
  width: 60px; height: 60px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid #2a2d35;
  display: block;
}
.inline-form {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.inline-form input, .inline-form textarea, .inline-form select {
  padding: 9px 12px;
  font-size: 13px;
}
.inline-form textarea {
  font-family: ui-monospace, "SF Mono", monospace;
  font-size: 12px;
  min-height: 40px;
}
.inline-form label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 11px; color: #8a8f98;
  text-transform: uppercase; letter-spacing: .4px; font-weight: 600;
}
.inline-form label input,
.inline-form label select { width: 100%; margin-top: 0; }

.trc20-cell {
  display: inline-flex; align-items: center; gap: 6px;
  font-family: ui-monospace, monospace; font-size: 11px; color: #4ade80;
}
.btn-copy {
  background: transparent; border: 1px solid #2a2d35;
  color: #8a8f98; border-radius: 4px; cursor: pointer;
  padding: 1px 6px; font-size: 11px;
}
.btn-copy:hover { color: #60a5fa; border-color: #60a5fa; }

/* Toggle switch */
.switch {
  position: relative; display: inline-block;
  width: 42px; height: 22px;
  cursor: pointer;
}
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch .slider {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: #2a2d35; border-radius: 22px;
  transition: .2s; border: 1px solid #2a2d35;
}
.switch .slider:before {
  content: ""; position: absolute;
  height: 16px; width: 16px; left: 2px; bottom: 2px;
  background: #575a62; border-radius: 50%;
  transition: .2s;
}
.switch input:checked + .slider {
  background: rgba(74,222,128,0.2); border-color: #4ade80;
}
.switch input:checked + .slider:before {
  transform: translateX(20px); background: #4ade80;
}
.switch:hover .slider { border-color: #3a3d45; }
.switch input:checked:hover + .slider { border-color: #86efac; }

.row-disabled { opacity: 0.5; }
.row-disabled td { color: #575a62 !important; }

/* BM subsection on /add-token */
.bm-block {
  background: #12141a;
  border: 1px solid #23262e;
  border-radius: 10px;
  padding: 14px 16px;
  margin-top: 14px;
}
.bm-block-head {
  display: flex; justify-content: space-between; align-items: center;
  flex-wrap: wrap; gap: 12px;
}
.bm-title {
  display: flex; align-items: center; gap: 10px;
  flex-wrap: wrap; font-size: 13px;
}
.bm-title small { color: #8a8f98; font-size: 11px; }
.bm-actions {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}
.ad-thumb.placeholder {
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; background: #1f222a; color: #8a8f98;
}
.thumb-link { display: inline-block; }
.thumb-link:hover .ad-thumb { border-color: #60a5fa; }

/* Comments hover popover */
.comments-cell {
  position: relative; cursor: pointer;
  color: #60a5fa !important;
  text-decoration: underline dotted #60a5fa;
}
.comments-cell:hover { color: #93c5fd !important; }
.comments-popover {
  display: none; position: absolute;
  right: 100%; top: 0; z-index: 1000;
  margin-right: 8px;
  width: 380px; max-height: 500px;
  background: #181a20; border: 1px solid #2a2d35;
  border-radius: 8px; padding: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  text-align: left; font-weight: normal;
  overflow-y: auto;
}
.comments-cell:hover .comments-popover,
.comments-cell.open .comments-popover { display: block; }
.cmt-loading, .cmt-empty {
  padding: 12px; text-align: center; color: #8a8f98; font-size: 12px;
}
.cmt-list { display: flex; flex-direction: column; gap: 8px; }
.cmt-item {
  background: #12141a; border-radius: 6px;
  padding: 8px 10px; font-size: 12px;
}
.cmt-head { color: #c7cad1; margin-bottom: 4px; }
.cmt-head small { color: #575a62; margin-left: 6px; }
.cmt-orig { color: #c7cad1; line-height: 1.4; }
.cmt-tr { color: #4ade80; line-height: 1.4; margin-top: 4px; padding-top: 4px; border-top: 1px solid #23262e; }

/* Кнопка-свернуть внутри виджета */
#now-collapse-btn {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 22px;
  height: 22px;
  padding: 0;
  background: transparent;
  color: #8a8f98;
  border: none;
  border-radius: 4px;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  z-index: 2;
}
#now-collapse-btn:hover { color: #e7e9ec; background: rgba(255,255,255,0.05); }

/* Кнопка-развернуть — когда виджет скрыт */
#now-expand-btn {
  display: none;
  position: fixed;
  top: 16px;
  right: 24px;
  z-index: 60;
  width: 38px;
  height: 38px;
  align-items: center;
  justify-content: center;
  background: #1a1d24;
  border: 1px solid #2a2e38;
  border-radius: 10px;
  color: #e7e9ec;
  font-size: 18px;
  cursor: pointer;
  box-shadow: 0 2px 10px rgba(0,0,0,0.4);
}
#now-expand-btn:hover { border-color: #3b82f6; }

/* ---- NOW widget (правый верхний угол) ---- */
#now-widget {
  position: relative;
  position: fixed;
  top: 16px;
  right: 24px;
  z-index: 50;
  background: linear-gradient(135deg, #1a1d24 0%, #141720 100%);
  border: 1px solid #2a2e38;
  border-radius: 14px;
  padding: 14px 20px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.5);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 260px;
}
#now-widget .now-time {
  font-size: 34px;
  font-weight: 700;
  color: #e7e9ec;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: 0.04em;
  line-height: 1;
  margin-bottom: 4px;
}
#now-widget .now-date {
  font-size: 13px;
  color: #c7cad1;
  letter-spacing: 0.02em;
  line-height: 1.2;
  text-align: center;
  margin-bottom: 10px;
}
/* Бейджи уведомлений в виджете */
#now-widget .notif-pills {
  display: flex;
  gap: 4px;
  margin: 6px 0 2px;
  justify-content: center;
  text-decoration: none;
  flex-wrap: wrap;
}
#now-widget .notif-pills:hover { text-decoration: none; }
#now-widget .notif-pills .pill {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 2px 7px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 10px;
  line-height: 1.2;
}
#now-widget .pill.critical { background: rgba(220, 38, 38, 0.18); color: #fca5a5; border: 1px solid rgba(220, 38, 38, 0.4); }
#now-widget .pill.warn     { background: rgba(234, 179, 8, 0.15);  color: #fcd34d; border: 1px solid rgba(234, 179, 8, 0.4); }
#now-widget .pill.info     { background: rgba(34, 197, 94, 0.15);  color: #86efac; border: 1px solid rgba(34, 197, 94, 0.4); }

/* Строка контролов внутри виджета времени */
.widget-controls-row {
  width: 100%;
  display: flex;
  gap: 10px;
  align-items: stretch;
  justify-content: space-between;
  padding-top: 10px;
  margin-top: 6px;
  border-top: 1px solid #23262e;
  position: relative;
  z-index: 1;
}
.widget-controls-row .col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 3px;
  min-width: 0;
}
.widget-controls-row .lbl {
  font-size: 9px;
  color: #8a8f98;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  text-align: center;
}
.widget-controls-row select {
  padding: 4px 8px;
  background: #0f1014;
  color: #e7e9ec;
  border: 1px solid #2a2e38;
  border-radius: 5px;
  font-size: 11px;
  width: 100%;
  box-sizing: border-box;
  cursor: pointer;
}
.widget-controls-row select:hover { border-color: #3b82f6; }
.widget-controls-row .autoref-countdown {
  color: #60a5fa;
  font-size: 9px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  line-height: 1.2;
}
#now-widget form { margin: 0; }
#data-refresh {
  padding: 6px 14px;
  background: #1e3a8a;
  color: #e7e9ec;
  border: 1px solid #3b82f6;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
}
#data-refresh:hover { background: #2563eb; border-color: #60a5fa; }
#data-refresh:disabled { background: #374151; border-color: #4b5563; cursor: not-allowed; color: #8a8f98; }
#data-refresh.spinning .icon { animation: spin 1s linear infinite; display: inline-block; }
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.content { padding-top: 110px; }

/* ---- View picker (сегменты «По аккаунтам / по баерам / по агентствам») ---- */
.view-picker {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: #12141a;
  border: 1px solid #23262e;
  border-radius: 8px;
}
.view-picker .vp-btn {
  padding: 6px 12px;
  background: transparent;
  color: #8a8f98;
  border: none;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.view-picker .vp-btn:hover {
  background: rgba(59, 130, 246, 0.08);
  color: #e7e9ec;
}
.view-picker .vp-btn.active {
  background: #1e3a8a;
  color: #ffffff;
}

/* ---- Dashboard tabs (Обзор / Drill-down / Учёт / Параметры) ---- */
.dash-tabs {
  display: flex;
  gap: 2px;
  margin: 0 0 18px;
  padding: 4px;
  background: #12141a;
  border: 1px solid #23262e;
  border-radius: 10px;
  max-width: max-content;
}
.dash-tabs a {
  padding: 7px 14px;
  color: #8a8f98;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  border-radius: 7px;
  transition: background 0.15s, color 0.15s;
  white-space: nowrap;
}
.dash-tabs a:hover {
  background: rgba(59, 130, 246, 0.08);
  color: #e7e9ec;
  text-decoration: none;
}
.dash-tabs a.active {
  background: #1e3a8a;
  color: #ffffff;
  border: 1px solid #3b82f6;
  padding: 6px 13px;
}

/* ---- Унифицированные кнопки ---- */
.btn, button.btn, input[type="submit"].btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  line-height: 1.2;
  color: #e7e9ec;
  background: #1f2229;
  border: 1px solid #2e323c;
  border-radius: 8px;
  cursor: pointer;
  letter-spacing: 0.01em;
  transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.06s;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover {
  background: #262a33;
  border-color: #3a3f4a;
  color: #ffffff;
  text-decoration: none;
}
.btn:active { transform: translateY(1px); }
.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  background: #1a1d24;
  color: #8a8f98;
}

/* Главная акцентная (Сохранить, Добавить, Обновить) */
.btn.primary {
  background: linear-gradient(180deg, #2563eb 0%, #1d4ed8 100%);
  border-color: #3b82f6;
  color: #ffffff;
  font-weight: 600;
  box-shadow: 0 1px 2px rgba(37, 99, 235, 0.4);
}
.btn.primary:hover {
  background: linear-gradient(180deg, #3b82f6 0%, #2563eb 100%);
  border-color: #60a5fa;
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(59, 130, 246, 0.5);
}

/* Опасная (удалить, сбросить) */
.btn.danger {
  background: #2d1618;
  border-color: rgba(248, 113, 113, 0.4);
  color: #fca5a5;
}
.btn.danger:hover {
  background: #3a1a1e;
  border-color: #f87171;
  color: #ffffff;
}

/* Успех (редко) */
.btn.success {
  background: linear-gradient(180deg, #16a34a 0%, #15803d 100%);
  border-color: #22c55e;
  color: #ffffff;
}
.btn.success:hover {
  background: linear-gradient(180deg, #22c55e 0%, #16a34a 100%);
  border-color: #4ade80;
}

/* Маленькая */
.btn.sm {
  padding: 4px 10px;
  font-size: 11px;
  border-radius: 6px;
}

/* Призрачная (не заливается фоном) */
.btn.ghost {
  background: transparent;
  border-color: #2a2d35;
  color: #c7cad1;
}
.btn.ghost:hover {
  background: rgba(59, 130, 246, 0.08);
  border-color: #3b82f6;
  color: #60a5fa;
}

/* ---- Sidebar user ---- */
.sidebar { display: flex; flex-direction: column; }
.sidebar-nav { flex: 1; }
.sidebar-user {
  border-top: 1px solid #23262e;
  padding: 12px 16px 16px;
  font-size: 12px;
}
.sidebar-user-name { color: #e7e9ec; font-weight: 600; margin-bottom: 4px; }
.sidebar-user-meta {
  display: flex; flex-direction: column; gap: 3px;
  color: #8a8f98; font-size: 11px;
  overflow: hidden;
}
.sidebar-user-meta span:last-child {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.role-pill {
  display: inline-block;
  padding: 1px 7px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  border-radius: 10px;
  letter-spacing: 0.04em;
  align-self: flex-start;
}
.notif-badge {
  display: inline-block;
  background: #dc2626;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  margin-left: 4px;
  min-width: 16px;
  text-align: center;
  vertical-align: middle;
}

.role-owner    { background: #3b1d5c; color: #d8b4fe; }
.role-teamlead { background: #1e3a8a; color: #93c5fd; }
.role-buyer    { background: #134e4a; color: #5eead4; }
.role-farmer   { background: #422006; color: #fbbf24; }

/* ---- Hover-tooltip с детализацией (position: fixed через JS) ---- */
.detail-hint {
  cursor: help;
  border-bottom: 1px dashed rgba(147, 197, 253, 0.35);
  display: inline-block;
}
.detail-body {
  display: none;
  position: fixed;
  z-index: 10000;
  min-width: 280px;
  max-width: 360px;
  padding: 12px 14px;
  background: #12141a;
  border: 1px solid #3b82f6;
  border-radius: 10px;
  box-shadow: 0 10px 32px rgba(0, 0, 0, 0.7);
  font-size: 12px;
  line-height: 1.5;
  color: #e7e9ec;
  text-align: left;
  white-space: normal;
  font-weight: 400;
  pointer-events: none;  /* не мешает мышке перейти на другие элементы */
}
.detail-hint .detail-body h5 {
  margin: 0 0 6px; padding-bottom: 6px;
  border-bottom: 1px solid #23262e;
  color: #60a5fa; font-size: 12px; font-weight: 600;
}
.detail-hint .detail-body .row {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 2px 0;
}
.detail-hint .detail-body .row.total {
  margin-top: 6px; padding-top: 6px;
  border-top: 1px solid #23262e;
  color: #4ade80; font-weight: 600;
}
.detail-hint .detail-body .row span:first-child { color: #8a8f98; }
.detail-hint .detail-body .row span:last-child { color: #e7e9ec; font-variant-numeric: tabular-nums; }
.detail-hint .detail-body .formula {
  margin-top: 6px;
  padding: 6px 8px;
  background: #0f1014;
  border-radius: 6px;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  color: #c7cad1;
}

/* ---- Модалка ---- */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(2px);
  z-index: 9000;
  align-items: flex-start;
  justify-content: center;
  padding: 60px 20px 20px;
  overflow-y: auto;
}
.modal-backdrop.show { display: flex; }
.modal-card {
  background: #12141a;
  border: 1px solid #3b82f6;
  border-radius: 12px;
  padding: 20px 22px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 12px 48px rgba(0,0,0,0.7);
}
.modal-head {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 14px; padding-bottom: 10px; border-bottom: 1px solid #23262e;
}
.modal-head h3 { margin: 0; font-size: 16px; color: #e7e9ec; }
.modal-card label {
  display: block; margin-bottom: 12px;
  color: #c7cad1; font-size: 13px;
}
.modal-card input[type=text], .modal-card textarea, .modal-card select {
  display: block; width: 100%; margin-top: 4px;
  padding: 8px 10px; background: #0f1014; color: #e7e9ec;
  border: 1px solid #2a2e38; border-radius: 6px;
  font-size: 13px; box-sizing: border-box;
  font-family: inherit;
}
.modal-card input:focus, .modal-card textarea:focus, .modal-card select:focus {
  outline: none; border-color: #3b82f6;
}
.modal-card input[disabled] { color: #8a8f98; background: #1a1d24; }
.modal-card textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: 11px; }

/* ---- Buyer inline badge ---- */
.buyer-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  color: #a5b4fc;
  background: rgba(99, 102, 241, 0.14);
  border: 1px solid rgba(99, 102, 241, 0.35);
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
  letter-spacing: 0.02em;
  white-space: nowrap;
}
.buyer-badge.empty {
  color: #575a62;
  background: transparent;
  border-color: #2a2d35;
  font-weight: 400;
}

/* ---- Finance matrix ---- */
.finance-matrix .row-highlight { background: rgba(59, 130, 246, 0.06); }
.finance-matrix .row-highlight td:first-child { border-left: 3px solid #3b82f6; }
.finance-matrix td:first-child, .finance-matrix th:first-child {
  position: sticky; left: 0; z-index: 2; background: #12141a;
}
.finance-matrix th.num:nth-child(2), .finance-matrix td.num:nth-child(2) {
  position: sticky; left: 140px; z-index: 2;
}
.finance-matrix td.editable { cursor: pointer; position: relative; }
.finance-matrix td.editable:hover {
  background: rgba(59, 130, 246, 0.18);
  box-shadow: inset 0 0 0 1px #3b82f6;
}
.finance-matrix td.editable:hover::before {
  content: "✎";
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: 10px;
  color: #60a5fa;
  opacity: 0.8;
}
.finance-matrix td.cell-edited { background: rgba(251, 191, 36, 0.08); }
.finance-matrix td.cell-edited::after { content: " ●"; color: #fbbf24; font-size: 10px; }
.finance-matrix th.day-edited .day-date { color: #fbbf24; }

/* Шапка с суммой спенда */
.finance-matrix th.day-header {
  padding: 6px 8px;
  text-align: center;
  vertical-align: middle;
  line-height: 1.2;
}
.finance-matrix th.day-header .day-date {
  font-size: 12px;
  font-weight: 600;
  color: #c7cad1;
}
.finance-matrix th.day-header .day-spend {
  font-size: 11px;
  color: #60a5fa;
  font-family: ui-monospace, monospace;
  margin-top: 2px;
}
.finance-matrix th.day-has-spend {
  background: rgba(34, 197, 94, 0.07);
  border-bottom: 2px solid #22c55e;
}
.finance-matrix th.day-has-spend .day-date {
  color: #86efac;
}


/* ===================== MOBILE / TABLET (до 900px) ===================== */
/* Стили включаются только на узких экранах — десктоп не меняется. */

#mobile-menu-btn {
  display: none;
  position: fixed;
  top: 10px;
  left: 10px;
  z-index: 900;
  width: 38px;
  height: 38px;
  padding: 0;
  background: #1a1d24;
  color: #e7e9ec;
  border: 1px solid #2a2e38;
  border-radius: 8px;
  font-size: 20px;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.5);
}
#mobile-sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.55);
  z-index: 850;
}

@media (max-width: 900px) {
  /* Базовая типографика — заметно крупнее */
  body { font-size: 15px; line-height: 1.45; }
  h1 { font-size: 22px; margin: 0 0 12px; letter-spacing: -0.01em; }
  .hint { font-size: 13px; margin-bottom: 14px; color: #8a8f98; }

  /* Меньше отступов — больше контента в экране */
  .content { padding: 58px 12px 20px; padding-top: 58px; }

  /* Гамбургер-меню */
  #mobile-menu-btn {
    display: flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; font-size: 20px;
    top: 9px; left: 9px;
  }

  /* Сайдбар-оверлей */
  body.layout { grid-template-columns: 1fr; }
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: 260px;
    z-index: 870;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 8px 0 24px rgba(0,0,0,0.55);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-open #mobile-sidebar-backdrop { display: block; }
  .sidebar-nav a { padding: 12px 16px; font-size: 15px; }
  .sidebar-user { font-size: 13px; padding: 14px 16px 18px; }

  /* ---- Виджет времени: компактный, но не крошечный ---- */
  #now-widget {
    top: 9px;
    right: 9px;
    padding: 8px 12px;
    min-width: 140px;
    max-width: 180px;
    border-radius: 10px;
    gap: 1px;
  }
  #now-widget .now-time { font-size: 20px; margin-bottom: 2px; }
  #now-widget .now-date { font-size: 11px; margin-bottom: 4px; }
  #now-widget .notif-pills { gap: 3px; margin: 4px 0 2px; }
  #now-widget .notif-pills .pill { font-size: 11px; padding: 2px 6px; }
  .widget-controls-row { flex-direction: column; gap: 5px; padding-top: 6px; margin-top: 4px; }
  .widget-controls-row .lbl { font-size: 9px; }
  .widget-controls-row select { padding: 5px 8px; font-size: 12px; }
  .widget-controls-row .autoref-countdown { font-size: 10px; }
  #now-collapse-btn { top: 4px; right: 4px; width: 22px; height: 22px; font-size: 14px; }

  /* ---- KPI — 3 колонки, компактно но читаемо ---- */
  .section-block {
    margin-bottom: 12px;
    padding: 12px 10px 4px;
    background: #14161c;
    border: 1px solid #23262e;
    border-radius: 10px;
  }
  .section-block-title {
    font-size: 11px;
    margin: 0 2px 10px;
    color: #a0a4ad;
    font-weight: 700;
    letter-spacing: .5px;
  }
  .kpi-row {
    grid-template-columns: repeat(3, 1fr) !important;
    gap: 6px;
    margin-bottom: 6px;
  }
  .kpi {
    padding: 9px 10px;
    border-radius: 8px;
    min-width: 0;
  }
  .kpi::before { width: 2px; }
  .kpi .l {
    font-size: 9px;
    letter-spacing: .3px;
    margin-bottom: 3px;
    color: #8a8f98;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .kpi .v {
    font-size: 15px !important;
    font-weight: 700;
    line-height: 1.15;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .kpi .sub { font-size: 10px; margin-top: 2px; }

  /* Заголовок страницы — вертикаль */
  .page-head { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 12px; }

  /* ---- Дашборд-табы — полноширинная лента ---- */
  .dash-tabs {
    max-width: 100%;
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    padding: 4px;
    margin-bottom: 12px;
    scrollbar-width: none;
  }
  .dash-tabs::-webkit-scrollbar { display: none; }
  .dash-tabs a { padding: 8px 14px; font-size: 13px; }
  .dash-tabs a.active { padding: 7px 13px; }

  /* ---- View picker — полная ширина, 3 в ряд ---- */
  .view-picker {
    display: grid !important;
    grid-template-columns: repeat(3, 1fr);
    width: 100%;
    gap: 2px;
  }
  .view-picker .vp-btn {
    padding: 8px 6px;
    font-size: 12px;
    text-align: center;
  }

  /* Период-табы */
  .tabs { flex-wrap: wrap; gap: 6px; }
  .tab { padding: 7px 12px; font-size: 13px; border-radius: 7px; }

  /* Фильтры */
  .filters {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    padding: 12px 14px;
  }
  .filters label {
    font-size: 11px;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
  }
  .filters select, .filters input { width: 100%; }

  /* ---- Таблицы — горизонт. скролл + читаемые шрифты ---- */
  .t-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .t-wrap .t { min-width: 0; }
  .t { border-radius: 10px; }
  .t th { padding: 8px 8px; font-size: 10px; }
  .t td { padding: 9px 8px; font-size: 12px; }
  .t-compact th { padding: 6px 6px; font-size: 9px; }
  .t-compact td { padding: 7px 6px; font-size: 12px; }
  .t-compact td small { font-size: 11px; }
  .t tr.bm-row td { padding: 8px 10px; font-size: 12px; font-weight: 600; }

  /* ---- Модалка ---- */
  .modal-card { max-width: 96%; padding: 16px 18px; }
  .modal-backdrop { padding: 40px 10px 12px; }
  .modal-head h3 { font-size: 16px; }
  .modal-card label { font-size: 13px; margin-bottom: 12px; }
  .modal-card input, .modal-card textarea, .modal-card select {
    font-size: 15px; padding: 11px 12px;
  }

  /* ---- Уведомления ---- */
  .notif-card { padding: 12px 14px; border-radius: 10px; }
  .notif-card strong { font-size: 14px; }
  .notif-detail { padding-left: 0; }
  .notif-detail .t td { font-size: 11px !important; padding: 6px 6px; }

  /* ---- BM-блоки на /add-token ---- */
  .bm-block { padding: 12px 14px; border-radius: 10px; }
  .bm-block-head { flex-direction: column; align-items: flex-start; gap: 10px; }
  .bm-title { font-size: 14px; flex-wrap: wrap; gap: 6px; }
  .bm-actions { flex-wrap: wrap; gap: 6px; width: 100%; }
  .bm-actions .btn, .bm-actions select, .bm-actions .btn-sm { font-size: 12px; }
  .bm-status-select { font-size: 12px !important; }

  /* ---- Кнопки — тап-френдли ---- */
  .btn { padding: 10px 14px; font-size: 13px; min-height: 40px; }
  .btn.sm { padding: 6px 10px; font-size: 12px; min-height: 32px; }
  .btn-sm { padding: 6px 12px; font-size: 12px; }

  /* Инпуты — тап-френдли, без zoom на iOS */
  input[type="text"], input[type="number"], input[type="date"],
  input[type="email"], input[type="password"], textarea, select {
    font-size: 16px;
    padding: 11px 14px;
  }
  .add-token-form { grid-template-columns: 1fr 1fr !important; gap: 10px; }
  .add-token-form label.full { grid-column: 1 / -1; }
}

/* Узкие телефоны (≤ 500px) — 2 колонки KPI */
@media (max-width: 500px) {
  body { font-size: 14px; }
  h1 { font-size: 20px; margin-bottom: 10px; }

  .content { padding: 54px 9px 16px; }

  .kpi-row { grid-template-columns: repeat(2, 1fr) !important; gap: 6px; }
  .kpi { padding: 8px 10px; }
  .kpi .v { font-size: 15px !important; }
  .kpi .l { font-size: 9px; }

  /* Виджет — ещё компактнее */
  #now-widget {
    min-width: 128px;
    max-width: 160px;
    padding: 6px 10px;
  }
  #now-widget .now-time { font-size: 18px; }
  #now-widget .now-date { font-size: 10px; }
  #now-widget .notif-pills .pill { font-size: 10px; padding: 1px 5px; }

  .section-block { padding: 10px 10px 3px; margin-bottom: 10px; }
  .section-block-title { font-size: 10px; margin-bottom: 8px; }

  .tab { padding: 6px 11px; font-size: 12px; }

  /* View picker — по-прежнему 3 колонки, но компактнее */
  .view-picker .vp-btn { padding: 8px 4px; font-size: 11px; }

  /* Форма добавления токена — 1 колонка на совсем узком */
  .add-token-form { grid-template-columns: 1fr !important; }
}

/* Совсем крошечные (≤ 380px) — одноколоночный KPI */
@media (max-width: 380px) {
  .kpi-row { grid-template-columns: 1fr !important; }
  .kpi .v { font-size: 16px !important; }
  .kpi .l { font-size: 10px; }
}

/* =================================================================
   Универсальная mobile-оптимизация (≤ 900px) — компоненты которые
   приходят inline-стилем из шаблонов и не покрыты выше.
   ================================================================= */
@media (max-width: 900px) {
  /* Kanban: 4 колонки → горизонтальный скролл, каждая мин 260px */
  .kanban {
    grid-template-columns: repeat(4, 260px) !important;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
    scrollbar-width: thin;
  }
  .kanban-card { padding: 10px 12px; }
  .kanban-card-title { font-size: 14px; line-height: 1.3; }
  .kanban-card-meta .pill { font-size: 11px; padding: 2px 8px; }

  /* HTML5 <dialog> — модалки задач/оплаты */
  dialog {
    width: 96vw !important;
    max-width: 96vw !important;
    max-height: 92vh;
    overflow-y: auto;
    margin: 4vh auto;
    border-radius: 10px;
  }

  /* Settings-grid — одна колонка на мобильном */
  .settings-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .settings-card { padding: 14px !important; }
  .settings-card h3 { font-size: 14px !important; }

  /* Графики Chart.js — уменьшаем высоту чтобы не съедал экран */
  canvas { max-height: 180px !important; height: auto !important; }
  /* Но крупные графики на /roadmap оставляем большими */
  #pnlChart, #walletChart { max-height: 240px !important; }

  /* Inline-сетка графиков (auto-fit grid) — одной колонкой */
  .section-block > div[style*="grid-template-columns:repeat(auto-fit"] {
    grid-template-columns: 1fr !important;
  }

  /* Kanban-card: внутренние ряды (creator → assignee) переносятся */
  .kanban-card-meta { flex-wrap: wrap; }

  /* Топовые KPI в дашборде buyer (8 карточек) — 2 колонки */
  div[style*="grid-template-columns:repeat(8, 1fr)"],
  div[style*="grid-template-columns:repeat(7, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }
  div[style*="grid-template-columns:repeat(4, 1fr)"],
  div[style*="grid-template-columns:repeat(3, 1fr)"] {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  /* P&L таблицы — ужимаем шрифт */
  .t.t td, .t td { font-size: 12px; }

  /* Inline формы с repeat grid — одна колонка */
  form[style*="display:grid"] {
    grid-template-columns: 1fr !important;
  }

  /* Заголовки страниц с h1 + кнопки рядом — стек */
  div[style*="display:flex"][style*="align-items:center"] h1 {
    font-size: 18px;
  }

  /* Убираем dim flex-wrap у меню вкладок-табов */
  nav.dash-tabs { flex-wrap: nowrap; overflow-x: auto; }

  /* sqlite-web style формы и др — гарантия безопасной ширины */
  textarea { font-size: 15px; }

  /* Карточки на /agencies — h-scroll wrap */
  .t-wrap { overflow-x: auto; }
}

/* Очень узкие (≤ 500px) — Kanban: одна колонка под другой */
@media (max-width: 500px) {
  .kanban {
    grid-template-columns: 1fr !important;
    overflow-x: visible;
  }
  /* KPI с 4 колонками — 2 на узком */
  div[style*="grid-template-columns:repeat(4, 1fr)"],
  div[style*="grid-template-columns:repeat(3, 1fr)"] {
    grid-template-columns: 1fr !important;
  }
  canvas { max-height: 160px !important; }
}
