/* ==========================================================================
   TimeWorked — timesheet app (index.html only)
   ========================================================================== */

.app {
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 1rem 1.5rem;
    width: 100%;
}

/* ----------------------------------------------------------------- Toolbar */

.toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem 1rem;
    margin-bottom: 1rem;
    padding: 0.85rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    align-items: center;
}

.toolbar-group {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.toolbar-group label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.toolbar-divider {
    width: 1px;
    align-self: stretch;
    min-height: 24px;
    background: var(--border);
    margin: 0 0.25rem;
}

.toolbar-spacer {
    flex: 1 1 auto;
}

.week-label {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--text-secondary);
    min-width: 190px;
    text-align: center;
}

.unit-hint {
    color: var(--text-muted);
    font-size: 0.78rem;
}

/* Collapsible advanced settings row */

.settings-panel {
    display: none;
    flex-wrap: wrap;
    gap: 0.75rem 1.25rem;
    align-items: center;
    padding: 0.85rem 1rem;
    margin-bottom: 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

.settings-panel.open {
    display: flex;
}

.settings-panel .field-input {
    min-width: 0;
}

.settings-panel .text-input {
    width: 170px;
    font-family: var(--font-sans);
}

/* ------------------------------------------------------------------- Grid */

.grid-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-secondary);
    /* Matches the rendered table height so the JS render causes no layout shift. */
    min-height: 388px;
    contain: layout;
}

.timesheet-grid {
    width: 100%;
    border-collapse: collapse;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    min-width: 1020px;
}

.timesheet-grid th {
    background: var(--grid-header);
    padding: 0.7rem 0.5rem;
    text-align: center;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 2px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 2;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
}

.timesheet-grid th:first-child {
    text-align: left;
    padding-left: 1rem;
    min-width: 130px;
}

.timesheet-grid th.col-hours { min-width: 78px; }
.timesheet-grid th.col-pay   { min-width: 104px; }

.timesheet-grid th.col-notes {
    min-width: 160px;
    text-align: left;
}

.timesheet-grid td {
    padding: 0;
    border-bottom: 1px solid var(--border);
    border-right: 1px solid var(--border);
    text-align: center;
    vertical-align: middle;
}

.timesheet-grid td:last-child {
    border-right: none;
}

.timesheet-grid tbody tr:nth-child(even) td { background: var(--cell-even); }
.timesheet-grid tbody tr:nth-child(odd) td  { background: var(--cell-odd); }
.timesheet-grid tbody tr:hover td           { background: var(--bg-hover); }

.timesheet-grid tr.is-today td {
    box-shadow: inset 0 0 0 9999px var(--accent-soft);
}

.timesheet-grid tr.total-row td {
    background: var(--grid-header);
    font-weight: 600;
    border-top: 2px solid var(--border);
}

.day-cell {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0.7rem 1rem;
    text-align: left;
}

.day-name {
    font-weight: 600;
    color: var(--text-primary);
    min-width: 34px;
}

.day-date {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.weekend .day-name {
    color: var(--warning);
}

.time-input,
.num-input,
.notes-input {
    width: 100%;
    padding: 0.6rem 0.25rem;
    font-family: var(--font-mono);
    font-size: 0.85rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    text-align: center;
}

.notes-input {
    font-family: var(--font-sans);
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: left;
    padding-left: 0.6rem;
}

.time-input:focus,
.num-input:focus,
.notes-input:focus {
    outline: none;
    background: var(--accent-soft);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.time-input::placeholder,
.num-input::placeholder,
.notes-input::placeholder {
    color: var(--text-muted);
}

.time-input.invalid {
    color: var(--danger);
    box-shadow: inset 0 0 0 1px var(--danger);
}

.hours-cell {
    font-weight: 500;
    padding: 0.6rem 0.5rem;
    color: var(--success);
    font-variant-numeric: tabular-nums;
}

.hours-cell.zero {
    color: var(--text-muted);
}

.hours-cell.overtime {
    color: var(--warning);
}

.earnings-cell {
    font-weight: 500;
    padding: 0.6rem 0.5rem;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.total-label {
    padding: 0.75rem 1rem;
    text-align: left;
    font-weight: 600;
    text-transform: uppercase;
    font-size: 0.72rem;
    letter-spacing: 0.05em;
    color: var(--text-secondary);
}

.total-hours {
    font-size: 1rem;
    color: var(--accent);
    padding: 0.75rem 0.5rem;
    font-variant-numeric: tabular-nums;
}

.total-earnings {
    font-size: 1rem;
    color: var(--success);
    padding: 0.75rem 0.5rem;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

/* ---------------------------------------------------------- Summary cards */

.summary-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
    contain: layout;
}

.summary-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.9rem 1.15rem;
    height: 90px;
    contain: layout style;
}

.summary-card-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
    height: 1rem;
    line-height: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.summary-card-value {
    font-family: var(--font-mono);
    font-size: 1.45rem;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.4;
    height: 2.1rem;
    display: block;
    font-variant-numeric: tabular-nums;
    overflow: hidden;
    width: 100%;
}

.summary-card-value.accent   { color: var(--accent); }
.summary-card-value.success  { color: var(--success); }
.summary-card-value.warning  { color: var(--warning); }

.summary-card-sub {
    font-size: 0.7rem;
    color: var(--text-muted);
    height: 1rem;
    line-height: 1rem;
    overflow: hidden;
}

/* ---------------------------------------------------------------- Status */

.status-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 1rem;
    flex-wrap: wrap;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
}

.status-dot.saving { background: var(--warning); animation: pulse 1s infinite; }
.status-dot.error  { background: var(--danger); animation: none; }

.status-hint {
    margin-left: auto;
    display: flex;
    gap: 0.35rem;
    align-items: center;
    flex-wrap: wrap;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%      { opacity: 0.4; }
}

/* -------------------------------------------------- Print-only timesheet head */

.print-head {
    display: none;
}

/* --------------------------------------------------------------- Responsive */

/* Below 900px the 12-column grid becomes one card per day. */
@media (max-width: 900px) {
    .app {
        padding: 0.75rem;
    }

    .toolbar {
        padding: 0.75rem;
    }

    .toolbar-group {
        flex-wrap: wrap;
    }

    .toolbar-divider,
    .toolbar-spacer {
        display: none;
    }

    .week-label {
        min-width: auto;
        font-size: 0.78rem;
        flex: 1 1 auto;
    }

    .week-nav {
        width: 100%;
    }

    .grid-container {
        overflow-x: visible;
        border: none;
        background: transparent;
        min-height: 0;
    }

    .timesheet-grid {
        min-width: 0;
        display: block;
    }

    .timesheet-grid thead {
        display: none;
    }

    .timesheet-grid tbody,
    .timesheet-grid tr,
    .timesheet-grid td {
        display: block;
        width: auto;
    }

    .timesheet-grid tr {
        background: var(--bg-secondary);
        border: 1px solid var(--border);
        border-radius: var(--radius);
        margin-bottom: 0.75rem;
        overflow: hidden;
        display: grid;
        grid-template-columns: 1fr 1fr;
    }

    .timesheet-grid tbody tr td,
    .timesheet-grid tbody tr:nth-child(even) td,
    .timesheet-grid tbody tr:nth-child(odd) td {
        background: transparent;
        border-right: none;
        border-bottom: 1px solid var(--border);
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 0.5rem;
        padding: 0.15rem 0.75rem;
        text-align: right;
        min-height: 40px;
    }

    .timesheet-grid tbody tr:hover td {
        background: transparent;
    }

    .timesheet-grid td[data-label]::before {
        content: attr(data-label);
        font-family: var(--font-sans);
        font-size: 0.7rem;
        text-transform: uppercase;
        letter-spacing: 0.05em;
        color: var(--text-muted);
        flex-shrink: 0;
    }

    /* Day header spans the full card width */
    .timesheet-grid td.cell-day {
        grid-column: 1 / -1;
        background: var(--grid-header) !important;
        padding: 0;
    }

    .timesheet-grid td.cell-day::before {
        content: none;
    }

    .timesheet-grid td.cell-brk {
        grid-column: 1 / -1;
    }

    .timesheet-grid td.cell-notes {
        grid-column: 1 / -1;
        border-bottom: none;
    }

    .timesheet-grid .time-input,
    .timesheet-grid .num-input {
        text-align: right;
        padding: 0.5rem 0;
    }

    .timesheet-grid .notes-input {
        padding-left: 0;
        text-align: right;
    }

    .timesheet-grid tr.total-row {
        grid-template-columns: 1fr;
        background: var(--grid-header);
    }

    .timesheet-grid tr.total-row td {
        background: transparent !important;
    }

    .timesheet-grid tr.total-row td:empty {
        display: none;
    }

    .timesheet-grid tr.total-row .total-label {
        text-align: left;
        justify-content: flex-start;
    }

    .summary-cards {
        grid-template-columns: repeat(2, 1fr);
        gap: 0.75rem;
    }

    .summary-card {
        padding: 0.75rem 0.9rem;
    }

    .summary-card-value {
        font-size: 1.25rem;
    }

    .status-hint {
        display: none;
    }
}

/* ------------------------------------------------------------------- Print */

@media print {
    .toolbar,
    .settings-panel,
    .status-bar,
    .summary-card-sub {
        display: none !important;
    }

    .app {
        padding: 0;
        max-width: none;
    }

    .print-head {
        display: block;
        margin-bottom: 0.75rem;
        border-bottom: 2px solid #000;
        padding-bottom: 0.5rem;
    }

    .print-head .print-title {
        font-size: 1.15rem;
        font-weight: 700;
        margin: 0 0 0.25rem;
        color: #000;
    }

    .print-head dl {
        display: flex;
        flex-wrap: wrap;
        gap: 0.25rem 1.5rem;
        font-size: 0.8rem;
        color: #000;
    }

    .print-head dt {
        font-weight: 600;
        display: inline;
    }

    .print-head dd {
        display: inline;
        margin: 0 0 0 0.35rem;
    }

    .print-head div {
        display: inline-block;
    }

    .grid-container {
        border: 1px solid #000;
        overflow: visible;
        min-height: 0;
        break-inside: avoid;
    }

    .timesheet-grid {
        min-width: 0;
        font-size: 0.75rem;
    }

    .timesheet-grid th,
    .timesheet-grid td {
        border: 1px solid #000 !important;
        color: #000 !important;
        background: #fff !important;
        box-shadow: none !important;
    }

    .timesheet-grid td *,
    .time-input,
    .num-input,
    .notes-input {
        color: #000 !important;
        background: #fff !important;
    }

    /* Placeholders are guidance on screen and clutter on paper. */
    .timesheet-grid ::placeholder {
        color: transparent !important;
        opacity: 0 !important;
    }

    .summary-cards {
        grid-template-columns: repeat(3, 1fr);
        gap: 0.5rem;
        margin-top: 0.75rem;
        break-inside: avoid;
    }

    .summary-card {
        border: 1px solid #000;
        height: auto;
        padding: 0.4rem 0.6rem;
    }

    .summary-card-label,
    .summary-card-value {
        color: #000 !important;
        height: auto;
    }

    .summary-card-value {
        font-size: 1rem;
    }

    .print-sign {
        display: flex !important;
        margin-top: 2.5rem;
        gap: 3rem;
        font-size: 0.8rem;
        color: #000;
        break-inside: avoid;
    }

    .print-sign div {
        flex: 1;
        border-top: 1px solid #000;
        padding-top: 0.35rem;
    }
}

.print-sign {
    display: none;
}
