:root {
  --bg: #f4f5f7;
  --panel-bg: #ffffff;
  --border: #dde1e6;
  --text: #1c2126;
  --text-muted: #626a73;
  --accent: #2054c9;
  --accent-contrast: #ffffff;
  --pending: #7a828c;
  --submitted: #b7791f;
  --confirmed: #1a7f4b;
  --late: #c62839;
  --overdue-bg: #fdecec;
  --soon-bg: #fdf6e3;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #14171a;
    --panel-bg: #1d2126;
    --border: #2c3238;
    --text: #e7e9ec;
    --text-muted: #9aa2ab;
    --accent: #5b8def;
    --accent-contrast: #0b0d0f;
    --pending: #9aa2ab;
    --submitted: #d9a441;
    --confirmed: #3fc582;
    --late: #ec5f6c;
    --overdue-bg: #341c1e;
    --soon-bg: #3a300f;
  }
}

:root[data-theme="dark"] {
  --bg: #14171a;
  --panel-bg: #1d2126;
  --border: #2c3238;
  --text: #e7e9ec;
  --text-muted: #9aa2ab;
  --accent: #5b8def;
  --accent-contrast: #0b0d0f;
  --pending: #9aa2ab;
  --submitted: #d9a441;
  --confirmed: #3fc582;
  --late: #ec5f6c;
  --overdue-bg: #341c1e;
  --soon-bg: #3a300f;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

a { color: var(--accent); }

.app-header {
  background: var(--panel-bg);
  border-bottom: 1px solid var(--border);
}
.app-header-inner {
  display: flex;
  align-items: center;
  gap: 24px;
  width: min(96%, 1800px);
  margin: 0 auto;
  padding: 12px 0;
  flex-wrap: wrap;
}

.app-brand { display: flex; align-items: center; gap: 10px; }
.app-logo {
  width: 32px; height: 32px; display: block; flex: none;
  background: #fff; border-radius: 8px; padding: 4px; box-sizing: border-box;
}
.app-title { font-weight: 700; font-size: 16px; white-space: nowrap; }
.app-subtitle { display: block; font-weight: 400; font-size: 12px; color: var(--text-muted); }

.main-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.main-nav a {
  padding: 6px 12px;
  border-radius: 6px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 14px;
}
.main-nav a.active { background: var(--accent); color: var(--accent-contrast); }
.main-nav a:not(.active):hover { background: var(--bg); }

.global-search { margin-left: auto; }
.global-search input {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  min-width: 240px;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  flex: none;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--text); }
/* Иконка показывает тему, В КОТОРУЮ переключит клик, а не текущую. */
.theme-toggle .icon-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

.view-root { width: min(96%, 1800px); margin: 0 auto; padding: 24px 0 40px; }

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; margin: 0; }

.panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px 20px;
  margin-bottom: 16px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; }
.panel-header { display: flex; align-items: center; justify-content: space-between; }
.panel-header h2 { margin: 0; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}
.kpi-tile {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.kpi-value { font-size: 26px; font-weight: 700; }
.kpi-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.kpi-tile.kpi-warn .kpi-value { color: var(--late); }

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: top; }
.table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: 0.02em; }
.table tr.row-overdue td { background: var(--overdue-bg); }
.table tr.row-soon td { background: var(--soon-bg); }
.table tr.row-inactive td { opacity: 0.55; }

.empty { color: var(--text-muted); font-size: 14px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: #fff;
  background: var(--pending);
}
.badge-pending { background: var(--pending); }
.badge-submitted { background: var(--submitted); }
.badge-confirmed { background: var(--confirmed); }
.badge-late { background: var(--late); }

.filters { display: flex; gap: 8px; margin-bottom: 12px; flex-wrap: wrap; }

.input, .select, textarea.input {
  padding: 7px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel-bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
textarea.input { width: 100%; min-height: 70px; resize: vertical; }

.btn {
  padding: 7px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--panel-bg);
  color: var(--text);
  font-size: 14px;
  cursor: pointer;
  display: inline-block;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-contrast); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

.field { margin-bottom: 12px; display: flex; flex-direction: column; gap: 4px; }
.field label { font-size: 12px; color: var(--text-muted); }

.checkbox-list { display: flex; flex-direction: column; gap: 6px; max-height: 220px; overflow-y: auto; }
.checkbox-row { font-size: 14px; display: flex; align-items: center; gap: 6px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.45);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
}
.modal-box {
  background: var(--panel-bg);
  border-radius: 10px;
  padding: 24px;
  width: 100%; max-width: 480px;
  border: 1px solid var(--border);
}
.modal-box h2 { margin-top: 0; font-size: 17px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.result-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; font-size: 14px; }

.summary-text { white-space: pre-line; }

.truncate { max-width: 380px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: inline-block; vertical-align: bottom; }

.row-highlight td { background: var(--accent); background: color-mix(in srgb, var(--accent) 25%, transparent); transition: background 0.3s; }

.table-fixed { table-layout: fixed; }
.table-fixed td, .table-fixed th { word-wrap: break-word; overflow-wrap: break-word; }

.hint { font-size: 12px; color: var(--text-muted); }
.hint code, .notice code { font-size: 12px; word-break: break-all; }

.notice {
  border: 1px solid var(--border);
  border-left-width: 3px;
  border-radius: 6px;
  padding: 10px 12px;
  margin: 12px 0;
  font-size: 13px;
}
.notice-warn { border-left-color: var(--submitted); }
.notice-error { border-left-color: var(--late); }
.notice .result-list { margin-top: 6px; }

.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translate(-50%, 12px);
  background: var(--text); color: var(--bg);
  padding: 10px 18px; border-radius: 8px; font-size: 14px;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; z-index: 200;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast-error { background: var(--late); color: #fff; }

.user-box {
  display: flex; align-items: center; gap: 8px;
  padding-left: 12px; margin-left: 4px;
  border-left: 1px solid var(--border);
  font-size: 13px; white-space: nowrap;
}
.user-box .user-name { font-weight: 600; }
.user-box .user-role { color: var(--text-muted); }

/* Полоса под шапкой: связь с сервером и чужие правки. Держится в потоке, а не поверх контента —
   сообщение «правка не сохранилась» не должно исчезать само и не должно ничего перекрывать. */
.sync-status {
  padding: 8px 24px; font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: var(--panel-bg); color: var(--text);
}
.sync-status-error { background: var(--overdue-bg); color: var(--late); }
.sync-status-conflict { background: var(--soon-bg); color: var(--submitted); }
.sync-status-info { color: var(--text-muted); }

@media (max-width: 640px) {
  .app-header-inner { flex-direction: column; align-items: stretch; }
  .global-search { margin-left: 0; }
  .global-search input { width: 100%; }
  .user-box { border-left: none; padding-left: 0; justify-content: flex-start; }
  .sync-status { padding: 8px 14px; }
}
