/* Lukas CRM (PHP UI) — stylesheet.
   Фирменная монохромная система Lukas.market (см. 01.Architecture/TZ_v05/DESIGN.md
   и apps/crm-web/src/styles.css). Light-first + dark через prefers-color-scheme.
   Акцент = Ink (синий убран), serif-заголовки сохранены. Спека 25 / план 48. */

:root {
  /* Lukas.market mono palette — light (см. DESIGN.md / React light :root) */
  --bg: #ffffff;          /* White */
  --panel: #ffffff;       /* White — карточка = White + бордюр + тень */
  --panel-2: #f3f4f6;     /* Ash — подложки / нажатое */
  --line: #e4e7ec;        /* Stone — бордеры/дивайдеры */
  --line-strong: #d3d8df; /* Slate — бордеры инпутов/кнопок */
  --text: #1c1d1f;        /* Ink */
  --muted: #6f7988;       /* Metal */
  --accent: #1c1d1f;      /* Ink — синий убран */
  --accent-fg: #ffffff;   /* текст на accent-кнопке */
  --danger: #772322;      /* Danger Red */
  --ok: #075a39;          /* Success Green */
  --warn: #705500;        /* Warning Yellow */
  --focus: #94b9ff;       /* Focus Blue — единственное «свечение» */
  --radius: 10px;         /* кнопки */
  --radius-card: 8px;
  --radius-input: 7px;
  --shadow-ui-frame: rgba(28, 40, 64, 0.1) 0 2px 3px -2px, rgba(28, 40, 64, 0.04) 0 4px 6px -2px;
  --focus-ring: 0 0 0 3px color-mix(in srgb, var(--focus) 40%, transparent);
  --font-inter: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-serif: "Tiempos Text", Newsreader, Lora, Georgia, serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    /* токены из React [data-theme="dark"] */
    --bg: #16181d;
    --panel: #1c1f26;
    --panel-2: #232732;
    --line: #2a2e37;
    --line-strong: #353a45;
    --text: #eef1f5;
    --muted: #a4adba;
    --accent: #eef1f5;      /* инверсия Ink */
    --accent-fg: #16181d;   /* тёмный текст на светлой кнопке */
    --danger: #f87171;
    --ok: #4ade80;
    --warn: #fbbf24;
    --focus: #94b9ff;
    --shadow-ui-frame: rgba(0, 0, 0, 0.5) 0 2px 3px -2px, rgba(0, 0, 0, 0.35) 0 4px 6px -2px;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font-inter);
  font-size: 14px;
  line-height: 1.45;
  font-feature-settings: "ss03";
  background: var(--bg);
  color: var(--text);
}
a { color: var(--text); text-decoration: none; }
a:hover { text-decoration: underline; }
button, select, input, textarea { font: inherit; }
button {
  background: var(--accent); color: var(--accent-fg); border: 0; border-radius: var(--radius);
  padding: 7px 12px; cursor: pointer;
}
button:hover { filter: brightness(1.08); }
select, input[type="text"], textarea {
  background: var(--bg); color: var(--text);
  border: 1px solid var(--line-strong); border-radius: var(--radius-input); padding: 7px 9px;
}
select:focus, input[type="text"]:focus, textarea:focus {
  outline: none; border-color: var(--focus); box-shadow: var(--focus-ring);
}
textarea { width: 100%; min-height: 64px; resize: vertical; }

/* Shell */
.crm-shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.crm-sidebar { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; }
.crm-brand { font-weight: 700; font-size: 16px; padding: 6px 8px 14px; }
.crm-nav { display: flex; flex-direction: column; gap: 2px; }
.crm-nav__item { padding: 8px 10px; border-radius: 8px; color: var(--muted); }
.crm-nav__item:hover { background: var(--panel-2); text-decoration: none; }
.crm-nav__item.is-active { background: var(--panel-2); color: var(--text); }
.crm-main { display: flex; flex-direction: column; min-width: 0; }
.crm-header {
  display: flex; justify-content: flex-end; align-items: center; gap: 14px;
  padding: 12px 20px; border-bottom: 1px solid var(--line);
}
.crm-user { color: var(--muted); }
.crm-logout { margin: 0; }
.crm-logout button { background: transparent; color: var(--muted); padding: 4px 8px; }
.crm-logout button:hover { color: var(--text); }
.crm-content { padding: 20px; min-width: 0; }

.crm-flash {
  background: color-mix(in srgb, var(--warn) 12%, transparent); border: 1px solid var(--warn);
  color: var(--warn); padding: 10px 12px; border-radius: var(--radius-card); margin-bottom: 16px;
}
.crm-error { color: var(--danger); }
.crm-empty, .crm-placeholder { color: var(--muted); }

.crm-page-head { display: flex; align-items: center; justify-content: space-between; }
.crm-page-title { font-size: 18px; margin: 0 0 14px; }
.crm-count {
  display: inline-block; background: var(--panel-2); color: var(--muted);
  border-radius: 999px; padding: 1px 9px; font-size: 12px; margin-left: 6px;
}

/* Table */
.crm-table { width: 100%; border-collapse: collapse; }
.crm-table th, .crm-table td {
  text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line);
}
.crm-table th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.crm-table tbody tr:hover { background: var(--panel); }

/* Badges */
.crm-badge {
  display: inline-block; background: var(--panel-2); color: var(--muted);
  border-radius: 6px; padding: 2px 8px; font-size: 12px;
}
.crm-badge--support { color: var(--text); border: 1px solid var(--line-strong); }
.crm-badge--sales { color: var(--text); border: 1px solid var(--line-strong); }
.crm-prio--urgent { color: var(--danger); }
.crm-prio--high { color: var(--warn); }

/* Metrics */
.crm-metrics { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.crm-metric { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 16px; box-shadow: var(--shadow-ui-frame); }
.crm-metric__label { color: var(--muted); font-size: 12px; }
.crm-metric__value { font-size: 26px; font-weight: 700; margin-top: 6px; }

/* Ticket workspace */
.crm-ticket__head { margin-bottom: 14px; }
.crm-ticket__badges { display: flex; gap: 8px; margin: 8px 0; }
.crm-ticket__client { color: var(--muted); }
.crm-ticket__grid { display: grid; grid-template-columns: 280px 1fr; gap: 18px; align-items: start; }
.crm-ticket__actions { display: flex; flex-direction: column; gap: 10px; }
.crm-ticket__actions form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 10px; margin: 0; box-shadow: var(--shadow-ui-frame); }
.crm-form-row { display: flex; gap: 8px; align-items: center; }
.crm-form-row select, .crm-form-row input { flex: 1; min-width: 0; }
.crm-form-col { display: flex; flex-direction: column; gap: 8px; }

.crm-ticket__dialog { display: flex; flex-direction: column; gap: 12px; min-width: 0; }
.crm-thread {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 14px; max-height: 56vh; overflow-y: auto; display: flex; flex-direction: column; gap: 10px;
  box-shadow: var(--shadow-ui-frame);
}
.crm-msg { max-width: 75%; padding: 8px 11px; border-radius: 10px; }
.crm-msg--in { align-self: flex-start; background: var(--panel-2); }
.crm-msg--out { align-self: flex-end; background: color-mix(in srgb, var(--accent) 8%, transparent); border: 1px solid var(--line-strong); }
.crm-msg__meta { color: var(--muted); font-size: 11px; margin-bottom: 3px; }
.crm-msg__text { white-space: normal; word-wrap: break-word; }
.crm-msg__media { color: var(--muted); font-size: 12px; margin-top: 4px; }
.crm-msg__delivery { font-size: 11px; color: var(--muted); margin-top: 4px; display: flex; gap: 8px; align-items: center; }
.crm-delivery--failed { color: var(--danger); }
.crm-delivery--delivered, .crm-delivery--sent { color: var(--ok); }
.crm-inline { display: inline; margin: 0; }
.crm-inline button { background: transparent; color: var(--danger); padding: 0 4px; font-size: 11px; }

.crm-composer { display: flex; gap: 8px; align-items: flex-start; }
.crm-composer textarea { min-height: 44px; }

/* Auth */
.crm-auth { display: grid; place-items: center; min-height: 100vh; }
.crm-auth__card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card);
  padding: 28px; min-width: 320px; text-align: center; box-shadow: var(--shadow-ui-frame);
}
.crm-auth__error { color: var(--danger); }
.crm-auth__hint, .crm-auth__detail { color: var(--muted); }
.crm-auth__dev { margin-top: 16px; }

/* Section pages (Phase 4) */
.crm-section-title { font-size: 14px; color: var(--muted); margin: 22px 0 10px; text-transform: uppercase; letter-spacing: 0.04em; }
.crm-muted { color: var(--muted); }
.crm-defs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px 18px; margin: 8px 0 4px; }
.crm-defs dt { color: var(--muted); font-size: 12px; }
.crm-defs dd { margin: 0 0 6px; }
.crm-actions-row { display: flex; flex-wrap: wrap; gap: 10px; }
.crm-actions-row form { margin: 0; }
.crm-list { list-style: none; padding: 0; margin: 8px 0; }
.crm-list li { padding: 6px 0; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 8px; }
.crm-table form.crm-form-row { margin: 0; }
.crm-table input[type="text"] { padding: 4px 7px; }
.crm-actions-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; }
.crm-actions-grid form { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 12px; margin: 0; gap: 8px; box-shadow: var(--shadow-ui-frame); }
.crm-actions-grid strong { font-size: 13px; }
.crm-details { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius-card); padding: 10px 14px; margin: 12px 0; box-shadow: var(--shadow-ui-frame); }
.crm-details summary { cursor: pointer; color: var(--muted); }
.crm-details form { margin-top: 12px; flex-wrap: wrap; }
.crm-check { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; }

/* Serif на крупные заголовки/числа (DESIGN.md: Tiempos только 28px+) */
h1, .crm-page-title, .crm-metric__value { font-family: var(--font-serif); }

@media (max-width: 880px) {
  .crm-shell { grid-template-columns: 1fr; }
  .crm-sidebar { display: none; }
  .crm-ticket__grid { grid-template-columns: 1fr; }
}
