/* Стиль под Google Таблицы / Material: системный шрифт с Google Sans и Roboto впереди,
   серые линии сетки, зелёный лист в логотипе и в строках-группах, синий Material в действиях.
   Внешних шрифтов и CDN нет — сервис личный и должен открываться в любых условиях. */
:root {
  --bg: #f8f9fa; --paper: #fff; --ink: #202124; --muted: #5f6368; --line: #dadce0;
  --grid: #e2e3e3; --grid-strong: #c0c0c0; --head: #f8f9fa; --gutter: #f8f9fa;
  --group: #e6f4ea; --group-hover: #d7ecdd; --group-ink: #137333;
  --sel: #1a73e8; --sel-bg: #e8f0fe; --blue: #1a73e8; --blue-dark: #1765cc; --blue-soft: #e8f0fe;
  --green: #0f9d58; --red: #d93025; --red-soft: #fce8e6; --warn-bg: #fef7e0; --warn-ink: #b06000;
  --hover: rgba(60,64,67,.08); --press: rgba(60,64,67,.12);
  --shadow-1: 0 1px 2px rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15);
  --shadow-3: 0 1px 3px rgba(60,64,67,.3), 0 4px 8px 3px rgba(60,64,67,.15);
  --font: "Google Sans", Roboto, "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--paper); color: var(--ink); font: 14px/1.4 var(--font); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; font-weight: 500; }
h1 { font-size: 18px; font-weight: 400; }
h2 { font-size: 18px; }
h3 { font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; }
[hidden] { display: none !important; }
.spacer { flex: 1; }

/* Иконки */
.ic { width: 20px; height: 20px; fill: currentColor; flex: none; }

/* Кнопки Material: outlined по умолчанию, filled для главного действия, text для второстепенных, icon — круглые */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 36px; padding: 0 14px; border-radius: 4px; border: 1px solid var(--line); background: var(--paper); color: var(--blue); font: inherit; font-size: 14px; font-weight: 500; letter-spacing: .25px; cursor: pointer; text-decoration: none; white-space: nowrap; user-select: none; -webkit-tap-highlight-color: transparent; transition: background .12s, box-shadow .12s; }
.btn:hover { background: #f6fafe; }
.btn:active { background: var(--blue-soft); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; box-shadow: var(--shadow-1); }
.btn.primary:hover { background: var(--blue-dark); box-shadow: var(--shadow-3); }
.btn.primary:active { background: var(--blue-dark); }
.btn.text { border-color: transparent; }
.btn.text:hover { background: var(--blue-soft); }
.btn.danger { color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.danger.filled { background: var(--red); border-color: var(--red); color: #fff; }
.btn.danger.filled:hover { background: #c5221f; }
.btn.icon { width: 40px; height: 40px; padding: 0; border-radius: 50%; border-color: transparent; color: var(--muted); }
.btn.icon:hover { background: var(--hover); }
.btn.icon:active { background: var(--press); }
.btn.icon .ic { width: 22px; height: 22px; }
.btn.icon.small { width: 32px; height: 32px; }
.btn.icon.small .ic { width: 18px; height: 18px; }
.btn.icon .lbl { display: none; }
.inline { display: inline; margin: 0; }

/* Шапка документа */
.top { display: flex; align-items: center; gap: 8px; height: 56px; padding: 0 8px 0 12px; background: var(--paper); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.logo { width: 28px; height: 36px; border-radius: 3px; background: var(--green); position: relative; flex: none; }
.logo::before { content: ""; position: absolute; left: 7px; right: 7px; top: 12px; bottom: 8px; border: 2px solid #fff; border-radius: 1px; }
.logo::after { content: ""; position: absolute; left: 7px; right: 7px; top: 19px; height: 2px; background: #fff; box-shadow: 0 5px 0 #fff; }
.logo.big { width: 40px; height: 52px; border-radius: 4px; }
.logo.big::before { left: 10px; right: 10px; top: 17px; bottom: 11px; }
.logo.big::after { left: 10px; right: 10px; top: 27px; height: 2px; box-shadow: 0 7px 0 #fff; }
.top .title { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.period { position: relative; display: inline-flex; align-items: center; }
.period::after { content: ""; position: absolute; right: 10px; top: 50%; width: 0; height: 0; margin-top: -2px; border: 5px solid transparent; border-top-color: var(--muted); pointer-events: none; }
.period select { appearance: none; -webkit-appearance: none; font: inherit; font-size: 14px; height: 36px; padding: 0 28px 0 12px; border: 1px solid var(--line); border-radius: 18px; background: var(--paper); color: var(--ink); cursor: pointer; max-width: 200px; text-overflow: ellipsis; }
.period select:hover { background: var(--bg); }
.period select:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }

/* Индикатор загрузки — тонкая полоса под шапкой, как в Material */
.progress { position: sticky; top: 56px; z-index: 5; height: 3px; margin-bottom: -3px; background: var(--blue-soft); overflow: hidden; }
.progress .bar { position: absolute; left: 0; top: 0; bottom: 0; width: 40%; background: var(--blue); animation: slide 1.2s ease-in-out infinite; }
@keyframes slide { from { transform: translateX(-100%); } to { transform: translateX(260%); } }

/* Панель действий, как тулбар Sheets */
.toolbar { display: flex; gap: 8px; align-items: center; padding: 6px 8px; margin: 10px 12px 8px; background: #f1f3f4; border-radius: 24px; }
.toolbar .btn { background: transparent; border-color: transparent; }
.toolbar .btn:hover { background: var(--hover); }
.toolbar .btn.primary { background: var(--blue); border-color: var(--blue); }
.toolbar .btn.primary:hover { background: var(--blue-dark); }

/* Баннеры: ошибки красные и остаются до закрытия, подсказки серые */
.banner { display: flex; align-items: flex-start; gap: 10px; margin: 0 12px 8px; padding: 10px 8px 10px 14px; border-radius: 8px; font-size: 13px; line-height: 20px; }
.banner .ic { margin-top: 0; width: 20px; height: 20px; }
.banner .text { flex: 1; word-break: break-word; padding-top: 0; }
.banner .btn.icon.small { margin: -6px -2px -6px 0; }
.banner.error { background: var(--red-soft); color: #a50e0e; }
.banner.error .ic { color: var(--red); }
.banner.info { background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.banner.info .ic { color: var(--blue); }
.banner.warn { background: var(--warn-bg); color: var(--warn-ink); }
.banner.warn .ic { color: #f29900; }
.banner.compact { margin: 0 0 12px; }
.hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* Сводка периода — чипы */
.summary { display: flex; gap: 8px; padding: 0 12px 10px; flex-wrap: wrap; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 28px; padding: 0 12px; border-radius: 14px; border: 1px solid var(--line); color: var(--muted); font-size: 12px; background: var(--paper); }
.chip b { color: var(--ink); font-weight: 500; font-variant-numeric: tabular-nums; }
.chip.total { background: var(--group); border-color: transparent; color: var(--group-ink); }
.chip.total b { color: var(--group-ink); }

/* Лист таблицы */
.sheet { overflow: auto; padding: 0 0 72px; border-top: 1px solid var(--grid-strong); }
table.sheet-table { border-collapse: separate; border-spacing: 0; min-width: 100%; font-size: 13px; }
table.sheet-table th, table.sheet-table td { border-right: 1px solid var(--grid); border-bottom: 1px solid var(--grid); padding: 0 8px; height: 30px; line-height: 20px; vertical-align: middle; background: var(--paper); white-space: nowrap; }
table.sheet-table thead th { background: var(--head); color: var(--muted); font-weight: 400; text-align: center; position: sticky; z-index: 2; }
table.sheet-table thead tr.letters th { top: 0; height: 22px; line-height: 22px; font-size: 11px; border-bottom-color: var(--grid); }
table.sheet-table thead tr.letters th[data-l]::before { content: attr(data-l); }
table.sheet-table thead tr.names th { top: 22px; color: var(--ink); font-weight: 500; text-align: left; border-bottom-color: var(--grid-strong); }
table.sheet-table thead tr.names th.c-num, table.sheet-table thead tr.names th.c-sum { text-align: right; }
table.sheet-table th.gutter, table.sheet-table td.gutter { background: var(--gutter); color: var(--muted); text-align: center; width: 40px; min-width: 40px; font-size: 11px; padding: 0 4px; border-right-color: var(--grid-strong); position: sticky; left: 0; z-index: 1; }
table.sheet-table thead th.gutter { z-index: 3; }
table.sheet-table td.c-num { text-align: right; color: var(--muted); width: 48px; font-variant-numeric: tabular-nums; }
table.sheet-table td.c-date { width: 132px; color: var(--muted); font-variant-numeric: tabular-nums; }
table.sheet-table td.c-fd { width: 100px; color: var(--muted); font-variant-numeric: tabular-nums; }
table.sheet-table td.c-name { white-space: normal; min-width: 260px; max-width: 560px; line-height: 18px; padding-top: 6px; padding-bottom: 6px; height: auto; }
table.sheet-table td.c-sum { text-align: right; font-variant-numeric: tabular-nums; width: 108px; }
table.sheet-table td.c-name .meta { display: none; }
table.sheet-table tr.group td { background: var(--group); color: var(--group-ink); font-weight: 500; cursor: pointer; }
table.sheet-table tr.group td.gutter { background: var(--gutter); color: var(--muted); font-weight: 400; }
table.sheet-table tr.group:hover td:not(.gutter) { background: var(--group-hover); }
table.sheet-table tr.item { cursor: pointer; }
table.sheet-table tr.item:hover td:not(.gutter) { background: #f5f5f5; }
table.sheet-table tr.selected td:not(.gutter) { background: var(--sel-bg) !important; box-shadow: inset 0 0 0 1px var(--sel); }
table.sheet-table tr.selected td.gutter { background: var(--sel-bg); color: var(--sel); }
table.sheet-table tr.total td { font-weight: 500; border-top: 2px solid var(--grid-strong); }
table.sheet-table tr.blank td { height: 30px; }
.badge { display: inline-block; font-size: 11px; line-height: 16px; color: var(--warn-ink); background: var(--warn-bg); padding: 0 7px; border-radius: 8px; margin-left: 6px; font-weight: 400; vertical-align: 1px; }
table.sheet-table td.empty { color: var(--muted); text-align: center; padding: 36px 16px; font-size: 13px; white-space: normal; height: auto; }
table.sheet-table td.empty .ic { display: block; margin: 0 auto 8px; width: 36px; height: 36px; color: #bdc1c6; }

/* Диалоги Material: на телефоне — шторка снизу, на широком экране — окно по центру */
.modal { position: fixed; inset: 0; background: rgba(32,33,36,.6); display: flex; align-items: flex-end; justify-content: center; z-index: 20; }
.modal-body { background: var(--paper); width: 100%; max-width: 680px; max-height: 94vh; overflow: auto; border-radius: 16px 16px 0 0; padding: 12px 16px 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); box-shadow: var(--shadow-3); }
@media (min-width: 720px) { .modal { align-items: center; padding: 24px; } .modal-body { border-radius: 8px; padding: 16px 24px 20px; } }
.modal-body.center { text-align: center; padding: 28px 32px; border-radius: 8px; width: auto; min-width: 260px; max-width: 320px; align-self: center; }
.modal-body.center p { margin: 0; }
.modal-body.center .hint { margin-top: 6px; }
.modal-body.confirm { max-width: 400px; border-radius: 8px; align-self: center; padding: 20px 24px 16px; }
.modal-body.confirm p { color: var(--muted); margin: 10px 0 0; }
.dialog-head { display: flex; align-items: center; gap: 8px; margin: 0 -8px 12px 0; min-height: 40px; }
.dialog-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.via { color: var(--muted); font-size: 12px; }
.scanner video { width: 100%; border-radius: 8px; background: #000; aspect-ratio: 3 / 4; object-fit: cover; }
.scanner .hint { text-align: center; }
.spinner { width: 36px; height: 36px; border: 4px solid #e8eaed; border-top-color: var(--blue); border-radius: 50%; margin: 0 auto 14px; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Поля формы: подпись сверху, как в Material outlined */
.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 14px; }
.grid label, .field { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.grid label > span, .field > span { font-size: 12px; color: var(--muted); }
.grid .wide { grid-column: 1 / -1; }
input[type=text], input[type=number], input[type=datetime-local], input[type=password] { font: inherit; font-size: 14px; height: 40px; padding: 0 12px; border: 1px solid var(--line); border-radius: 4px; width: 100%; min-width: 0; background: var(--paper); color: var(--ink); }
input::placeholder { color: #9aa0a6; }
input:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
input[type=number] { -moz-appearance: textfield; }
input[type=number]::-webkit-outer-spin-button, input[type=number]::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }

/* Позиции чека внутри редактора */
.items-head { display: flex; align-items: center; justify-content: space-between; margin: 4px 0 2px; }
.items-head .btn { height: 32px; padding: 0 10px 0 6px; }
table.items { width: 100%; border-collapse: collapse; font-size: 13px; }
table.items th { text-align: left; color: var(--muted); font-weight: 500; padding: 4px 4px 6px; font-size: 12px; border-bottom: 1px solid var(--grid); }
table.items td { padding: 3px 2px; }
table.items td input { height: 36px; padding: 0 8px; }
table.items th.n, table.items td.n { width: 30px; color: var(--muted); text-align: right; padding-right: 6px; font-variant-numeric: tabular-nums; }
table.items th.q, table.items td.q { width: 64px; }
table.items th.s, table.items td.s { width: 96px; }
table.items td.s input, table.items td.q input { text-align: right; }
table.items th.x, table.items td.x { width: 32px; padding: 0; }
table.items tfoot td { color: var(--muted); padding: 8px 4px 0; border-top: 1px solid var(--grid); }
table.items tfoot td#itemsSum { text-align: right; font-weight: 500; color: var(--ink); padding-right: 10px; font-variant-numeric: tabular-nums; }
table.items tfoot td#itemsSum.mismatch { color: var(--red); }
#mismatch { margin-top: 10px; }
.fiscal { margin: 12px 0 4px; font-size: 13px; color: var(--muted); }
.fiscal summary { cursor: pointer; padding: 6px 0; list-style: none; display: flex; align-items: center; gap: 6px; }
.fiscal summary::-webkit-details-marker { display: none; }
.fiscal summary::before { content: ""; width: 0; height: 0; border: 5px solid transparent; border-left-color: var(--muted); margin-left: 4px; transition: transform .12s; }
.fiscal[open] summary::before { transform: rotate(90deg); }
.fiscal .grid { margin-top: 8px; }
.editor-foot { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-top: 16px; }
.editor-foot .btn { padding: 0 12px; }

/* Тост-снекбар: не перекрывает кнопки, тянется по ширине на телефоне */
.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 30; display: flex; align-items: center; gap: 8px; max-width: calc(100vw - 24px); min-width: 280px; padding: 12px 8px 12px 16px; border-radius: 4px; background: #323232; color: #fff; font-size: 14px; line-height: 20px; box-shadow: var(--shadow-3); animation: rise .18s ease-out; }
.toast .text { flex: 1; }
.toast-action { font: inherit; font-weight: 500; color: #8ab4f8; background: none; border: 0; padding: 6px 8px; border-radius: 4px; cursor: pointer; text-transform: uppercase; letter-spacing: .5px; white-space: nowrap; }
.toast-action:hover { background: rgba(255,255,255,.08); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } to { opacity: 1; transform: translate(-50%, 0); } }

/* Вход */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); padding: 16px; }
.login { background: var(--paper); padding: 32px 28px 28px; border-radius: 8px; width: min(100%, 360px); display: flex; flex-direction: column; gap: 14px; border: 1px solid var(--line); align-items: stretch; }
.login .logo { align-self: center; margin-bottom: 4px; }
.login h1 { font-size: 24px; text-align: center; }
.login .sub { margin: -8px 0 8px; text-align: center; color: var(--muted); font-size: 14px; }
.login .btn { height: 40px; margin-top: 4px; }
.err { color: var(--red); margin: -6px 0 0; font-size: 13px; }

/* Телефон: шапка в одну строку, в таблице только п/п · наименование · сумма, а дата и номер чека
   уходят в подстроку строки-группы — иначе наименование и сумму пришлось бы искать скроллом. */
@media (max-width: 600px) {
  .top { gap: 4px; padding: 0 4px 0 10px; }
  .top .title { flex: none; font-size: 17px; }
  .period { flex: 1; min-width: 0; margin: 0 4px 0 6px; }
  .period select { width: 100%; max-width: none; }
  .toolbar { margin: 8px 8px 8px; padding: 6px; gap: 6px; }
  .toolbar .btn { flex: 1; padding: 0 8px; gap: 6px; }
  .lbl { display: none; }
  .banner, .summary { margin-left: 8px; margin-right: 8px; }
  .summary { padding-left: 8px; padding-right: 8px; gap: 6px; }
  .chip { padding: 0 10px; }
  table.sheet-table th.gutter, table.sheet-table td.gutter { width: 32px; min-width: 32px; }
  table.sheet-table th.c-date, table.sheet-table td.c-date, table.sheet-table th.c-fd, table.sheet-table td.c-fd { display: none; }
  table.sheet-table thead tr.letters th[data-m]::before { content: attr(data-m); }
  table.sheet-table td.c-num { width: 40px; padding: 0 6px; }
  table.sheet-table td.c-name { min-width: 0; max-width: none; width: auto; }
  table.sheet-table td.c-sum { width: 92px; padding: 0 8px 0 4px; }
  table.sheet-table td.c-name .meta { display: block; font-size: 11px; line-height: 14px; font-weight: 400; color: var(--muted); margin-top: 1px; }
  table.sheet-table tr.group td.c-name { padding-top: 5px; padding-bottom: 5px; }
  input[type=datetime-local] { padding: 0 6px 0 8px; font-size: 13px; letter-spacing: -.2px; }
  table.items th.q, table.items td.q { width: 56px; }
  table.items th.s, table.items td.s { width: 88px; }
  table.items td input { padding: 0 6px; }
  .editor-foot .btn.text { padding: 0 10px; }
  .toast { left: 8px; right: 8px; transform: none; min-width: 0; max-width: none; }
  @keyframes rise { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
}

/* Срез по месяцам в режиме «Все чеки»: заголовок месяца как секция листа. */
table.sheet-table tr.month td { background: #f1f3f4; color: var(--ink); font-weight: 500; text-transform: uppercase; letter-spacing: .3px; font-size: 12px; border-top: 2px solid var(--grid-strong); }
table.sheet-table tr.month td.gutter { background: var(--gutter); color: var(--muted); font-weight: 400; text-transform: none; }
