:root {
    --primary: #2357d6;
    --primary-dark: #163a93;
    --accent: #0f766e;
    --bg: #eef2f7;
    --surface: #ffffff;
    --surface-muted: #f6f8fb;
    --text: #172033;
    --muted: #647085;
    --border: #d9e1ec;
    --danger: #dc2626;
    --danger-bg: #fff1f2;
    --ok: #15803d;
    --warning: #b45309;
    --shadow: 0 18px 50px rgba(23, 32, 51, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: Inter, "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    background:
        radial-gradient(circle at top left, rgba(35, 87, 214, 0.12), transparent 34rem),
        linear-gradient(135deg, #f8fafc 0%, var(--bg) 100%);
    color: var(--text);
    line-height: 1.5;
}

button,
input,
textarea,
select {
    font: inherit;
}

button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 46px;
    padding: 11px 18px;
    border: 0;
    border-radius: 8px;
    background: var(--primary);
    color: #ffffff;
    font-weight: 750;
    cursor: pointer;
    transition: transform 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

button:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 12px 24px rgba(35, 87, 214, 0.18);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

button.secondary {
    background: #334155;
}

button.ghost {
    width: auto;
    min-height: 36px;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-weight: 700;
}

button.danger {
    background: var(--danger);
}

button.compact {
    width: auto;
    min-height: 38px;
    padding: 8px 14px;
}

input,
textarea,
select {
    width: 100%;
    min-height: 46px;
    padding: 11px 12px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

textarea {
    resize: vertical;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(35, 87, 214, 0.13);
}

label span {
    display: block;
    margin-bottom: 7px;
    color: var(--muted);
    font-size: 0.86rem;
    font-weight: 700;
}

.app-shell {
    width: min(1060px, calc(100% - 32px));
    margin: 32px auto;
    padding: 28px;
    border: 1px solid rgba(217, 225, 236, 0.86);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 24px;
    border-bottom: 1px solid var(--border);
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 16px;
}

.app-logo {
    width: 66px;
    height: 66px;
    object-fit: contain;
    border-radius: 8px;
}

h1,
h2,
h3,
p {
    margin: 0;
}

h1 {
    font-size: clamp(1.35rem, 2.6vw, 2rem);
    line-height: 1.1;
    letter-spacing: 0;
}

.brand-lockup p,
.panel-title p,
.failure-panel p,
.modal-head p {
    color: var(--muted);
}

.stepper {
    display: flex;
    gap: 8px;
}

.step-dot {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border: 1px solid var(--border);
    border-radius: 50%;
    color: var(--muted);
    font-weight: 800;
}

.step-dot.active {
    border-color: var(--primary);
    background: var(--primary);
    color: #ffffff;
}

.step-dot.done {
    border-color: rgba(15, 118, 110, 0.32);
    background: rgba(15, 118, 110, 0.1);
    color: var(--accent);
}

.step {
    display: none;
    padding-top: 28px;
}

.step.active {
    display: block;
    animation: fadeIn 0.26s ease;
}

.step-heading {
    margin-bottom: 22px;
}

.step-heading > span {
    display: block;
    margin-bottom: 4px;
    color: var(--accent);
    font-size: 0.84rem;
    font-weight: 800;
    text-transform: uppercase;
}

.step-heading h2 {
    font-size: clamp(1.45rem, 3vw, 2rem);
    line-height: 1.15;
}

.date-selection-group,
.button-group,
.rule-grid,
.shift-input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.button-group {
    margin-top: 22px;
}

.full-field {
    display: block;
}

.calc-box,
.shift-panel,
.global-settings,
.failure-panel {
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-muted);
}

.calc-box label {
    display: block;
    margin-bottom: 10px;
    font-weight: 800;
}

.stat-info {
    margin-top: 10px;
    color: var(--primary-dark);
    font-size: 0.92rem;
}

.shift-panel {
    margin-top: 16px;
}

.panel-title,
.result-header,
.modal-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.panel-title h3 {
    font-size: 1.1rem;
}

.counter {
    min-width: 58px;
    padding: 6px 10px;
    border-radius: 999px;
    background: #e0f2fe;
    color: #075985;
    text-align: center;
    font-weight: 800;
}

.shift-input-row {
    grid-template-columns: 1fr auto;
    margin-top: 16px;
}

.shift-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.shift-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 14px;
}

.shift-chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 38px;
    padding: 5px 6px 5px 10px;
    border: 1px solid #bfdbfe;
    border-radius: 999px;
    background: #eff6ff;
    color: #1e3a8a;
    font-weight: 800;
}

.shift-index {
    display: grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #dbeafe;
    font-size: 0.78rem;
}

.icon-button {
    width: 28px;
    min-height: 28px;
    padding: 0;
    border-radius: 50%;
    background: transparent;
    color: currentColor;
    font-size: 1.1rem;
    line-height: 1;
}

.icon-button:hover:not(:disabled) {
    box-shadow: none;
    background: rgba(15, 23, 42, 0.08);
}

.icon-button.large {
    width: 36px;
    min-height: 36px;
}

.empty-state {
    width: 100%;
    padding: 12px;
    border: 1px dashed var(--border);
    border-radius: 8px;
    color: var(--muted);
    background: #ffffff;
}

.global-settings {
    display: grid;
    grid-template-columns: auto 120px 120px auto;
    align-items: end;
    gap: 12px;
    margin-bottom: 16px;
}

.person-list-head,
.person-row {
    display: grid;
    grid-template-columns: minmax(180px, 1fr) 92px 92px 110px;
    gap: 12px;
    align-items: center;
}

.person-list-head {
    padding: 0 14px 8px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 800;
}

.people-list {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.person-row {
    padding: 12px 14px;
    background: #ffffff;
    border-bottom: 1px solid var(--border);
}

.person-row:last-child {
    border-bottom: 0;
}

.person-name span {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: 0.82rem;
}

.mini-field span {
    margin-bottom: 4px;
    font-size: 0.74rem;
}

.small-input {
    min-height: 38px;
    padding: 8px;
    text-align: center;
}

.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: rgba(15, 23, 42, 0.52);
}

.modal-content {
    width: min(560px, 100%);
    max-height: 90vh;
    overflow-y: auto;
    padding: 22px;
    border-radius: 8px;
    background: #ffffff;
    box-shadow: 0 24px 80px rgba(15, 23, 42, 0.3);
}

.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 7px;
    margin: 20px 0;
}

.calendar-head {
    color: var(--muted);
    text-align: center;
    font-size: 0.78rem;
    font-weight: 800;
}

.day-box {
    min-height: 42px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #f8fafc;
    color: var(--text);
    font-weight: 800;
}

.day-box.weekend {
    border-color: #fdba74;
    background: #fff7ed;
}

.day-box.selected {
    border-color: var(--danger);
    background: var(--danger);
    color: #ffffff;
    text-decoration: line-through;
}

.result-header {
    align-items: flex-start;
}

.result-header button {
    width: auto;
}

.result-area {
    overflow-x: auto;
}

.result-summary,
.shift-balance {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}

.result-summary div,
.shift-balance div {
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface-muted);
}

.result-summary strong,
.shift-balance strong {
    display: block;
    font-size: 1.45rem;
}

.result-summary span,
.shift-balance span {
    display: block;
    color: var(--muted);
    font-size: 0.84rem;
    font-weight: 700;
}

.shift-balance {
    grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 16px;
    background: #ffffff;
}

th,
td {
    padding: 11px 10px;
    border: 1px solid var(--border);
    text-align: center;
    vertical-align: top;
}

th {
    background: #1f2937;
    color: #ffffff;
    font-size: 0.84rem;
    white-space: nowrap;
}

td {
    min-width: 110px;
}

.roster-table td:first-child,
.roster-table td:nth-child(2) {
    min-width: 76px;
    font-weight: 800;
}

.weekend-row {
    background: #fff7ed;
}

.cell-shift {
    display: block;
    margin-top: 3px;
    color: var(--accent);
    font-size: 0.78rem;
    font-weight: 800;
}

.muted-cell {
    color: #94a3b8;
}

.section-title {
    margin-top: 26px;
}

.stats-table td span {
    color: var(--muted);
    font-size: 0.8rem;
}

.ok-text {
    color: var(--ok);
    font-weight: 800;
}

.warn-text {
    color: var(--danger);
    font-weight: 800;
}

.failure-panel {
    background: var(--danger-bg);
    border-color: #fecdd3;
}

.failure-panel h3 {
    color: var(--danger);
}

.failure-panel ul {
    margin: 14px 0 0;
    padding-left: 20px;
}

.failure-panel li + li {
    margin-top: 8px;
}

.failure-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 18px;
}

.failure-actions button {
    width: auto;
}

.suggestion-box {
    display: none;
}

.restart-button {
    width: auto;
    margin-top: 18px;
}

.spinner-container {
    display: grid;
    place-items: center;
    gap: 14px;
    min-height: 220px;
    color: var(--muted);
}

.spinner {
    width: 42px;
    height: 42px;
    border: 4px solid #dbeafe;
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.85s linear infinite;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@media (max-width: 760px) {
    .app-shell {
        width: min(100% - 20px, 1060px);
        margin: 10px auto;
        padding: 18px;
    }

    .app-header,
    .brand-lockup,
    .panel-title,
    .result-header,
    .modal-head {
        align-items: flex-start;
        flex-direction: column;
    }

    .stepper {
        width: 100%;
        justify-content: space-between;
    }

    .date-selection-group,
    .button-group,
    .rule-grid,
    .shift-input-row,
    .global-settings,
    .person-list-head,
    .person-row,
    .result-summary {
        grid-template-columns: 1fr;
    }

    .person-list-head {
        display: none;
    }

    .person-row {
        gap: 10px;
    }

    .failure-actions button,
    .result-header button,
    .restart-button,
    .shift-input-row button {
        width: 100%;
    }

    td {
        min-width: 128px;
    }
}
