/* =====================================================================
   Carmetric Design Tokens — Phase 16 (Claude Design, Conservative variant)
   Source of truth: ~/Downloads/carmetric/project/Carmetric Dashboard.html
   Подключается из _header_v2.php. НЕ трогать старые страницы — они
   продолжают использовать Tailwind (D-02/D-03, две системы до Phase 22).
   ===================================================================== */

/* ---------- Self-hosted fonts (per D-13/D-14, D-17) ---------- */
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-400.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-500.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-600.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-700.woff2') format('woff2'); font-weight: 700; font-style: normal; font-display: swap; }
@font-face { font-family: 'Inter'; src: url('/assets/fonts/inter-800.woff2') format('woff2'); font-weight: 800; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/assets/fonts/jetbrainsmono-400.woff2') format('woff2'); font-weight: 400; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/assets/fonts/jetbrainsmono-500.woff2') format('woff2'); font-weight: 500; font-style: normal; font-display: swap; }
@font-face { font-family: 'JetBrains Mono'; src: url('/assets/fonts/jetbrainsmono-600.woff2') format('woff2'); font-weight: 600; font-style: normal; font-display: swap; }

/* ---------- Design tokens :root (per D-04) ---------- */
:root {
  /* Font stacks */
  --font-humanist: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --font-display: var(--font-humanist);
  --font-numeric: var(--font-humanist);

  /* Type scale */
  --text-2xs: 10px;
  --text-xs: 11px;
  --text-sm: 12px;
  --text-md: 13px;
  --text-base: 14px;
  --text-lg: 15px;
  --text-xl: 17px;
  --text-title: 24px;
  --lh-tight: 1.15;
  --lh-ui: 1.3;
  --lh-body: 1.45;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Conservative palette — 15 colors */
  --c-bg: #f6f7f9;
  --c-surface: #ffffff;
  --c-border: #e7e9ee;
  --c-border-strong: #d4d7de;
  --c-text: #0e1116;
  --c-text-2: #4b5361;
  --c-text-3: #8a90a0;
  --c-primary-fill: #374151; /* softer graphite for primary CTAs (nav-v2-cta, +Добавить, Сохранить, etc.) */
  --c-accent: #2563eb;
  --c-accent-soft: #eff4ff;
  --c-success: #0f9b6e;
  --c-success-soft: #e7f6ef;
  --c-warn: #c27a00;
  --c-warn-soft: #fff4e0;
  --c-danger: #d64545;
  --c-danger-soft: #fdecec;

  /* Spacing scale */
  --space-1: 2px;
  --space-2: 4px;
  --space-3: 6px;
  --space-4: 8px;
  --space-5: 10px;
  --space-6: 12px;
  --space-7: 14px;
  --space-8: 16px;
  --space-9: 18px;
  --space-10: 20px;
  --space-12: 24px;
  --space-14: 28px;

  /* Radius scale */
  --radius-xs: 4px;
  --radius-control: 8px;
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-card: 14px;

  /* Density (fixed `default` per D-04, no data-density variants) */
  --pad-card: 20px;
  --pad-section: 20px;
  --gap-grid: 14px;

  /* Phase 18 additions — sheet / toast / swipe (see 18-CONTEXT D-13..D-16, handoff 1463-1515) */
  --shadow-sheet: 0 -8px 24px -8px rgba(14,17,22,0.18);
  --shadow-toast: 0 12px 28px -8px rgba(14,17,22,0.22);
  --z-tabbar: 50;            /* documents existing _mobile_nav_v2.php z-index */
  --z-fab: 60;               /* documents existing */
  --z-sheet-backdrop: 140;
  --z-sheet: 150;
  --z-toast: 200;
  --sheet-radius: 20px;
  --sheet-handle-w: 40px;
  --sheet-handle-h: 4px;
}

/* ---------- Utility classes (per D-26, handoff 215-227) ---------- */
.kicker {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
  color: var(--c-text-3);
}
.num {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
  letter-spacing: 0;
}
.num-mono {
  font-family: var(--font-mono);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

/* ---------- Card (per D-08, handoff lines 207-213) ---------- */
.cm-card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  padding: var(--pad-card);
}

/* ---------- Form primitives (per D-23, handoff lines 2002-2053) ---------- */

/* Field (label wrapper) */
.cm-field { display: block; margin-bottom: 14px; }
.cm-field-label {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-2);
}
.cm-field-label .cm-required { color: var(--c-danger); margin-left: 3px; }
.cm-field-hint {
  font-size: 11px;
  color: var(--c-text-3);
}
.cm-field-error {
  font-size: 11px;
  color: var(--c-danger);
  margin-top: 4px;
}

/* Input wrapper (allows prefix/suffix) */
.cm-input-wrap {
  display: flex;
  align-items: center;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-surface);
  overflow: hidden;
  transition: border-color .15s;
}
.cm-input-wrap:focus-within { border-color: var(--c-accent); }
.cm-input-wrap .cm-input-prefix { padding: 0 10px 0 12px; color: var(--c-text-3); font-size: 13px; }
.cm-input-wrap .cm-input-suffix { padding: 0 12px 0 6px; color: var(--c-text-3); font-size: 13px; }

/* Bare input (for use inside .cm-input-wrap OR standalone) */
.cm-input {
  flex: 1;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-surface);
  padding: 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--c-text);
  outline: none;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  transition: border-color .15s;
}
.cm-input:focus { border-color: var(--c-accent); }
/* Numeric inputs — mono font + tabular nums so digits line up and use the
   same glyphs everywhere. Every time we forget this, a user complains that
   «цифры разных шрифтов в шторке заправки». See feedback_numeric_input_style.md. */
.cm-input.num, .cm-input-wrap .cm-input.num {
    font-family: var(--font-mono);
    font-variant-numeric: tabular-nums;
}

/* When .cm-input sits inside .cm-input-wrap, drop its own border */
.cm-input-wrap .cm-input {
  border: 0;
  background: transparent;
  padding: 10px 12px;
}

textarea.cm-input { resize: vertical; min-height: 72px; line-height: 1.4; }

/* Select (▾ absolute indicator) */
.cm-select-wrap { position: relative; }
.cm-select {
  width: 100%;
  border: 1px solid var(--c-border);
  border-radius: 8px;
  background: var(--c-surface);
  padding: 10px 32px 10px 12px;
  font-size: 14px;
  font-family: inherit;
  color: var(--c-text);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
  cursor: pointer;
  outline: none;
  box-sizing: border-box;
  transition: border-color .15s;
}
.cm-select:focus { border-color: var(--c-accent); }
.cm-select[data-empty="1"] { color: var(--c-text-3); }
.cm-select-wrap::after {
  content: '▾';
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--c-text-3);
  pointer-events: none;
  font-size: 10px;
}

/* Checkbox (custom 18×18) */
.cm-checkbox {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 13px;
  color: var(--c-text);
  user-select: none;
}
.cm-checkbox input[type="checkbox"] { display: none; }
.cm-checkbox .cm-checkbox-box {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 1.5px solid var(--c-border-strong);
  background: transparent;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all .15s;
}
.cm-checkbox input[type="checkbox"]:checked + .cm-checkbox-box {
  border-color: var(--c-accent);
  background: var(--c-accent);
}
.cm-checkbox .cm-checkbox-box svg { display: none; width: 10px; height: 10px; stroke: #fff; stroke-width: 3.5; fill: none; stroke-linecap: round; stroke-linejoin: round; }
.cm-checkbox input[type="checkbox"]:checked + .cm-checkbox-box svg { display: block; }

/* FormSection / CollapsibleSection (per D-25, handoff 2041-2053 + 2886-2900) */
.cm-form-section {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius-card);
  overflow: hidden;
  margin-bottom: 14px;
}
.cm-form-section-header {
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: default;
  border-bottom: 1px solid var(--c-border);
  user-select: none;
}
.cm-form-section[data-collapsible="1"] .cm-form-section-header { cursor: pointer; }
.cm-form-section:not(.open) .cm-form-section-header { border-bottom: none; }
.cm-form-section-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--c-text-3);
}
.cm-form-section-chev {
  font-size: 12px;
  color: var(--c-text-3);
  transition: transform .2s;
}
.cm-form-section.open .cm-form-section-chev { transform: rotate(180deg); }
.cm-form-section-body { padding: 18px 20px; display: none; }
.cm-form-section.open .cm-form-section-body { display: block; }
/* Non-collapsible sections — body always visible */
.cm-form-section:not([data-collapsible="1"]) .cm-form-section-body { display: block; }

/* ---------- Base body font wiring (не навязываем — каждая v2-страница сама ставит class) ---------- */
.cm-scope {
  font-family: var(--font-display);
  color: var(--c-text);
  background: var(--c-bg);
  -webkit-font-smoothing: antialiased;
}

/* ---------- Bottom sheet (Phase 18 / D-13..D-15, handoff lines 1463-1515) ---------- */
.cm-sheet-backdrop { position:fixed; inset:0; background:rgba(14,17,22,0.45); z-index:var(--z-sheet-backdrop); }
.cm-sheet { position:fixed; left:0; right:0; bottom:0; background:var(--c-surface); border-top-left-radius:var(--sheet-radius); border-top-right-radius:var(--sheet-radius); padding:10px 0 20px; max-height:78vh; overflow:auto; z-index:var(--z-sheet); box-shadow:var(--shadow-sheet); }
@media (min-width: 769px) {
  .cm-sheet {
    max-width: 1100px;
    margin-inline: auto;
  }
}
.cm-sheet-handle { width:var(--sheet-handle-w); height:var(--sheet-handle-h); background:var(--c-border); border-radius:999px; margin:6px auto 14px; touch-action:none; }
.cm-sheet-title { padding:0 20px 10px; font-size:16px; font-weight:700; }
.cm-sheet-content { padding:0 20px; }
.cm-sheet-actions { padding:14px 20px 0; display:flex; gap:10px; }
.cm-sheet-action { flex:1; padding:14px; border-radius:12px; border:0; font-family:inherit; font-size:14px; font-weight:600; cursor:pointer; }
.cm-sheet-action-primary { background:var(--c-primary-fill); color:#fff; }
.cm-sheet-action-ghost   { background:var(--c-surface); color:var(--c-text-2); border:1px solid var(--c-border); }
.cm-sheet-action-danger  { background:var(--c-danger-soft); color:var(--c-danger); }

/* ---------- Toast (Phase 18 / D-10, specifics line 254) ---------- */
#cm-toast-container { position:fixed; left:50%; bottom:80px; transform:translateX(-50%); z-index:var(--z-toast); display:flex; flex-direction:column; gap:8px; }
.cm-toast { background:var(--c-text); color:#fff; padding:12px 16px; border-radius:12px; font-size:13px; box-shadow:var(--shadow-toast); display:flex; align-items:center; gap:12px; min-width:280px; max-width:400px; }
.cm-toast-msg { flex:1; }
.cm-toast-action { background:transparent; border:0; color:#fff; font-weight:600; cursor:pointer; padding:0; font-family:inherit; }
.cm-toast-countdown { color:rgba(255,255,255,0.5); font-family:var(--font-mono); font-size:12px; min-width:14px; text-align:right; }

@media (min-width: 769px) {
  #cm-toast-container { left:auto; right:24px; bottom:24px; transform:none; }
}

/* ---------- Swipe rows (Phase 18 / D-09) ---------- */
[data-cm-swipe] { touch-action:pan-y; will-change:transform; position:relative; }
.cm-swipe-actions { position:absolute; inset:0; display:flex; justify-content:flex-end; pointer-events:none; }
.cm-swipe-action { width:74px; display:flex; align-items:center; justify-content:center; font-size:12px; font-weight:600; pointer-events:auto; cursor:pointer; border:0; }
.cm-swipe-action.edit   { background:var(--c-accent-soft); color:var(--c-accent); }
.cm-swipe-action.delete { background:var(--c-danger); color:#fff; }
