/* Ruka CRM: общие стили. Раскладка Pipedrive, палитра Ruka, одна светлая тема.
   Все цвета только здесь, в :root; дальше везде var(--токен). */

/* ---- шрифты (локальные, без CDN); unicode-range как у fontsource ---- */
@font-face { font-family: "Onest"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/onest-cyrillic-400-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("/static/fonts/onest-latin-400-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/fonts/onest-cyrillic-500-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 500; font-display: swap;
  src: url("/static/fonts/onest-latin-500-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/onest-cyrillic-600-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 600; font-display: swap;
  src: url("/static/fonts/onest-latin-600-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/onest-cyrillic-700-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Onest"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("/static/fonts/onest-latin-700-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Unbounded"; font-style: normal; font-weight: 800; font-display: swap;
  src: url("/static/fonts/unbounded-cyrillic-800-normal.woff2") format("woff2");
  unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Unbounded"; font-style: normal; font-weight: 800; font-display: swap;
  src: url("/static/fonts/unbounded-latin-800-normal.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* ---- токены (единственное место для цветов) ---- */
:root {
  --paper: #f3efe6;        /* фон страницы */
  --paper-2: #e9e3d4;      /* фон колонок, наведение */
  --surface: #fffdf8;      /* карточки, панели */
  --ink: #14130f;          /* текст, боковая панель */
  --ink-2: #5a5548;        /* второстепенный текст */
  --ink-3: #8a8473;        /* подписи */
  --line: rgba(20, 19, 15, .13);
  --line-strong: rgba(20, 19, 15, .3);
  --accent: #ff5a1f;       /* оранжевый Ruka: главные действия */
  --accent-hover: #ee4d13;
  --accent-soft: #ffe6db;
  --green: #0f3d2e;        /* деньги, выполнено */
  --green-soft: #dfeae3;
  --ok: #2f8a57; --ok-soft: #e1f0e6;
  --warn: #c98a00; --warn-soft: #fbefcc;
  --bad: #d23c2a; --bad-soft: #fbe1dd;
  --on-dark: #f3efe6;      /* текст на тёмном (боковая панель, подсказки) */
  --on-accent: #fff;       /* текст на акценте, зелёном, красном */
  --rail-text: #cfc8b6;    /* иконки боковой панели */
  --rail-hover: #2a2820;
  --rail-active: #2e2b22;
  --rail-avatar: #3a362b;
  --shadow-card: 0 1px 0 rgba(20, 19, 15, .04);
  --shadow-pop: 0 8px 24px rgba(20, 19, 15, .18);
  --display: "Unbounded", "Onest", system-ui, sans-serif;
  --body: "Onest", system-ui, -apple-system, "Segoe UI", sans-serif;
  --r: 10px;
  --rail-w: 64px;
  --rail-h: 62px;          /* высота нижнего меню на телефоне */
  color-scheme: light;
}

/* ---- основа ---- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; max-width: 100%; overflow-x: hidden; }
body {
  margin: 0; min-width: 0; max-width: 100%;
  background: var(--paper); color: var(--ink);
  font: 400 14px/1.45 var(--body); -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--ink); text-decoration-color: var(--line-strong); text-underline-offset: 2px; }
a:hover { text-decoration-color: var(--accent); }
h1, h2, h3 { line-height: 1.25; margin: 0 0 .6rem; font-weight: 600; }
h1 { font-size: 22px; } h2 { font-size: 18px; } h3 { font-size: 15px; }
p { margin: 0 0 .75rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
svg.i { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
svg.i-sm { width: 16px; height: 16px; }

/* ---- утилиты ---- */
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.overdue { color: var(--bad); font-weight: 600; }
.money { color: var(--green); font-weight: 600; font-variant-numeric: tabular-nums; }
.stack > * + * { margin-top: .75rem; }
.row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.row-between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.nowrap { white-space: nowrap; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
[hidden] { display: none !important; }

/* ---- каркас: панель слева + верхняя полоса + страница ---- */
.app { display: grid; grid-template-columns: var(--rail-w) minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; max-width: 100%; }
.main { display: flex; flex-direction: column; min-width: 0; }
.page { flex: 1; min-width: 0; padding: 16px 20px 32px; padding-right: max(20px, env(safe-area-inset-right, 0px)); }
.page.flush { padding: 0; }
.page-guest { max-width: 760px; margin: 0 auto; }

.rail {
  position: sticky; top: 0; height: 100vh; height: 100dvh; z-index: 40;
  background: var(--ink); color: var(--on-dark);
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding-block: 14px; padding-left: env(safe-area-inset-left, 0px);
}
.rail .logo { font: 800 15px var(--display); letter-spacing: -.03em; margin-bottom: 14px; color: var(--on-dark); text-decoration: none; }
.rail .logo span { color: var(--accent); }
.rail a:not(.logo), .rail .avatar-btn {
  width: 44px; height: 44px; border-radius: 10px; display: grid; place-items: center;
  color: var(--rail-text); text-decoration: none; position: relative; background: none; border: 0; padding: 0;
}
.rail a:not(.logo):hover, .rail .avatar-btn:hover { background: var(--rail-hover); color: var(--on-dark); }
.rail a.active { background: var(--rail-active); color: var(--on-dark); }
.rail a.active::before { content: ""; position: absolute; left: -10px; top: 10px; bottom: 10px; width: 3px; border-radius: 2px; background: var(--accent); }
.rail-badge {
  position: absolute; top: 5px; right: 4px; min-width: 16px; height: 16px; border-radius: 8px; padding: 0 4px;
  background: var(--accent); color: var(--on-accent); font-size: 10px; font-weight: 700; display: grid; place-items: center;
}
.rail .tip { display: none; }
.rail-bottom { margin-top: auto; display: flex; flex-direction: column; align-items: center; gap: 6px; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; flex: none; display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--ink); font-weight: 700; font-size: 12px; line-height: 1;
}
.avatar-sm { width: 22px; height: 22px; font-size: 10px; }
.avatar-lg { width: 40px; height: 40px; font-size: 14px; }
.rail .avatar { background: var(--rail-avatar); color: var(--on-dark); }

.top {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  padding-block: 10px; padding-left: 20px; padding-right: max(16px, env(safe-area-inset-right, 0px));
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.page-title { font: 600 18px var(--body); margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.search {
  flex: 1; max-width: 420px; margin-left: auto; min-width: 0; display: flex; align-items: center; gap: 8px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 8px; padding: 0 10px; color: var(--ink-3);
}
.search input { border: 0; background: transparent; outline: 0; width: 100%; min-height: 36px; padding: 0; color: var(--ink); }
.search:focus-within { outline: 2px solid var(--accent); outline-offset: 2px; }
.top-user { display: none; background: none; border: 0; padding: 0; }

.user-panel {
  position: fixed; left: calc(var(--rail-w) + 8px); bottom: 12px; z-index: 60; width: 260px; max-width: calc(100vw - 16px);
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); box-shadow: var(--shadow-pop);
}
.user-panel-in { padding: 8px; display: grid; gap: 2px; }
.user-panel-in > a, .user-panel-in .btn { padding: 8px 10px; border-radius: 8px; text-decoration: none; display: flex; align-items: center; gap: 8px; }
.user-panel-in > a:hover { background: var(--paper); }
.user-panel-in form { margin: 4px 0 0; }
.user-panel-in .btn { width: 100%; justify-content: flex-start; }
.user-panel-name { padding: 8px 10px; display: grid; }

/* ---- панели, заголовки, подписи ---- */
.panel, .card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; min-width: 0; }
.card { margin-bottom: 1rem; }
.panel + .panel { margin-top: 12px; }
.panel h3, .section-title {
  font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--ink-3); margin: 0 0 10px; font-weight: 600;
}
.section-title { margin-top: 6px; }
label { display: block; margin: 0 0 4px; font-size: 13px; color: var(--ink-3); }
.hint { color: var(--ink-3); font-size: 12.5px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; margin-bottom: 14px; }
.page-head h1, .page-head h2 { margin: 0; }
dl.kv { display: grid; grid-template-columns: 110px minmax(0, 1fr); gap: 7px 10px; margin: 0; }
dl.kv dt { color: var(--ink-3); }
dl.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }

/* ---- сетка страницы ---- */
.grid { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
.grid-2 { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-side { display: grid; gap: 16px; grid-template-columns: 320px minmax(0, 1fr); align-items: start; }

/* ---- кнопки ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; min-height: 36px;
  padding: 7px 12px; font-weight: 500; text-decoration: none; white-space: nowrap; cursor: pointer;
  color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px;
  transition: background .15s, border-color .15s;
}
.btn:hover { background: var(--paper); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-green { background: var(--green); border-color: var(--green); color: var(--on-accent); }
.btn-green:hover { background: var(--green); filter: brightness(1.15); }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-2); }
.btn-ghost:hover { background: var(--paper-2); }
.btn-danger { background: transparent; border-color: var(--line); color: var(--bad); }
.btn-danger:hover { background: var(--bad-soft); border-color: var(--bad); }
.btn-sm { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

/* ---- поля форм ---- */
input, select, textarea {
  display: block; width: 100%; min-height: 40px; padding: 8px 10px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 8px; color: var(--ink);
}
textarea { min-height: 88px; resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input[type=checkbox], input[type=radio] { display: inline-block; width: 18px; min-height: 18px; height: 18px; padding: 0; vertical-align: middle; accent-color: var(--green); }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.form-row { margin-bottom: 12px; min-width: 0; }
.form-grid { display: grid; gap: 0 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.check-row { display: flex; align-items: center; gap: 8px; }
.check-row label { margin: 0; color: var(--ink); font-size: inherit; }

/* ---- чипы, аватар, бейджи ---- */
.chip { display: inline-block; font-size: 11.5px; padding: 1px 7px; border-radius: 99px; background: var(--paper-2); color: var(--ink-2); white-space: nowrap; }
.chip-green { background: var(--green-soft); color: var(--green); }
.chip-accent { background: var(--accent-soft); color: var(--ink); }
.chip-warn { background: var(--warn-soft); color: var(--ink); }
.chip-bad { background: var(--bad-soft); color: var(--bad); }
.badge { display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 12px; background: var(--paper-2); color: var(--ink-2); white-space: nowrap; }
.act { width: 22px; height: 22px; border-radius: 50%; display: inline-grid; place-items: center; flex: none; }
.act svg { width: 13px; height: 13px; stroke-width: 2.2; }
.act.ok { background: var(--ok-soft); color: var(--ok); }
.act.late { background: var(--bad-soft); color: var(--bad); }
.act.none { background: var(--warn-soft); color: var(--warn); }

/* ---- таблицы ---- */
.table-wrap { overflow-x: auto; max-width: 100%; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r); }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 9px 12px; border-top: 1px solid var(--line); text-align: left; vertical-align: top; }
.table thead th { border-top: 0; color: var(--ink-3); font-weight: 600; font-size: 12px; letter-spacing: .04em; text-transform: uppercase; white-space: nowrap; }
.table tbody tr:hover { background: var(--paper); }
.table .r { text-align: right; }

/* ---- вкладки, уведомления ---- */
.tabs { display: flex; gap: 4px; overflow-x: auto; border-bottom: 1px solid var(--line); margin-bottom: 14px; }
.tabs a, .tabs button {
  display: inline-flex; align-items: center; min-height: 38px; padding: 0 12px; white-space: nowrap; color: var(--ink-2);
  text-decoration: none; background: none; border: 0; border-bottom: 2px solid transparent; font-weight: 500; cursor: pointer;
}
.tabs .active, .tabs [aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; background: var(--warn-soft); border: 1px solid var(--line); }
.alert-error { background: var(--bad-soft); color: var(--bad); }
.alert-ok { background: var(--ok-soft); }
.empty { padding: 24px 16px; text-align: center; color: var(--ink-3); }

/* ---- телефон: нижнее меню вместо панели слева ---- */
@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .rail {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto; height: auto; z-index: 50;
    flex-direction: row; justify-content: space-around; align-items: stretch; gap: 0;
    padding: 6px max(8px, env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) max(8px, env(safe-area-inset-left, 0px));
  }
  .rail .logo, .rail-bottom { display: none; }
  .rail a:not(.logo) { flex: 1; width: auto; height: auto; min-height: 44px; flex-direction: column; display: flex; align-items: center; justify-content: center; gap: 2px; padding: 4px 6px; font-size: 10.5px; }
  .rail .tip { display: block; }
  .rail a.active { background: transparent; color: var(--accent); }
  .rail a.active::before { display: none; }
  .rail-badge { top: 0; right: calc(50% - 20px); }
  .page { padding: 14px max(16px, env(safe-area-inset-right, 0px)) calc(var(--rail-h) + 24px + env(safe-area-inset-bottom, 0px)) max(16px, env(safe-area-inset-left, 0px)); }
  .page.flush { padding: 0 0 calc(var(--rail-h) + env(safe-area-inset-bottom, 0px)); }
  .top { padding-left: max(16px, env(safe-area-inset-left, 0px)); }
  .top .search { display: none; }
  .top .btn-new { margin-left: auto; }
  .top .btn-new .lbl { display: none; }
  .top-user { display: inline-grid; }
  .user-panel { left: auto; right: 8px; bottom: auto; top: 56px; }
  .grid-2, .form-grid, .grid-side { grid-template-columns: minmax(0, 1fr); }
  dl.kv { grid-template-columns: 96px minmax(0, 1fr); }
}
@media (min-width: 761px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (min-width: 1100px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
