:root {
  --bg: #f7f3ee;
  --surface: #fffdfa;
  --line: #e8ddd2;
  --text: #332b27;
  --muted: #8b7e74;
  --primary: #a24b3a;
  --primary-dark: #873c2e;
  --accent: #6d5172;
  --good: #3f7d5b;
  --warm: #b6652b;
  --radius: 14px;
  --shadow: 0 2px 12px rgba(70, 45, 30, .07);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

/* Верхняя панель */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
  background: rgba(255, 253, 250, .94);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; }
.brand-mark { color: var(--primary); font-size: 20px; }
.sync { font-size: 12px; color: var(--muted); white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.sync.saved { color: var(--good); }
.sync.offline { color: var(--warm); }
.sync.saving { color: var(--accent); }

/* Подсказка для iOS */
.ios-hint {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 16px 0;
  padding: 12px 14px;
  border: 1px solid #e6cfbf;
  background: #fff5ec;
  border-radius: var(--radius);
  font-size: 13px;
}
.ios-hint p { margin: 4px 0 0; color: #6f5b4d; }
.ios-hint[hidden] { display: none; }

/* Навигация */
.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 30;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  box-shadow: 0 -2px 14px rgba(70, 45, 30, .06);
}
.tabs button {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  min-height: 58px;
  padding: 7px 2px 6px;
  border: 0;
  background: none;
  color: var(--muted);
  font-size: 10.5px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}
.tabs button span { font-size: 19px; line-height: 1; }
.tabs button.active { color: var(--primary); font-weight: 700; }

/* Контент */
main { max-width: 900px; margin: 0 auto; padding: 16px 16px 100px; }
.panel[hidden] { display: none; }
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 4px 0 14px; }
.panel-head h1 { margin: 0; font-size: 22px; letter-spacing: -.3px; }
.panel-head .sub { display: block; font-size: 12px; color: var(--muted); font-weight: 400; margin-top: 2px; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(112px, 1fr)); gap: 8px; margin-bottom: 14px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; box-shadow: var(--shadow); min-width: 0; }
.stat b { display: block; font-size: 19px; line-height: 1.2; }
.stat span { font-size: 11px; color: var(--muted); overflow-wrap: anywhere; display: block; }

.section-title {
  display: flex; align-items: center; justify-content: space-between;
  margin: 22px 2px 10px; font-size: 13px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px; color: var(--muted);
}

.list { display: flex; flex-direction: column; gap: 10px; }
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 14px;
  box-shadow: var(--shadow);
}
.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.card-title { font-weight: 700; font-size: 16px; word-break: break-word; }
.card-sub { color: var(--muted); font-size: 13px; margin-top: 2px; word-break: break-word; }
.card-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; margin-top: 9px; font-size: 12px; color: var(--muted); }
.card-actions { display: flex; gap: 6px; flex-shrink: 0; }
.price { font-weight: 700; color: var(--accent); white-space: nowrap; }
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px;
  font-size: 11px; font-weight: 700; background: #efe9e2; color: #6d6158;
}
.badge.made { background: #e9eef7; color: #425e86; }
.badge.stock { background: #f6eadb; color: #9a6226; }
.badge.sold, .badge.done { background: #e3f2e9; color: #357152; }
.badge.new { background: #eee8f3; color: #6d5172; }
.badge.work { background: #f6eadb; color: #9a6226; }
.badge.cancel { background: #f1e5e5; color: #9b4b4b; }
.badge.empty { background: #f5e2e2; color: #9b4b4b; }
.note { margin-top: 8px; font-size: 12.5px; color: var(--muted); white-space: pre-wrap; }

.empty-state {
  text-align: center; padding: 36px 20px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: var(--radius);
  background: rgba(255, 253, 250, .6);
}
.empty-state .big { font-size: 28px; display: block; margin-bottom: 6px; }

/* Кнопки */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 42px; padding: 9px 14px;
  border: 1px solid var(--line); border-radius: 10px;
  background: var(--surface); font-weight: 600; font-size: 14px;
}
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.primary:active { background: var(--primary-dark); }
.btn.danger { color: #a13f3f; border-color: #e7c9c5; background: #fff7f5; }
.btn.small { min-height: 34px; padding: 5px 10px; font-size: 12px; }
.icon-btn {
  width: 36px; height: 36px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--line); border-radius: 9px;
  background: var(--surface); color: var(--muted); font-size: 15px;
}
.icon-btn:active { background: #f2ece5; }
.add-row { width: 100%; border-style: dashed; color: var(--primary); }

/* Модальное окно */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(40, 28, 22, .42); }
.sheet {
  position: relative; width: 100%; max-height: 92vh; overflow-y: auto;
  background: var(--surface); border-radius: 20px 20px 0 0;
  padding: 16px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -8px 30px rgba(40, 28, 22, .2);
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sheet-head h2 { margin: 0; font-size: 19px; }
.sheet-actions { display: flex; gap: 8px; margin-top: 18px; }
.sheet-actions .btn { flex: 1; }

.field { display: block; margin-bottom: 12px; }
.field > span { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%; min-height: 44px; padding: 10px 12px;
  border: 1px solid var(--line); border-radius: 10px;
  background: #fff; font-size: 16px;
}
.field textarea { resize: vertical; min-height: 68px; }
.mat-row { display: flex; gap: 6px; margin-bottom: 8px; }
.mat-row select { flex: 1; min-width: 0; }
.mat-row input { width: 76px; }

.toast {
  position: fixed; left: 50%; transform: translateX(-50%);
  bottom: calc(76px + env(safe-area-inset-bottom, 0px));
  z-index: 60; padding: 10px 16px; border-radius: 999px;
  background: #332b27; color: #fff; font-size: 13px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, .2);
}
.toast[hidden] { display: none; }

/* Десктоп */
@media (min-width: 760px) {
  .tabs {
    position: static; max-width: 900px; margin: 16px auto 0;
    border: 1px solid var(--line); border-radius: 12px; overflow: hidden;
    box-shadow: var(--shadow);
  }
  .tabs button { min-height: 46px; flex-direction: row; gap: 7px; font-size: 13px; }
  .tabs button span { font-size: 16px; }
  main { padding-bottom: 40px; }
  .stats { gap: 12px; }
  .stat { padding: 14px 16px; }
  .stat b { font-size: 23px; }
  .modal { align-items: center; }
  .sheet { max-width: 520px; border-radius: 18px; padding-bottom: 20px; max-height: 86vh; }
  .toast { bottom: 28px; }
}
