/* ProЦифры - светлая тема в духе Ресториума: пепельно-синий фон, белые карточки,
   индиго-акцент, сериф-заголовки с курсивным акцентным словом. */
* { box-sizing: border-box; margin: 0; }
img { height: auto; max-width: 100%; }
:root {
  --bg: #eef1f7;
  --card: #ffffff;
  --line: #e3e7f1;
  --text: #1d2436;
  --muted: #7b849c;
  --accent: #4f6bf5;
  --accent-ink: #3d55d6;
  --accent-soft: #e9edfe;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(29, 36, 54, .04), 0 8px 24px rgba(29, 36, 54, .06);
}
html, body { height: 100%; }
body {
  font: 15px/1.5 -apple-system, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text);
  overflow-x: hidden; /* широкие таблицы скроллятся в карточках, не страницей */
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: #d64545; min-height: 1.2em; }
.serif { font-family: "Iowan Old Style", "Palatino", Georgia, serif; font-weight: 600; letter-spacing: -.01em; }
.serif em { font-style: italic; color: var(--accent); }
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.crumb {
  font-size: 11px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 2px;
}
button { font: inherit; cursor: pointer; }
.primary {
  background: var(--accent); border: 0; border-radius: 12px;
  padding: 12px 20px; color: #fff; font-weight: 600;
}
.primary:hover { background: var(--accent-ink); }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 10px; padding: 8px 12px; font-size: 14px;
}

/* ---------- вход ---------- */
#login-view { display: flex; align-items: center; justify-content: center; min-height: 100dvh; padding: 24px; }
.login-card { width: 100%; max-width: 380px; display: flex; flex-direction: column; gap: 12px; text-align: center; padding: 36px 28px; }
.login-card h1 { font-size: 34px; }
.logo-dot {
  width: 44px; height: 44px; margin: 0 auto 4px; border-radius: 14px;
  background: linear-gradient(135deg, #7b90f8, var(--accent));
}
.login-card input {
  background: #f7f8fc; border: 1px solid var(--line); border-radius: 12px;
  padding: 13px 14px; font-size: 16px; color: var(--text);
}
.login-card input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }

/* ---------- каркас ---------- */
#app-view { display: flex; height: 100dvh; }
#sidebar {
  width: 264px; flex-shrink: 0; display: flex; flex-direction: column;
  background: #f7f8fb; border-right: 1px solid var(--line); padding: 16px 12px;
  gap: 16px;
}
.ws-card {
  display: flex; align-items: center; gap: 10px; padding: 10px;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: var(--shadow); cursor: pointer; position: relative;
}
.ws-card:hover { border-color: var(--accent); }
.ws-meta { flex: 1; min-width: 0; }
.ws-cap {
  font-size: 10px; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--muted);
}
.ws-chev { color: var(--muted); font-size: 22px; line-height: 1; }
.side-sep {
  margin: 14px 12px 4px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .1em; text-transform: uppercase; color: var(--muted);
}
.fc-good { color: #1e8e4e; font-weight: 700; }
.ws-avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
}
.ws-avatar img { width: 100%; height: 100%; display: block; }
.ws-name {
  font-size: 16px; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ws-menu {
  display: none; position: absolute; top: calc(100% + 8px); left: 0; min-width: 100%;
  background: var(--card); border: 1px solid var(--line); border-radius: 14px;
  box-shadow: 0 12px 34px rgba(29, 36, 54, .16); padding: 6px; z-index: 60;
}
.ws-card.open .ws-menu { display: block; }
.ws-card.open .ws-chev { transform: rotate(180deg); }
.ws-chev { transition: transform .15s; }
.ws-item {
  display: flex; align-items: center; gap: 10px; width: 100%;
  background: none; border: 0; border-radius: 10px; padding: 9px 10px;
  font-size: 15px; font-weight: 600; color: var(--text); text-align: left;
}
.ws-item:hover { background: var(--accent-soft); }
.ws-item img { width: 28px; height: 28px; border-radius: 50%; flex-shrink: 0; }
.ws-item .check {
  margin-left: auto; width: 16px; height: 16px; flex-shrink: 0;
  fill: none; stroke: var(--accent-ink); stroke-width: 2.4;
  stroke-linecap: round; stroke-linejoin: round;
}
.ws-item.active { color: var(--accent-ink); }
#sidenav { display: flex; flex-direction: column; gap: 2px; }
#sidenav button {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: none; border: 0; border-radius: 12px; padding: 11px 12px;
  color: var(--text); font-size: 15px; font-weight: 500;
}
.ico {
  width: 19px; height: 19px; flex-shrink: 0;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
}
#sidenav button .ico { color: var(--muted); }
#sidenav button:hover { background: #eef0f6; }
#sidenav button.active { background: var(--accent-soft); color: var(--accent-ink); }
#sidenav button.active .ico { color: var(--accent-ink); }
.side-footer { margin-top: auto; display: flex; flex-direction: column; gap: 8px; padding: 8px 6px; font-size: 13px; }

#content { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#mobile-header {
  display: none; gap: 8px; align-items: center; padding: 10px 14px;
  padding-top: calc(10px + env(safe-area-inset-top));
  background: var(--card); border-bottom: 1px solid var(--line);
}
main { flex: 1; overflow: hidden; display: flex; }
.tab { flex: 1; display: flex; flex-direction: column; overflow-y: auto; padding: 22px 22px 28px; }
.tab > * { flex-shrink: 0; } /* дети скролл-колонки не сжимаются, скроллим а не плющим */
.page-head { margin-bottom: 14px; }
.page-head h2 { font-size: 26px; }
.empty-card { padding: 32px; text-align: center; }
.empty-card h3 { font-size: 21px; margin-bottom: 6px; }

/* ---------- чат ---------- */
#tab-chat { overflow: hidden; padding: 0; }
#chat-tools {
  display: flex; gap: 8px; justify-content: flex-end;
  padding: 12px 20px 0; max-width: 760px; margin: 0 auto; width: 100%;
}
#chat-scroll { flex: 1; overflow-y: auto; padding: 24px 20px 12px; }
#chat-hero { max-width: 620px; margin: 6vh auto 0; text-align: center; }
.hero-mark {
  width: 64px; height: 64px; margin: 0 auto 18px; border-radius: 50%;
  display: block; box-shadow: 0 10px 26px rgba(12, 42, 36, .25);
}
#chat-hero h1 { font-size: 34px; margin-bottom: 10px; }
#chat-hero p { max-width: 480px; margin: 0 auto; }
#fn-cards { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 22px; text-align: left; }
.fn-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; display: flex; flex-direction: column; gap: 3px; box-shadow: var(--shadow);
}
.fn-card:hover { border-color: var(--accent); }
.fn-card b { font-size: 15px; }
.fn-card span { font-size: 13px; color: var(--muted); }
#chat-log { max-width: 720px; margin: 0 auto; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 86%; padding: 11px 15px; border-radius: var(--radius); white-space: pre-wrap; overflow-wrap: break-word; }
.msg.user { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 6px; }
.msg.assistant { align-self: flex-start; background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow); border-bottom-left-radius: 6px; }
.msg.typing::after { content: "▍"; color: var(--accent); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0; } }
#chat-form {
  display: flex; gap: 8px; padding: 10px 20px calc(14px + env(safe-area-inset-bottom));
  max-width: 760px; margin: 0 auto; width: 100%;
}
#chat-input {
  flex: 1; resize: none; background: var(--card); border: 1px solid var(--line);
  border-radius: 18px; padding: 13px 16px; font-size: 16px; color: var(--text);
  max-height: 140px; box-shadow: var(--shadow);
}
#chat-input:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
#chat-send { border-radius: 50%; width: 48px; height: 48px; padding: 0; font-size: 17px; align-self: flex-end; }
#chat-send:disabled { opacity: .5; }

/* ---------- аналитика ---------- */
#subtabs, #kitchen-subtabs, #report-subtabs {
  display: flex; gap: 4px; background: var(--card); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px; margin-bottom: 12px; width: fit-content; max-width: 100%;
  overflow-x: auto;
}
#kitchen-search {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 14px; font-size: 15px; color: var(--text); margin-bottom: 12px; width: 100%; max-width: 420px;
}
#kitchen-search:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.prod-count { margin: 0 0 10px 2px; font-size: 13px; }
.prod-row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.prod-row small { color: var(--muted); }
.prod-row .chev { color: var(--muted); }
.chart-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.chart-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.chart-table th, .chart-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.chart-table th { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.chart-table td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.chart-table tr.linked { cursor: pointer; }
.chart-table tr.linked:hover td { background: var(--accent-soft); }
.back-btn { margin-bottom: 12px; }
#tpl-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; margin-bottom: 14px; }
.tpl {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 14px; display: flex; flex-direction: column; gap: 2px; text-align: left;
  box-shadow: var(--shadow);
}
.tpl:hover { border-color: var(--accent); }
.tpl b { font-size: 14px; }
.tpl span { font-size: 12px; color: var(--muted); }
.tpl:disabled { opacity: .6; }
.report-tag {
  display: inline-block; font-size: 11px; font-weight: 700; letter-spacing: .05em;
  text-transform: uppercase; color: var(--accent-ink); background: var(--accent-soft);
  border-radius: 6px; padding: 2px 8px; margin-right: 8px;
}
.abc {
  font-weight: 700; letter-spacing: .15em; font-size: 13px; color: var(--accent-ink);
  background: var(--accent-soft); border-radius: 6px; padding: 2px 6px;
}
/* Статусный красный только для FC выше нормы, всегда с самим числом рядом */
.fc-high { color: #c0392b; font-weight: 700; }
.report-body {
  white-space: pre-wrap; overflow-x: auto; font-size: 14px; line-height: 1.55;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
}
.subtab {
  border: 0; background: none; border-radius: 9px; padding: 8px 14px;
  color: var(--muted); font-weight: 500; white-space: nowrap;
}
.subtab.active { background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.subtab:disabled { cursor: default; opacity: .55; }
#period-chips { display: flex; gap: 8px; margin-bottom: 16px; }
.chip {
  background: var(--card); border: 1px solid var(--line); border-radius: 999px;
  padding: 7px 14px; font-size: 13px; color: var(--text);
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }

#analytics-body { display: flex; flex-direction: column; gap: 14px; }
.kpi-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.kpi { padding: 16px 18px; }
.kpi .kpi-label { font-size: 12px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); }
.kpi .kpi-value { font-size: 26px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .kpi-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.chart-card { padding: 18px; overflow-x: auto; }
.duo > * { min-width: 0; }
.chart-card h3 { font-size: 15px; margin-bottom: 12px; }
.chart-card h3 small { color: var(--muted); font-weight: 400; }
.duo { display: grid; grid-template-columns: 3fr 2fr; gap: 14px; align-items: start; }
.bar-chart { width: 100%; display: block; }
.bar-chart rect.bar { fill: var(--accent); }
.bar-chart rect.bar:hover { fill: var(--accent-ink); }
.bar-chart text { font: 11px -apple-system, sans-serif; fill: var(--muted); }
.bar-chart line.grid { stroke: var(--line); stroke-width: 1; }

.rank-list { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.rank-list li { display: flex; flex-direction: column; gap: 3px; }
.rank-top { display: flex; justify-content: space-between; gap: 10px; font-size: 13.5px; }
.rank-top .val { font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--text); font-weight: 600; }
.rank-top .qty { color: var(--muted); font-weight: 400; }
.rank-bar { height: 6px; border-radius: 4px; background: var(--accent-soft); overflow: hidden; }
.rank-bar i { display: block; height: 100%; border-radius: 4px; background: var(--accent); }

.empty-analytics { padding: 40px 24px; text-align: center; }
.empty-analytics h3 { font-size: 22px; margin-bottom: 8px; }
.skeleton { padding: 32px; text-align: center; color: var(--muted); }

#tooltip {
  position: fixed; z-index: 50; pointer-events: none;
  background: #1d2436; color: #fff; font-size: 12px; line-height: 1.4;
  border-radius: 8px; padding: 7px 10px; box-shadow: 0 6px 20px rgba(0,0,0,.25);
  max-width: 240px;
}

/* ---------- списки ---------- */
.list { list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list li { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; cursor: pointer; }
.list li:hover { border-color: var(--accent); }
.list li small { display: block; color: var(--muted); }

/* ---------- таб-бар (мобайл) ---------- */
#tabbar { display: none; border-top: 1px solid var(--line); background: var(--card); padding-bottom: env(safe-area-inset-bottom); }
#tabbar button {
  flex: 1; background: none; border: 0; color: var(--muted);
  padding: 8px 0 6px; display: flex; flex-direction: column; align-items: center; gap: 3px;
}
#tabbar button .ico { width: 22px; height: 22px; }
#tabbar button span { font-size: 10.5px; }
#tabbar button.active { color: var(--accent-ink); }

.ws-card-m { flex: 1; padding: 6px 10px; box-shadow: none; min-width: 0; }
.ws-avatar-m { width: 30px; height: 30px; }
.more-plans { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin: 8px 16px; }

#tab-more .card { padding: 20px; display: flex; flex-direction: column; gap: 10px; align-items: flex-start; }

@media (max-width: 1023px) {
  #sidebar { display: none; }
  #mobile-header { display: flex; }
  #tabbar { display: flex; }
  .tab { padding: 16px 14px 20px; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .duo { grid-template-columns: 1fr; }
  #fn-cards { grid-template-columns: 1fr; }
  #chat-hero h1 { font-size: 27px; }
  .page-head h2 { font-size: 22px; }
  #tpl-row { grid-template-columns: 1fr 1fr; }
  #tab-chat { padding: 0; }
}
