:root {
    --bg: #f7f8fa;
    --surface: #ffffff;
    --border: #e3e6eb;
    --text: #1f2328;
    --text-muted: #646a73;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --danger: #b42318;
    --danger-bg: #fef3f2;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 12px 24px;
}

.topbar__brand {
    font-weight: 700;
    font-size: 18px;
    color: var(--primary);
}

.topbar__user {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar__name { font-weight: 500; }

.topbar__role {
    font-size: 12px;
    color: var(--text-muted);
    background: #eef2ff;
    padding: 2px 8px;
    border-radius: 10px;
}

.topbar__logout button {
    background: none;
    border: 1px solid var(--border);
    padding: 6px 12px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
}
.topbar__logout button:hover { background: var(--bg); }

.main {
    max-width: 960px;
    margin: 32px auto;
    padding: 0 24px;
}

.login {
    max-width: 380px;
    margin: 80px auto;
    background: var(--surface);
    padding: 32px;
    border-radius: 12px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
}

.login h1 {
    margin: 0 0 20px;
    font-size: 22px;
}

.form { display: flex; flex-direction: column; gap: 14px; }
.form label { display: flex; flex-direction: column; gap: 4px; }
.form label span { font-size: 13px; color: var(--text-muted); }
.form input {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    outline: none;
}
.form input:focus { border-color: var(--primary); }

.btn-primary {
    background: var(--primary);
    color: #fff;
    border: none;
    padding: 10px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    margin-top: 6px;
}
.btn-primary:hover { background: var(--primary-hover); }

.error {
    background: var(--danger-bg);
    color: var(--danger);
    border: 1px solid #fee4e2;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 14px;
    margin-bottom: 14px;
}

.home h1 { margin-top: 0; }
.muted { color: var(--text-muted); }

/* --- Страницы --- */
.page__header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 20px;
}
.page__header h1 { margin: 0; }

/* --- Таблицы --- */
.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.table th, .table td {
    padding: 10px 14px; text-align: left;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: #f9fafb;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #fafbfc; }
.table a { color: var(--primary); text-decoration: none; }
.table a:hover { text-decoration: underline; }

/* --- Бейджи --- */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}
.badge--ok { background: #dcfce7; color: #15803d; }
.badge--off { background: #fef3f2; color: #b42318; }

/* --- Поиск --- */
.search {
    display: flex; gap: 8px; margin-bottom: 16px;
    align-items: center;
}
.search input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
}
.search button {
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
}
.search__reset { color: var(--text-muted); font-size: 13px; margin-left: 8px; }
.link-muted { color: var(--text-muted); text-decoration: none; font-size: 14px; }
.link-muted:hover { text-decoration: underline; }

/* --- Состояния --- */
.empty {
    text-align: center; padding: 48px;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 8px;
}
.empty a { color: var(--primary); }
.warn {
    background: #fffbeb; color: #92400e;
    border: 1px solid #fde68a;
    padding: 10px 14px; border-radius: 6px;
    margin-bottom: 14px; font-size: 14px;
}
.muted { color: var(--text-muted); font-size: 14px; margin-bottom: 14px; }

/* --- Формы --- */
.form--wide { max-width: 700px; }
.form__row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 14px;
}
.form textarea {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    font-family: inherit;
    resize: vertical;
}
.form__actions {
    margin-top: 8px;
    display: flex; gap: 10px;
}
.checkbox {
    flex-direction: row;
    align-items: center;
    gap: 8px;
}
.checkbox input { margin: 0; }
.checkbox span { font-size: 15px; color: var(--text); }

.metadata {
    margin-top: 24px;
    padding: 12px 16px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 13px;
    color: var(--text-muted);
    display: flex; gap: 24px;
}

/* --- Секции формы --- */
.section-title {
    margin-top: 28px;
    margin-bottom: 12px;
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
}
.section-title:first-of-type { margin-top: 8px; }

.worker-block {
    background: #f9fafb;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin-top: 12px;
}

.form select {
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
    background: var(--surface);
}

/* --- Автоподсказки дубликатов --- */
.dup-suggest {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: 8px;
    padding: 12px 16px;
    margin: 8px 0 4px;
}
.dup-suggest__title {
    font-weight: 600;
    color: #92400e;
    font-size: 14px;
    margin-bottom: 8px;
}
.dup-suggest__list {
    list-style: none;
    padding: 0;
    margin: 0;
}
.dup-suggest__item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 0;
    border-top: 1px solid #fde68a;
}
.dup-suggest__item:first-child { border-top: none; }
.dup-suggest__name {
    font-weight: 500;
    color: var(--text);
    flex: 1;
}
.dup-suggest__info {
    color: var(--text-muted);
    font-size: 13px;
}
.dup-suggest__open {
    color: var(--primary);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
    padding: 4px 10px;
    border: 1px solid var(--primary);
    border-radius: 6px;
}
.dup-suggest__open:hover {
    background: var(--primary);
    color: #fff;
}

/* --- Главная: плитки действий --- */
.dashboard h1 { margin-bottom: 4px; }
.dashboard .muted { margin: 0 0 24px; }

.actions {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 14px;
}

.action {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 20px;
    text-decoration: none;
    color: var(--text);
    transition: transform 0.1s, border-color 0.1s, box-shadow 0.1s;
}
.action:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.08);
    transform: translateY(-1px);
}

.action__title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 4px;
    color: var(--text);
}
.action__desc {
    font-size: 13px;
    color: var(--text-muted);
}

.action--primary .action__title {
    color: var(--primary);
}

/* --- Быстрый поиск на главной --- */
.quick-search {
    margin-top: 32px;
}
.quick-search input {
    width: 100%;
    padding: 12px 16px;
    font-size: 15px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    outline: none;
}
.quick-search input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.quick-search__results {
    margin-top: 10px;
}
.quick-search__list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
.quick-search__item {
    border-top: 1px solid var(--border);
}
.quick-search__item:first-child { border-top: none; }

.quick-search__link {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 14px;
    text-decoration: none;
    color: var(--text);
}
.quick-search__link:hover {
    background: #fafbfc;
}
.quick-search__name {
    font-weight: 500;
}
.quick-search__info {
    color: var(--text-muted);
    font-size: 13px;
}
.quick-search__empty {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 8px;
    font-size: 14px;
}

/* --- Навигация в шапке --- */
.topbar__left {
    display: flex;
    align-items: center;
    gap: 16px;
}

.topbar__brand {
    text-decoration: none;
}
.topbar__brand:hover {
    color: var(--primary-hover);
}

.topbar__nav {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 14px;
    padding: 6px 10px;
    border-radius: 6px;
}
.topbar__nav:hover {
    background: var(--bg);
    color: var(--text);
}

/* --- Сетка справочников --- */
.refs-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 16px;
}

.refs-card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    text-decoration: none;
    color: var(--text);
    transition: border-color 0.1s;
}
.refs-card:hover {
    border-color: var(--primary);
}

.refs-card__title {
    font-weight: 600;
    font-size: 15px;
    margin-bottom: 4px;
}
.refs-card__count {
    font-size: 12px;
    color: var(--text-muted);
}

/* --- Подсказка под полем --- */
.hint {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 4px;
}

/* Readonly input visual */
.form input[readonly] {
    background: var(--bg);
    color: var(--text-muted);
    cursor: not-allowed;
}

/* --- Карточка просмотра --- */
.view-section {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px 20px 16px;
    margin-bottom: 16px;
}

.view-dl {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 8px 20px;
    margin: 12px 0 0;
}
.view-dl dt {
    color: var(--text-muted);
    font-size: 14px;
}
.view-dl dd {
    margin: 0;
    color: var(--text);
    font-size: 15px;
}

.view-notes {
    white-space: pre-wrap;
    font-size: 14px;
    color: var(--text);
    margin-top: 8px;
}

/* --- Переключатель режимов (смены) --- */
.mode-switch {
    display: inline-flex;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
    background: var(--surface);
}
.mode-btn {
    padding: 10px 18px;
    background: var(--surface);
    border: none;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-muted);
}
.mode-btn--active {
    background: var(--primary);
    color: #fff;
}

/* --- Поиск работника --- */
.worker-search {
    position: relative;
}
.worker-search input[type="text"] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 15px;
}
.worker-search__results {
    margin-top: 4px;
}
.worker-search__list {
    list-style: none;
    padding: 0;
    margin: 0;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.worker-search__item {
    padding: 10px 14px;
    border-top: 1px solid var(--border);
    cursor: pointer;
}
.worker-search__item:first-child { border-top: none; }
.worker-search__item:hover { background: #fafbfc; }

.selected-worker {
    margin-top: 8px;
    padding: 8px 12px;
    background: #eef2ff;
    border: 1px solid #c7d2fe;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.selected-worker button {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 2px 8px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 14px;
}

/* --- Массовый список работников --- */
.bulk-list { margin-top: 10px; }
.bulk-list__empty { padding: 12px 0; }
.bulk-list__items {
    list-style: none;
    padding: 0;
    margin: 0 0 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
}
.bulk-list__item {
    padding: 8px 12px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 8px;
}
.bulk-list__item:first-child { border-top: none; }
.bulk-list__item strong { flex: 1; }
.bulk-remove {
    background: none;
    border: 1px solid var(--border);
    padding: 2px 10px;
    border-radius: 6px;
    cursor: pointer;
    color: var(--text-muted);
}
.bulk-remove:hover {
    background: var(--danger-bg);
    color: var(--danger);
}

/* --- Inline-редактирование в таблице --- */
.notes-edit {
    width: 100%;
    padding: 5px 8px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    font-size: 14px;
    font-family: inherit;
}
.notes-edit:hover {
    border-color: var(--border);
    background: var(--surface);
}
.notes-edit:focus {
    border-color: var(--primary);
    background: var(--surface);
    outline: none;
}
.notes-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: 6px;
}

/* --- Компактный инпут в форме --- */
.form label.compact input {
    padding: 7px 10px;
    font-size: 14px;
}

/* --- Подсветка новеньких в списке смен --- */
.row-newbie {
    background: #fdf2f8 !important;
}
.row-newbie:hover {
    background: #fce7f3 !important;
}
.badge--new {
    background: #fce7f3;
    color: #9d174d;
    margin-left: 6px;
}

/* --- Баннер успешного сохранения --- */
.success {
    background: #dcfce7;
    color: #15803d;
    border: 1px solid #bbf7d0;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 14px;
    font-size: 14px;
}

/* --- Горизонтальная форма ввода смены --- */
.form-horizontal { width: 100%; }

.shift-row {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    padding: 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: 16px;
}

.shift-row__field {
    display: flex;
    flex-direction: column;
    flex: 1 1 140px;
    min-width: 120px;
    position: relative;
}

.shift-row__field label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 4px;
    display: block;
}

.shift-row__field input,
.shift-row__field select {
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}

.shift-row__field--small {
    flex: 0 0 110px;
}

.shift-row__field--wide {
    flex: 1 1 200px;
}

.shift-row__field--action {
    flex: 0 0 auto;
}
.shift-row__field--action button {
    padding: 8px 18px;
    font-size: 14px;
}

/* --- Выпадающий список автокомплита в горизонтальной форме --- */
.shift-row__field .worker-search__results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    z-index: 10;
    margin-top: 2px;
}
.shift-row__field .worker-search__list {
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
}

/* --- Новые размеры полей в горизонтальной форме --- */
.shift-row {
    flex-wrap: wrap;            /* переносим при нехватке места */
}

.shift-row__field--xs {
    flex: 0 0 80px;
}
.shift-row__field--sm {
    flex: 0 0 130px;
}
.shift-row__field--small {
    flex: 0 0 100px;
}
.shift-row__field {
    flex: 1 1 130px;
    min-width: 100px;
}
.shift-row__field--wide {
    flex: 1 1 160px;
}

/* На широких экранах всё в строку; на узких — переносим (fallback) */
@media (max-width: 1200px) {
    .shift-row { flex-wrap: wrap; overflow-x: visible; }
}

/* --- Расширенная страница для ввода смен --- */
body.page-shifts .main,
body.page-brigadier-shifts .main {
    max-width: 100%;
    padding: 0 24px;
}

/* --- Кнопка отмены смены --- */
.btn-cancel {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 2px 10px;
    font-size: 16px;
    line-height: 1;
    border-radius: 6px;
    cursor: pointer;
}
.btn-cancel:hover {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: var(--danger);
}

/* --- Inline-поля смены --- */
.inline-field {
    padding: 3px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    font-size: 13px;
    font-family: inherit;
    max-width: 100%;
    cursor: pointer;
}
.inline-field:hover {
    border-color: var(--border);
    background: var(--surface);
}
.inline-field:focus {
    border-color: var(--primary);
    background: var(--surface);
    outline: none;
}
.inline-field--saving {
    border-color: #fde047;
    background: #fefce8;
}
.inline-field--ok {
    border-color: #86efac;
    background: #f0fdf4;
}
.inline-field--error {
    border-color: var(--danger);
    background: var(--danger-bg);
}

/* --- Сводка смен за сегодня --- */
.day-summary {
    margin-top: 32px;
    padding: 14px 18px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 10px;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 20px;
    align-items: center;
}
.day-summary__total {
    font-size: 16px;
    color: #1e40af;
}
.day-summary__depts {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
}
.day-summary__dept {
    font-size: 14px;
    color: #1e40af;
    padding: 3px 10px;
    background: #fff;
    border: 1px solid #bfdbfe;
    border-radius: 20px;
}
