/* Shared foundation. Layout dimensions are defined once, rather than by patch layers. */
:root {
  --navy: #182d3d; --navy-deep: #122330; --paper: #f5f6f7;
  --ink: #1c2c37; --muted: #64727c; --line: #dce2e6;
  --accent: #9bc6bd; --white: #fff;
  --sidebar-width: 300px; --sidebar-rail: 72px;
  --page-x: 44px; --page-top: 28px; --page-bottom: 20px;
  --rating-group-height: 42px; --rating-subhead-height: 32px;
  --rating-header-height: calc(var(--rating-group-height) + var(--rating-subhead-height));
}
* { box-sizing: border-box; }
html { scrollbar-gutter: stable; }
body { margin: 0; font-family: Arial, Helvetica, sans-serif; color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.5; }
button, input, textarea, select { font: inherit; }
button, a, input { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
a { color: inherit; }
button:focus-visible, a:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, [tabindex="0"]:focus-visible { outline: 3px solid #428caa; outline-offset: 3px; }
h1, h2, p, figure { margin: 0; }
h1, h2 { font-weight: 500; letter-spacing: -.035em; }
h1 { font-size: 32px; line-height: 1.15; }
h2 { font-size: 30px; line-height: 1.2; }
[hidden] { display: none !important; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; border: 0; }
.muted { color: var(--muted); }
.eyebrow { font-size: 11px; letter-spacing: .16em; font-weight: 700; }
.skip { position: fixed; top: -100px; left: 20px; background: white; padding: 12px; z-index: 20; }
.skip:focus { top: 10px; }
::selection { background: #c7e1dc; color: var(--ink); }

/* Portal shell: one viewport; only navigation and working tables scroll. */
.portal { display: grid; grid-template-columns: var(--sidebar-width) minmax(0, 1fr); height: 100vh; height: 100dvh; overflow: hidden; }
.sidebar { min-width: 0; min-height: 0; overflow: auto; background: var(--navy); color: white; padding: 24px 22px; display: flex; flex-direction: column; }
.sidebar-toggle-row { display: flex; flex: 0 0 auto; justify-content: flex-end; margin-bottom: 14px; }
.sidebar-toggle { width: 32px; height: 32px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid #607685; border-radius: 4px; background: transparent; color: #d2dce3; padding: 6px; }
.sidebar-toggle:hover, .logout-icon-button:hover { background: #2a475a; color: white; border-color: var(--accent); }
.sidebar-toggle svg { width: 20px; height: 20px; }
.sidebar-identity { flex: 0 0 auto; min-width: 0; }
.crests { display: flex; align-items: center; gap: 12px; padding: 0 8px; margin-bottom: 26px; }
.crests figure { display: flex; justify-content: center; flex: 1; min-width: 0; }
.crests img { display: block; height: 62px; width: 54px; object-fit: contain; }
.crest-divider { flex: 0 0 1px; height: 62px; background: #425564; }
.program-title { margin: 0 8px 24px; font-size: 10.25px; line-height: 1.6; font-weight: 700; color: var(--white); }
.program-title > span { display: block; }
.sidebar nav { display: grid; flex: 0 0 auto; gap: 3px; }
.sidebar nav a { display: flex; align-items: center; gap: 11px; padding: 11px 10px; font-size: 13px; line-height: 1.4; border-radius: 4px; border-left: 2px solid transparent; color: #d2dce3; text-decoration: none; min-width: 0; }
.sidebar nav a:hover { background: #223f52; }
.sidebar nav a.active { background: #2a475a; color: white; border-left-color: var(--accent); }
.nav-text { min-width: 0; overflow-wrap: break-word; }
.nav-icon { width: 21px; height: 21px; flex-shrink: 0; color: #b5c7d3; }
.sidebar nav .active .nav-icon { color: var(--accent); }
.sidebar-logout { margin-top: auto; padding: 28px 8px 0; flex: 0 0 auto; }
.logout-icon-button { display: inline-flex; align-items: center; justify-content: center; width: 44px; height: 44px; padding: 10px; border: 1px solid #607685; border-radius: 4px; background: transparent; color: #d2dce3; }
.logout-icon-button svg { width: 22px; height: 22px; }
.portal.sidebar-collapsed { grid-template-columns: var(--sidebar-rail) minmax(0, 1fr); }
.sidebar-collapsed .sidebar { padding: 18px 10px 24px; }
.sidebar-collapsed .sidebar-toggle-row { justify-content: center; margin-bottom: 20px; }
.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
.sidebar-collapsed .sidebar-identity, .sidebar-collapsed .nav-text { display: none; }
.sidebar-collapsed .sidebar nav a { justify-content: center; padding: 11px 0; min-height: 44px; }
.sidebar-collapsed .sidebar-logout { padding: 28px 0 0; align-self: center; }
.workspace { min-width: 0; min-height: 0; }
.workspace main { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; padding: var(--page-top) var(--page-x) var(--page-bottom); overflow: auto; }
.workspace .data-main { overflow: hidden; }

/* Working table controls and containment. */
.table-toolbar { display: flex; flex: 0 0 auto; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 18px; min-width: 0; }
.search-field { position: relative; flex: 1; max-width: 470px; min-width: 0; }
.search-field > svg { position: absolute; left: 14px; top: 14px; width: 16px; height: 16px; color: var(--muted); pointer-events: none; }
.search-field input { display: block; height: 44px; width: 100%; min-width: 0; padding: 10px 14px 10px 40px; border: 1px solid #aebbc5; border-radius: 4px; background: var(--white); color: var(--ink); font-size: 13px; }
.mobile-table-hint { display: none; flex: 0 0 auto; font-size: 11px; color: var(--muted); margin-bottom: 12px; }
.table-scroll { flex: 1 1 0; min-height: 0; min-width: 0; max-width: 100%; overflow: auto; overscroll-behavior: contain; background: var(--white); border: 1px solid var(--line); border-radius: 4px; scrollbar-gutter: stable; scrollbar-color: #a7b8c3 #edf1f3; }
.data-table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; text-align: left; font-size: 13px; line-height: 1.5; }
.data-table th, .data-table td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; overflow-wrap: anywhere; }
.data-table thead th { position: sticky; top: 0; z-index: 3; background: #edf1f3; font-size: 12px; line-height: 18px; font-weight: 600; height: 60px; color: #435462; border-bottom-color: #cad3da; }
.data-table .number-col { width: 55px; }
.data-table tbody th { font-weight: 400; }
.row-number { color: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.rating-table { min-width: 880px; }
.rating-table .max-col { width: 66px; }
.rating-table .value-col { width: 106px; }
.rating-table .score-col { width: 92px; }
.rating-table th, .rating-table td { padding: 7px 10px; }
.rating-table thead th { padding: 4px 10px; }
.rating-table thead tr:first-child th { height: var(--rating-group-height); top: 0; }
.rating-table thead tr:first-child th[rowspan] { height: var(--rating-header-height); }
.rating-table thead tr:first-child th[colspan] { text-align: center; }
.rating-table thead th span { font-weight: 400; margin-left: 3px; }
.rating-table thead tr:last-child th { height: var(--rating-subhead-height); top: var(--rating-group-height); text-align: center; font-weight: 400; }
.rating-table td:nth-child(n+3) { text-align: center; }
.rating-table .max-score { color: #526875; text-align: center; font-weight: 600; font-variant-numeric: tabular-nums; font-size: 12px; white-space: nowrap; overflow-wrap: normal; }
.rating-table .total-row th, .rating-table .total-row td { position: sticky; top: var(--rating-header-height); z-index: 2; background: var(--navy); color: white; height: 52px; border-bottom: 0; }
.rating-table .total-row th { padding-left: 12px; font-size: 18px; font-weight: 600; }
.total-row output { display: block; font-size: 21px; font-weight: 600; font-variant-numeric: tabular-nums; }
.rating-table .total-row .max-score { color: white; font-size: 20px; }
.rating-table .block-row th { background: #e8edef; font-size: 11px; font-weight: 600; padding: 9px 12px; color: #435462; }
.block-row th > span { display: inline-block; min-width: 26px; color: var(--muted); }
.indicator-row:hover, .subindicator-row:hover { background: #f5f8f8; }
.method-button, .event-name { display: inline; color: var(--ink); border: 0; background: none; padding: 0; max-width: 100%; text-align: left; font: inherit; line-height: inherit; overflow-wrap: anywhere; cursor: pointer; }
.event-name:hover { color: #286179; text-decoration: underline; text-underline-offset: 3px; }
.composite-row { background: #f5f7f8; }
.composite-row .method-button { font-weight: 600; }
.rating-table .subindicator-row th { padding-left: 24px; font-size: 12px; color: #455864; }
.rating-table .subindicator-row .row-number { padding-left: 12px; font-size: 10px; }
.score-input { display: block; width: 100%; min-width: 0; height: 30px; border: 1px solid #ccd6dc; border-radius: 3px; background: white; color: var(--ink); text-align: center; padding: 4px 8px; font-size: 13px; font-variant-numeric: tabular-nums; }
.score-input::placeholder { color: #64727c; text-align: center; }
.score-input:hover { border-color: #96acb9; }
.score-input[readonly] { border-color: transparent; background: #edf1f3; color: #435462; cursor: default; }
.score-input[readonly]:hover { border-color: #ccd6dc; }
.score-input[data-dirty="true"] { border-color: #bb8b46; background: #fffaf0; }
.score-input[aria-invalid="true"] { border-color: #a53737; background: #fff1f1; }
.computed-score { font-weight: 600; font-size: 13px; font-variant-numeric: tabular-nums; }
.table-error { flex: 0 0 auto; padding: 12px 14px; border-radius: 4px; background: #f7e8e8; color: #8d2525; font-size: 12px; margin-bottom: 12px; }
#save-status { color: #356457; }
#save-status[data-state="unsaved"] { color: #8a4e12; }
#save-status[data-state="saving"] { color: var(--muted); }

/* Plan table and actions. */
.primary-button, .secondary-button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 10px 18px; border-radius: 4px; font-size: 13px; font-weight: 600; }
.primary-button { border: 1px solid var(--navy); background: var(--navy); color: var(--white); }
.primary-button:hover { background: #28465c; }
.primary-button:disabled { cursor: wait; opacity: .65; }
.secondary-button { border: 1px solid #aebbc5; color: var(--ink); background: var(--white); }
.secondary-button:hover { background: #edf1f3; }
.plan-toolbar { justify-content: flex-end; }
.plan-table { min-width: 790px; }
.plan-table .responsible-col { width: 180px; }
.plan-table .date-col { width: 135px; }
.plan-table .status-col { width: 125px; }
.plan-table .event-name { font-weight: 500; }
.event-due { font-variant-numeric: tabular-nums; font-size: 12px; }
.status-badge { display: inline-block; padding: 5px 9px; border-radius: 3px; font-size: 11px; color: #53616b; background: #edf0f2; white-space: nowrap; }
.status-badge[data-status="В работе"] { color: #245d7a; background: #e7f0f6; }
.status-badge[data-status="Выполнено"] { color: #2c6551; background: #e5f0ea; }
.status-badge[data-status="Отложено"] { color: #865d23; background: #f6efdf; }
.plan-table .table-empty { padding: 0; }
.table-empty { text-align: center; color: var(--muted); padding: 60px 24px; }
.empty-plan-content { padding: 60px 24px; }
.empty-plan-symbol { font-size: 26px; color: #8d9fa9; margin-bottom: 16px; }
.table-empty h2 { color: var(--ink); font-size: 22px; margin-bottom: 10px; }
.table-empty p { font-size: 13px; }
#event-status { flex: 0 0 auto; color: #356457; font-size: 12px; margin-top: 10px; }
#event-status:empty { display: none; }

/* Dialogs use their own scroll container on every screen size. */
dialog { color: var(--ink); border: 1px solid #ccd6dc; border-radius: 8px; padding: 0; background: var(--white); box-shadow: 0 18px 70px #12233033; max-height: 90vh; max-height: 90dvh; overflow: auto; }
dialog::backdrop { background: #12233099; }
.method-dialog { width: min(840px, calc(100vw - 40px)); }
.dialog-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 24px; padding: 28px 30px 18px; }
.dialog-heading .eyebrow { color: var(--muted); font-size: 10px; margin-bottom: 12px; }
.dialog-heading h2 { font-size: 25px; line-height: 1.25; overflow-wrap: anywhere; }
.dialog-close { flex-shrink: 0; border: 1px solid var(--line); width: 36px; height: 36px; border-radius: 4px; background: white; color: var(--muted); font-size: 25px; line-height: 1; }
.dialog-close:hover { background: #edf1f3; }
.method-source { padding: 0 30px 20px; color: var(--muted); font-size: 11px; border-bottom: 1px solid var(--line); }
.method-body { max-height: 49vh; max-height: 49dvh; overflow: auto; padding: 24px 30px; font-size: 14px; line-height: 1.7; overscroll-behavior: contain; overflow-wrap: anywhere; }
.method-body p + p { margin-top: 12px; }
.method-subheading { font-weight: 600; }
.method-body .selected-method-part { background: #eaf3ef; padding: 8px 12px; border-radius: 3px; }
.method-formula { background: #edf1f3; padding: 14px 18px; font-size: 15px; text-align: center; }
.method-maximum { padding: 10px 12px; background: #edf1f3; border-radius: 3px; font-weight: 600; }
.method-max-note { padding: 12px; background: #f6efdf; border-radius: 3px; color: #76501e; }
.dialog-footer { border-top: 1px solid var(--line); display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 16px; padding: 18px 30px; font-size: 12px; }
.dialog-footer a { color: #286179; text-underline-offset: 3px; }
.event-dialog { width: min(620px, calc(100vw - 40px)); }
.event-fields { padding: 0 30px 26px; }
.event-fields label { display: block; font-size: 12px; font-weight: 600; margin: 18px 0 8px; }
.event-fields input, .event-fields textarea, .event-fields select { display: block; width: 100%; min-width: 0; border: 1px solid #aebbc5; border-radius: 4px; padding: 11px 12px; font: inherit; color: var(--ink); background: white; }
.event-fields textarea { resize: vertical; }
.required-note { float: right; font-weight: 400; font-size: 10px; color: var(--muted); }
.field-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.event-fields .table-error { margin-top: 18px; margin-bottom: 0; }
.event-dialog .dialog-footer { justify-content: flex-end; }

/* Login and registry. */
.login-layout { min-height: 100vh; min-height: 100dvh; display: grid; grid-template-columns: 1fr; }
.login-side { display: flex; align-items: center; justify-content: center; padding: 40px 24px; }
.login-box { max-width: 370px; width: 100%; }
.login-box h1 { font-size: 32px; margin-bottom: 12px; }
.login-box form { margin-top: 32px; }
.login-box label { display: block; font-weight: 600; font-size: 13px; margin: 20px 0 8px; }
.login-box input { width: 100%; height: 50px; background: white; border: 1px solid #aebbc5; border-radius: 4px; padding: 12px 14px; }
.login-box button { display: flex; justify-content: space-between; width: 100%; margin-top: 28px; background: var(--navy); color: white; border: 0; border-radius: 4px; padding: 14px 18px; font-weight: 600; }
.login-box button:hover { background: #28465c; }
.error { padding: 12px 14px; background: #f7e8e8; border-left: 3px solid #a53737; color: #8d2525; margin-top: 24px; font-size: 13px; }
.empty-state { padding: 48px 16px; text-align: center; flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; }
.document-mark { width: 44px; height: 56px; border: 1px solid #9eafb9; border-radius: 3px; padding: 17px 10px; margin-bottom: 28px; }
.document-mark span { display: block; height: 1px; background: #9eafb9; margin-bottom: 7px; }
.document-mark span:last-child { width: 60%; }
.empty-state .eyebrow { color: var(--muted); font-size: 10px; margin-bottom: 14px; }
.empty-state h2 { font-size: 26px; }
.empty-state > p:last-child { color: var(--muted); font-size: 14px; line-height: 1.75; margin-top: 14px; }

/* Responsive dimensions and behavior live together. */
@media (min-width: 1500px) { :root { --page-x: 60px; } }
@media (min-width: 701px) and (max-width: 1000px) {
  :root { --sidebar-width: 260px; --page-x: 26px; }
  .sidebar { padding-inline: 16px; }
  .program-title { font-size: 9px; }
}
@media (max-width: 1100px) {
  .mobile-table-hint { display: block; }
  .search-field { max-width: none; }
}
@media (max-width: 700px) {
  :root { --page-x: 18px; --page-top: 20px; --page-bottom: 20px; }
  html { scrollbar-gutter: auto; }
  .portal { display: flex; flex-direction: column; height: auto; min-height: 100vh; min-height: 100dvh; overflow: visible; }
  .sidebar { overflow: visible; padding: 18px; }
  .sidebar-toggle-row { margin-bottom: 12px; }
  .sidebar-identity { display: grid; grid-template-columns: 1fr; }
  .crests { max-width: 270px; margin-bottom: 18px; padding: 0 8px; }
  .crests img { height: 48px; }
  .crest-divider { height: 48px; }
  .program-title { max-width: 340px; margin-bottom: 18px; }
  .sidebar nav a { padding: 9px 10px; }
  .sidebar-logout { margin-top: 16px; padding: 0 8px; }
  .portal.sidebar-collapsed .sidebar { display: flex; flex-direction: row; align-items: center; gap: 10px; padding: 12px 18px; }
  .sidebar-collapsed .sidebar-toggle-row { margin: 0; }
  .sidebar-collapsed .sidebar nav { display: flex; flex: 1; gap: 4px; }
  .sidebar-collapsed .sidebar nav a { width: 40px; padding: 9px 0; }
  .sidebar-collapsed .sidebar-logout { margin: 0; padding: 0; }
  .sidebar-collapsed .logout-icon-button { width: 40px; height: 40px; }
  .workspace { width: 100%; }
  .workspace main { height: auto; min-height: 380px; overflow: visible; }
  .workspace .data-main { overflow: visible; }
  .table-scroll { flex: 0 0 auto; max-height: 70vh; max-height: 70dvh; }
  .empty-plan-content { width: calc(100vw - 38px); position: sticky; left: 0; padding: 50px 18px; }
  .table-scroll { border-radius: 0; }
  .method-dialog, .event-dialog { width: calc(100vw - 24px); max-height: 94vh; max-height: 94dvh; }
  .dialog-heading { padding: 22px 18px 16px; gap: 16px; }
  .dialog-heading h2 { font-size: 21px; }
  .method-source { padding: 0 18px 16px; }
  .method-body { max-height: 46vh; max-height: 46dvh; padding: 20px 18px; font-size: 13px; }
  .dialog-footer { padding: 16px 18px; font-size: 11px; }
  .event-fields { padding: 0 18px 24px; }
  .field-pair { grid-template-columns: 1fr; gap: 0; }
  .login-box h1 { font-size: 28px; }
}
@media (prefers-reduced-motion: no-preference) {
  .method-button, .event-name, .primary-button, .secondary-button { transition: color .15s, background-color .15s; }
}
