:root,
html[data-theme="light"],
html[data-theme="dark"] {
  color-scheme: light;
  --primary: #3562bd;
  --secondary: #202c43;
  --accent: #edf2fc;
  --primary-fg: #ffffff;
  --body-fg: #182336;
  --body-bg: #f2f4f8;
  --body-quiet-color: #5f6c83;
  --body-loud-color: #182336;
  --header-color: #ffffff;
  --header-branding-color: #ffffff;
  --header-bg: #202c43;
  --header-link-color: #e9effa;
  --breadcrumbs-fg: #5f6c83;
  --breadcrumbs-link-fg: #3562bd;
  --breadcrumbs-bg: #edf2fc;
  --link-fg: #3562bd;
  --link-hover-color: #294f9e;
  --link-selected-fg: #202c43;
  --hairline-color: #dce2eb;
  --border-color: #dce2eb;
  --error-fg: #a33e3e;
  --message-success-bg: #e7f5ed;
  --message-warning-bg: #fff4dd;
  --message-error-bg: #fcebea;
  --darkened-bg: #edf2fc;
  --selected-bg: #edf2fc;
  --selected-row: #f8f9fc;
  --button-fg: #ffffff;
  --button-bg: #3562bd;
  --button-hover-bg: #294f9e;
  --default-button-bg: #3562bd;
  --default-button-hover-bg: #294f9e;
  --close-button-bg: #66738a;
  --close-button-hover-bg: #526078;
  --delete-button-bg: #a33e3e;
  --delete-button-hover-bg: #873333;
  --object-tools-fg: #ffffff;
  --object-tools-bg: #3562bd;
  --object-tools-hover-bg: #294f9e;
}

* { box-sizing: border-box; }
html { background: #f2f4f8; }
body {
  min-width: 320px;
  background: #f2f4f8;
  color: #182336;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
.theme-toggle { display: none !important; }
a:link, a:visited { color: #3562bd; }
a:hover { color: #294f9e; }

/* Верхняя панель */
#header {
  min-height: 70px;
  padding: 0 24px;
  background: #202c43;
  color: #ffffff;
  box-shadow: 0 8px 28px rgba(32, 44, 67, 0.18);
}
#branding { display: flex; align-items: center; min-width: 245px; }
.unified-brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  color: #ffffff !important;
  text-decoration: none;
}
.unified-brand__mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: #edf2fc;
  color: #202c43;
  font-size: 19px;
  font-weight: 900;
}
.unified-brand strong, .unified-brand small { display: block; }
.unified-brand strong { font-size: 16px; line-height: 1.2; }
.unified-brand small { color: #aebbd0; font-size: 11px; }
#user-tools { color: #aebbd0; font-size: 12px; }
#user-tools a, #user-tools button { color: #e9effa; }
#user-tools a:hover, #user-tools button:hover { color: #ffffff; }
#logout-form button { font: inherit; }
#nav-global { margin-left: auto; }
.admin-global-nav { display: flex; align-items: center; gap: 8px; }
.admin-shortcuts { display: none; gap: 4px; }
.admin-shortcuts a {
  padding: 8px 9px;
  border-radius: 7px;
  color: #d7deeb !important;
  font-size: 11px;
  font-weight: 700;
  text-decoration: none;
}
.admin-shortcuts a:hover { background: #2b3a55; color: #ffffff !important; }
.back-to-dashboard {
  display: inline-flex;
  align-items: center;
  min-height: 36px;
  padding: 8px 12px;
  border: 1px solid #465670;
  border-radius: 8px;
  color: #e9effa !important;
  font-size: 12px;
  font-weight: 700;
  text-decoration: none;
}
.back-to-dashboard:hover { border-color: #a9c2fa; background: #2b3a55; color: #ffffff !important; }

/* Хлебные крошки и область страницы */
div.breadcrumbs {
  min-height: 44px;
  padding: 13px 28px;
  border-bottom: 1px solid #dce2eb;
  background: #edf2fc;
  color: #5f6c83;
  font-size: 12px;
}
div.breadcrumbs a { color: #3562bd; font-weight: 700; }
.main { background: #f2f4f8; }
#content {
  width: 100%;
  max-width: 1480px;
  margin: 0 auto;
  padding: 28px 32px 48px;
}
#content h1 {
  margin: 0 0 22px;
  color: #182336;
  font-size: 27px;
  font-weight: 750;
  letter-spacing: -0.03em;
}
#content h2, #content h3 { color: #182336; }

/* Боковое меню Django */
#nav-sidebar {
  width: 240px;
  flex: 0 0 240px;
  border-right: 0;
  background: #202c43;
  color: #e9effa;
  box-shadow: 8px 0 25px rgba(32, 44, 67, 0.08);
}
#nav-sidebar .sticky { top: 0; }
#nav-sidebar input {
  margin: 13px 12px;
  width: calc(100% - 24px);
  border: 1px solid #465670;
  border-radius: 8px;
  background: #263651;
  color: #ffffff;
}
#nav-sidebar input::placeholder { color: #aebbd0; }
#nav-sidebar .module { margin: 0; background: transparent; }
#nav-sidebar .module caption,
#nav-sidebar .module h2 {
  padding: 12px 14px 7px;
  background: transparent;
  color: #aebbd0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
#nav-sidebar table { width: 100%; }
#nav-sidebar tr { border: 0; }
#nav-sidebar tbody tr { background: transparent; }
#nav-sidebar th, #nav-sidebar td { padding: 0; }
#nav-sidebar a {
  display: block;
  margin: 2px 8px;
  padding: 9px 10px;
  border-radius: 7px;
  color: #d7deeb;
  font-size: 12px;
  text-decoration: none;
}
#nav-sidebar a:hover, #nav-sidebar .current-model a { background: #2b3a55; color: #ffffff; }
#nav-sidebar .addlink { color: #91c7a7; }
.toggle-nav-sidebar {
  width: 34px;
  border: 0;
  border-right: 1px solid #465670;
  background: #202c43;
  color: #d7deeb;
}

/* Карточки, таблицы и списки */
.module,
.inline-group,
#changelist .results,
#changelist-filter,
.dashboard #content-related .module {
  overflow: hidden;
  border: 1px solid #dce2eb;
  border-radius: 9px;
  background: #ffffff;
  box-shadow: 0 5px 20px rgba(32, 44, 67, 0.05);
}
#changelist .results { overflow-x: auto; }
#changelist .results table { min-width: 720px; }
.module h2,
.module caption,
.inline-group h2 {
  padding: 13px 16px;
  border: 0;
  background: #edf2fc;
  color: #202c43;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
#nav-sidebar .module { border: 0; border-radius: 0; box-shadow: none; }
.module caption a { color: #202c43; }
table { border-collapse: collapse; }
thead th {
  padding: 11px 12px;
  border-bottom: 1px solid #dce2eb;
  background: #f2f4f8;
  color: #5f6c83;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.02em;
}
tbody tr { border-bottom: 1px solid #edf2fc; }
tbody tr:last-child { border-bottom: 0; }
tbody tr:hover { background: #f8f9fc; }
td, th { padding: 11px 12px; vertical-align: middle; }
.row1 { background: #ffffff; }
.row2 { background: #fcfdff; }
#changelist table input { margin: 0; }
#changelist .paginator { border-top: 1px solid #dce2eb; background: #ffffff; }
#changelist-filter { margin-left: 18px; }
#changelist-filter h2 { background: #202c43; color: white; }
#changelist-filter h3 { color: #66738a; font-size: 12px; }
#changelist-filter li.selected a { color: #3562bd; font-weight: 800; }
#toolbar {
  margin-bottom: 16px;
  padding: 13px;
  border: 1px solid #dce2eb;
  border-radius: 9px;
  background: #ffffff;
}
#toolbar form input[type="text"] { min-width: 260px; }
.actions {
  margin-bottom: 14px;
  padding: 11px 13px;
  border: 1px solid #dce2eb;
  border-radius: 9px;
  background: #ffffff;
}

/* Формы */
fieldset.module {
  margin-bottom: 18px;
  padding: 4px 20px 10px;
}
.form-row {
  display: grid;
  grid-template-columns: minmax(170px, 240px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
  padding: 15px 0;
  border-bottom: 1px solid #edf2fc;
}
.form-row:last-child { border-bottom: 0; }
.form-row > div { min-width: 0; }
.form-row label { padding-top: 8px; color: #182336; font-weight: 700; }
.form-row .help, .help, p.help, form p.help { color: #5f6c83; font-size: 11px; }
input[type="text"],
input[type="password"],
input[type="email"],
input[type="url"],
input[type="number"],
input[type="tel"],
input[type="date"],
textarea,
select,
.vTextField {
  min-height: 40px;
  max-width: 100%;
  padding: 9px 11px;
  border: 1px solid #cbd4e2;
  border-radius: 8px;
  background: #ffffff;
  color: #182336;
  font: inherit;
  box-shadow: 0 1px 2px rgba(32, 44, 67, 0.03);
}
textarea { min-height: 120px; resize: vertical; }
select { padding-right: 32px; }
input:focus, textarea:focus, select:focus {
  border-color: #3562bd;
  outline: 3px solid #a9c2fa;
  outline-offset: 2px;
}
input[readonly], input[disabled], textarea[disabled], select[disabled] { background: #edf2fc; color: #5f6c83; }
.errorlist { margin: 5px 0; color: #a33e3e; }
.errors input, .errors select, .errors textarea { border-color: #a33e3e; }
.calendarbox, .clockbox { border: 1px solid #dce2eb; border-radius: 9px; box-shadow: 0 14px 45px rgba(32, 44, 67, 0.16); }

/* Вложенные таблицы */
.inline-group { margin: 20px 0; }
.inline-related { border-bottom: 1px solid #dce2eb; }
.inline-related:last-child { border-bottom: 0; }
.inline-related h3 { padding: 11px 14px; background: #f2f4f8; color: #182336; }
.inline-group .tabular tr.has_original td { padding-top: 10px; }
.inline-group .add-row td { padding: 12px; background: #f8f9fc; }
.inline-group .add-row a { color: #3562bd; font-weight: 800; }

/* Кнопки */
input[type="submit"], button, .button, a.button {
  min-height: 38px;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  background: #3562bd;
  color: #ffffff;
  font-weight: 750;
  cursor: pointer;
}
input[type="submit"]:hover, button:hover, .button:hover, a.button:hover { background: #294f9e; color: #ffffff; }
#content input[type="submit"], #content button, #content .button, #content a.button { background: #3562bd; color: #ffffff; }
#content input[type="submit"]:hover, #content button:hover, #content .button:hover, #content a.button:hover { background: #294f9e; color: #ffffff; }
#content #toolbar form input[type="submit"], #content .actions input[type="submit"], #content .actions button, #content .actions .button { background: #3562bd; color: #ffffff; }
#content #toolbar form input[type="submit"]:hover, #content .actions input[type="submit"]:hover, #content .actions button:hover, #content .actions .button:hover { background: #294f9e; color: #ffffff; }
#content .deletelink, #content .deletelink-box a { background: #a33e3e !important; color: #ffffff !important; }
input[type="submit"].default { background: #3562bd; }
input[type="submit"]:active, button:active, .button:active, a.button:active { transform: translateY(1px); }
input[type="submit"]:disabled, button:disabled, .button[aria-disabled="true"] { cursor: not-allowed; opacity: .55; }
input:focus-visible, textarea:focus-visible, select:focus-visible,
button:focus-visible, a:focus-visible, input[type="submit"]:focus-visible {
  outline: 3px solid #a9c2fa;
  outline-offset: 2px;
}
.deletelink, .deletelink-box a { background: #a33e3e !important; color: #ffffff !important; }
.object-tools { display: flex; gap: 7px; margin-top: -49px; }
.object-tools li { float: none; }
.object-tools a:link, .object-tools a:visited {
  border-radius: 8px;
  padding: 9px 13px;
  background: #3562bd;
  color: #ffffff;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
}
.submit-row {
  position: sticky;
  bottom: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 22px 0 0;
  padding: 14px;
  border: 1px solid #dce2eb;
  border-radius: 9px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 -8px 25px rgba(32, 44, 67, 0.08);
  backdrop-filter: blur(8px);
}
.submit-row input { margin: 0; }
.submit-row a.deletelink { margin-left: auto; }

/* Главная административной панели */
.dashboard #content { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 22px; }
.dashboard #content > h1 { grid-column: 1 / -1; }
.dashboard #content-main { min-width: 0; }
.dashboard #content-related { margin: 0; width: auto; }
.dashboard #content-related .module { padding: 16px; }
.dashboard #content-related h2 { margin: -16px -16px 14px; }

/* Экран входа */
body.login { display: grid; place-items: center; min-height: 100vh; padding: 18px; background: #f2f4f8; }
.login #container { width: min(440px, 100%); min-height: 0; border: 1px solid #dce2eb; border-radius: 13px; background: #ffffff; box-shadow: 0 24px 70px rgba(32, 44, 67, 0.14); }
.login #header { min-height: 88px; padding: 18px 22px; border-radius: 13px 13px 0 0; }
.login #branding { min-width: 0; }
.login #nav-global, .login .back-to-dashboard { display: none; }
.login .main { background: transparent; }
.login #content { padding: 26px; }
.login #content-main { width: 100%; }
.login .form-row { display: block; padding: 10px 0; }
.login .form-row label { display: block; margin-bottom: 6px; padding: 0; }
.login .form-row input { width: 100%; }
.login .submit-row { position: static; padding: 12px 0 0; border: 0; box-shadow: none; backdrop-filter: none; }
.login .submit-row input { width: 100%; }

/* Уведомления */
ul.messagelist { max-width: 1480px; margin: 18px auto 0; padding: 0 32px; }
ul.messagelist li { border-radius: 9px; background-position: 12px 14px; }
.errornote { border-radius: 9px; }

@media (max-width: 1024px) {
  #content { padding: 22px 20px 40px; }
  #nav-sidebar { width: 205px; flex-basis: 205px; }
  .dashboard #content { grid-template-columns: 1fr; }
  .dashboard #content-related { width: 100%; }
  .form-row { grid-template-columns: 160px minmax(0, 1fr); }
}

@media (max-width: 767px) {
  #header { min-height: auto; padding: 12px 14px; flex-wrap: wrap; gap: 10px; }
  #branding { min-width: 0; }
  #nav-global { order: 3; width: 100%; margin: 0; }
  .admin-global-nav { width: 100%; flex-wrap: wrap; overflow: visible; padding-bottom: 2px; }
  .admin-shortcuts { display: flex; flex: 1 1 100%; flex-wrap: wrap; }
  .back-to-dashboard { flex: 0 0 auto; justify-content: center; }
  #user-tools { margin-left: auto; }
  div.breadcrumbs { padding: 11px 14px; overflow-x: auto; white-space: nowrap; }
  #content { padding: 18px 12px 34px; }
  #content h1 { padding-right: 0; font-size: 22px; }
  #nav-sidebar { width: 220px; flex-basis: 220px; }
  .form-row { display: block; padding: 13px 0; }
  .form-row label { display: block; margin-bottom: 6px; padding: 0; }
  .form-row input:not([type="checkbox"]):not([type="radio"]),
  .form-row textarea,
  .form-row select { width: 100%; }
  fieldset.module { padding-right: 14px; padding-left: 14px; }
  .object-tools { float: none; margin: 0 0 15px; padding: 0; }
  .object-tools li { float: none; }
  .object-tools a { display: block; text-align: center; }
  .submit-row { flex-wrap: wrap; }
  .submit-row input, .submit-row p, .submit-row a { flex: 1 1 auto; text-align: center; }
  #changelist-filter { margin-left: 0; }
  #toolbar form input[type="text"] { min-width: 0; width: 100%; }
  .inline-group { overflow-x: auto; }
  ul.messagelist { padding: 0 12px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
