:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --border: #e4e8ef;
  --text: #1a2233;
  --muted: #6b7484;
  --primary: #2f6fed;
  --primary-dark: #1f56c4;
  --primary-soft: #e8f0ff;
  --danger: #e5484d;
  --success: #16a34a;
  --warning: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(20, 30, 60, .06), 0 6px 20px rgba(20, 30, 60, .06);
  --shadow-lg: 0 12px 40px rgba(20, 30, 60, .16);
}

* { box-sizing: border-box; }

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.5;
  -webkit-font-smoothing: antialiased;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; margin: 6px 0; }

h1, h2, h3 { margin: 0 0 8px; font-weight: 650; }

/* ---------- Вход ---------- */
.login-screen {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  padding: 32px 28px;
  width: 100%; max-width: 360px;
  text-align: center;
}
.login-logo { font-size: 44px; }
.login-card h1 { margin: 6px 0 0; font-size: 22px; }
.login-card label { display: block; text-align: left; margin: 14px 0 4px; font-weight: 600; font-size: 13px; }

/* ---------- Формы ---------- */
input, select, textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  font-size: 15px;
  color: var(--text);
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
label { font-weight: 600; font-size: 13px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px; font-weight: 600;
  cursor: pointer;
  transition: background .12s, transform .05s, box-shadow .12s;
  white-space: nowrap;
}
.btn:hover { background: #f1f4f9; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: rgba(0,0,0,.05); }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-block { width: 100%; }

.icon-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 22px; color: var(--muted); line-height: 1; padding: 4px 8px;
  border-radius: 8px;
}
.icon-btn:hover { background: rgba(0,0,0,.06); }

/* ---------- Шапка ---------- */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 16px;
  z-index: 30;
}
.topbar-title { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; }
.topbar-title .logo { font-size: 22px; }
.topbar-user { display: flex; align-items: center; gap: 8px; }

/* ---------- Навигация ---------- */
.nav {
  position: fixed; top: 56px; left: 0; bottom: 0; width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 10px;
  display: flex; flex-direction: column; gap: 4px;
  z-index: 20;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  border: none; background: transparent; cursor: pointer;
  padding: 11px 14px; border-radius: 10px;
  font-size: 15px; font-weight: 600; color: var(--muted);
  text-align: left;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: #f1f4f9; }
.nav-item.active { background: var(--primary-soft); color: var(--primary); }
.nav-ico { font-size: 18px; }

/* ---------- Контент ---------- */
.content {
  margin: 56px 0 0 200px;
  padding: 20px 24px 60px;
  max-width: 1040px;
}

.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.btn.excel { background: var(--success); border-color: var(--success); color: #fff; }
.btn.excel:hover { background: #128a3e; }
.page-title { font-size: 22px; font-weight: 700; }

/* Карточки-статистика */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card .k { color: var(--muted); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .3px; }
.card .v { font-size: 22px; font-weight: 700; margin-top: 4px; }

/* День */
.day-nav { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.day-nav input[type=date] { width: auto; }

/* Список заказов */
.order-list { display: flex; flex-direction: column; gap: 10px; }
.order-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  cursor: pointer;
  transition: box-shadow .12s, transform .05s;
}
.order-card:hover { box-shadow: var(--shadow-lg); }
.order-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.order-client { font-weight: 700; }
.order-phone { color: var(--muted); font-size: 13px; }
.order-sum { font-weight: 800; font-size: 17px; color: var(--primary); white-space: nowrap; }
.order-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.order-items { color: var(--text); font-size: 13px; margin-top: 6px; }
.order-items div { padding: 1px 0; }
.order-actions {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin-top: 10px; padding-top: 10px; border-top: 1px dashed var(--border);
}
.chk-label {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 13px; font-weight: 600; cursor: pointer; user-select: none;
}
.chk-label input { width: auto; }
.order-card.done { border-left: 4px solid var(--success); }
.order-card.rejected { border-left: 4px solid var(--danger); opacity: .65; }
.reject-active { color: var(--danger); }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: #eef1f6; color: var(--muted);
}
.badge.debt { background: #fde8e8; color: var(--danger); }
.badge.cash { background: #e5f7ec; color: var(--success); }
.badge.done { background: #e5f7ec; color: var(--success); }
.badge.rejected { background: #fde8e8; color: var(--danger); }
.badge.warn { background: #fdf3e0; color: var(--warning); }

.empty { text-align: center; color: var(--muted); padding: 40px 0; }

/* Карточки материалов */
.mat-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 10px; }
.mat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.mat-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.mat-name { font-weight: 700; }
.mat-meta { color: var(--muted); font-size: 13px; margin-top: 4px; }
.mat-price { font-weight: 700; color: var(--primary); margin-top: 6px; }
.mat-actions { display: flex; gap: 6px; margin-top: 10px; }

/* Плавающая кнопка «+ Новый заказ» (видна на телефоне) */
.fab {
  display: none;
  position: fixed;
  right: 16px;
  bottom: 76px;
  z-index: 40;
  align-items: center;
  gap: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 999px;
  padding: 16px 22px;
  font-size: 16px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(47, 111, 237, .45);
  cursor: pointer;
}

/* Таблицы */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 11px 14px; border-bottom: 1px solid var(--border); }
th { background: #f8fafc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .3px; font-weight: 700; }
tr:last-child td { border-bottom: none; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--primary-soft); }
td.num, th.num { text-align: right; }

/* Поиск */
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.search { max-width: 340px; }

/* Модальные окна */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 24px 14px; z-index: 50; overflow-y: auto;
}
.modal-card {
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 640px;
  margin: auto 0;
  animation: pop .16s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 20px; border-top: 1px solid var(--border); }
.field { margin-bottom: 12px; }
.field label { display: block; margin-bottom: 4px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* Позиции заказа */
.item-row {
  display: grid;
  grid-template-columns: 1.6fr 1fr .8fr .7fr .9fr auto;
  gap: 8px; align-items: center;
  padding: 8px; margin-bottom: 8px;
  border: 1px solid var(--border); border-radius: 12px; background: #fafbfd;
}
.item-amount { font-weight: 700; text-align: right; font-size: 14px; white-space: nowrap; }
.suggest { border: 1px solid var(--border); border-radius: 10px; background: #fff; margin-top: 4px; max-height: 220px; overflow-y: auto; }
.suggest button { display: block; width: 100%; text-align: left; border: none; background: none; padding: 10px 12px; cursor: pointer; font-size: 14px; }
.suggest button:hover { background: var(--primary-soft); }

.total-bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--primary-soft); border-radius: 12px; padding: 12px 16px; margin-top: 8px;
  font-size: 15px;
}
.total-bar b { font-size: 20px; color: var(--primary); }

/* Тосты */
#toast-root { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: #1a2233; color: #fff; padding: 11px 18px; border-radius: 10px;
  box-shadow: var(--shadow-lg); font-size: 14px; animation: pop .16s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

/* ---------- Мобильные ---------- */
@media (max-width: 760px) {
  .nav {
    top: auto; bottom: 0; left: 0; right: 0; width: auto; height: 60px;
    flex-direction: row; border-right: none; border-top: 1px solid var(--border);
    padding: 4px 6px; justify-content: space-around;
  }
  .nav-item { flex-direction: column; gap: 2px; padding: 6px 10px; font-size: 11px; }
  .nav-ico { font-size: 20px; }
  .content { margin: 56px 0 0 0; padding: 16px 14px 80px; }
  .cards { grid-template-columns: 1fr 1fr; }
  .topbar-user #user-name { display: none; }
  .item-row { grid-template-columns: 1fr 1fr; }
  .row2 { grid-template-columns: 1fr; }

  /* --- мобильная оптимизация --- */
  /* 16px в полях — iOS не будет приближать экран при вводе */
  input, select, textarea { font-size: 16px; }
  /* крупные зоны нажатия (минимум 44px — рекомендация Apple) */
  .btn { min-height: 44px; }
  input, select { min-height: 44px; }
  /* в позиции заказа: материал и наименование на всю ширину */
  .item-row .it-mat { grid-column: 1 / -1; }
  .item-row .it-name { grid-column: 1 / -1; }
  /* кнопки действий в заказе (выполнено/перенос/отказ) крупнее */
  .order-actions { gap: 8px; }
  .order-actions .btn { min-height: 42px; }
  .chk-label { font-size: 14px; }
  /* плавающая кнопка «+ Новый заказ» на телефоне */
  .fab { display: flex; }
  .mat-list { grid-template-columns: 1fr; }
}
