:root {
    --bg: #f4f1e8;
    --card: #ffffff;
    --accent: #1b4332;
    --accent-2: #2d6a4f;
    --warning: #b02a37;
    --text: #1b1b1b;
    --muted: #6c757d;
    --grid: #d6d0c4;
    --co: #e63946;
    --cm: #f4a261;
    --liber: #ffd166;
    --liber-weekend: #ffb84d;
    --name-col-width: 150px;
    --name-col-bg: #e8f9ee;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", "Trebuchet MS", sans-serif;
    color: var(--text);
    background: linear-gradient(180deg, #f7f1e1, #efe8d7);
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 24px;
    background: var(--card);
    border-bottom: 2px solid var(--grid);
}

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

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

.actions button, .actions .link {
    text-decoration: none;
}

.actions .primary {
    background: var(--accent);
    color: #fff;
}

.danger {
    border-color: var(--warning);
    color: var(--warning);
}

.container {
    padding: 24px;
}

.admin-layout {
    display: grid;
    grid-template-columns: 220px 1fr;
    gap: 16px;
}

.admin-nav {
    display: grid;
    gap: 8px;
    background: var(--card);
    border: 1px solid var(--grid);
    border-radius: 12px;
    padding: 12px;
    height: fit-content;
}

.admin-nav .nav-item {
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: #f3ecdc;
    cursor: pointer;
    text-align: left;
    font-weight: 600;
}

.admin-nav .nav-item.is-active {
    border-color: var(--accent);
    color: var(--accent);
    background: #fff;
}

.admin-content {
    display: grid;
    gap: 16px;
}

.is-hidden {
    display: none;
}

.toolbar {
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-item {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.toolbar select {
    padding: 6px 8px;
    border: 1px solid var(--grid);
    border-radius: 6px;
    background: #fff;
}

button,
.actions button,
.actions .link,
.toolbar select,
.toolbar input,
.inline-form input,
.inline-form select,
.login-card input,
.login-card button {
    min-height: 44px;
    padding: 12px 14px;
    font-size: 14px;
}

#month-picker {
    min-height: 44px;
    padding: 12px 14px;
    font-size: 14px;
}

button,
.actions .link,
.row-actions button,
.mobile-action,
.danger {
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: #fff;
    color: var(--accent);
    cursor: pointer;
    font-weight: 600;
}

button.primary,
.actions .primary {
    background: var(--accent);
    color: #fff;
}

#table-wrapper {
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--grid);
    border-radius: 10px;
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.08);
    touch-action: pan-x pan-y;
}

#summary-wrapper {
    margin-top: 16px;
    overflow-x: auto;
    background: var(--card);
    border: 1px solid var(--grid);
    border-radius: 10px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.06);
}

.schedule-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 800px;
    position: relative;
}

.col-name {
    width: var(--name-col-width);
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
}

.schedule-table th,
.schedule-table td {
    border: 1px solid var(--grid);
    padding: 6px 8px;
    text-align: center;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.schedule-table .today {
    box-shadow: inset 0 0 0 2px #c1121f;
}

.summary-table th,
.summary-table td {
    border: 1px solid var(--grid);
    padding: 6px 10px;
    text-align: center;
    font-size: 13px;
}

.summary-table th {
    background: #e9e2d3;
}

.summary-sticky {
    position: sticky;
    left: 0;
    background: #e7dfcf;
    z-index: 3;
    box-shadow: 2px 0 0 0 var(--grid);
}

.schedule-table th {
    background: #e9e2d3;
    position: sticky;
    top: 0;
    z-index: 1;
}

.week-table {
    margin-bottom: 16px;
}

.week-table:last-child {
    margin-bottom: 0;
}

.week-table .week-label {
    background: #e7dfcf;
    font-weight: 700;
    min-width: var(--name-col-width);
    width: var(--name-col-width);
}

.cell-empty {
    background: #f6f1e6;
}

.schedule-table .weekend {
    background: #ffe8b3;
}

.schedule-table td.weekend {
    background: #fff2cf;
}

.employee-header {
    background: #e7dfcf;
    min-width: var(--name-col-width);
    width: var(--name-col-width);
}

/* apply light green only to data cells that show employee names */
td.employee-cell {
    text-align: left;
    font-weight: 600;
    background: var(--name-col-bg);
    min-width: var(--name-col-width);
    width: var(--name-col-width);
}

.sticky-col {
    position: sticky;
    left: 0;
    z-index: 5;
    box-shadow: 2px 0 0 0 var(--grid);
}

.sticky-col.header-cell {
    top: 0;
    z-index: 8;
}

.cell-value {
    cursor: pointer;
    font-weight: 600;
    touch-action: manipulation;
    user-select: none;
    min-width: 56px;
}

.cell-value.selected {
    outline: 2px solid #2a9d8f;
    outline-offset: -2px;
}

.cell-co { background: var(--co); color: #fff; }
.cell-cm { background: var(--cm); color: #fff; }
.cell-liber { background: var(--liber); color: #000; }

/* Weekend-specific free day styling */
.cell-liber.weekend,
.schedule-table td.cell-liber.weekend {
    background: var(--liber-weekend);
    color: #000;
}

.schedule-table td.has-custom-bg,
.profile-table td.has-custom-bg {
    color: #111;
    text-shadow: 0 1px 2px rgba(255, 255, 255, 0.7), 0 -1px 2px rgba(0, 0, 0, 0.25);
}

.status {
    margin-top: 12px;
    color: var(--muted);
}

.quick-actions {
    margin: 8px 0 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.quick-actions.is-hidden {
    display: none;
}

.quick-actions button {
    border-radius: 8px;
    border: 1px solid var(--accent);
    background: #fff;
    color: var(--accent);
    cursor: pointer;
    font-weight: 600;
    padding: 8px 12px;
}

.card {
    margin-top: 16px;
    background: var(--card);
    border: 1px solid var(--grid);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.06);
}

.card-header {
    font-weight: 700;
    margin-bottom: 12px;
}

@media (max-width: 720px) {
    .container {
        padding: 16px;
    }

    .toolbar {
        flex-wrap: wrap;
    }

    .actions {
        flex-wrap: wrap;
        justify-content: flex-end;
    }

    .toolbar-item {
        font-size: 14px;
    }

    .cell-value {
        padding: 14px 10px;
        min-height: 52px;
        min-width: 64px;
        font-size: 14px;
    }

    .schedule-table th,
    .schedule-table td {
        padding: 10px 8px;
    }

    .employee-cell,
    .employee-header,
    .week-table .week-label {
        min-width: 170px;
        width: 170px;
        font-size: 14px;
    }

    .mobile-actions {
        position: sticky;
        bottom: 12px;
        z-index: 5;
        display: flex;
        gap: 8px;
        padding: 10px;
        margin-bottom: 16px;
        overflow-x: auto;
        background: rgba(255, 255, 255, 0.92);
        border: 1px solid var(--grid);
        border-radius: 12px;
        box-shadow: 0 8px 18px rgba(0, 0, 0, 0.12);
        backdrop-filter: blur(6px);
    }

    .mobile-action {
        flex: 0 0 auto;
        padding: 10px 12px;
        border-radius: 10px;
        border: 1px solid var(--accent);
        background: #fff;
        color: var(--accent);
        font-weight: 700;
        cursor: pointer;
        min-width: 70px;
        text-align: center;
    }

    .card {
        padding: 12px;
    }

    .summary-table,
    .schedule-table {
        min-width: 640px;
    }

    #tomorrow-wrapper .summary-table {
        min-width: 0;
        width: 100%;
        font-size: 12px;
    }

    #tomorrow-wrapper .summary-table th,
    #tomorrow-wrapper .summary-table td {
        padding: 6px 6px;
    }

    .profile-table {
        min-width: 0;
        width: 100%;
    }

    .profile-table th,
    .profile-table td {
        padding: 4px 4px;
        font-size: 11px;
        white-space: normal;
        width: auto;
    }

    .profile-table .name-col {
        min-width: 110px;
    }

    .profile-shifts {
        -webkit-overflow-scrolling: touch;
    }
}

.admin-section {
    background: var(--card);
    border: 1px solid var(--grid);
    border-radius: 10px;
    padding: 16px;
    margin-bottom: 16px;
}

.muted {
    color: var(--muted);
    font-size: 13px;
    margin: 0 0 10px 0;
}

.admin-section h2 {
    margin-top: 0;
}

.inline-form {
    display: grid;
    gap: 10px;
    margin-top: 10px;
}

.inline-form label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.inline-form input,
.inline-form select {
    padding: 8px;
    border: 1px solid var(--grid);
    border-radius: 6px;
    background: #fff;
}

.list-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 8px 10px;
    border-bottom: 1px solid var(--grid);
}

.row-label {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    font-weight: 600;
}

.row-order {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 28px;
    height: 24px;
    padding: 0 6px;
    border-radius: 999px;
    background: #e7dfcf;
    border: 1px solid var(--grid);
    font-size: 12px;
    color: var(--accent);
}

.list-row:last-child {
    border-bottom: none;
}

.row-actions {
    display: flex;
    gap: 8px;
}

.row-actions button {
    color: var(--accent);
}

.backgrounds-list {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.background-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 10px;
    border: 1px solid var(--grid);
    border-radius: 10px;
    background: #fff;
}

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

.background-thumb {
    width: 54px;
    height: 40px;
    border-radius: 8px;
    border: 1px solid var(--grid);
    object-fit: cover;
}

.profile-grid {
    display: grid;
    grid-template-columns: minmax(280px, 360px) 1fr;
    gap: 16px;
    align-items: start;
}

.profile-view {
    display: grid;
    gap: 10px;
}

.profile-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--grid);
}

.profile-row:last-child {
    border-bottom: none;
}

.profile-label {
    font-size: 12px;
    color: var(--muted);
}

.profile-value {
    font-weight: 600;
}

.profile-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
}

.profile-toolbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.profile-range {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.profile-bg-controls {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.profile-bg-controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

.profile-range label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--muted);
}

.profile-range input {
    padding: 6px 8px;
    border: 1px solid var(--grid);
    border-radius: 8px;
}

.profile-range button {
    padding: 8px 10px;
    border: 1px solid var(--grid);
    border-radius: 10px;
    background: #fff;
    color: var(--accent);
    font-weight: 600;
}

.profile-quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.profile-quick-actions button {
    padding: 8px 12px;
    border: 1px solid var(--grid);
    border-radius: 10px;
    background: #fff;
    color: var(--accent);
    font-weight: 600;
}

.profile-month-controls {
    display: inline-flex;
    align-items: center;
    gap: 10px;
}

.profile-month-hidden {
    display: none;
}

.month-nav {
    width: 40px;
    height: 40px;
    border-radius: 999px;
    border: 1px solid var(--grid);
    background: #fff;
    color: var(--accent);
    font-size: 16px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.month-label {
    font-weight: 700;
    min-width: 140px;
}

.profile-shifts {
    overflow-x: auto;
}

.profile-shifts.is-selecting {
    touch-action: none;
}

.profile-note {
    margin: 8px 0 0 0;
    color: var(--muted);
}

.profile-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 620px;
    table-layout: fixed;
}

.profile-table th,
.profile-table td {
    border: 1px solid var(--grid);
    padding: 6px 8px;
    text-align: center;
    font-size: 12px;
    width: 14.285%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.profile-table th {
    background: #e9e2d3;
}

.profile-table .weekend {
    background: #ffe8b3;
}

.profile-table .name-col {
    background: #e7dfcf;
    font-weight: 700;
    text-align: left;
    min-width: 160px;
}

.profile-table .out-range,
.profile-table .cell-empty {
    background: #f6f1e6;
    color: #8b8b8b;
}

.profile-table .today-col {
    border-left: 6px solid #c1121f;
    border-right: 6px solid #c1121f;
}

.profile-table thead tr:first-child .today-col {
    border-top: 6px solid #c1121f;
    border-top-left-radius: 6px;
    border-top-right-radius: 6px;
}

.profile-table tbody tr:last-child .today-col {
    border-bottom: 6px solid #c1121f;
    border-bottom-left-radius: 6px;
    border-bottom-right-radius: 6px;
}

.profile-table td.is-editable {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    touch-action: manipulation;
}

.profile-table td.selected {
    box-shadow: inset 0 0 0 3px var(--accent);
    background: #dff3e6 !important;
    color: #0f2f22 !important;
}

@media (max-width: 900px) {
    .profile-grid {
        grid-template-columns: 1fr;
    }

    .profile-info {
        order: 2;
    }

    .profile-shifts-section {
        order: 1;
    }
}

.tab-row {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

.tab {
    padding: 6px 12px;
    border: 1px solid var(--grid);
    border-radius: 999px;
    background: #fff;
    color: var(--muted);
}

.tab.is-active {
    background: #e8f9ee;
    color: var(--accent);
}

.tab-panel {
    display: none;
}

.tab-panel.is-active {
    display: block;
}

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
}

.login-card {
    background: var(--card);
    padding: 24px;
    border-radius: 12px;
    width: 320px;
    border: 1px solid var(--grid);
}

.login-card h1 {
    margin-top: 0;
}

.login-card input {
    width: 100%;
    margin-bottom: 12px;
    padding: 8px;
    border: 1px solid var(--grid);
    border-radius: 6px;
}

.login-card button {
    width: 100%;
}

.alert {
    background: #fbe9e7;
    color: #8a1c0e;
    padding: 10px;
    margin-bottom: 12px;
    border-radius: 6px;
}

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal.is-open {
    display: flex;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
}

.modal-card {
    position: relative;
    background: var(--card);
    border: 1px solid var(--grid);
    border-radius: 12px;
    padding: 18px 20px;
    width: min(420px, calc(100% - 32px));
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.18);
    z-index: 1;
}

.modal-title {
    margin: 0 0 8px 0;
    font-size: 18px;
}

.modal-text {
    margin: 0 0 16px 0;
    color: var(--muted);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

.modal-confirm {
    min-width: 120px;
}

.modal-open {
    overflow: hidden;
    touch-action: none;
}

.modal-form {
    display: grid;
    gap: 12px;
    margin-bottom: 12px;
}

.modal-form label {
    display: grid;
    gap: 6px;
    font-size: 13px;
    color: var(--muted);
}

.modal-form input {
    padding: 10px 12px;
    border: 1px solid var(--grid);
    border-radius: 8px;
    background: #fff;
    font-size: 14px;
}

.modal-error {
    margin: 0 0 12px 0;
    color: var(--warning);
    font-size: 13px;
    min-height: 18px;
}
