/* FILE: static/style.css
   VERSION: 1.1.0
   PURPOSE: Стили адаптивного интерфейса voice_sheet — header, таблица приёмки,
            inline-редактирование, FAB микрофона, автокомплит, тосты.
            Mobile-first; протестировано mental-modal на Chrome и iOS Safari.
   CHANGE_SUMMARY:
     1.1.0 — таблица влезает в viewport смартфона без горизонтального скролла:
             снят min-width: 720px, добавлен <colgroup> в HTML, на ≤640px
             включается table-layout: fixed, скрывается колонка «№ п/п»,
             ячейки сжимаются (font-size 12px, padding 6px), длинные имена
             поставщиков переносятся словами. ISO-даты сохранены.
*/

* { box-sizing: border-box; }

:root {
  --bg: #f3f5f9;
  --surface: #ffffff;
  --border: #d8dde5;
  --text: #14202e;
  --muted: #6a7484;
  --primary: #0f3a66;
  --primary-contrast: #ffffff;
  --accent: #e8efff;
  --active: #fff5cc;
  --active-border: #f1c14b;
  --danger: #c0392b;
  --shadow: 0 6px 18px rgba(15, 58, 102, 0.18);
  --radius: 10px;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }

/* ---------- Header ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px env(safe-area-inset-top) 14px;
  padding-top: max(10px, env(safe-area-inset-top));
  background: var(--primary);
  color: var(--primary-contrast);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}

.brand {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}
.brand__name { font-size: 18px; font-weight: 700; }
.brand__sub { font-size: 12px; opacity: 0.75; }

.auth { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.auth__form { display: flex; gap: 6px; }
.auth__form input {
  height: 36px;
  border: none;
  border-radius: var(--radius);
  padding: 0 12px;
  background: rgba(255, 255, 255, 0.95);
  font-size: 14px;
  width: 170px;
}
.auth__form button,
.btn-link {
  height: 36px;
  padding: 0 14px;
  border: none;
  border-radius: var(--radius);
  background: #2563a8;
  color: #fff;
  font-weight: 600;
  cursor: pointer;
}
.auth__form button:hover,
.btn-link:hover { background: #1f4f87; }
.auth__status {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
}
.auth__status.is-editor { background: #2cb67d; }

/* ---------- Main ---------- */
.main { padding: 14px; max-width: 1200px; margin: 0 auto; }

.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

table.rows {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

table.rows th,
table.rows td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

table.rows th {
  background: #eef3fa;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  border-bottom: 2px solid var(--border);
  position: sticky;
  top: 0;
}

table.rows tbody tr {
  transition: background-color 0.15s ease;
}
table.rows tbody tr:hover {
  background: var(--accent);
}
table.rows tbody tr.active {
  background: var(--active);
  outline: 2px solid var(--active-border);
  outline-offset: -2px;
}

/* Десктопные ширины колонок (mobile-overrides ниже в @media). */
col.col-num,
th.col-num,
td.col-num { width: 56px; text-align: right; color: var(--muted); }
col.col-supplier,
th.col-supplier,
td.col-supplier { white-space: normal; }
col.col-date,
th.col-date,
td.col-date { width: 140px; }
col.col-doc,
th.col-doc,
td.col-doc { width: 130px; }

.cell {
  display: block;
  width: 100%;
  min-height: 1.4em;
  cursor: default;
}

body.is-editor .cell { cursor: text; }
body.is-editor .cell:hover { box-shadow: inset 0 -2px 0 0 var(--accent); }

.cell--empty { color: var(--muted); font-style: italic; }
.cell--empty::before { content: "—"; }
.cell--empty:not(:empty)::before { content: ""; }

.cell-input {
  width: 100%;
  padding: 6px 8px;
  font-size: inherit;
  font-family: inherit;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: #fff;
  outline: none;
}

.row-placeholder {
  cursor: pointer;
  color: var(--muted);
  text-align: center;
  font-style: italic;
}
.row-placeholder td { padding: 14px 12px; }
.row-placeholder:hover { background: var(--accent); color: var(--primary); }

/* ---------- Help panel ---------- */
.help-panel {
  margin: 16px 0 80px;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 2px 8px rgba(15, 58, 102, 0.08);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text);
}

.help-panel__toggle {
  display: block;
  padding: 12px 16px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  color: var(--primary);
  list-style: none;
  user-select: none;
}
.help-panel__toggle::-webkit-details-marker { display: none; }
.help-panel__toggle::before {
  content: "▸ ";
  display: inline-block;
  transition: transform 0.15s ease;
}
.help-panel[open] > .help-panel__toggle::before { transform: rotate(90deg); }
.help-panel__toggle:hover { color: #1c4f86; }

.help-panel__body {
  padding: 0 16px 16px;
  line-height: 1.55;
}

.help-section { margin-bottom: 14px; }
.help-section:last-child { margin-bottom: 0; }

.help-section__title {
  font-size: 13px;
  font-weight: 700;
  color: var(--primary);
  margin: 0 0 4px;
}

.help-section p { margin: 0; color: var(--muted); }
.help-section ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
}
.help-section li { margin-bottom: 3px; }
.help-section li:last-child { margin-bottom: 0; }

.help-section kbd {
  display: inline-block;
  padding: 1px 5px;
  font-size: 11px;
  font-family: inherit;
  background: #eef3fa;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
}

.help-section em { font-style: italic; color: var(--text); }

/* ---------- FAB микрофона ---------- */
.mic {
  position: fixed;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  width: 64px;
  height: 64px;
  border-radius: 50%;
  border: none;
  background: var(--primary);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  z-index: 100;
  transition: transform 0.1s ease, background 0.15s ease;
}
.mic:hover { background: #1c4f86; }
.mic:active { transform: scale(0.94); }
.mic.is-recording {
  background: var(--danger);
  animation: pulse 1.1s infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0.6); }
  70% { box-shadow: 0 0 0 18px rgba(192, 57, 43, 0); }
  100% { box-shadow: 0 0 0 0 rgba(192, 57, 43, 0); }
}

/* ---------- Автокомплит ---------- */
.autocomplete {
  position: absolute;
  z-index: 200;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  max-width: 90vw;
  min-width: 240px;
  overflow: hidden;
}
.autocomplete__item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.autocomplete__item:last-child { border-bottom: none; }
.autocomplete__item:hover,
.autocomplete__item.focused { background: var(--accent); }

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translateX(-50%);
  background: rgba(15, 32, 46, 0.92);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 300;
  box-shadow: var(--shadow);
  max-width: 90vw;
  text-align: center;
}

/* ---------- Mobile tweaks ---------- */
@media (max-width: 640px) {
  .main { padding: 8px; }
  .auth__form input { flex: 1 1 110px; min-width: 0; width: auto; }
  .brand__sub { display: none; }
  .mic { width: 56px; height: 56px; }
  .mic__icon svg { width: 28px; height: 28px; }

  /* Таблица должна влезть во viewport без горизонтального скролла.
     Полный overflow:hidden даёт чистый clip border-radius на правом краю. */
  .table-wrap { overflow: hidden; }

  table.rows {
    table-layout: fixed;
    width: 100%;
  }
  table.rows th,
  table.rows td {
    padding: 6px 6px;
    font-size: 12px;
    line-height: 1.25;
    white-space: normal;
  }
  table.rows th {
    font-size: 11px;
    /* Заголовкам можно переноситься, чтобы не вылезать за свою колонку. */
    white-space: normal;
  }

  /* Колонка «№ п/п» не редактируется и не критична — скрываем целиком. */
  col.col-num,
  table.rows th.col-num,
  table.rows td.col-num { display: none; }

  /* Жёсткие ширины: даты по 76px (ISO YYYY-MM-DD влезает 12px шрифтом),
     «Документ» — 60px, поставщик забирает остаток. */
  col.col-supplier,
  table.rows th.col-supplier,
  table.rows td.col-supplier {
    width: auto;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  col.col-date,
  table.rows th.col-date { width: 76px; text-align: center; }
  table.rows td.col-date {
    width: 76px;
    text-align: center;
    white-space: nowrap;
  }
  col.col-doc,
  table.rows th.col-doc { width: 60px; text-align: center; }
  table.rows td.col-doc {
    width: 60px;
    text-align: center;
    white-space: nowrap;
  }

  /* iOS Safari делает auto-zoom при тапе на input с font-size < 16px.
     Поднимаем размер шрифта в редакторе до 16px — auto-zoom гасится,
     а пользовательский pinch-zoom остаётся доступным. */
  .cell-input {
    font-size: 16px;
    padding: 4px 6px;
  }
}

/* На очень узких экранах (iPhone SE 1-го поколения) ужать ещё чуть-чуть. */
@media (max-width: 360px) {
  table.rows th,
  table.rows td { padding: 5px 4px; font-size: 11px; }
  col.col-date,
  table.rows th.col-date,
  table.rows td.col-date { width: 70px; }
  col.col-doc,
  table.rows th.col-doc,
  table.rows td.col-doc { width: 48px; }
}
