:root {
  --navy: #1a2b3c;
  --text: #1a2b3c;
  --accent: #c45c26;
  --bg: #f7f3ee;
  --bg-glow-1: #efe4d6;
  --bg-glow-2: #e8ddd0;
  --card: #ffffff;
  --border: #d9d0c5;
  --muted: #6b6560;
  --ok: #2f6b4f;
  --danger: #b42318;
  --warn: #b54708;
  --input-bg: #ffffff;
  --table-stripe: rgba(26, 43, 60, 0.03);
  --shadow: 0 1px 2px rgba(26, 43, 60, 0.06), 0 8px 24px rgba(26, 43, 60, 0.06);
  --radius: 12px;
  --font: "Segoe UI", "PT Sans", system-ui, sans-serif;
  color-scheme: light;
}

html[data-theme="dark"] {
  --text: #e8eef4;
  --accent: #d4a06a;
  --bg: #0f161d;
  --bg-glow-1: #1a2836;
  --bg-glow-2: #152028;
  --card: #1a2430;
  --border: #2f3d4c;
  --muted: #9aa8b8;
  --ok: #5cb88a;
  --danger: #e5736a;
  --warn: #e0a45c;
  --input-bg: #141c26;
  --table-stripe: rgba(255, 255, 255, 0.03);
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.35), 0 10px 28px rgba(0, 0, 0, 0.35);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html {
  margin: 0;
  padding: 0;
  background: var(--bg);
  overflow-x: clip;
  max-width: 100%;
}
body {
  margin: 0;
  padding: 0;
  font-family: var(--font);
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--bg-glow-1) 0%, transparent 55%),
    radial-gradient(900px 400px at 100% 0%, var(--bg-glow-2) 0%, transparent 50%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  max-width: 100%;
  overflow-x: clip;
  -webkit-text-size-adjust: 100%;
}
body.nav-lock { overflow: hidden; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.layout {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.content-col {
  min-width: 0;
  width: 100%;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow-x: clip;
}
.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(26, 43, 60, 0.45);
  z-index: 40;
}
.sidebar {
  background: var(--navy);
  color: #f5efe7;
  padding: 24px 18px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  z-index: 50;
  -webkit-overflow-scrolling: touch;
}
.sidebar-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}
.sidebar-close {
  display: none;
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 8px;
  background: rgba(255,255,255,0.08);
  color: #f5efe7;
  font-size: 1.6rem;
  line-height: 1;
  cursor: pointer;
}
.brand { font-weight: 700; font-size: 1.15rem; letter-spacing: 0.02em; margin-bottom: 4px; }
.brand span { color: #e8a078; }
.brand-logo { display: block; margin: 0 0 10px; text-decoration: none; flex: 1; min-width: 0; }
.brand-logo img {
  width: 100%;
  max-width: 220px;
  height: auto;
  border-radius: 0;
  display: block;
  background: transparent;
}
.brand-sub { font-size: 0.75rem; opacity: 0.7; margin-bottom: 28px; }
.login-logo { text-align: center; }
.login-logo img {
  width: min(340px, 100%);
  height: auto;
  border-radius: 0;
  display: inline-block;
  background: transparent;
}
.nav a {
  display: block;
  color: #f5efe7;
  padding: 10px 12px;
  border-radius: 8px;
  margin-bottom: 4px;
  text-decoration: none;
  font-size: 0.95rem;
}
.nav a:hover, .nav a.active { background: rgba(255,255,255,0.1); }
.user-box {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.15);
  font-size: 0.85rem;
  opacity: 0.9;
}
.user-box a { color: #e8a078; }
.user-role { color: #cfc5b8 !important; }
.user-logout { margin-top: 8px; }
.btn-sidebar-push,
.btn-sidebar-theme {
  display: block;
  width: 100%;
  margin-top: 10px;
  padding: 8px 10px;
  border: 1px solid rgba(232, 160, 120, 0.55);
  border-radius: 8px;
  background: transparent;
  color: #e8a078;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  text-align: center;
}
.btn-sidebar-push:hover:not(:disabled),
.btn-sidebar-theme:hover:not(:disabled) {
  background: rgba(232, 160, 120, 0.12);
}
.btn-sidebar-push:disabled {
  opacity: 0.65;
  cursor: default;
  border-color: rgba(255, 255, 255, 0.25);
  color: #cfc5b8;
}

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 30;
  align-items: center;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
  padding: 10px 12px;
  padding-top: max(10px, env(safe-area-inset-top));
  padding-right: max(12px, env(safe-area-inset-right));
  padding-left: max(12px, env(safe-area-inset-left));
  background: rgba(26, 43, 60, 0.96);
  color: #f5efe7;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  backdrop-filter: blur(8px);
  overflow: visible;
}
.topbar-brand {
  color: #f5efe7;
  font-weight: 700;
  font-size: 0.95rem;
  text-decoration: none;
  flex: 1 1 auto;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.topbar-brand:hover { text-decoration: none; color: #fff; }
.topbar-user {
  flex: 0 1 auto;
  font-size: 0.78rem;
  opacity: 0.85;
  max-width: 4.8rem;
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.menu-toggle {
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 10px;
  background: rgba(255,255,255,0.1);
  color: #f5efe7;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.menu-toggle-bars {
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: relative;
}
.menu-toggle-bars::before,
.menu-toggle-bars::after {
  content: "";
  display: block;
  width: 18px;
  height: 2px;
  background: currentColor;
  border-radius: 2px;
  position: absolute;
  left: 0;
}
.menu-toggle-bars::before { top: -6px; }
.menu-toggle-bars::after { top: 6px; }

.main {
  padding: 28px 32px 48px;
  min-width: 0;
  max-width: 100%;
  width: 100%;
  overflow-x: clip;
}
.main > * {
  max-width: 100%;
}
.page-title { margin: 0 0 6px; font-size: 1.6rem; line-height: 1.25; overflow-wrap: anywhere; }
.page-lead { margin: 0 0 22px; color: var(--muted); line-height: 1.4; overflow-wrap: anywhere; }

.grid {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.grid > * { min-width: 0; max-width: 100%; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }

.period-bar {
  margin-bottom: 16px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.period-bar-grid {
  display: grid;
  gap: 12px 14px;
  grid-template-columns: minmax(0, 220px) minmax(0, 1fr) minmax(0, 180px);
  align-items: end;
  width: 100%;
  min-width: 0;
}
.period-dates {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  align-items: end;
  min-width: 0;
  width: 100%;
}
.period-dates .field,
.period-bar .field {
  min-width: 0;
  width: 100%;
  max-width: 100%;
}
.period-actions {
  display: grid;
  gap: 6px;
  align-content: end;
  min-width: 0;
}
.period-actions .btn { width: 100%; text-align: center; }
.period-bar input[type="date"] {
  display: block;
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-sizing: border-box;
}

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .period-bar-grid {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }
  .period-actions { grid-column: 1 / -1; }
  .period-actions .btn { width: auto; justify-self: start; min-width: 140px; }
}

@media (max-width: 900px) {
  .layout {
    grid-template-columns: minmax(0, 1fr);
  }
  .sidebar-backdrop {
    display: block;
  }
  .sidebar-backdrop[hidden] {
    display: none !important;
  }
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(300px, 86vw);
    height: 100vh;
    height: 100dvh;
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: none;
    padding: 16px 14px;
    padding-top: max(16px, env(safe-area-inset-top));
    padding-bottom: max(16px, env(safe-area-inset-bottom));
  }
  .layout.nav-open .sidebar {
    transform: translateX(0);
    box-shadow: 12px 0 40px rgba(0,0,0,0.28);
  }
  .sidebar-close { display: inline-flex; align-items: center; justify-content: center; }
  .topbar { display: flex; }
  .main {
    padding: 14px 12px 36px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
  }
  .topbar-user { max-width: 4.2rem; }
  @media (max-width: 380px) {
    .topbar-user { display: none; }
  }
  .page-title { font-size: 1.25rem; }
  .page-lead { margin-bottom: 14px; font-size: 0.9rem; }
  .grid { gap: 12px; width: 100%; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row,
  .form-row.three,
  .form-row-task-new,
  .form-row-expense { grid-template-columns: 1fr; }
  .form-row-dates {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    max-width: 360px;
  }
  .field-date,
  .salary-form .field-date,
  .expense-form .field-date {
    max-width: 100%;
  }
  .salary-form input[type="date"],
  .expense-form input[type="date"] {
    width: 100%;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
  }
  .period-bar {
    margin-bottom: 12px;
    padding: 12px;
    overflow: visible;
  }
  .period-bar-grid {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .period-dates {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .period-dates .field,
  .period-bar .field,
  .period-actions {
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }
  .period-actions .btn {
    width: 100%;
    min-width: 0;
    justify-self: stretch;
  }
  .period-bar input[type="date"],
  .period-bar select {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    box-sizing: border-box;
    padding-left: 8px;
    padding-right: 6px;
  }
  .period-bar input[type="date"] {
    font-size: 15px;
  }
  .filters {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    align-items: stretch;
    width: 100%;
    max-width: 100%;
  }
  .filters .field { min-width: 0; width: 100%; }
  .filters .btn { width: 100%; text-align: center; }
  .toolbar { align-items: stretch; }
  .toolbar .btn { width: 100%; text-align: center; }
  .card {
    padding: 14px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    overflow-x: clip;
    overflow-y: visible;
  }
  .stat-label {
    font-size: 0.75rem;
    line-height: 1.3;
    overflow-wrap: anywhere;
  }
  .stat-value {
    font-size: 1.25rem;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
  .section-title {
    font-size: 0.98rem;
    overflow-wrap: anywhere;
  }
  .muted { overflow-wrap: anywhere; }
  .table-wrap,
  .card.table-wrap {
    display: block;
    width: 100%;
    max-width: 100%;
    min-width: 0;
    margin: 0;
    padding: 0;
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
  }
  .card > .table-wrap {
    margin: 0;
    min-width: 0;
  }
  table {
    width: max-content;
    min-width: 100%;
    max-width: none;
    table-layout: auto;
    font-size: 0.78rem;
  }
  th, td {
    padding: 8px 6px;
    overflow-wrap: break-word;
    word-break: normal;
    vertical-align: top;
  }
  th {
    font-size: 0.66rem;
    letter-spacing: 0.02em;
    line-height: 1.25;
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--card);
  }
  td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--card);
  }
  th:first-child {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 3;
    background: var(--card);
  }
  tr:hover td:first-child {
    background: #fcfaf7;
  }
  html[data-theme="dark"] tr:hover td:first-child {
    background: var(--card);
  }
  tr.row-warn td:first-child {
    background: color-mix(in srgb, var(--warn) 12%, var(--card));
  }
  td a { overflow-wrap: anywhere; word-break: break-word; }
  .badge {
    white-space: nowrap;
    line-height: 1.25;
  }
  .kanban-col { flex: 0 0 min(280px, 82vw); max-width: min(280px, 82vw); }
  .kanban-body { max-height: none; }
  .kanban-card-title { overflow-wrap: anywhere; word-break: break-word; }
  .btn, .menu-toggle, .sidebar-close { touch-action: manipulation; }
  input, select, textarea {
    font-size: 16px;
    min-height: 42px;
    max-width: 100%;
    width: 100%;
    min-width: 0;
  }
  input[type="date"] {
    min-width: 0;
    max-width: 100%;
  }
  .perm-grid { grid-template-columns: 1fr; }
  .stack { width: 100%; max-width: 100%; }
}

@media (max-width: 480px) {
  .grid-4 { grid-template-columns: 1fr; }
  table { font-size: 0.74rem; }
  th { font-size: 0.62rem; }
  .stat-value { font-size: 1.15rem; }
  .period-dates {
    grid-template-columns: 1fr;
    max-width: 220px;
  }
  .period-actions .btn {
    max-width: 220px;
  }
}

@media (min-width: 901px) {
  .topbar { display: none !important; }
  .sidebar-backdrop { display: none !important; }
  .sidebar-close { display: none !important; }
  body.nav-lock { overflow: auto; }
}

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}
/* Единый вертикальный шаг между блоками страницы (карточки / сворачиваемые панели) */
.main > .card,
.main > details.card,
.main > form.card,
.main > section.card {
  margin-bottom: 16px;
}
.stat-label { font-size: 0.8rem; color: var(--muted); }
.stat-value { font-size: 1.6rem; font-weight: 700; margin-top: 4px; }
.stat-value.danger { color: var(--danger); }
.stat-value.ok { color: var(--ok); }

.table-wrap {
  overflow-x: auto;
  max-width: 100%;
  min-width: 0;
  -webkit-overflow-scrolling: touch;
}
table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
  max-width: 100%;
}
th, td {
  text-align: left;
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  overflow-wrap: break-word;
  word-break: normal;
  line-height: 1.35;
}
.employees-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: auto;
}
.employees-table th,
.employees-table td {
  vertical-align: middle;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  line-height: 1.4;
  box-shadow: none;
}
.employees-table th {
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}
.employees-table .emp-person {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}
.employees-table .emp-name {
  font-weight: 600;
  line-height: 1.35;
}
.employees-table .avatar,
.employees-table .avatar-empty {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  margin: 0;
}
.employees-table .col-actions {
  width: 118px;
  white-space: nowrap;
  text-align: right;
}
.emp-actions {
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 12px;
  margin: 0;
  padding: 0;
  line-height: 1.4;
}
.emp-del {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}
.emp-link {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
  box-shadow: none;
  font: inherit;
  font-size: 0.9rem;
  line-height: 1.4;
  color: var(--navy);
  text-decoration: underline;
  text-underline-offset: 2px;
  cursor: pointer;
  vertical-align: baseline;
}
.emp-link.danger,
.emp-link.danger-text {
  color: var(--danger);
}
.emp-link:hover {
  opacity: 0.85;
}
th {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  white-space: nowrap;
}
tr:hover td { background: #fcfaf7; }
.cell-nowrap,
td.cell-status { white-space: nowrap; }
.deals-table {
  border-collapse: collapse;
  width: 100%;
}
.deals-table th,
.deals-table td {
  vertical-align: middle;
  border-bottom: 1px solid var(--border);
}
.deals-table .col-actions {
  width: 1%;
  white-space: nowrap;
  text-align: right;
}
.deals-table .inline-delete {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
}
.deals-table .link-danger {
  border: none;
  background: transparent;
  padding: 0;
  margin: 0;
  color: var(--danger);
  font: inherit;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.deals-table .link-danger:hover {
  opacity: 0.8;
}
.deals-table .badge {
  border: none;
  box-shadow: none;
}
.history-table {
  border-collapse: collapse;
  width: 100%;
}
.history-table th,
.history-table td {
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  background: #efe6dc;
  color: var(--navy);
  white-space: nowrap;
}
.badge.warn { background: #fff1e0; color: var(--warn); }
.badge.danger { background: #fee4e2; color: var(--danger); }
.badge.ok { background: #e4f5ec; color: var(--ok); }

.btn {
  display: inline-block;
  border: none;
  background: var(--accent);
  color: #fff;
  padding: 9px 14px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
  font-weight: 600;
}
.btn:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--navy); color: #fff; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.small { padding: 5px 10px; font-size: 0.85rem; white-space: nowrap; }
.row-actions .btn { white-space: nowrap; }

.form-row { display: grid; gap: 12px; grid-template-columns: repeat(2, 1fr); margin-bottom: 12px; }
.form-row.one { grid-template-columns: 1fr; }
.form-row.three { grid-template-columns: repeat(3, 1fr); }
label { display: block; font-size: 0.8rem; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--input-bg);
  color: var(--text);
}
textarea { min-height: 80px; resize: vertical; }
.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: end; }
.filters .field { min-width: 140px; }
.toolbar { display: flex; justify-content: space-between; gap: 12px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card { width: min(420px, 100%); }
.login-card h1 { margin: 0 0 4px; }
.error { color: var(--danger); margin: 8px 0 12px; font-size: 0.9rem; }
.muted { color: var(--muted); font-size: 0.9rem; }
.ok { color: var(--ok); }
.danger { color: var(--danger); }
.danger-text { color: var(--danger) !important; }
tfoot td { padding-top: 12px; border-top: 2px solid var(--border); }
.row-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; align-items: center; white-space: nowrap; }
.row-actions form { display: inline-flex; margin: 0; padding: 0; border: 0; }
.phone-link { font-weight: 600; white-space: nowrap; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.perm-item { display: flex; gap: 8px; align-items: center; font-size: 0.92rem; padding: 6px 8px; background: #faf7f2; border-radius: 8px; }
.perm-block { margin-top: 10px; }
.perm-tables {
  display: grid;
  grid-template-columns: 1fr 1.35fr;
  gap: 12px;
  align-items: start;
}
.perm-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: #fff;
}
.perm-heading {
  margin: 0;
  padding: 7px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  background: #f7f3ee;
  border-bottom: 1px solid var(--border);
}
.perm-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin: 0;
}
.perm-table th,
.perm-table td {
  padding: 4px 8px;
  line-height: 1.25;
  border-bottom: 1px solid #eee8e0;
  vertical-align: middle;
}
.perm-table tr:last-child td { border-bottom: 0; }
.perm-table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #fbf9f6;
  padding: 5px 8px;
}
.perm-table .perm-check {
  width: 40px;
  text-align: center;
  white-space: nowrap;
}
.perm-table .perm-check input {
  width: 14px;
  height: 14px;
  margin: 0;
  vertical-align: middle;
  accent-color: var(--navy);
}
.perm-label {
  display: block;
  cursor: pointer;
  font-size: 0.78rem;
  line-height: 1.25;
  color: inherit;
}
@media (max-width: 900px) {
  .perm-tables { grid-template-columns: 1fr; }
}
.avatar { width: 36px; height: 36px; border-radius: 50%; object-fit: cover; }
.avatar-empty { width: 36px; height: 36px; border-radius: 50%; background: var(--navy); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 0.85rem; font-weight: 600; }
.stack { display: grid; gap: 16px; }
.section-title {
  font-size: 1.05rem;
  margin: 0 0 10px;
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 8px;
}
.hr { height: 1px; background: var(--border); margin: 18px 0; border: 0; }
.creds { font-size: 0.85rem; background: #efe6dc; padding: 10px 12px; border-radius: 8px; margin-top: 14px; }

/* Kanban */
.kanban {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 12px;
  align-items: flex-start;
}
.kanban-col {
  flex: 0 0 280px;
  max-width: 280px;
  background: #efe8df;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-height: 180px;
  display: flex;
  flex-direction: column;
}
.kanban-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 12px 12px 8px;
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--navy);
  border-bottom: 1px solid var(--border);
}
.kanban-body {
  padding: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: calc(100vh - 280px);
  overflow-y: auto;
}
.kanban-card {
  display: block;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 11px;
  box-shadow: var(--shadow);
  color: inherit;
  text-decoration: none;
}
.kanban-card:hover {
  border-color: var(--accent);
  text-decoration: none;
}
.kanban-card-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  margin-bottom: 6px;
}
.kanban-card-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  font-size: 0.78rem;
  margin-top: 4px;
}
.kanban-empty {
  color: var(--muted);
  font-size: 0.85rem;
  padding: 8px 4px;
}

.field-grow { flex: 1; min-width: 160px; }
.field-date { max-width: 170px; width: 100%; min-width: 0; }
.form-row-task-new {
  grid-template-columns: minmax(0, 1fr) 170px;
  align-items: end;
}
.form-row-dates {
  grid-template-columns: 170px 170px;
  align-items: end;
}
.form-row-expense {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 170px;
  align-items: end;
}
.salary-form .field-date,
.expense-form .field-date {
  max-width: 170px;
}
.row-ok td { background: #f0faf4; }
.row-warn td { background: #fff8f0; }
.micro-ok { border-color: #9dceb3; background: #f3fbf6; }
.micro-warn { border-color: #e8c4a0; background: #fff9f3; }
.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  margin-top: 8px;
}
.settings-actions .btn {
  min-width: 0;
}
.settings-compact-card .section-title {
  font-size: 1rem;
  margin-bottom: 6px;
}
.settings-lead {
  margin: 0 0 10px;
  font-size: 0.8rem;
}
.settings-mini-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}
.settings-mini-table th,
.settings-mini-table td {
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  line-height: 1.3;
}
.settings-mini-table th {
  width: 140px;
  text-align: left;
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  white-space: nowrap;
}
.settings-mini-table input[type="text"],
.settings-mini-table input[type="password"],
.settings-mini-table input:not([type]) {
  width: 100%;
  max-width: 420px;
  font-size: 0.85rem;
  padding: 6px 8px;
}
.settings-push-table { margin: 0; }
.price-table-card { padding: 0; overflow: hidden; }
.price-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  margin: 0;
}
.price-table th,
.price-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #eee8e0;
  vertical-align: top;
  line-height: 1.3;
}
.price-table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #fbf9f6;
  white-space: nowrap;
  padding: 6px 8px;
}
.price-table tr:last-child td { border-bottom: 0; }
.price-table .col-num { width: 36px; white-space: nowrap; }
.price-table .col-dir { width: 110px; white-space: nowrap; }
.price-table .col-cost { width: 110px; white-space: nowrap; font-weight: 600; }
.price-table .col-acts { width: 96px; text-align: right; white-space: nowrap; }
.price-table .price-name { font-weight: 600; font-size: 0.8rem; }
.price-table .price-note {
  font-size: 0.74rem;
  max-width: 420px;
  overflow-wrap: anywhere;
}
.price-form-table select {
  width: 100%;
  max-width: 420px;
  font-size: 0.85rem;
  padding: 6px 8px;
}
.stage-dir { margin-bottom: 12px; }
.stage-dir .perm-heading {
  border: 1px solid var(--border);
  border-bottom: 0;
  border-radius: 8px 8px 0 0;
}
.stage-table-wrap {
  border: 1px solid var(--border);
  border-radius: 0 0 8px 8px;
  overflow: hidden;
}
.stages-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 0.78rem;
  margin: 0;
}
.stages-table th,
.stages-table td {
  padding: 5px 8px;
  border-bottom: 1px solid #eee8e0;
  vertical-align: middle;
  line-height: 1.25;
}
.stages-table thead th {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--muted);
  background: #fbf9f6;
  text-align: left;
}
.stages-table .col-order { width: 56px; }
.stages-table .col-share { width: 78px; }
.stages-table .col-acts { width: 108px; text-align: right; }
.stages-table tr:last-child td { border-bottom: 0; }
.stages-table .stage-order,
.stages-table .stage-share,
.stages-table .stage-name {
  display: block;
  width: 100%;
  max-width: 100%;
  margin: 0;
  padding: 4px 6px;
  font-size: 0.78rem;
  line-height: 1.25;
  box-sizing: border-box;
}
.stages-table .stage-inline-form {
  display: inline;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}
.stages-table .col-acts .emp-actions {
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
}
.cell-money { white-space: nowrap; }
.brand-sub { display: none; }
.desktop-only { display: block; }
.mobile-only { display: none; }

.deal-micro-list {
  display: none;
  flex-direction: column;
  gap: 8px;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}
.deal-micro {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  overflow: hidden;
  width: 100%;
  max-width: 100%;
}
.deal-micro-summary {
  list-style: none;
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 10px 12px;
  cursor: pointer;
  user-select: none;
}
.deal-micro-summary::-webkit-details-marker { display: none; }
.deal-micro-main { flex: 1; min-width: 0; }
.deal-micro-title {
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.35;
  overflow-wrap: break-word;
  word-break: normal;
  hyphens: auto;
  margin-bottom: 4px;
}
.deal-micro-list > .muted {
  padding: 8px 2px;
  font-size: 0.88rem;
}
.deal-micro-line {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 10px;
  align-items: center;
  font-size: 0.78rem;
}
.deal-micro-chevron {
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-top: 6px;
  border-right: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.deal-micro[open] .deal-micro-chevron {
  transform: rotate(-135deg);
  margin-top: 10px;
}
.deal-micro-body {
  padding: 0 12px 12px;
  display: grid;
  gap: 8px;
  border-top: 1px solid var(--border);
  padding-top: 10px;
}
.deal-micro-row {
  display: grid;
  grid-template-columns: minmax(0, 42%) minmax(0, 1fr);
  gap: 8px;
  font-size: 0.82rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}
.deal-micro-body .btn { width: 100%; text-align: center; margin-top: 4px; }

@media (max-width: 900px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }
  .deal-micro-list.mobile-only { display: flex; }
  .field-grow { min-width: 0; width: 100%; flex: none; }
  .cell-money { white-space: normal; }
  .phone-link { white-space: nowrap; }
  .row-actions {
    white-space: normal;
    flex-wrap: wrap;
  }
  .card.table-wrap {
    overflow: auto;
  }
  /* Скролл внутри .table-wrap; без min-width:40rem — иначе flex раздувает всю страницу */
  .table-wrap > table,
  .card.table-wrap > table,
  .card > .table-wrap > table {
    width: max-content !important;
    min-width: 100%;
    max-width: none !important;
    table-layout: auto !important;
  }
  .table-wrap th,
  .card.table-wrap th,
  .card > .table-wrap th {
    white-space: nowrap;
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--card);
  }
  .table-wrap td:first-child,
  .card.table-wrap td:first-child,
  .card > .table-wrap td:first-child {
    position: sticky;
    left: 0;
    z-index: 1;
    background: var(--card);
    min-width: 8rem;
  }
  .table-wrap th:first-child,
  .card.table-wrap th:first-child,
  .card > .table-wrap th:first-child {
    position: sticky;
    top: 0;
    left: 0;
    z-index: 3;
    background: var(--card);
    min-width: 8rem;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .toolbar > div { min-width: 0; max-width: 100%; }
  ul { padding-left: 1.1rem; }
  li { overflow-wrap: anywhere; }
  .creds { overflow-wrap: anywhere; }
  .btn.small { font-size: 0.8rem; }
  .form-row { margin-bottom: 10px; }
  .main img { max-width: 100%; height: auto; }
  .settings-actions {
    flex-direction: column;
  }
  .settings-actions .btn {
    width: 100%;
    min-width: 0;
    text-align: center;
  }
}

/* Подсказка (?) и инструкция внизу вкладки */
.stat-label {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.hint {
  position: relative;
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  margin-left: 4px;
  flex: 0 0 auto;
}
.hint-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid #c9bfb4;
  background: #fff;
  color: var(--muted);
  font-size: 0.68rem;
  font-weight: 700;
  font-family: inherit;
  line-height: 1;
  cursor: help;
  user-select: none;
}
.hint-mark:hover,
.hint.is-open .hint-mark {
  color: var(--navy);
  border-color: var(--navy);
  background: #f3ebe3;
}
.hint-pop {
  position: absolute;
  z-index: 60;
  left: 50%;
  top: calc(100% + 8px);
  transform: translateX(-50%);
  width: min(260px, 18rem);
  max-width: 18rem;
  padding: 10px 28px 10px 12px;
  background: #1a2b3c;
  color: #f5efe7;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 400;
  line-height: 1.4;
  box-shadow: 0 8px 24px rgba(26, 43, 60, 0.28);
  /* display:none — иначе visibility:hidden всё равно расширяет scroll overflow */
  display: none;
  pointer-events: none;
}
.hint-pop::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -5px;
  width: 10px;
  height: 10px;
  margin-left: -5px;
  background: #1a2b3c;
  transform: rotate(45deg);
}
.hint-text {
  display: block;
  white-space: normal;
  word-break: normal;
  overflow-wrap: break-word;
  writing-mode: horizontal-tb;
}
.hint-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: #cfc5b8;
  font-size: 1rem;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}
.hint-close:hover { color: #fff; background: rgba(255,255,255,0.1); }

/* Наведение / тап */
.hint:hover .hint-pop,
.hint:focus-within .hint-pop,
.hint.is-open .hint-pop {
  display: block;
  pointer-events: auto;
}
/* После закрытия крестиком — не показывать по hover, пока не уйдут с элемента */
.hint.is-closed:hover .hint-pop,
.hint.is-closed:focus-within .hint-pop {
  display: none;
  pointer-events: none;
}
.hint.is-closed.is-open .hint-pop {
  display: block;
  pointer-events: auto;
}

.page-guide {
  margin-top: 22px;
}
.page-guide-body {
  font-size: 0.92rem;
  color: var(--muted);
  line-height: 1.45;
}
.page-guide-body ol,
.page-guide-body ul {
  margin: 0;
  padding-left: 1.2rem;
}
.page-guide-body li { margin-bottom: 6px; }
.page-guide-body strong { color: var(--navy); }

@media (max-width: 900px) {
  .hint-pop {
    left: 0;
    right: auto;
    transform: none;
    /* не 100% от .hint (~16px) — иначе буквы в столбик */
    width: 15rem;
    max-width: 15rem;
    min-width: 12rem;
    margin-left: 0;
  }
  .hint-pop::before {
    left: 12px;
    right: auto;
    margin-left: 0;
  }
}

/* --- ������� 2: ���� / �������� / ����� --- */
.dir-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0 0 14px;
}
.dir-tab {
  display: inline-flex;
  align-items: center;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--line, #d5dde6);
  background: #fff;
  color: var(--navy, #1a2b3c);
  text-decoration: none;
  font-size: 0.9rem;
}
.dir-tab.active {
  background: var(--navy, #1a2b3c);
  color: #fff;
  border-color: var(--navy, #1a2b3c);
}
.collapsible > summary.collapsible-sum {
  cursor: pointer;
  list-style: none;
  font-weight: 600;
  color: var(--navy, #1a2b3c);
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}
.collapsible > summary.collapsible-sum::-webkit-details-marker { display: none; }
.collapsible > summary.collapsible-sum::marker { content: ""; }
.collapsible > summary.collapsible-sum::after {
  content: "";
  flex: 0 0 auto;
  width: 8px;
  height: 8px;
  margin-left: auto;
  border-right: 2px solid var(--muted, #8a8075);
  border-bottom: 2px solid var(--muted, #8a8075);
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}
.collapsible[open] > summary.collapsible-sum::after {
  transform: rotate(-135deg);
}
.deal-row.urgency-overdue,
.deal-micro.urgency-overdue,
.kanban-card.urgency-overdue {
  background: #fde8e8;
}
.deal-row.urgency-soon,
.deal-micro.urgency-soon,
.kanban-card.urgency-soon {
  background: #fff4df;
}
.deal-row.urgency-ok td:first-child { box-shadow: inset 3px 0 0 #7cb87c; }
.badge.warn { background: #f0e0d0; color: #8a4b1a; }
.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}
.deals-pager {
  justify-content: space-between;
  flex-wrap: wrap;
}
.deals-pager .pager-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.phone-menu {
  position: relative;
  display: inline-block;
  max-width: 100%;
}
.phone-menu-sum {
  cursor: pointer;
  color: var(--accent, #2a6f97);
  list-style: none;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.phone-menu-sum::-webkit-details-marker { display: none; }
.deals-table td:nth-child(2),
.deals-table th:nth-child(2) {
  white-space: nowrap;
}
.phone-menu-list {
  position: absolute;
  z-index: 20;
  left: 0;
  top: 100%;
  margin-top: 4px;
  min-width: 140px;
  background: #fff;
  border: 1px solid var(--line, #d5dde6);
  border-radius: 8px;
  box-shadow: 0 6px 18px rgba(20, 40, 60, 0.12);
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.phone-menu-list a {
  padding: 6px 8px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--navy, #1a2b3c);
  font-size: 0.88rem;
}
.phone-menu-list a:hover { background: #f0f4f8; }
.site-footer {
  padding: 16px 20px 28px;
  text-align: center;
  font-size: 0.78rem;
  color: var(--muted, #6b7785);
  line-height: 1.45;
}
.site-footer-line { margin: 0 0 8px; max-width: 960px; margin-left: auto; margin-right: auto; }
.site-footer-operator { margin-bottom: 0; }
.site-footer a {
  color: var(--muted, #6b7785);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.site-footer a:hover { color: var(--navy, #1a2b3c); }
.requisites-table th {
  text-align: left;
  width: 34%;
  color: var(--muted, #6b7785);
  font-weight: 500;
  vertical-align: top;
}
.requisites-pre {
  white-space: pre-wrap;
  background: #f5f7fa;
  border: 1px solid var(--line, #d5dde6);
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  overflow-x: auto;
}
.legal-page { max-width: 760px; margin: 24px auto; padding: 0 16px 40px; }
.legal-card .page-title { margin-top: 8px; }
.lawyer-history {
  margin: 0;
  padding-left: 1.1rem;
  line-height: 1.5;
}
.lawyer-history li { margin-bottom: 6px; }
.contact-phone { margin: 0 0 14px; }

/* alerts + docs */
.alerts-menu { position: relative; margin-left: 0; margin-right: 0; flex: 0 0 auto; }
.alerts-sum {
  list-style: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 8px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.25);
  background: rgba(255, 255, 255, 0.1);
  color: #f5efe7;
  font-size: 0.95rem;
}
.alerts-sum::-webkit-details-marker { display: none; }
.alerts-count {
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #c45c26;
  color: #fff;
  font-size: 0.72rem;
  line-height: 18px;
  text-align: center;
}
.alerts-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  width: min(340px, 20rem);
  max-width: 20rem;
  max-height: 70vh;
  overflow: auto;
  background: #fff;
  border: 1px solid var(--line, #d5dde6);
  border-radius: 10px;
  box-shadow: 0 10px 28px rgba(20,40,60,0.14);
  z-index: 45;
}
@media (max-width: 900px) {
  .topbar {
    overflow: visible;
    z-index: 35;
    width: 100%;
    max-width: 100%;
  }
  .topbar .alerts-panel {
    position: fixed;
    left: max(12px, env(safe-area-inset-left));
    right: max(12px, env(safe-area-inset-right));
    width: auto;
    max-width: none;
    top: calc(env(safe-area-inset-top, 0px) + 58px);
    z-index: 60;
  }
}
.alerts-list { list-style: none; margin: 0; padding: 6px; }
.alert-item { margin: 0; }
.alert-item a {
  display: block;
  padding: 8px 10px;
  border-radius: 8px;
  text-decoration: none;
  color: var(--navy, #1a2b3c);
  font-size: 0.88rem;
}
.alert-item a:hover { background: #f0f4f8; }
.alert-item.alert-danger a { border-left: 3px solid #c0392b; }
.alert-item.alert-warn a { border-left: 3px solid #d68910; }
.topbar { display: flex; align-items: center; gap: 8px; max-width: 100%; box-sizing: border-box; }

.dev-stats { list-style: none; margin: 0; padding: 0; }
.dev-stats li {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.dev-stats li:last-child { border-bottom: 0; }
.dev-stats strong { margin-left: auto; font-size: 1.1rem; }
.dev-tabs .btn { text-decoration: none; }

/* ---- Тёмная тема (контент; сайдбар остаётся тёмным брендовым) ---- */
html[data-theme="dark"] .badge {
  background: #2a3746;
  color: var(--text);
}
html[data-theme="dark"] .badge.warn { background: #3a2e1c; color: #f0c48a; }
html[data-theme="dark"] .badge.danger { background: #3a2220; color: #f0a39c; }
html[data-theme="dark"] .badge.ok { background: #1e3a2e; color: #8fd6b0; }
html[data-theme="dark"] .perm-item { background: #141c26; }
html[data-theme="dark"] .alerts-panel {
  background: var(--card);
  border-color: var(--border);
  box-shadow: var(--shadow);
}
html[data-theme="dark"] .alert-item a { color: var(--text); }
html[data-theme="dark"] .alert-item a:hover { background: #243140; }
html[data-theme="dark"] .deal-row.urgency-overdue,
html[data-theme="dark"] .deal-micro.urgency-overdue,
html[data-theme="dark"] .kanban-card.urgency-overdue {
  background: #2a1c1c;
}
html[data-theme="dark"] .deal-row.urgency-soon,
html[data-theme="dark"] .deal-micro.urgency-soon,
html[data-theme="dark"] .kanban-card.urgency-soon {
  background: #2a2418;
}
html[data-theme="dark"] .page-guide,
html[data-theme="dark"] .kanban-col,
html[data-theme="dark"] .dir-tabs {
  background: transparent;
}
html[data-theme="dark"] .dir-tab {
  background: var(--card);
  color: var(--text);
  border-color: var(--border);
}
html[data-theme="dark"] .dir-tab.active {
  background: #2a3d50;
  color: #fff;
  border-color: #2a3d50;
}
html[data-theme="dark"] .collapsible > summary.collapsible-sum {
  color: var(--text);
}
html[data-theme="dark"] th {
  color: var(--muted);
}
html[data-theme="dark"] .site-footer {
  color: var(--muted);
}
html[data-theme="dark"] .site-footer a { color: var(--accent); }
html[data-theme="dark"] .site-footer a:hover { color: var(--text); }
html[data-theme="dark"] .btn.secondary {
  background: #2a3d50;
  color: #fff;
}
html[data-theme="dark"] a { color: var(--accent); }
html[data-theme="dark"] .link-danger { color: var(--danger); }
html[data-theme="dark"] .content-col .page-title,
html[data-theme="dark"] .content-col h1,
html[data-theme="dark"] .content-col h2 {
  color: var(--text);
}

/* ---------- Calendar month grid (table) ---------- */
.cal-page { margin-bottom: 24px; max-width: 100%; }
.cal-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-toolbar-left,
.cal-toolbar-right {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.cal-title { margin: 0; font-size: 1.35rem; }
.cal-lead { margin-bottom: 14px; }
.cal-month-label { font-size: 1.05rem; min-width: 7rem; }
.cal-create-btn { white-space: nowrap; }
.cal-create-card { margin-bottom: 14px; }
.cal-create-actions { display: flex; gap: 8px; margin-top: 10px; }
.cal-filter-card {
  margin-bottom: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 10px 12px;
  align-items: flex-end;
}
.cal-filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 10px;
  align-items: flex-end;
  flex: 1 1 280px;
  min-width: 0;
}
.cal-filter-label {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  align-self: center;
}
.cal-filter-actions { display: flex; gap: 8px; }
.cal-ms {
  position: relative;
  width: 240px;
  max-width: min(320px, 100%);
  flex: 0 1 auto;
}
.cal-ms-toggle {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--card);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  text-align: left;
}
.cal-ms.is-open .cal-ms-toggle {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.cal-ms-summary {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-ms-caret { color: var(--muted); font-size: 0.75rem; }
.cal-ms-panel {
  position: absolute;
  z-index: 40;
  top: calc(100% + 4px);
  left: 0;
  width: max-content;
  min-width: 100%;
  max-width: min(360px, 92vw);
  padding: 4px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  box-shadow: 0 10px 28px rgba(0,0,0,.12);
  max-height: 280px;
  overflow: auto;
}
.cal-ms-option {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 8px;
  width: auto;
  margin: 0;
  padding: 6px 8px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
  box-sizing: border-box;
}
.cal-ms-option input[type="checkbox"] {
  flex: 0 0 auto;
  margin: 0;
  width: 1rem;
  height: 1rem;
}
.cal-ms-option > span:last-child {
  flex: 0 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-ms-option:hover { background: color-mix(in srgb, var(--accent) 8%, transparent); }
.cal-ms-all { font-weight: 600; }
.cal-ms-divider {
  height: 1px;
  background: var(--border);
  margin: 2px 4px;
}
.cal-ms-panel-actions {
  margin-top: 4px;
  padding: 6px 4px 2px;
  border-top: 1px solid var(--border);
}
.cal-color-dot {
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.15);
  flex: 0 0 auto;
  vertical-align: middle;
}
.cal-legend { margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
.cal-legend-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  margin-bottom: 4px;
}

.cal-view-switch {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  background: var(--card);
}
.cal-view-btn {
  padding: 6px 10px;
  font-size: 0.8rem;
  color: var(--text);
  text-decoration: none;
  border-right: 1px solid var(--border);
  background: transparent;
}
.cal-view-btn:last-child { border-right: 0; }
.cal-view-btn:hover { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.cal-view-btn.is-active {
  background: var(--accent);
  color: #fff;
}

.cal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(240px, 300px);
  gap: 14px;
  align-items: start;
}
.cal-board.card {
  padding: 0;
  overflow: hidden;
  min-width: 0;
}
.cal-sidebar {
  padding: 14px;
  position: sticky;
  top: 12px;
  max-height: calc(100vh - 40px);
  overflow: auto;
}
.cal-sidebar-lead { margin: 0 0 10px; font-size: 0.85rem; }
.cal-hearing-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.cal-hearing-item {
  display: block;
  padding: 10px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  text-decoration: none;
  color: var(--text);
  background: color-mix(in srgb, var(--accent) 6%, var(--card));
}
.cal-hearing-item:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--border));
}
.cal-hearing-when {
  display: flex;
  gap: 8px;
  align-items: baseline;
  margin-bottom: 4px;
  font-size: 0.8rem;
}
.cal-hearing-date { font-weight: 600; }
.cal-hearing-time { color: var(--muted); }
.cal-hearing-title { font-size: 0.92rem; font-weight: 600; line-height: 1.3; }
.cal-hearing-note {
  margin-top: 4px;
  font-size: 0.8rem;
  color: var(--muted);
  line-height: 1.35;
}
.cal-table-wrap {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.cal-table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  background: var(--card);
}
.cal-table thead th {
  padding: 10px 6px;
  text-align: center;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: lowercase;
  border-bottom: 1px solid var(--border);
  background: #f3eee7;
  width: 14.28%;
}
.cal-table td.cal-cell {
  vertical-align: top;
  border: 1px solid var(--border);
  padding: 6px;
  height: 118px;
  background: var(--card);
  width: 14.28%;
}
.cal-table-week td.cal-cell,
.cal-table-twoweek td.cal-cell {
  height: 150px;
}
.cal-table-day {
  table-layout: auto;
}
.cal-table-day td.cal-cell {
  width: 100%;
  height: auto;
  min-height: 280px;
}
.cal-table td.cal-cell.is-out {
  background: #f3f0eb;
}
.cal-table td.cal-cell.is-out .cal-daynum {
  color: var(--muted);
  opacity: 0.75;
}
.cal-table td.cal-cell.is-today {
  outline: 2px solid color-mix(in srgb, var(--accent) 70%, transparent);
  outline-offset: -2px;
}
.cal-cell-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  gap: 4px;
}
.cal-daynum {
  font-size: 0.85rem;
  font-weight: 600;
  line-height: 1.2;
}
.cal-table td.cal-cell.is-today .cal-daynum {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.55rem;
  height: 1.55rem;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem;
}
.cal-cell-add {
  border: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0 2px;
  opacity: 0;
}
.cal-table td.cal-cell:hover .cal-cell-add,
.cal-cell-add:focus { opacity: 1; }
.cal-cell-events {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.cal-event {
  display: flex;
  align-items: baseline;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  padding: 2px 4px 2px 6px;
  border-radius: 4px;
  border-left: 3px solid #6b7280;
  font-size: 0.72rem;
  line-height: 1.25;
  color: var(--text);
  text-decoration: none;
  overflow: hidden;
  box-sizing: border-box;
}
a.cal-event:hover { filter: brightness(0.97); }
.cal-event-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex: 0 0 auto;
  margin-top: 0.2em;
  background: #6b7280;
}
.cal-event-task {
  font-style: italic;
}
.cal-event-time {
  flex: 0 0 auto;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.cal-event-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cal-more { margin-top: 2px; }
.cal-more > summary {
  list-style: none;
  cursor: pointer;
  font-size: 0.7rem;
  color: var(--muted);
  padding: 1px 4px;
}
.cal-more > summary::-webkit-details-marker { display: none; }
.cal-more-list {
  display: flex;
  flex-direction: column;
  gap: 2px;
  margin-top: 2px;
}
.cal-event-del { margin: 0; }

@media (max-width: 1100px) {
  .cal-layout {
    grid-template-columns: 1fr;
  }
  .cal-sidebar {
    position: static;
    max-height: none;
  }
}
@media (max-width: 900px) {
  .cal-table td.cal-cell { height: 96px; padding: 4px; }
  .cal-table-week td.cal-cell,
  .cal-table-twoweek td.cal-cell { height: 120px; }
  .cal-event { font-size: 0.68rem; }
  .cal-cell-add { opacity: 0.55; }
  .cal-title { font-size: 1.15rem; }
}
@media (max-width: 640px) {
  .cal-table thead th { padding: 8px 2px; font-size: 0.7rem; }
  .cal-event-time { display: none; }
  .cal-view-btn { padding: 6px 8px; font-size: 0.72rem; }
}

html[data-theme="dark"] .cal-table thead th {
  background: #223040;
  color: var(--muted);
}
html[data-theme="dark"] .cal-table td.cal-cell.is-out {
  background: #15202b;
}

/* этап 2: колокольчик личных уведомлений */
.alerts-count[hidden] { display: none; }
.alerts-count-muted { background: #7a8794; }
.bell-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 8px 10px 2px; font-size: 0.85rem; }
.bell-link { background: none; border: 0; padding: 0 0 0 8px; color: var(--muted, #6b7785); cursor: pointer; font-size: 0.78rem; }
.bell-link:hover { text-decoration: underline; }
.bell-item a { display: flex; flex-direction: column; gap: 2px; border-left: 3px solid #c45c26; }
.bell-item.is-read a { border-left-color: transparent; opacity: .72; }
.bell-title { font-weight: 600; }
.bell-body { font-size: 0.82rem; color: var(--muted, #556270); }
.bell-at { font-size: 0.72rem; color: var(--muted, #8a96a3); }

/* этап 3: направления в меню, кнопки направлений, колонка «Задача» */
.nav-group { margin-bottom: 4px; }
.nav-group-head { display: flex; align-items: stretch; gap: 2px; }
.nav-group-head > a { flex: 1; margin-bottom: 0; }
.nav-caret { background: transparent; border: 0; color: #f5efe7; width: 38px; border-radius: 8px; cursor: pointer; font-size: 0.85rem; }
.nav-caret:hover { background: rgba(255,255,255,0.1); }
.nav-caret span { display: inline-block; transition: transform .15s ease; }
.nav-group.open .nav-caret span { transform: rotate(90deg); }
.nav-sub { display: none; padding: 2px 0 0 14px; }
.nav-group.open .nav-sub { display: block; }
.nav-sub a { font-size: 0.9rem; padding: 8px 12px; margin-bottom: 2px; opacity: .92; }
.dir-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 12px; }
.dir-tab { padding: 6px 12px; border-radius: 999px; border: 1px solid rgba(127,127,127,.35); text-decoration: none; color: inherit; font-size: 0.9rem; }
.dir-tab:hover { border-color: #c45c26; }
.dir-tab.active { background: #c45c26; border-color: #c45c26; color: #fff; }
.toolbar { position: relative; }
.dir-create { margin-left: auto; position: relative; }
.dir-create > summary { list-style: none; cursor: pointer; }
.dir-create > summary::-webkit-details-marker { display: none; }
.dir-create-form { position: absolute; right: 0; top: calc(100% + 6px); z-index: 30; width: min(320px, 86vw); }
.dir-create-form input { width: 100%; }
.deal-next-task { min-width: 140px; font-size: 0.9rem; }
@media (max-width: 900px) {
  .nav-caret { width: 46px; }
  .dir-create-form { position: static; width: 100%; margin-top: 8px; }
  .dir-tabs { flex-wrap: nowrap; overflow-x: auto; padding-bottom: 4px; }
  .dir-tab { white-space: nowrap; }
}

/* этап 4: карточка дела в две колонки, блок задач, файлы */
.deal-layout {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(320px, 1fr);
  grid-template-areas: "main side" "rest side";
  gap: 0 16px;
  align-items: start;
}
.deal-main { grid-area: main; min-width: 0; }
.deal-side { grid-area: side; min-width: 0; position: sticky; top: 16px; max-height: calc(100vh - 32px); overflow-y: auto; align-self: start; margin-bottom: 16px; scrollbar-width: thin; }
.deal-rest { grid-area: rest; min-width: 0; }
.deal-rest > .card + .card { margin-top: 16px; }
.deal-tasks {
  background: color-mix(in srgb, var(--accent) 7%, var(--card, #fff));
  border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--border, #e3d9cc));
  box-shadow: inset 4px 0 0 color-mix(in srgb, var(--accent) 55%, transparent);
}
.deal-tasks-lists > div + div { margin-top: 10px; }
.deal-inside { margin-top: 28px; padding-top: 14px; border-top: 1px dashed var(--border, #ddd); }
.deal-inside-title { font-size: 1.25rem; margin: 0 0 12px; }
.deal-files { margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border, #eee); }
.deal-file-row { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: baseline; padding: 5px 0; border-bottom: 1px dotted var(--border, #eee); }
.deal-file-name { font-weight: 600; word-break: break-word; }
.deal-file-form { margin-top: 10px; }
.deal-file-form input[type=file] { width: 100%; }
@media (max-width: 1100px) {
  .deal-layout { grid-template-columns: minmax(0, 1fr); grid-template-areas: "main" "side" "rest"; }
  .deal-side { position: static; max-height: none; overflow: visible; }
}
.deal-file-row .link-danger, #files .link-danger { background: none; border: 0; padding: 0 4px; color: #b3412e; cursor: pointer; font: inherit; font-size: 0.85rem; text-decoration: underline; }
.deal-file-row .inline-delete { display: inline; margin: 0; }

/* этап 5: история изменений */
.change-history { margin-top: 14px; }
.change-history > summary { cursor: pointer; font-weight: 600; }
.change-history-list { list-style: none; padding: 0; margin: 8px 0 0; max-height: 420px; overflow-y: auto; }
.change-history-list li { padding: 6px 0; border-bottom: 1px solid var(--border, rgba(127,127,127,.2)); line-height: 1.4; overflow-wrap: anywhere; }
.change-history-list li:last-child { border-bottom: 0; }
.change-old { text-decoration: line-through; opacity: .75; white-space: pre-wrap; }
.change-new { white-space: pre-wrap; }
.pre-wrap { white-space: pre-wrap; }
