/* TimeSheet — unified layout & project theme (--brand, --primary from config.js) */

html.ts-page,
html.ts-page body {
    height: 100%;
    margin: 0;
    overflow: hidden;
}

html.ts-page body {
    display: flex;
    flex-direction: column;
    background-color: var(--workspace-bg, #f9fafb);
}

.ts-page .container {
    padding: 6px 10px 10px;
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
    box-sizing: border-box;
    gap: 6px;
}

.ts-page .card {
    background: var(--surface, #fff);
    padding: 8px 10px 10px;
    border-radius: 12px;
    border: 1px solid var(--border-subtle, #e5e7eb);
    box-shadow: var(--shadow-card, 0 4px 24px rgba(15, 23, 42, 0.06));
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    gap: 8px;
}

/* —— Header (timesheet bar) —— */
.header-bar--timesheet > .header-bar__title {
    display: none;
}

.header-bar--timesheet .ts-h-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
}

.header-bar--timesheet .ts-h-field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    white-space: nowrap;
}

.header-bar--timesheet .ts-h-field input,
.header-bar--timesheet .ts-h-field select {
    padding: 6px 8px;
    border: 1px solid var(--border-default, #e2e8f0);
    border-radius: 8px;
    font-size: 14px;
    min-height: 36px;
    box-sizing: border-box;
    background: #fff;
    color: var(--text-body, #334155);
}

.header-bar--timesheet .period-days-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.header-bar--timesheet .ts-h-field #monthDays {
    width: 4.25rem;
}

.header-bar--timesheet .ts-h-field #periodInput {
    min-width: 8.5rem;
}

.header-bar--timesheet .ts-h-field #monthDays.input-dirty {
    outline: 2px solid var(--primary, #f59e0b);
    outline-offset: 1px;
}

.header-bar--timesheet .period-end-month {
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--brand, #1e40af);
    line-height: 1;
    white-space: nowrap;
}

.header-bar--timesheet .period-end-month.is-current {
    text-shadow: 0 0 12px color-mix(in srgb, var(--brand, #dc2626) 35%, transparent);
}

.header-bar--timesheet .period-range {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #64748b);
    margin-top: 2px;
}

.header-bar--timesheet .ts-h-field select#siteFilter {
    min-width: 140px;
    max-width: min(220px, 28vw);
}

/* Project badge — uses active site theme */
.header-bar--timesheet .site-name-badge {
    background: linear-gradient(
        135deg,
        #fff 0%,
        color-mix(in srgb, var(--brand, #3b82f6) 10%, #fff) 100%
    ) !important;
    border: 2px solid var(--brand, #94a3b8) !important;
    box-shadow: 0 2px 12px color-mix(in srgb, var(--brand, #000) 18%, transparent) !important;
}

.header-bar--timesheet .site-name-badge .nav-site-label,
.header-bar--timesheet .site-name-badge .nav-site-switcher {
    color: var(--brand, #0f172a) !important;
}

/* Toolbar buttons */
.ts-action-bar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
}

.ts-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 12px;
    min-height: 36px;
    border: none;
    border-radius: 8px;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    transition: filter 0.15s ease, transform 0.15s ease, opacity 0.15s ease;
    color: #fff;
    background: var(--primary, #3b82f6);
}

.ts-btn:hover:not(:disabled) {
    filter: brightness(1.06);
    transform: translateY(-1px);
}

.ts-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.ts-btn--primary {
    background: var(--brand, #1e40af);
}

.ts-btn--muted {
    background: #64748b;
}

.ts-btn--danger {
    background: #dc2626;
}

.ts-btn--warn {
    background: #d97706;
}

.ts-btn--icon {
    padding: 8px 10px;
    min-width: 36px;
}

.ts-btn--icon .fa-solid {
    font-size: 0.95rem;
}

.ts-btn__lbl {
    display: inline;
}

@media (min-width: 1100px) {
    .header-bar--timesheet .ts-action-bar .ts-btn--icon {
        min-width: 36px;
    }
}

.ts-btn--lock.is-unlocked {
    background: #7c3aed;
}

.ts-btn--lock.is-locked {
    background: #16a34a;
}

.ts-more-menu {
    position: relative;
}

.ts-more-menu > summary {
    list-style: none;
}

.ts-more-menu > summary::-webkit-details-marker {
    display: none;
}

.ts-more-menu__panel {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 120;
    min-width: 11rem;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--border-default, #e2e8f0);
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.14);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ts-more-menu__panel .ts-btn {
    width: 100%;
    justify-content: flex-start;
}

.ts-more-menu__panel .ts-btn--block {
    width: 100%;
}

/* —— Add employees toolbar —— */
.ts-add-toolbar {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.ts-add-toolbar__row {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 10px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-default, #e2e8f0);
    background: #f8fafc;
}

.ts-add-toolbar__row .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin: 0;
}

.ts-add-toolbar__row .field label {
    font-weight: 600;
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

.ts-add-toolbar__row .field input {
    padding: 7px 9px;
    border: 1px solid var(--border-default, #e2e8f0);
    border-radius: 8px;
    font-size: 13px;
    min-height: 36px;
}

.ts-add-toolbar__search {
    flex: 1 1 180px;
    max-width: 240px;
}

.ts-panel {
    border: 1px solid var(--border-default, #e2e8f0);
    border-radius: 10px;
    background: #fff;
    overflow: hidden;
}

.ts-panel > summary {
    padding: 8px 12px;
    font-size: 12px;
    font-weight: 700;
    color: var(--brand, #334155);
    cursor: pointer;
    list-style: none;
    user-select: none;
    background: color-mix(in srgb, var(--brand, #3b82f6) 6%, #f8fafc);
}

.ts-panel > summary::-webkit-details-marker {
    display: none;
}

.ts-panel > summary::before {
    content: '+ ';
    font-weight: 800;
}

.ts-panel[open] > summary::before {
    content: '− ';
}

.ts-panel__body {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 8px 10px;
    padding: 10px 12px;
    border-top: 1px solid var(--border-default, #e2e8f0);
}

.ts-panel__body .field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ts-panel__body .field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #64748b);
}

#addEmployeeBtn {
    width: 38px;
    min-width: 38px;
    height: 38px;
    padding: 0;
    border-radius: 10px;
    background: var(--brand, #1e40af);
    color: #fff;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

#addEmployeeBtn:hover:not(:disabled) {
    filter: brightness(1.08);
}

#borrowPickSelect {
    min-width: 12rem;
    max-width: min(100%, 22rem);
    padding: 6px 8px;
    border-radius: 8px;
    border: 1px solid var(--border-default, #e2e8f0);
    font-size: 13px;
}

.ts-borrow-badge {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    color: var(--brand, #1d4ed8);
    vertical-align: middle;
}

.ts-temp-badge {
    display: inline-block;
    margin-left: 6px;
    font-size: 10px;
    font-weight: 700;
    color: #b45309;
}

/* —— Table —— */
.ts-page .table-wrap {
    flex: 1;
    min-height: 0;
    overflow: auto;
    border-radius: 12px;
    border: 1px solid var(--border-default, #e2e8f0);
    background: var(--surface, #fff);
}

.ts-page table {
    width: 100%;
    border-collapse: collapse;
}

.ts-page th,
.ts-page td {
    border: 1px solid var(--border-default, #e2e8f0);
    padding: 6px 8px;
    font-size: 12px;
    line-height: 1.45;
    text-align: center;
    color: var(--text-body, #334155);
}

.ts-page th {
    background: var(--table-header-bg, #f1f5f9);
    color: var(--text-muted, #64748b);
    font-weight: 600;
    position: sticky;
    top: 0;
    z-index: 10;
    border-bottom: 2px solid var(--border-default, #e2e8f0);
}

.ts-page tbody tr:nth-child(even) td {
    background: var(--table-row-alt, #fafbfc);
}

#attendanceTable tbody tr {
    transition: background-color 0.12s ease;
}

#attendanceTable tbody tr:hover td {
    background: color-mix(in srgb, var(--primary, #3b82f6) 14%, #fff) !important;
}

#attendanceTable th:nth-child(2),
#attendanceTable td.name {
    white-space: nowrap;
}

#attendanceTable td.name {
    font-size: 12px;
    font-weight: 700;
    max-width: 175px;
    overflow: hidden;
    text-overflow: ellipsis;
}

#attendanceTable td.name.ts-temp-cell {
    white-space: normal;
    max-width: 16rem;
    overflow: visible;
    text-overflow: clip;
}

.ts-temp-input {
    width: 100%;
    max-width: 14rem;
    box-sizing: border-box;
    padding: 4px 6px;
    font: inherit;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid #94a3b8;
    border-radius: 4px;
    background: #fff;
}

.ts-temp-input:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

#attendanceTable th.ts-metric,
#attendanceTable td.ts-metric {
    font-size: 9px;
    font-weight: 600;
    padding: 3px 4px;
    line-height: 1.2;
    max-width: 2.5rem;
}

#attendanceTable th.day-cell {
    font-size: 10px;
    padding: 4px 4px;
    font-weight: 700;
    min-width: 1.6rem;
}

.ts-day-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    line-height: 1.1;
}

.ts-day-count {
    display: block;
    font-size: 11px;
    font-weight: 800;
    color: var(--brand, #0d9488);
    min-height: 1em;
}

.ts-day-count.is-zero {
    color: #94a3b8;
    font-weight: 600;
}

.ts-day-num {
    display: block;
    font-size: 10px;
    font-weight: 700;
    color: #64748b;
}

#attendanceTable td.day-cell {
    font-size: 10px;
    padding: 4px;
}

.ts-att-btn {
    width: 13px;
    min-width: 13px;
    max-width: 13px;
    height: 13px;
    min-height: 13px;
    max-height: 13px;
    border-radius: 3px;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 800;
    padding: 0;
    margin: 0;
    cursor: pointer;
    transition: all 0.15s ease;
}

.ts-att-btn.is-on {
    color: #fff;
    border-color: transparent;
}

.ts-att-btn.is-on .fa-check {
    font-size: 8px;
    line-height: 1;
    pointer-events: none;
}

.ts-att-btn.is-day {
    background: var(--primary, #2563eb);
}

.ts-att-btn.is-night {
    background: #0f172a;
}

.ts-shift-picker {
    position: fixed;
    z-index: 4000;
    display: flex;
    gap: 6px;
    padding: 8px;
    border-radius: 10px;
    border: 1px solid #cbd5e1;
    background: #fff;
    box-shadow: 0 10px 28px rgba(15, 23, 42, 0.2);
}

.ts-shift-option {
    min-height: 30px;
    border: none;
    border-radius: 8px;
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    padding: 6px 10px;
    cursor: pointer;
    white-space: nowrap;
}

.ts-shift-option.day {
    background: var(--primary, #2563eb);
}

.ts-shift-option.night {
    background: #0f172a;
}

.ts-shift-option.clear {
    background: #94a3b8;
    color: #0f172a;
}

.draggable-row {
    cursor: grab;
}

.draggable-row.dragging {
    opacity: 0.5;
}

/* Archives modal */
.archive-modal {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.55);
    z-index: 2600;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
}

.archive-modal.is-open {
    display: flex;
}

.archive-panel {
    width: min(1000px, 96vw);
    max-height: 88vh;
    background: #fff;
    border-radius: 12px;
    border: 1px solid var(--border-default, #e2e8f0);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.archive-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-default, #e2e8f0);
}

.archive-body {
    overflow: auto;
    padding: 10px;
}

.archive-table {
    min-width: 840px;
}

.archive-actions {
    display: flex;
    gap: 8px;
}

@media (max-width: 768px) {
    #attendanceTable th {
        position: static !important;
        top: auto !important;
        z-index: auto !important;
    }

    .archive-modal {
        position: absolute !important;
    }

    .ts-action-bar {
        width: 100%;
    }

    .ts-action-bar .ts-btn:not(.ts-btn--icon) {
        flex: 1 1 auto;
    }
}

/* —— Daily wage cost row (below TimeSheet) —— */
.ts-wage-toolbar[hidden],
body:not(.ts-has-daily-cost-panels) .ts-wage-toolbar,
body:not(.ts-has-daily-cost-panels) .ts-daily-wage-summary,
body:not(.ts-has-daily-cost-panels) #attendanceTable tfoot .ts-wage-foot-row,
body:not(.ts-has-daily-cost-panels) #attendanceTable tfoot .ts-invoice-foot-row {
    display: none !important;
}

.ts-wage-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 16px;
    padding: 6px 4px 2px;
    border-top: 1px dashed var(--border-default, #e2e8f0);
    margin-top: 4px;
}

.ts-wage-toggle {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 700;
    color: var(--text-heading, #0f172a);
    cursor: pointer;
    user-select: none;
}

.ts-wage-toggle input {
    width: 16px;
    height: 16px;
    accent-color: var(--primary, #4a5fa8);
}

.ts-wage-toolbar__hint {
    margin: 0;
    font-size: 11px;
    color: var(--text-muted, #64748b);
    flex: 1 1 200px;
}

.ts-daily-wage-summary {
    margin: 0 4px 4px;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid rgba(74, 95, 168, 0.22);
    background: linear-gradient(180deg, rgba(74, 95, 168, 0.08) 0%, rgba(255, 255, 255, 0.92) 100%);
    font-size: 13px;
    color: var(--text-body, #334155);
}

.ts-daily-wage-summary[hidden] {
    display: none !important;
}

.ts-daily-wage-summary__inner strong {
    color: var(--brand, #1f3864);
}

.ts-daily-wage-summary__msg {
    margin: 0;
    font-size: 13px;
    color: var(--text-muted, #64748b);
}

#attendanceTable tfoot .ts-wage-foot-row td {
    background: linear-gradient(180deg, #eef2fb 0%, #e8edf8 100%) !important;
    border-top: 2px solid var(--brand-mid, #3d4f8f);
    font-weight: 700;
    vertical-align: middle;
}

.ts-wage-foot-label {
    text-align: start;
    color: var(--brand, #1f3864);
    font-size: 12px;
    white-space: nowrap;
}

.ts-wage-foot-day {
    text-align: center;
    min-width: 52px;
    padding: 6px 4px !important;
}

.ts-wage-foot-cost {
    font-size: 11px;
    font-weight: 800;
    color: var(--brand, #1f3864);
    line-height: 1.25;
}

.ts-wage-foot-warn {
    font-size: 9px;
    font-weight: 600;
    color: #b45309;
    line-height: 1.2;
    margin-top: 2px;
}

.ts-wage-foot-total {
    text-align: center;
    font-size: 12px;
    font-weight: 800;
    color: var(--brand, #1f3864);
    background: rgba(74, 95, 168, 0.12) !important;
}

.ts-wage-foot-metric {
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

#attendanceTable tfoot .ts-invoice-foot-row td {
    background: linear-gradient(180deg, #ecfdf5 0%, #d1fae5 100%) !important;
    border-top: 2px solid #059669;
    font-weight: 700;
    vertical-align: middle;
}

.ts-invoice-foot-label {
    text-align: start;
    color: #047857;
    font-size: 12px;
    white-space: nowrap;
}

.ts-invoice-foot-day {
    text-align: center;
    min-width: 52px;
    padding: 6px 4px !important;
}

.ts-invoice-foot-revenue {
    font-size: 11px;
    font-weight: 800;
    color: #047857;
    line-height: 1.25;
}

.ts-invoice-foot-warn {
    font-size: 9px;
    font-weight: 600;
    color: #b45309;
    line-height: 1.2;
    margin-top: 2px;
}

.ts-invoice-foot-total {
    text-align: center;
    font-size: 12px;
    font-weight: 800;
    color: #047857;
    background: rgba(5, 150, 105, 0.12) !important;
}

.ts-invoice-foot-metric {
    font-size: 12px;
    color: var(--text-muted, #64748b);
}

.ts-daily-invoice-summary {
    border-color: rgba(5, 150, 105, 0.35);
    background: rgba(236, 253, 245, 0.65);
}
