/* ============ Корпоративный портал «Континент» ============
   Две темы: светлая (:root) и тёмная ([data-theme="dark"]).
   Тема выбирается в localStorage / по системной, переключатель в меню.
   Адаптив: sidebar превращается в верхнюю панель на мобильных.
============================================================= */

:root {
  --bg: #eef1f6;
  --card: #ffffff;
  --line: #e4e9f0;
  --line-soft: #f0f3f8;
  --text: #1c2733;
  --muted: #64748b;
  --accent: #1668e3;
  --accent-2: #0d4fba;
  --accent-soft: #e3edff;
  --danger: #c62b2b;
  --ok: #178a4c;
  --hover: #f6f9fd;
  --soft: #f4f7fb;
  --input-bg: #ffffff;
  --bubble: #f4f7fb;
  --bubble-line: #eaeff6;
  --code-bg: #eef2f8;
  --overlay: rgba(12, 22, 40, .5);
  --toast-bg: #16202e;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 34, 60, .06), 0 4px 16px rgba(16, 34, 60, .05);
}
[data-theme="dark"] {
  --bg: #0b1220;
  --card: #141d30;
  --line: #27334d;
  --line-soft: #1f2a42;
  --text: #e7edf7;
  --muted: #93a3bc;
  --accent: #4d8dff;
  --accent-2: #7aa7ff;
  --accent-soft: #1d3358;
  --danger: #e5484d;
  --ok: #3dd68c;
  --hover: #1a2440;
  --soft: #1a2338;
  --input-bg: #0f1830;
  --bubble: #182238;
  --bubble-line: #24304a;
  --code-bg: #1a2338;
  --overlay: rgba(2, 6, 14, .62);
  --toast-bg: #2a3852;
  --shadow: 0 1px 2px rgba(0, 0, 0, .35), 0 4px 16px rgba(0, 0, 0, .28);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.5 -apple-system, "Segoe UI", Roboto, "Inter", "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  transition: background .2s ease, color .2s ease;
}
h1, h2, h3 { margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 22px; margin: 4px 0 16px; }
h3 { font-size: 15px; }
a { color: var(--accent); text-decoration: none; }
code { background: var(--code-bg); padding: 1px 6px; border-radius: 6px; font-size: 12.5px; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.text-danger { color: var(--danger) !important; font-weight: 600; }
.pre { white-space: pre-wrap; word-break: break-word; }
.boot-splash { padding: 60px; text-align: center; color: var(--muted); }

/* ---------- структура ---------- */
.shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 248px; flex: 0 0 248px;
  background: var(--card); border-right: 1px solid var(--line);
  padding: 18px 14px; display: flex; flex-direction: column; gap: 14px;
  position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 2px 4px 10px; }
.logo-badge {
  width: 40px; height: 40px; border-radius: 11px; flex: 0 0 40px;
  background: linear-gradient(135deg, #2f7fff, var(--accent-2));
  color: #fff; font-weight: 800; font-size: 21px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 10px rgba(22, 104, 227, .35);
}
.logo-badge.big { width: 54px; height: 54px; font-size: 28px; border-radius: 14px; }
.logo-name { font-weight: 800; font-size: 16px; letter-spacing: .2px; }
.logo-sub { font-size: 11px; color: var(--muted); }
.sidebar nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: 10px; color: var(--text); font-weight: 500;
}
.nav-item svg { width: 18px; height: 18px; flex: 0 0 18px; }
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-2); font-weight: 600; }
.sidebar-bottom { border-top: 1px solid var(--line); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.userchip { display: flex; align-items: center; gap: 10px; color: inherit; padding: 4px; border-radius: 10px; min-width: 0; }
.userchip:hover { background: var(--hover); }
.userchip b { display: block; font-size: 13px; }
.userchip small { color: var(--muted); font-size: 11px; }
.btnrow { display: flex; gap: 8px; align-items: center; }
.btn-theme { flex: 0 0 42px; padding: 8px 0; font-size: 15px; }

.mainarea { flex: 1; min-width: 0; }
.content { max-width: 1120px; margin: 0 auto; padding: 26px 30px 60px; }

/* ---------- кнопки, формы ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 8px 15px; border-radius: 10px; border: 1px solid transparent;
  font: 600 13.5px/1.2 inherit; cursor: pointer; color: #fff; background: var(--accent);
  transition: filter .12s ease;
}
.btn:hover { filter: brightness(1.07); }
.btn:disabled { opacity: .45; cursor: default; }
.btn-primary { background: var(--accent); }
.btn-success { background: var(--ok); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: var(--card); color: var(--text); border-color: var(--line); }
.btn-ghost:hover { background: var(--hover); filter: none; }
.btn-block { width: 100%; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 8px; }

.input, .textarea, .select {
  width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; color: var(--text); background: var(--input-bg); outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(77, 141, 255, .18); }
.textarea { resize: vertical; min-height: 60px; }
.inputfile { padding: 7px; cursor: pointer; }
.inputfile::file-selector-button {
  border: 1px solid var(--line); background: var(--soft); color: var(--text);
  padding: 6px 12px; border-radius: 8px; margin-right: 10px; cursor: pointer; font: inherit; font-size: 12.5px;
}
label { display: block; font-size: 12.5px; font-weight: 600; color: var(--muted); margin: 12px 0 5px; }
form button[type=submit] { margin-top: 16px; }
.search { max-width: 320px; }
.select-sm { padding: 5px 8px; font-size: 12.5px; border-radius: 8px; width: auto; max-width: 170px; }
.form-row { display: flex; gap: 14px; }
.form-row > div { flex: 1; }
.form-card { max-width: 640px; }

/* ---------- карточки, статистика ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px 20px; box-shadow: var(--shadow); margin-bottom: 16px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 10px; }
.card-head h3 { margin: 0; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat { padding: 14px 18px; margin-bottom: 0; }
.stat-v { font-size: 26px; font-weight: 800; letter-spacing: .3px; }
.stat-l { font-size: 12px; color: var(--muted); margin-top: 2px; }
.inline-form .form-row { margin-bottom: 12px; }

/* ---------- таблицы ---------- */
.table-card { padding: 6px 6px 2px; }
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .5px;
  color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--line);
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.rowlink { cursor: pointer; }
.rowlink:hover { background: var(--hover); }
.cell-user { display: flex; align-items: center; gap: 8px; }

/* ---------- чипы ---------- */
.chip {
  display: inline-flex; align-items: center; padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.st-new      { background: var(--accent-soft); color: var(--accent-2); }
.st-assigned { background: #ede9fe; color: #6d28d9; }
.st-progress { background: #fef3c7; color: #b45309; }
.st-done     { background: #dcfce7; color: #15803d; }
.st-closed   { background: #e2e8f0; color: #475569; }
.st-declined { background: #fee2e2; color: #b91c1c; }
.st-overdue  { background: var(--danger); color: #fff; }
.pr-low      { background: var(--soft); color: var(--muted); }
.pr-normal   { background: #e0f2fe; color: #0369a1; }
.pr-high     { background: #ffedd5; color: #c2410c; }
.pr-critical { background: #fee2e2; color: #b91c1c; }
[data-theme="dark"] .st-assigned { background: rgba(167, 139, 250, .16); color: #c4b5fd; }
[data-theme="dark"] .st-progress { background: rgba(251, 191, 36, .14);  color: #fcd34d; }
[data-theme="dark"] .st-done     { background: rgba(61, 214, 140, .14);  color: #6ee7a8; }
[data-theme="dark"] .st-closed   { background: var(--soft);              color: var(--muted); }
[data-theme="dark"] .st-declined { background: rgba(229, 72, 77, .16);   color: #ff9b9e; }
[data-theme="dark"] .st-overdue  { background: rgba(229, 72, 77, .25);   color: #ffb3b5; }
[data-theme="dark"] .pr-normal   { background: rgba(56, 189, 248, .14);  color: #7dd3fc; }
[data-theme="dark"] .pr-high     { background: rgba(251, 146, 60, .15);  color: #fdba74; }
[data-theme="dark"] .pr-critical { background: rgba(229, 72, 77, .2);    color: #ff9b9e; }
.chip-btn { cursor: pointer; border: 2px solid transparent; background: var(--soft); color: var(--muted); padding: 4px 12px; }
.chip-on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-2); }
.chip-danger.chip-on { border-color: var(--danger); background: rgba(229, 72, 77, .16); color: var(--danger); }
.chiprow { display: flex; flex-wrap: wrap; gap: 7px; margin-bottom: 14px; }

/* ---------- аватары, пользователи ---------- */
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 50%; color: #fff; font-weight: 700; flex: 0 0 auto; user-select: none;
}
.assignee-row { display: flex; flex-wrap: wrap; gap: 8px; }
.assignee {
  display: inline-flex; align-items: center; gap: 7px; background: var(--soft);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 12px 4px 5px; font-size: 13px;
}

/* ---------- тулбар, табы ---------- */
.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 14px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.tabs button {
  border: none; background: transparent; cursor: pointer; font: 600 13.5px inherit;
  color: var(--muted); padding: 7px 13px; border-radius: 9px;
}
.tabs button:hover { background: var(--soft); }
.tabs button.active { background: var(--accent); color: #fff; }
.backlink { display: inline-block; margin-bottom: 10px; color: var(--muted); font-weight: 600; }
.backlink:hover { color: var(--accent); }

/* ---------- обращение ---------- */
.t-title-row { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.t-num { color: var(--muted); font-weight: 700; }
.t-chips { display: flex; gap: 7px; flex-wrap: wrap; margin: 8px 0 12px; }
.t-meta { display: flex; flex-wrap: wrap; gap: 6px 22px; color: var(--muted); font-size: 13px; }
.t-meta b { color: var(--text); }
.t-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 15px; padding-top: 14px; border-top: 1px dashed var(--line); }
.report-card { border-left: 4px solid var(--ok); }

/* ---------- вложения ---------- */
.attach-list { display: flex; flex-direction: column; gap: 8px; }
.attach-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px;
  background: var(--soft); border: 1px solid var(--line); border-radius: 10px;
}
.attach-ico { flex: 0 0 auto; font-size: 17px; }
.attach-info { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.attach-info a { font-weight: 600; word-break: break-all; }
.attach-form { display: flex; align-items: center; gap: 10px; margin-top: 12px; }

/* ---------- комментарии, история ---------- */
.comments { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.comment { display: flex; gap: 10px; }
.bubble { background: var(--bubble); border: 1px solid var(--bubble-line); border-radius: 12px; padding: 8px 13px; flex: 1; min-width: 0; }
.bubble-head { margin-bottom: 4px; }
.cform { display: flex; gap: 10px; align-items: flex-end; }
.cform .textarea { flex: 1; }
.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { position: relative; padding: 0 0 16px 22px; border-left: 2px solid var(--line-soft); margin-left: 6px; }
.tl-item:last-child { padding-bottom: 2px; }
.tl-dot {
  position: absolute; left: -6px; top: 3px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--soft);
}
.feed-item { padding: 8px 2px; border-bottom: 1px dashed var(--line); }
.feed-item:last-child { border-bottom: none; }

/* ---------- отделы ---------- */
.dept-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.dept-card { margin-bottom: 0; }
.dept-head-row { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dept-lead { display: flex; align-items: center; gap: 9px; margin: 10px 0; }
.dept-meta { display: flex; gap: 7px; flex-wrap: wrap; font-size: 12.5px; color: var(--muted); }

/* ---------- чек-лист назначения ---------- */
.check-list { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow: auto; }
.check-item {
  display: flex; align-items: center; gap: 10px; padding: 7px 10px; border-radius: 10px;
  cursor: pointer; border: 1px solid transparent; font-weight: 500;
}
.check-item:hover { background: var(--hover); }
.check-item input { width: 16px; height: 16px; accent-color: var(--accent); }
.check-item .small { margin-left: auto; }

/* ---------- пусто, загрузка ---------- */
.empty { text-align: center; color: var(--muted); padding: 34px 10px; }
.loading { text-align: center; color: var(--muted); padding: 30px; }

/* ---------- авторизация ---------- */
.auth-wrap {
  min-height: 100vh; display: flex; flex-direction: column; align-items: center; justify-content: center;
  padding: 30px 16px; position: relative;
  background:
    radial-gradient(900px 480px at 12% 0%, rgba(64, 140, 255, .5), transparent 60%),
    radial-gradient(800px 460px at 88% 100%, rgba(13, 79, 186, .55), transparent 55%),
    linear-gradient(135deg, #0e2a5c, #14437e 55%, #1668e3);
}
.auth-card {
  width: 100%; max-width: 430px; background: var(--card); border-radius: 18px;
  padding: 28px 30px 24px; box-shadow: 0 18px 50px rgba(5, 20, 45, .45);
}
.auth-card .auth-logo { display: flex; justify-content: center; margin-bottom: 10px; }
.auth-card h1 { text-align: center; font-size: 24px; margin: 0 0 4px; }
.auth-sub { text-align: center; color: var(--muted); margin: 0 0 16px; font-size: 13px; }
.auth-tabs { display: flex; background: var(--soft); border-radius: 11px; padding: 4px; margin-bottom: 8px; }
.auth-tabs button {
  flex: 1; border: none; background: transparent; padding: 8px; border-radius: 8px;
  font: 600 13.5px inherit; color: var(--muted); cursor: pointer;
}
.auth-tabs button.active { background: var(--card); color: var(--text); box-shadow: 0 1px 4px rgba(10, 30, 60, .12); }
.auth-hint { text-align: center; color: var(--muted); font-size: 12px; margin-top: 14px; }
.auth-note { color: rgba(255, 255, 255, .75); font-size: 12.5px; margin-top: 18px; }
.auth-theme { position: absolute; top: 16px; right: 16px; }

/* ---------- профиль ---------- */
.profile-card { display: flex; align-items: center; gap: 16px; }
.profile-card h3 { margin-bottom: 2px; }
.profile-card p { margin: 2px 0; }

/* ---------- модальные окна ---------- */
.overlay {
  position: fixed; inset: 0; background: var(--overlay);
  display: flex; align-items: flex-start; justify-content: center; padding: 7vh 16px 16px;
  z-index: 50;
}
.modal {
  background: var(--card); border-radius: 16px; width: 100%; max-width: 560px;
  max-height: 82vh; overflow: auto; box-shadow: 0 24px 60px rgba(0, 5, 15, .45);
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 20px 10px; border-bottom: 1px solid var(--line);
  position: sticky; top: 0; background: var(--card); z-index: 1;
}
.modal-head h3 { margin: 0; font-size: 16px; }
.mclose {
  border: none; background: var(--soft); width: 30px; height: 30px; border-radius: 8px;
  font-size: 18px; line-height: 1; cursor: pointer; color: var(--muted);
}
.modal-body { padding: 14px 20px 20px; }
.modal-body label:first-of-type { margin-top: 2px; }
.modal-actions { display: flex; gap: 9px; margin-top: 16px; flex-wrap: wrap; }

/* ---------- тосты ---------- */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--toast-bg); color: #fff; padding: 11px 16px; border-radius: 11px;
  font-size: 13.5px; box-shadow: 0 8px 24px rgba(0, 5, 15, .4); max-width: 360px;
  transition: opacity .3s ease, transform .3s ease;
}
.toast.err { background: var(--danger); }
.toast.hide { opacity: 0; transform: translateY(6px); }

/* ================= адаптив: мобильные и планшеты ================= */
@media (max-width: 860px) {
  .shell { display: block; }
  .sidebar {
    width: 100%; flex-basis: auto; height: auto; position: sticky; top: 0; z-index: 20;
    border-right: none; border-bottom: 1px solid var(--line);
    padding: 10px 12px 12px; gap: 10px;
    box-shadow: var(--shadow);
  }
  .logo { padding: 0 2px; }
  .logo-sub { display: none; }
  .sidebar nav {
    flex-direction: row; overflow-x: auto; gap: 4px; padding-bottom: 2px;
    scrollbar-width: none;
  }
  .sidebar nav::-webkit-scrollbar { display: none; }
  .nav-item { flex: 0 0 auto; padding: 8px 12px; }
  .sidebar-bottom {
    flex-direction: row; align-items: center; border-top: none; padding-top: 0; gap: 10px;
  }
  .userchip { flex: 1; min-width: 0; }
  .userchip span { min-width: 0; overflow: hidden; }
  .userchip b, .userchip small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .content { padding: 14px 10px 44px; }
  h2 { font-size: 19px; }
  .stat-v { font-size: 21px; }
  .stat { padding: 11px 13px; }
  .toolbar { gap: 8px; }
  .toolbar .search { max-width: none; flex: 1 1 100%; order: 2; }
  .form-row { flex-direction: column; gap: 0; }
  .t-actions .btn { flex: 1 1 auto; justify-content: center; }
  .t-meta { gap: 4px 14px; }
  .overlay { padding: 4vh 8px 8px; }
  .modal { max-height: 90vh; }
  .cform { flex-direction: column; align-items: stretch; }
  .auth-card { padding: 22px 18px 18px; }
  .dept-grid { grid-template-columns: 1fr; }
}
@media (max-width: 420px) {
  .logo-name { font-size: 14px; }
  .btn { padding: 8px 12px; }
  #toast-root { left: 12px; right: 12px; }
  .toast { max-width: none; }
}
