/* ===== div-grid lists: table-like on desktop, cards on mobile, swipeable ===== */
.dgrid { width: 100%; }
.dgrid-head, .drow-fg, .dgrid-foot { display: grid; align-items: center; }
.dgrid-head { color: var(--muted); font-size: 13px; border-bottom: 1px solid var(--line); }
.dgrid-head .cell { padding: 6px 10px; }

.drow { position: relative; overflow: hidden; border-bottom: 1px solid var(--line); touch-action: pan-y; }
.drow-fg { position: relative; z-index: 1; background: #fff; }
.drow:hover > .drow-fg { background: var(--hover); }
.drow-fg > .cell { padding: 8px 10px; min-width: 0; overflow-wrap: anywhere; word-break: break-word; }
.cell.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.cell.center { text-align: center; }
.cell.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.cell.act { text-align: center; padding: 8px 2px; }
.cell.act::before { content: none !important; }
.cell.act a { text-decoration: none; }
.drow-fg input:not([type=checkbox]) { width: 100%; border: 1px solid var(--line); background: #fff; padding: 6px 7px; border-radius: 6px; font: inherit; }
.cell.num input { text-align: right; }
.drow-fg.kind-topup .cell.num { color: var(--accent); }
.drow-fg.kind-carryover { color: var(--muted); }
.dgrid-foot { padding: 10px 0; }
.dgrid-foot .cell { padding: 0 10px; }

/* swipe reveal layers (mobile) */
.drow-action { position: absolute; inset: 0; display: none; align-items: center; font-size: 22px; color: #fff; padding: 0 26px; z-index: 0; }
.drow-action.edit { background: var(--accent); justify-content: flex-start; }
.drow-action.del  { background: #d9534f; justify-content: flex-end; }
.drow.sw-right .drow-action.edit { display: flex; }
.drow.sw-left  .drow-action.del  { display: flex; }

/* per-view column templates */
.dgrid.exp .dgrid-head, .dgrid.exp .drow-fg, .dgrid.exp .dgrid-foot {
  grid-template-columns: 124px 138px minmax(0, 1fr) 36px 36px;
}
.dgrid.exp .cell:first-child { white-space: nowrap; }
.exp-foot .cell { padding: 4px 10px; }
.exp-foot .foot-line { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; padding: 3px 0; }
.exp-foot .foot-line b { font-variant-numeric: tabular-nums; font-size: 16px; }
.exp-foot .foot-line.on-card { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 6px; color: var(--muted); }
.exp-foot .foot-line.on-card b { font-size: 14px; }
.exp-foot .foot-line.on-card.neg b { color: #d9534f; }
.amt-cell { display: flex; gap: 4px; align-items: center; }
.amt-cell input { flex: 1; min-width: 0; }
.cur-pick { padding: 5px 20px 5px 6px; font-size: 12px; background-position: right 5px center; }
.dgrid.veh .dgrid-head, .dgrid.veh .drow-fg {
  grid-template-columns: minmax(110px,1.4fr) minmax(70px,.8fr) minmax(86px,1fr) minmax(62px,.7fr) minmax(92px,1.05fr) minmax(150px,1.6fr) minmax(70px,.85fr) minmax(96px,1.15fr) 34px 34px;
}
.dgrid.con .dgrid-head, .dgrid.con .drow-fg {
  grid-template-columns: 168px minmax(0,1fr) minmax(0,1.5fr) 36px 36px;
}
.dgrid.rec .dgrid-head, .dgrid.rec .drow-fg {
  grid-template-columns: 76px 200px 152px 104px 104px 88px 32px 32px;
}
/* visual groups: статус·трата·сумма·период | дата | уведомлять | действия */
.dgrid.rec .cell:nth-child(4), .dgrid.rec .cell:nth-child(5), .dgrid.rec .cell:nth-child(6) {
  border-right: 1px solid var(--line);
}
.dgrid.dl .dgrid-head, .dgrid.dl .drow-fg {
  grid-template-columns: 28px minmax(120px,1.5fr) 110px 110px 150px;
}
.dl-filters { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin: 4px 0 10px; }
.dl-filters select, .dl-filters input[type="date"] { padding: 6px 8px; }
.dl-filters .alldates { display: inline-flex; align-items: center; gap: 5px; font-size: 14px; color: var(--muted); white-space: nowrap; }
.dl-filters input[type="date"]:disabled { opacity: .45; }
.dl-filters .dl-dash { color: var(--muted); }
.dgrid.rem .dgrid-head, .dgrid.rem .drow-fg {
  grid-template-columns: minmax(120px,1fr) 130px 34px 34px;
}
.dgrid.dash .dgrid-head, .dgrid.dash .drow-fg, .dgrid.dash .dgrid-foot {
  grid-template-columns: 30px minmax(120px,1.4fr) 132px 66px 66px 66px 66px;
}
.dgrid.dash .dgrid-foot { display: grid; padding: 10px 0; border-top: 2px solid var(--line); }
.dgrid.dash .dgrid-foot .cell { padding: 0 10px; }
.dgrid.dash .cell a { text-decoration: none; }
.dgrid.dash .cell a:hover { text-decoration: underline; }
.loc-name { background: none; border: 0; padding: 0; cursor: pointer; font: inherit; font-weight: 600; color: var(--accent); text-align: left; }
.loc-name:hover { text-decoration: underline; }
.loc-actions { display: flex; gap: 8px; align-items: center; justify-content: center; border-left: 1px solid var(--line); }
.loc-actions a { text-decoration: none; }
.add-loc { margin: 8px 0 4px; }
.link-add { background: none; border: 0; color: var(--accent); cursor: pointer; font: inherit; padding: 6px 0; }
.link-add:hover { text-decoration: underline; }
.bd-nav { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.bd-nav a { text-decoration: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 11px; font-size: 13px; color: var(--fg); }
.bd-nav a:hover { border-color: var(--accent); }
.cur-form select { padding: 4px 24px 4px 8px; font-size: 13px; }
.bd-toggle { background: none; border: 0; cursor: pointer; font-size: 13px; color: var(--muted); padding: 2px 4px; }
.bd-panel { border-top: 1px dashed var(--line); background: var(--hover); }
.bd { padding: 10px 14px; }
.bd-h { margin-bottom: 6px; }

.doc-cat { padding: 0 10px 6px; }
.doc-cat select { width: 100%; font-size: 12px; padding: 5px 24px 5px 8px; }
.doc-exp { display: flex; gap: 6px; padding: 0 10px 10px; }
.doc-exp input { flex: 1; min-width: 0; padding: 5px 7px; border: 1px solid var(--line); border-radius: 6px; font: inherit; font-size: 12px; }
.doc-exp button { border: 1px solid var(--line); background: var(--hover); border-radius: 6px; cursor: pointer; font-size: 12px; padding: 4px 8px; }
.doc-scan { padding: 0 10px 10px; }
.doc-scan .link { font-size: 12px; color: var(--muted); cursor: pointer; background: none; border: none; padding: 0; }
.doc-scan .link:hover { color: var(--accent); }
.scan-all { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; flex-wrap: wrap; }
.scan-all button { padding: 8px 14px; border: 1px solid var(--line); background: var(--hover); border-radius: 8px; cursor: pointer; font: inherit; }
.scan-all button:disabled { opacity: .5; cursor: default; }
.scan-msg { margin: 4px 0 12px; padding: 8px 12px; border-radius: 8px; background: var(--accent-bg, #eef6ee); color: var(--accent); font-size: 14px; }

/* recurring: alert dots + calendar */
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; vertical-align: middle; background: #c8ccc9; }
.dot.overdue { background: #d9534f; }
.dot.soon { background: #e6b800; }
.dot.ok, .dot.done { display: none; }   /* оплачено / в порядке → без точки */
.rec-due { font-size: 12px; color: var(--muted); }
.rec-notify button, .rec-paid button { background: none; border: 1px solid var(--line); border-radius: 7px; cursor: pointer; font: inherit; padding: 4px 8px; }
.rec-notify button { border: 0; font-size: 16px; padding: 2px; }
.rec-paid button.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }

.closed-note { background: var(--hover); border: 1px solid var(--line); border-radius: 8px; padding: 10px 14px; color: var(--muted); margin-top: 14px; }
.drow-fg.extra { background: #f1f2f4; color: var(--muted); }
.drow-fg.extra .cell.num { color: var(--muted); }
.extra-chk { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); margin-top: 4px; }
.freq { display: none; width: 100%; }
.freq.show { display: block; }
.rec-month { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; margin-bottom: 6px; max-width: 560px; }
.rec-mrow { display: flex; align-items: center; gap: 12px; padding: 9px 14px; border-bottom: 1px solid var(--line); }
.rec-mrow:last-child { border-bottom: 0; }
.rec-mrow.paid .rec-name { color: var(--muted); text-decoration: line-through; }
.rec-mrow .rec-name { flex: 1; }
.rec-mrow .num { font-variant-numeric: tabular-nums; }
.rec-total { padding: 10px 14px; background: var(--hover); }

/* merged bills list — fixed grid so columns never shift */
.bills-list { max-width: 840px; }
.bills-list .rec-mrow {
  display: grid; align-items: center; gap: 8px;
  grid-template-columns: minmax(90px,1fr) 18px 116px 110px 42px 106px 30px 30px;
}
.bills-list .dot { margin: 0; }
.bills-list .rec-name { min-width: 0; overflow-wrap: anywhere; }
.bill-meta { font-size: 12px; }
.bills-list .num { text-align: right; }
.bill-edit { text-decoration: none; text-align: center; }
.rec-paid button.on { background: var(--accent-bg); color: var(--accent); border-color: var(--accent); }
.month-bill .rec-name { font-weight: 600; }
.month-bill-open .rec-name { color: var(--muted); }

.loc-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.btn-green { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 8px 14px; cursor: pointer; font: inherit; }
.btn-green:hover { filter: brightness(1.05); }

/* tidy add-bill form (separate dashed box, uniform fields) */
.bill-add { display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin: 12px 0 4px; padding: 12px 14px; border: 1px dashed var(--line); border-radius: 12px; max-width: 840px; }
.bill-add input:not([type=checkbox]), .bill-add select {
  border: 1px solid var(--line); border-radius: 8px; padding: 0 9px; font: inherit; height: 36px; box-sizing: border-box; background: #fff; }
.bill-add .bill-name-in { flex: 1; min-width: 140px; }
.bill-add .bill-amt-in { width: 92px; text-align: right; }
.bill-add .rec-period { width: 104px; }
.bill-add .freq { width: 112px; }
.bill-add .cur-pick { width: 74px; }
.bill-add .extra-chk { margin: 0; }
.bill-add .add { width: auto; min-width: 40px; height: 36px; padding: 0 14px; font-size: 18px; line-height: 1; border-radius: 8px; }

/* ===== mobile: stack each row into a labelled card ===== */
@media (max-width: 720px) {
  main { padding: 16px 12px 72px; }
  .nav { gap: 10px; padding: 10px 12px; flex-wrap: wrap; }
  .nav nav { gap: 6px; font-size: 14px; flex-wrap: wrap; }
  .nav .user { margin-left: 0; }
  h1 { font-size: 23px; }

  .dgrid-head { display: none; }
  .dgrid .drow-fg, .dgrid .dgrid-foot { grid-template-columns: 1fr !important; }
  .bills-list .rec-mrow { display: flex; flex-wrap: wrap; }
  .drow-fg { padding: 6px 2px; }
  .drow-fg > .cell { display: flex; gap: 10px; padding: 3px 14px; }
  .drow-fg > .cell::before {
    content: attr(data-label); color: var(--muted); font-size: 12px;
    flex: 0 0 86px; padding-top: 1px;
  }
  .cell.num { text-align: left; }
  /* hide the desktop action-icon cells and any empty cells on mobile */
  .drow-fg > .cell.act, .drow-fg > .cell-empty { display: none; }
  .addrow .drow-fg > .cell.act { display: flex; justify-content: center; }
  .dgrid.rec .cell { border-right: none; }
  .swipe-hint { display: block; }
}
.swipe-hint { display: none; color: var(--muted); font-size: 12px; margin: 4px 2px 10px; }

/* report: "need" statement + send form */
.need { border: 1px solid var(--line); border-radius: 12px; padding: 16px 20px; margin: 8px 0 4px; display: inline-block; }
.need-sum { font-size: 30px; font-weight: 700; }
.need-cap { color: var(--muted); margin-top: 2px; }
.sendform { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.nick { padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; width: 140px; }

/* add-year button */
.yearpick { display: flex; align-items: center; gap: 8px; }
.addyear { padding: 6px 10px; border: 1px solid var(--line); background: transparent; border-radius: 8px; cursor: pointer; font-size: 13px; color: var(--muted); }
.addyear:hover { color: var(--fg); border-color: var(--muted); }

/* ===== project selector (nav) ===== */
.brand { display: flex; align-items: center; gap: 2px; }
.brand select.projsel { font-weight: 700; font-size: 16px; color: var(--accent);
  border-color: var(--accent); background-color: var(--accent-bg); padding: 7px 30px 7px 12px; }
.brand select.projsel:hover { filter: brightness(0.98); }
.addproj-form { margin: 0; }
.addproj { background: none; border: 0; color: var(--muted); font-size: 18px; line-height: 1; cursor: pointer; padding: 2px 6px; }
.addproj:hover { color: var(--accent); }

/* ===== user menu (top-right) ===== */
.usermenu { position: relative; margin-left: auto; }
.um-btn { background: none; border: 1px solid transparent; border-radius: 8px; padding: 5px 10px; cursor: pointer; font: inherit; color: var(--muted); }
.um-btn:hover { background: var(--hover); }
.um-pop { display: none; position: absolute; right: 0; top: 100%; margin-top: 6px; width: 270px;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12); padding: 12px; z-index: 50; }
.usermenu.open .um-pop { display: block; }
.um-form { margin-bottom: 10px; }
.um-form label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.um-row { display: flex; gap: 6px; }
.um-row input { flex: 1; min-width: 0; padding: 7px 9px; border: 1px solid var(--line); border-radius: 7px; font: inherit; }
.um-row button { border: 0; background: var(--accent); color: #fff; border-radius: 7px; padding: 0 12px; cursor: pointer; }
.um-logout { display: block; color: #d9534f; text-decoration: none; padding-top: 8px; border-top: 1px solid var(--line); }

/* locations (dashboard) edit/delete */
.loc-cell { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.loc-cell a { text-decoration: none; }
.loc-edit { font-size: 13px; }
.disp-form { margin: 12px 0 4px; }
.disp-form label { color: var(--muted); }

/* ===== AI assistant (🧠) ===== */
.toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ai { position: relative; margin-left: auto; display: flex; align-items: center; gap: 8px; }
.ai-btn { font-size: 22px; line-height: 1; background: none; border: 0; cursor: pointer; padding: 2px 4px; }
.ai-pop { display: flex; align-items: center; gap: 6px; }
.ai-form { order: 1; display: flex; gap: 6px; }
.ai-close { order: 2; background: none; border: 0; color: var(--muted); font-size: 15px; line-height: 1; cursor: pointer; padding: 4px 6px; }
.ai-close:hover { color: var(--fg); }
.ai-input { padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px; font: inherit; width: 300px; max-width: 60vw; }
.ai-input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-bg); }
.ai-go { background: var(--accent); color: #fff; border: 0; border-radius: 8px; padding: 0 14px; font-size: 16px; cursor: pointer; }
.ai-answer { order: 3; position: absolute; top: 100%; right: 0; margin-top: 8px; width: 380px; max-width: 86vw;
  background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 30px rgba(0,0,0,.12);
  padding: 14px; font-size: 14px; line-height: 1.5; white-space: pre-wrap; z-index: 40; }

@media (max-width: 720px) {
  .ai { margin-left: auto; }
  .ai-pop { display: none; position: fixed; left: 12px; right: 12px; top: 70px;
    background: #fff; border: 1px solid var(--line); border-radius: 14px;
    box-shadow: 0 12px 40px rgba(0,0,0,.2); padding: 30px 14px 14px; z-index: 60; }
  .ai.open .ai-pop { display: flex; flex-direction: column; align-items: stretch; gap: 10px; }
  .ai-close { position: absolute; top: 6px; right: 8px; font-size: 18px; padding: 6px 8px; }
  .ai.open::before { content: ""; position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 55; }
  .ai-input { width: 100%; max-width: none; }
  .ai-answer { position: static; width: auto; max-width: none; box-shadow: none; border: 0;
    border-top: 1px solid var(--line); border-radius: 0; padding: 12px 0 0; margin-top: 4px; }
}
