:root {
  --bg: #f4f6f8;
  --panel: #fff;
  --text: #1f2933;
  --muted: #6b7785;
  --border: #dde2e8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --in: #16a34a;
  --out: #ea580c;
  --danger: #dc2626;
  --warn-bg: #fff7e6;
  --danger-bg: #fdecec;
  --radius: 8px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 20px 0 6px; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }

/* Шапка */
.topbar { display: flex; align-items: center; gap: 18px; background: #111827; color: #fff; padding: 0 20px; min-height: 52px; flex-wrap: wrap; }
.brand { color: #fff; font-weight: 700; font-size: 16px; white-space: nowrap; }
.brand:hover { text-decoration: none; }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a { color: #cbd5e1; padding: 15px 12px; white-space: nowrap; border-bottom: 3px solid transparent; }
.nav a:hover { color: #fff; text-decoration: none; }
.nav a.active { color: #fff; border-bottom-color: var(--primary); }
.user { display: flex; gap: 12px; align-items: center; font-size: 14px; color: #cbd5e1; white-space: nowrap; }
.user a { color: #fff; }

.container { max-width: 1280px; margin: 0 auto; padding: 20px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Кнопки */
.btn { display: inline-block; padding: 8px 14px; border: 1px solid var(--border); background: #fff; color: var(--text); border-radius: 6px; cursor: pointer; font: inherit; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: #f1f4f8; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-in { background: var(--in); border-color: var(--in); color: #fff; }
.btn-in:hover { background: #15803d; }
.btn-out { background: var(--out); border-color: var(--out); color: #fff; }
.btn-out:hover { background: #c2410c; }
.btn-danger { color: var(--danger); border-color: #f5c2c2; }
.btn-danger:hover { background: var(--danger-bg); }
.btn-small { padding: 5px 9px; font-size: 13px; }
.btn-block { display: block; width: 100%; }

/* Панели и карточки */
.panel { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; margin-bottom: 16px; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; margin-bottom: 16px; }
.cards-2 { grid-template-columns: 1fr 1fr; align-content: start; }
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.card-warn { background: var(--warn-bg); border-color: #f5d89a; }
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 22px; font-weight: 700; margin-top: 4px; }
.card-value small { font-size: 14px; font-weight: 400; color: var(--muted); }
.card-sub { color: var(--muted); font-size: 13px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; }
.two-col > .panel { margin-bottom: 0; }
.two-col + * { margin-top: 16px; }

/* Таблицы */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; background: #fff; }
.table th, .table td { padding: 8px 10px; border-bottom: 1px solid var(--border); text-align: left; vertical-align: top; }
.table th { font-size: 13px; color: var(--muted); font-weight: 600; background: #f8fafc; white-space: nowrap; }
.table tbody tr:hover { background: #f8fafc; }
.table tfoot td { font-weight: 600; background: #f8fafc; }
.table .r { text-align: right; }
.table .c { text-align: center; }
.row-warn { background: var(--warn-bg); }
.row-danger { background: var(--danger-bg); }
.panel > .table-wrap > .table, .panel > .table { border: 1px solid var(--border); }

.badge { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 13px; font-weight: 600; background: #e5e7eb; color: #374151; white-space: nowrap; }
.badge-in { background: #dcfce7; color: #166534; }
.badge-out { background: #ffedd5; color: #9a3412; }

/* Формы */
label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label input, label select, label textarea { margin-top: 4px; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; font: inherit; color: var(--text); background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--primary); }
input[type=checkbox] { width: auto; margin: 0 6px 0 0; }
label.check { display: inline-flex; align-items: center; gap: 4px; color: var(--text); font-size: 14px; margin: 0; white-space: nowrap; }
label.check input[type=date] { width: auto; margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid3 { display: grid; grid-template-columns: 1fr 2fr 2fr; gap: 0 16px; }
.form-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }
.form .check { margin: 12px 0 4px; }
.inline { display: inline-flex; gap: 6px; align-items: center; margin: 0; }
.input-small { width: 150px; padding: 5px 8px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 14px; }
.filters input[type=search] { flex: 1; min-width: 200px; width: auto; }
.filters select { width: auto; max-width: 240px; }
.danger-zone { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }

.lines input { margin: 0; }
.lines td { vertical-align: top; }
.lines .qty, .lines .price { min-width: 90px; }
.lines .line-sum { padding-top: 16px; white-space: nowrap; }
.hint { display: block; font-size: 12px; color: var(--muted); margin-top: 3px; min-height: 16px; }
.hint-err { color: var(--danger); font-weight: 600; }

.props { display: grid; grid-template-columns: 180px 1fr; gap: 6px 12px; margin: 0; }
.props dt { color: var(--muted); }
.props dd { margin: 0; }

/* Сообщения */
.alert { padding: 10px 14px; border-radius: 6px; margin-bottom: 14px; border: 1px solid; }
.alert ul { margin: 0; padding-left: 18px; }
.alert-ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.alert-err { background: var(--danger-bg); border-color: #f5c2c2; color: #991b1b; }
.alert-warn { background: var(--warn-bg); border-color: #f5d89a; color: #92400e; }

.pager { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 10px; }
.pager a, .pager span { padding: 5px 10px; border: 1px solid var(--border); border-radius: 4px; background: #fff; }
.pager a.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* Вход / установка */
.auth-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 20px; }
.auth-box { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 28px; width: 100%; max-width: 380px; }
.auth-box.wide { max-width: 680px; }
.auth-box h1 { margin-bottom: 4px; }

.print-only { display: none; }
.doc-title { font-size: 18px; }
.signatures { display: flex; justify-content: space-between; margin-top: 50px; }

@media (max-width: 800px) {
  .container { padding: 12px; }
  .topbar { padding: 0 12px; gap: 0 12px; }
  .nav { order: 3; flex-basis: 100%; }
  .nav a { padding: 10px 10px; }
  .user { margin-left: auto; }
  .two-col, .grid2, .grid3, .cards-2 { grid-template-columns: 1fr; }
  .props { grid-template-columns: 1fr; }
  .props dt { margin-top: 6px; }
  .filters select, .filters input[type=search] { flex: 1 1 100%; max-width: none; }
  .lines .product-input { min-width: 220px; }
}

@media print {
  body { background: #fff; font-size: 12px; }
  .topbar, .no-print, .filters, .actions, .danger-zone, .alert { display: none !important; }
  .print-only { display: block; }
  .signatures.print-only { display: flex; }
  .container { max-width: none; padding: 0; }
  .panel { border: 0; padding: 0; }
  a { color: inherit; }
  .table th { background: #eee !important; }
  .row-warn, .row-danger { background: none; }
}

/* ===== Дополнения для учёта кормов ===== */
.badge-wait { background: #e0e7ff; color: #3730a3; }
.badge-warn { background: #fef3c7; color: #92400e; }
.badge-ok { background: #dcfce7; color: #166534; }
a.card { color: inherit; display: block; }
a.card:hover { text-decoration: none; border-color: var(--primary); }
.link-btn { background: none; border: 0; padding: 0; color: var(--primary); cursor: pointer; font: inherit; font-size: 13px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.inline.wrap { flex-wrap: wrap; }
.input-date { width: 150px; padding: 5px 8px; }
.input-err { border-color: var(--danger) !important; background: var(--danger-bg); }
.row-muted td { color: var(--muted); }
.big-check { font-size: 15px !important; margin: 12px 0 !important; }
.big-check input { width: 18px; height: 18px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.tabs a { padding: 8px 14px; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tabs a.active { color: var(--text); border-bottom-color: var(--primary); font-weight: 600; }
.tabs a:hover { text-decoration: none; color: var(--text); }

.pick-total { background: #f1f5f9; border-radius: 6px; padding: 10px 14px; margin: 10px 0; font-size: 15px; }
.pick-total .big { font-size: 18px; color: var(--in); }

.issue { border: 1px solid var(--border); border-radius: 6px; padding: 10px 12px; margin-bottom: 8px; }
.issue-open { background: var(--warn-bg); border-color: #f5d89a; }
.issue-closed { background: #f8fafc; }
.issue-head { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.issue-head select { width: auto; padding: 4px 8px; }
.issue-actions { display: flex; gap: 16px; flex-wrap: wrap; margin-top: 8px; }

.report { scroll-margin-top: 10px; }
.report-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 6px; }
.report-head h2 { margin: 0; }
.report-month input[type=month] { width: 170px; padding: 5px 8px; }
.report-total { font-size: 30px; font-weight: 700; margin: 6px 0 2px; }
.report details summary { cursor: pointer; color: var(--primary); margin: 6px 0; }
.chip { display: inline-block; background: #f1f5f9; border-radius: 14px; padding: 3px 10px; margin: 2px 4px 2px 0; font-size: 13px; }
label.check input[type=month] { width: auto; margin: 0; }

@media (max-width: 800px) {
  .report-total { font-size: 24px; }
  .lines input { min-width: 70px; }
  .lines .p-name { min-width: 200px; }
}

/* ===================== ТЕЛЕФОН ===================== */
.tabbar, .m-title, .m-only { display: none; }

/* Кнопки − / + у количества */
.stepper { display: inline-flex; align-items: stretch; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: #fff; }
.stepper input { border: 0 !important; border-radius: 0; width: 56px !important; min-width: 0 !important; max-width: 56px !important; text-align: center; padding: 6px 2px; margin: 0 !important; }
.stepper button { border: 0; background: #f1f5f9; width: 36px; font-size: 20px; line-height: 1; cursor: pointer; color: var(--text); padding: 0; touch-action: manipulation; }
.stepper button:active { background: #dbe3ec; }
.stepper.input-err-wrap { border-color: var(--danger); }

.menu-list { display: flex; flex-direction: column; gap: 8px; }
.menu-list a { display: flex; align-items: center; gap: 12px; background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 16px; font-size: 17px; color: var(--text); }
.menu-list a span { font-size: 22px; }
.menu-list a:hover { text-decoration: none; border-color: var(--primary); }

/* Карточки остатков для телефона */
.stock-cards { display: flex; flex-direction: column; gap: 8px; }
.stock-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 12px; }
.stock-card .sc-title { font-weight: 600; font-size: 16px; }
.stock-card .sc-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 8px; }
.stock-card .sc-grid div { background: #f8fafc; border-radius: 6px; padding: 6px 8px; }
.stock-card .sc-grid small { display: block; color: var(--muted); font-size: 11px; }
.stock-card .sc-grid b { font-size: 17px; }

@media (max-width: 800px) {
  body { font-size: 16px; }
  body.has-tabbar { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  input, select, textarea { font-size: 16px; padding: 10px 12px; } /* без авто-зума на iPhone */
  .btn { padding: 11px 16px; font-size: 15px; }
  .btn-small { padding: 8px 12px; font-size: 14px; }
  h1 { font-size: 20px; }

  /* шапка */
  .topbar { min-height: 48px; padding: 0 14px; padding-top: env(safe-area-inset-top); gap: 10px; flex-wrap: nowrap; }
  .topbar .nav, .topbar .user { display: none; }
  .brand { font-size: 14px; opacity: .7; overflow: hidden; text-overflow: ellipsis; max-width: 45%; }
  .m-title { display: block; color: #fff; font-weight: 600; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .m-only { display: block; }
  .d-only { display: none !important; }

  /* нижнее меню */
  .tabbar { display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; background: #fff; border-top: 1px solid var(--border);
            padding-bottom: env(safe-area-inset-bottom); box-shadow: 0 -2px 10px rgba(0,0,0,.05); }
  .tabbar a { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 8px 0 7px; color: var(--muted); font-size: 11px; }
  .tabbar a.active { color: var(--primary); }
  .tabbar a:hover { text-decoration: none; }

  .container { padding: 12px; }
  .page-head { margin-bottom: 12px; }
  .page-head h1 { width: 100%; }
  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1; text-align: center; }
  .cards { grid-template-columns: 1fr 1fr; gap: 8px; }
  .card { padding: 10px 12px; }
  .card-value { font-size: 19px; }
  .panel { padding: 12px; border-radius: 10px; }
  .filters { gap: 6px; }
  .filters > * { flex: 1 1 45%; }
  .filters input[type=search] { flex-basis: 100%; }
  .filters .btn { flex: 1 1 100%; }

  /* Таблицы → карточки */
  .table-wrap { overflow: visible; }
  .table.stack, .table.stack tbody, .table.stack tfoot, .table.stack tr, .table.stack td { display: block; width: 100%; }
  .table.stack thead { display: none; }
  .table.stack { background: transparent; border: 0 !important; }
  .table.stack tr { background: #fff; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 8px; padding: 8px 12px; }
  .table.stack tbody tr:hover { background: #fff; }
  .table.stack tr.row-warn { background: var(--warn-bg); border-color: #f5d89a; }
  .table.stack tr.row-danger { background: var(--danger-bg); }
  .table.stack td { border: 0; padding: 5px 0; display: flex; justify-content: space-between; align-items: center; gap: 12px; text-align: right !important; min-height: 30px; }
  .table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 14px; text-align: left; flex-shrink: 0; }
  .table.stack td[data-label=""]::before { content: none; }
  .table.stack td.td-title { display: block; text-align: left !important; font-weight: 600; font-size: 16px; padding-bottom: 4px; border-bottom: 1px solid var(--border); margin-bottom: 2px; }
  .table.stack td.td-empty { display: none; }
  .table.stack td input:not([type=checkbox]), .table.stack td select { width: auto; max-width: 62%; flex: 1; }
  .table.stack td .stepper { flex: 0 0 auto; }
  .table.stack td .p-name { max-width: 100%; }
  .table.stack tfoot tr { background: #f1f5f9; }
  .table.stack tfoot td { font-weight: 600; }
  .lines .line-sum { padding-top: 5px; }

  /* главная кнопка формы всегда под рукой */
  .sticky-actions { position: sticky; bottom: calc(64px + env(safe-area-inset-bottom)); z-index: 20; background: var(--bg);
                    margin: 12px -12px -12px; padding: 10px 12px; border-top: 1px solid var(--border); border-radius: 0 0 10px 10px; }
  .sticky-actions .btn { flex: 1; text-align: center; font-size: 16px; padding: 13px; }

  .props { grid-template-columns: 1fr; gap: 0; }
  .props dt { margin-top: 8px; font-size: 13px; }
  .issue-actions form { width: 100%; }
  .issue-actions .input-small, .issue-actions .input-date { flex: 1; width: auto; }
  .danger-zone .btn { flex: 1; }
  .report-total { font-size: 26px; }
  .report-month { width: 100%; }
  .report-month input[type=month] { flex: 1; width: auto; }
  .two-col { gap: 12px; }
  .tabs a { padding: 8px 10px; }
  .grid2, .grid3 { gap: 0; }
}
@media (max-width: 800px) {
  .table.stack tr { display: flex; flex-direction: column; }
  .table.stack td.td-title { order: -1; }
}
td.plan-off > * { visibility: hidden; }
@media (max-width: 800px) {
  .table.stack td.plan-off { display: none; }
  .m-title { display: none; }
  .brand { opacity: 1; max-width: 100%; font-size: 16px; }
}
@media (max-width: 800px) {
  .table.stack td.td-title input { width: 100%; max-width: none; }
  .table.stack td:has(> select.r-plan) { flex-direction: column; align-items: stretch; gap: 4px; }
  .table.stack td select.r-plan { max-width: none; width: 100%; }
}
@media (min-width: 801px) { .m-only { display: none !important; } }
@media (max-width: 800px) { .stock-cards.m-only { display: flex; } }

/* База кормов, «Поделиться» */
input[readonly] { background: #f1f5f9; color: var(--muted); }
.grid-add { display: grid; grid-template-columns: 2fr 1fr 1fr auto; gap: 0 12px; align-items: end; }
.grid-add .btn { margin-bottom: 10px; }
.share-box { border-color: #bfdbfe; background: #f8fbff; }
.share-text { white-space: pre-wrap; font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; background: #fff;
              border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 0 0 10px; }
.share-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.share-hint:empty { display: none; }
@media (max-width: 800px) {
  .grid-add { grid-template-columns: 1fr; }
  .share-actions .btn { flex: 1; text-align: center; }
}
