:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #fcfcfd; --border: #e4e7ec; --border-soft: #f2f4f7;
  --text: #101828; --text-2: #344054; --muted: #667085; --input: #d0d5dd;
  --accent: #1d4ed8; --accent-hover: #1e40af; --accent-soft: #eff4ff;
  --red: #b42318; --red-soft: #fef3f2; --red-line: #fecdca;
  --amber: #b54708; --amber-soft: #fffaeb;
  --green: #067647; --green-soft: #ecfdf3;
  --purple: #5925dc; --purple-soft: #f4f3ff;
  --blue: #175cd3; --blue-soft: #eff8ff;
  --gray-soft: #f2f4f7; --gray: #475467;
  --radius: 12px;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); text-decoration: underline; }
h1 { margin: 0; font-size: 26px; font-weight: 700; letter-spacing: -0.01em; }
h2 { margin: 0; font-size: 16px; font-weight: 600; }
h3 { margin: 0 0 8px; font-size: 14px; font-weight: 600; }
p { margin: 0; }
code, .mono { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }
.strong { font-weight: 600; }
.red { color: var(--red); } .amber { color: var(--amber); } .green { color: var(--green); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* каркас */
.layout { display: flex; flex-wrap: wrap; min-height: 100vh; }
.sidebar { flex: 1 1 220px; max-width: 100%; background: var(--surface); border-right: 1px solid var(--border); padding: 20px 12px; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 22px; font-weight: 700; font-size: 15px; color: var(--text); }
.brand:hover { text-decoration: none; color: var(--text); }
.brand-mark { width: 32px; height: 32px; border-radius: 8px; background: var(--accent); display: flex; align-items: center; justify-content: center; }
.nav { display: flex; flex-direction: column; gap: 4px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; min-height: 44px; }
.nav a:hover { background: var(--gray-soft); text-decoration: none; color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav svg { flex-shrink: 0; }
.sidebar-spacer { flex-grow: 1; }
.me { display: flex; align-items: center; gap: 10px; padding: 12px 12px 4px; border-top: 1px solid var(--border-soft); margin-top: 8px; }
.avatar { width: 32px; height: 32px; border-radius: 999px; background: #d1e0ff; color: var(--accent); font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.me form { margin-left: auto; }
.main { flex: 999 1 560px; min-width: 0; padding: 28px 32px 48px; display: flex; flex-direction: column; gap: 20px; }

/* шапка страницы */
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px; }
.page-head .sub { color: var(--muted); margin-top: 4px; }
.crumbs { font-size: 13px; color: var(--muted); display: flex; gap: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }

/* кнопки */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--input); background: var(--surface); color: var(--text-2); font: 600 14px Inter, system-ui, sans-serif; cursor: pointer; white-space: nowrap; }
.btn:hover { background: var(--surface-2); text-decoration: none; color: var(--text); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); color: #fff; }
.btn-danger { color: var(--red); border-color: var(--red-line); }
.btn-danger:hover { background: var(--red-soft); color: var(--red); }
.btn-sm { min-height: 32px; padding: 0 10px; font-size: 13px; }
.btn-link { background: none; border: none; color: var(--accent); padding: 0; min-height: 0; font-weight: 600; cursor: pointer; font-size: 13px; }
.btn-link:hover { text-decoration: underline; }
button:focus-visible, a:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* карточки и плитки */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 18px 20px; display: flex; flex-direction: column; gap: 8px; }
.tile.alert { border-color: var(--red-line); }
.tile-label { font-size: 13px; color: var(--muted); font-weight: 500; }
.tile-value { font-size: 24px; font-weight: 700; letter-spacing: -0.02em; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); }
.card-pad { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 20px; border-top: 1px solid var(--border); font-size: 13px; color: var(--muted); }
.cols { display: flex; flex-wrap: wrap; gap: 20px; align-items: flex-start; }
.col-main { flex: 999 1 560px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.col-side { flex: 1 1 320px; min-width: 0; display: flex; flex-direction: column; gap: 20px; }
.kv { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.kv .k { font-size: 12px; color: var(--muted); font-weight: 500; }
.kv .v { font-weight: 500; }
.line { display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.list-rows > * { padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.list-rows > *:last-child { border-bottom: none; }

/* таблицы */
.table-wrap { overflow-x: auto; }
table.data { border-collapse: collapse; width: 100%; }
table.data th { font-size: 12px; font-weight: 600; color: var(--muted); text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; background: var(--surface-2); }
table.data td { padding: 12px; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
table.data tr:last-child td { border-bottom: none; }
table.data tr.row-alert td { background: #fffbfa; }
table.data tr.row-closed td { color: var(--muted); }
table.data.wide { min-width: 1100px; }
.cell-sub { font-size: 12px; color: var(--muted); }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }

/* метки */
.pill { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.pill-red { background: var(--red-soft); color: var(--red); }
.pill-amber { background: var(--amber-soft); color: var(--amber); }
.pill-green { background: var(--green-soft); color: var(--green); }
.pill-blue { background: var(--blue-soft); color: var(--blue); }
.pill-purple { background: var(--purple-soft); color: var(--purple); }
.pill-gray { background: var(--gray-soft); color: var(--gray); }
.docs { display: flex; gap: 4px; }
.doc { display: inline-flex; align-items: center; justify-content: center; min-width: 26px; height: 22px; padding: 0 4px; border-radius: 5px; font-size: 10px; font-weight: 700; letter-spacing: 0.02em; }
.doc-ok { background: #dcfae6; color: var(--green); }
.doc-sent { background: #e0eaff; color: var(--accent); }
.doc-hand { background: var(--amber-soft); color: var(--amber); }
.doc-no { background: var(--gray-soft); color: var(--muted); border: 1px dashed var(--input); }
.dot { width: 8px; height: 8px; border-radius: 999px; margin-top: 6px; flex-shrink: 0; }
.dot-red { background: #d92d20; } .dot-amber { background: #f79009; } .dot-purple { background: #7f56d9; } .dot-blue { background: var(--accent); } .dot-green { background: var(--green); } .dot-gray { background: var(--input); }
.todo { display: flex; gap: 12px; align-items: flex-start; }

/* вкладки и поиск */
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }
.tabs { display: flex; flex-wrap: wrap; gap: 6px; }
.tab { display: inline-flex; align-items: center; min-height: 36px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--input); background: var(--surface); color: var(--text-2); font-weight: 600; font-size: 13px; }
.tab:hover { text-decoration: none; background: var(--surface-2); color: var(--text); }
.tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.tab.alert:not(.active) { background: var(--red-soft); border-color: var(--red-line); color: var(--red); }
.search { display: flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--input); background: var(--surface); flex: 0 1 320px; margin-left: auto; }
.search input { border: none; outline: none; font: 14px Inter, system-ui, sans-serif; width: 100%; background: transparent; color: var(--text); min-height: 38px; }

/* формы */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field.full { grid-column: 1 / -1; }
.field > span, .label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.field .hint { font-size: 12px; color: var(--muted); }
input[type=text], input[type=tel], input[type=email], input[type=password], input[type=date], input[type=number], input[type=search], input[type=file], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--input); background: var(--surface); font: 14px Inter, system-ui, sans-serif; color: var(--text);
}
textarea { resize: vertical; min-height: 72px; }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); margin: 0; }
.check { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-2); }
.inline-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-end; }
.inline-form .field { flex: 1 1 160px; }
.form-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: flex-end; padding-top: 4px; }
fieldset { border: none; padding: 0; margin: 0; }
details > summary { cursor: pointer; font-weight: 600; color: var(--accent); font-size: 13px; list-style: none; min-height: 32px; display: inline-flex; align-items: center; }
details > summary::-webkit-details-marker { display: none; }
details[open] > summary { margin-bottom: 10px; }

/* сообщения */
.flash { padding: 12px 16px; border-radius: 10px; font-weight: 500; border: 1px solid; }
.flash-ok { background: var(--green-soft); border-color: #abefc6; color: var(--green); }
.flash-error { background: var(--red-soft); border-color: var(--red-line); color: var(--red); }
.errors { padding: 12px 16px; border-radius: 10px; background: var(--red-soft); border: 1px solid var(--red-line); color: var(--red); }
.errors ul { margin: 0; padding-left: 18px; }
.note-box { padding: 12px 14px; border-radius: 10px; background: var(--surface-2); border: 1px solid var(--border); }
.progress { height: 6px; border-radius: 999px; background: var(--gray-soft); overflow: hidden; }
.progress > div { height: 100%; background: var(--green); }

/* история */
.timeline { display: flex; flex-direction: column; gap: 14px; }
.timeline .item { display: flex; gap: 12px; }

/* вход */
.auth { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; padding: 32px 28px; display: flex; flex-direction: column; gap: 18px; }

/* уведомление о проблемах связи */
.net-toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000; max-width: calc(100% - 32px); display: flex; align-items: center; gap: 12px; padding: 12px 12px 12px 16px; border-radius: 10px; background: var(--text); color: #fff; font-size: 14px; box-shadow: 0 6px 24px rgba(16, 24, 40, 0.18); }
.net-toast button { background: none; border: none; color: #fff; font-size: 20px; line-height: 1; cursor: pointer; min-width: 32px; min-height: 32px; }

/* узкие экраны */
@media (max-width: 1100px) { .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 760px) {
  .sidebar { flex-basis: 100%; border-right: none; border-bottom: 1px solid var(--border); padding: 12px; flex-direction: row; flex-wrap: wrap; align-items: center; }
  .brand { padding: 4px 8px; flex: 1 1 auto; }
  .nav { flex-direction: row; flex-wrap: wrap; flex-basis: 100%; }
  .nav a { min-height: 40px; padding: 8px 10px; }
  .sidebar-spacer { display: none; }
  .me { border-top: none; margin: 0; padding: 4px 8px; }
  .main { padding: 20px 16px 40px; }
  .tiles, .kv, .form-grid, .form-grid.three { grid-template-columns: minmax(0, 1fr); }
  .search { flex-basis: 100%; margin-left: 0; }
  h1 { font-size: 22px; }
}
