@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Condensed:wght@400;500;600;700&display=swap&subset=cyrillic');

:root {
    color-scheme: light;
    --color-bg: #f3f2ef;
    --color-surface: #fffefd;
    --color-surface-muted: #f6f3f0;
    --color-text: #1f2328;
    --color-text-muted: #5d6672;
    --color-border: #d9dde3;
    --color-accent: #d4553f;
    --color-accent-soft: #fbe5e0;
    --color-danger: #c7352a;
    --color-success: #2f7f55;
    --color-warning: #a67625;
    --color-disabled: #a4adb9;
    --shadow-soft: 0 2px 8px rgba(28, 35, 39, 0.04);
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --color-bg: #171a20;
        --color-surface: #1f242c;
        --color-surface-muted: #262c35;
        --color-text: #eef2f6;
        --color-text-muted: #aeb8c4;
        --color-border: #333b47;
        --color-accent: #eb6a54;
        --color-accent-soft: rgba(235, 106, 84, 0.18);
        --color-danger: #ff7868;
        --color-success: #5db184;
        --color-warning: #d8a85a;
        --color-disabled: #778293;
        --shadow-soft: none;
    }
}

* { box-sizing: border-box; }
body {
    margin: 0;
    background: var(--color-bg);
    color: var(--color-text);
    font-family: "IBM Plex Sans Condensed", "Segoe UI Emoji", "Apple Color Emoji", system-ui, sans-serif;
    font-size: 15px;
    line-height: 1.35;
}
a { color: var(--color-accent); }
.app { min-height: 100vh; }

.topbar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between;
    gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--color-border);
    background: color-mix(in srgb, var(--color-surface) 92%, transparent);
    backdrop-filter: blur(8px);
}
.brand { display: flex; flex-direction: column; gap: 2px; }
.brand strong { font-size: 16px; line-height: 1.2; }
.brand span, .muted { color: var(--color-text-muted); font-size: 13px; }
.userbar { display: flex; align-items: center; justify-content: flex-end; gap: 8px; }

.studio-chip { display: inline-flex; flex-direction: column; min-height: 34px; padding: 4px 8px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface-muted); font-weight: 600; }
.studio-chip small { color: var(--color-text-muted); font-weight: 500; }
.compact-select { min-width: 200px; }
.avatar { width: 30px; height: 30px; border-radius: 50%; object-fit: cover; background: var(--color-border); }
.shell { width: min(1040px, 100%); margin: 0 auto; padding: 10px; }

.panel, .hero, .sidebar { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: 10px; box-shadow: var(--shadow-soft); }
.sidebar { padding: 12px; }
.hero { width: min(860px, calc(100% - 16px)); margin: 12px auto; padding: 16px; }
.hero h1 { margin: 0 0 8px; font-size: 24px; line-height: 1.1; }
.hero p { margin: 0 0 8px; color: var(--color-text-muted); font-size: 15px; }
.content { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.panel { padding: 12px; }
.panel h2 { margin: 0 0 8px; font-size: 18px; }
.panel h3 { margin: 0 0 6px; font-size: 16px; }
.main-tabs {
    position: sticky;
    top: 58px;
    z-index: 8;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    box-shadow: var(--shadow-soft);
}
.main-tab { background: transparent; border-color: transparent; color: var(--color-text-muted); }
.main-tab.active { background: var(--color-accent); color: #fff; }
.app-section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.section-head h2 { margin-bottom: 2px; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px; }
.row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.row.split { justify-content: space-between; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.hidden { display: none !important; }
.onboarding-actions { width: min(560px, 100%); margin: 0 auto; }
.onboarding-switcher { display: flex; gap: 8px; justify-content: center; }
.compact-stack { gap: 6px; }
.project-list, .project-settings, .project-blocks { margin-top: 8px; }
.compact-project-list { display: flex; flex-direction: column; gap: 6px; }
.project-summary-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) auto;
    gap: 6px 10px;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
}
.project-summary-main { display: flex; flex-wrap: wrap; align-items: baseline; gap: 8px; min-width: 0; }
.project-summary-main strong { overflow-wrap: anywhere; }
.project-summary-actions { justify-self: end; }
.project-summary-blocks { grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 5px; }
.project-editor-actions { align-self: end; }
.shift-wizard { margin: 0; }
.shift-step {
    margin: 0;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    padding: 10px;
}
.shift-step[disabled] { opacity: .58; }
.shift-step-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.shift-step-head h3 { margin: 0; font-size: 16px; }
.shift-settings-tabs { margin: 2px 0 8px; }
.shift-settings-panel { display: flex; flex-direction: column; gap: 8px; }
.shift-settings-panel[hidden] { display: none; }
.quick-create-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 8px; margin-top: 8px; }
.quick-create-box { border: 1px dashed var(--color-border); border-radius: 8px; padding: 8px; background: var(--color-surface-muted); }
.quick-create-box strong { display: block; margin-bottom: 6px; font-size: 13px; }
.tabs { display: inline-flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; padding: 3px; border: 1px solid var(--color-border); border-radius: 9px; background: var(--color-surface-muted); }

button, .button {
    display: inline-flex; align-items: center; justify-content: center; min-height: 34px; padding: 0 10px;
    border: 1px solid transparent; border-radius: 8px; background: var(--color-accent); color: #fff;
    font: inherit; font-weight: 600; text-decoration: none; cursor: pointer; white-space: nowrap;
}
button:hover, .button:hover { filter: brightness(0.95); }
button:disabled { cursor: not-allowed; background: var(--color-disabled); border-color: var(--color-disabled); color: #fff; opacity: 1; }
button.secondary, .button.secondary { background: var(--color-surface-muted); border-color: var(--color-border); color: var(--color-text); }
button.danger { background: transparent; border-color: color-mix(in srgb, var(--color-danger) 42%, var(--color-border)); color: var(--color-danger); }
button.ghost { background: transparent; border-color: transparent; color: var(--color-accent); padding: 0; min-height: auto; }

.tabs button.studio-tab { background: transparent; border-color: transparent; color: var(--color-text-muted); }
.tabs button.studio-tab.active { background: var(--color-accent-soft); border-color: var(--color-accent); color: var(--color-accent); }

input, select, textarea {
    width: 100%; min-height: 34px; border: 1px solid var(--color-border); border-radius: 8px;
    background: var(--color-surface-muted); color: var(--color-text); font: inherit; padding: 6px 9px;
}
input:focus, select:focus, textarea:focus, button:focus-visible, .button:focus-visible {
    outline: none; border-color: var(--color-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-accent) 20%, transparent);
}
textarea { min-height: 70px; resize: vertical; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--color-text-muted); font-size: 12px; font-weight: 600; }

.card { border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface); padding: 10px; }
.studio-button { width: 100%; justify-content: flex-start; margin-bottom: 6px; text-align: left; }
.studio-button.active { border-color: var(--color-accent); color: var(--color-accent); background: var(--color-accent-soft); }
.badge { display:inline-flex; align-items:center; min-height:20px; padding:0 7px; border-radius:999px; background:var(--color-surface-muted); color:var(--color-text); font-size:11px; font-weight:700; }
.badge.ok { background: color-mix(in srgb, var(--color-success) 18%, transparent); color: var(--color-success); }
.badge.warn { background: color-mix(in srgb, var(--color-warning) 20%, transparent); color: var(--color-warning); }
.badge.danger { background: color-mix(in srgb, var(--color-danger) 20%, transparent); color: var(--color-danger); }

.table-wrap { width:100%; overflow-x:auto; border:1px solid var(--color-border); border-radius:8px; }
table { width:100%; border-collapse:collapse; min-width:720px; background: var(--color-surface); }
.calendar-wrap table { min-width:880px; }
.calendar-toolbar { display: flex; flex-wrap: wrap; align-items: end; gap: 8px; margin-bottom: 8px; }
.calendar-toolbar .tabs { margin-bottom: 0; }
.matrix th { min-width: 170px; }
.matrix th:first-child, .matrix .date-cell { min-width: 130px; position: sticky; left: 0; z-index: 1; background: var(--color-surface); }
.matrix .date-cell b { display:block; }
.matrix .date-cell small { display:block; margin-top:2px; font-size:11px; color: var(--color-text-muted); }
.calendar-project { display:block; color:var(--color-text); font-size:12px; }
.matrix th small { display:block; margin-top:2px; color:var(--color-text-muted); font-size:11px; font-weight:600; text-transform:none; }
.matrix-cell {
    display: block;
    width: 100%;
    min-width: 150px;
    min-height: auto;
    margin-bottom: 6px;
    padding: 8px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface-muted);
    color: var(--color-text);
    font-size: 12px;
    font-weight: 500;
    line-height: 1.35;
    text-align: left;
    white-space: normal;
}
.matrix-cell-button { cursor: pointer; }
.matrix-cell-button:hover { filter: brightness(0.98); border-color: var(--color-accent); }
.master-cell {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 64px;
    margin-bottom: 0;
}
.master-cell.cell-empty {
    align-items: flex-start;
    justify-content: center;
    border-color: transparent;
    background: transparent;
    color: color-mix(in srgb, var(--color-text-muted) 55%, transparent);
}
.master-cell.cell-shift_without_mode_data {
    border-style: dashed;
    background: color-mix(in srgb, var(--color-surface-muted) 72%, transparent);
    color: var(--color-text-muted);
}
.master-cell.cell-filled {
    background: var(--color-surface-muted);
    border-color: var(--color-border);
}
.master-cell:hover { border-color: var(--color-accent); color: var(--color-text); }
.master-cell small { display: inline-flex; width: fit-content; }
.conflict-mark { color: var(--color-warning); font-weight: 700; }
.matrix-cell-draft {
    color: var(--color-warning);
    background-color: color(srgb 0.847059 0.658824 0.352941 / 0.2);
}
.matrix-empty-cell {
    width: 100%;
    min-height: 58px;
    padding: 8px;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--color-text-muted);
    justify-content: flex-start;
}
.matrix-empty-cell:hover { border-color: var(--color-border); background: var(--color-surface-muted); color: var(--color-accent); }
th, td { border-bottom:1px solid var(--color-border); padding:7px 6px; text-align:left; vertical-align:top; }
th { color:var(--color-text-muted); font-size:11px; text-transform:uppercase; letter-spacing: .04em; }

.notice { border:1px solid var(--color-border); border-left:3px solid var(--color-accent); background:var(--color-accent-soft); padding:8px 10px; border-radius:8px; font-size: 13px; }
.notice.error { border-left-color: var(--color-danger); background: color-mix(in srgb, var(--color-danger) 14%, transparent); }
.assignment-row { display:grid; grid-template-columns: minmax(160px,1fr) minmax(130px,.8fr) minmax(150px,1fr) auto; gap:6px; align-items:end; }
.department-assignment-row { grid-template-columns: minmax(180px,1fr) minmax(150px,.8fr) minmax(180px,1fr) auto; }
.modal-context { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 8px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface-muted); }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.2fr) minmax(260px, .8fr); gap: 12px; }
.settings-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 8px; }
.settings-placeholders { display: flex; flex-direction: column; gap: 6px; }
.settings-placeholder { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 9px 10px; border: 1px solid var(--color-border); border-radius: 8px; background: var(--color-surface-muted); }
.loading { padding:24px; }
.toast { position:fixed; right:10px; bottom:10px; z-index:40; display:flex; align-items:center; gap:8px; width:min(380px, calc(100vw - 20px)); padding:10px; border:1px solid var(--color-border); border-left:3px solid var(--color-accent); border-radius:8px; background:var(--color-surface); box-shadow: var(--shadow-soft); }
.toast.error { border-left-color: var(--color-danger); }
.toast span { flex:1; font-size:13px; }
.disabled-block { opacity: .45; pointer-events: none; }
.modal-overlay {
    position: fixed; inset: 0; z-index: 1000;
    background: color-mix(in srgb, #000 44%, transparent);
    backdrop-filter: blur(8px);
    display: flex; align-items: center; justify-content: center; padding: 18px;
}
.modal-window {
    width: min(980px, 100%); max-height: calc(100vh - 36px); background: var(--color-surface); border: 1px solid var(--color-border);
    border-radius: 12px; display: flex; flex-direction: column; overflow: hidden;
}
.modal-header {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    padding: 12px; border-bottom: 1px solid var(--color-border); position: sticky; top: 0; background: var(--color-surface); z-index: 1;
}
.modal-header h2 { margin: 0; }
.modal-body { padding: 12px; overflow: auto; }
body.modal-open { overflow: hidden; }

@media (max-width: 900px) {
    .shell { padding: 8px; }
    .topbar { align-items:flex-start; flex-direction:column; }
    .main-tabs { top: 0; }
    .userbar { width:100%; justify-content:space-between; }
    .compact-select { min-width: 0; width: 100%; }
    .tabs { width: 100%; }
    .tabs button { flex: 1; }
    .assignment-row { grid-template-columns: 1fr; }
    .department-assignment-row { grid-template-columns: 1fr; }
    .project-summary-row { grid-template-columns: 1fr; }
    .project-summary-actions { justify-self: start; }
    .shift-step-head { align-items: flex-start; flex-direction: column; }
    .section-head, .calendar-toolbar { align-items: stretch; flex-direction: column; }
    .settings-grid { grid-template-columns: 1fr; }
}
