:root {
    color-scheme: light;
    --navy: #0f172a;
    --slate: #475569;
    --pale: #f1f5f9;
    --line: #dbe3ed;
    --white: #fff;
    --red: #dc2626;
    --shadow: 0 12px 30px rgba(15, 23, 42, .09);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--pale);
    color: var(--navy);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, input { font: inherit; }
button { touch-action: manipulation; }

.app-header {
    position: sticky;
    top: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: .8rem max(1rem, env(safe-area-inset-left));
    background: var(--navy);
    color: var(--white);
    box-shadow: 0 4px 12px rgba(0, 0, 0, .18);
}

.brand { font-size: 1.35rem; font-weight: 800; letter-spacing: .08em; }
.tagline { color: #cbd5e1; font-size: .78rem; }
.header-actions { display: flex; align-items: center; gap: .5rem; }
.app-header a.button { display: inline-flex; align-items: center; text-decoration: none; }

.connection-panel { padding: .38rem max(1rem, env(safe-area-inset-left)); background: white; border-bottom: 1px solid var(--line); box-shadow: 0 3px 9px rgba(15,23,42,.05); }
.connection-status { display: flex; align-items: center; gap: .45rem; width: min(100%, 920px); margin: 0 auto; color: var(--slate); font-size: .78rem; }
.connection-dot { width: .65rem; height: .65rem; flex: 0 0 auto; border-radius: 99px; background: #d97706; box-shadow: 0 0 0 3px #fef3c7; }
.connection-dot.online { background: #16a34a; box-shadow: 0 0 0 3px #dcfce7; }
.connection-dot.offline { background: #dc2626; box-shadow: 0 0 0 3px #fee2e2; }
.last-contact { margin-left: auto; }
.failed-save { display: flex; align-items: center; justify-content: space-between; gap: .75rem; width: min(100%, 920px); margin: .45rem auto .1rem; padding: .65rem .75rem; color: #991b1b; background: #fee2e2; border: 1px solid #fca5a5; border-radius: .6rem; font-size: .86rem; font-weight: 750; }
.failed-save[hidden] { display: none; }
.failed-save-dismiss { min-height: 34px; border: 1px solid #991b1b; border-radius: .45rem; padding: .3rem .65rem; color: #991b1b; background: white; font-weight: 750; cursor: pointer; }

.container {
    width: min(100% - 2rem, 920px);
    margin: 1.25rem auto 3rem;
}

.timer-card {
    margin-bottom: 2rem;
    padding: clamp(1.3rem, 5vw, 2.5rem);
    text-align: center;
    background: var(--white);
    border-radius: 1.25rem;
    box-shadow: var(--shadow);
}

.timer-label { min-height: 1.5em; color: var(--slate); font-weight: 700; }
.timer-display { margin: .15rem 0 1.2rem; font-size: clamp(2.8rem, 12vw, 5.5rem); font-variant-numeric: tabular-nums; font-weight: 750; letter-spacing: -.04em; }

h1, h2 { margin: 0; }
h1 { font-size: 1.35rem; }
h2 { font-size: 1.2rem; }
p { margin: .25rem 0 0; color: var(--slate); }

.section-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin: 0 0 .9rem;
}

.button {
    min-height: 44px;
    border: 0;
    border-radius: .7rem;
    padding: .65rem 1rem;
    font-weight: 750;
    cursor: pointer;
}
.button:disabled { cursor: not-allowed; opacity: .4; }
.button-primary { background: #2563eb; color: white; }
.button-secondary { border: 1px solid #64748b; background: #1e293b; color: white; }
.button-quiet { background: #e2e8f0; color: var(--navy); }
.button-save { background: #dcfce7; color: #166534; }
.button-remove { background: #fee2e2; color: #991b1b; }
.button-stop { width: min(100%, 360px); background: var(--red); color: white; font-size: 1.2rem; }
.button-inject { background: #d97706; color: white; font-size: 1.05rem; }
.button-comment { background: #0369a1; color: white; font-size: 1.05rem; }
.full-width { width: 100%; }

.timer-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .65rem; width: min(100%, 600px); margin: 0 auto; }
.timer-actions .button { width: 100%; }
.active-comment { width: fit-content; max-width: 100%; margin: .55rem auto 0; padding: .35rem .7rem; color: #075985; background: #e0f2fe; border-radius: 99px; font-size: .88rem; overflow-wrap: anywhere; }

.activity-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: .85rem;
}

.activity-button {
    position: relative;
    min-height: 94px;
    overflow: hidden;
    border: 0;
    border-radius: 1rem;
    padding: 1rem;
    color: white;
    font-size: clamp(1rem, 4vw, 1.25rem);
    font-weight: 800;
    text-shadow: 0 1px 2px rgba(0, 0, 0, .28);
    box-shadow: 0 7px 16px rgba(15, 23, 42, .14);
    cursor: pointer;
}
.activity-button::after { content: "START"; display: block; margin-top: .35rem; font-size: .7rem; letter-spacing: .15em; opacity: .78; }
.activity-button.active { outline: 5px solid rgba(15, 23, 42, .2); transform: translateY(-2px); }

.entries-section { margin-top: 2.2rem; }
.entries-list { display: grid; gap: .55rem; }
.entry {
    display: grid;
    grid-template-columns: 12px 1fr auto;
    align-items: center;
    gap: .8rem;
    padding: .85rem 1rem;
    background: white;
    border-radius: .8rem;
}
.entry-colour { width: 12px; height: 42px; border-radius: 99px; }
.entry-name { font-weight: 750; }
.entry-time { color: var(--slate); font-size: .85rem; }
.entry-duration { font-variant-numeric: tabular-nums; font-weight: 800; }
.entry-badge { display: inline-block; margin-left: .4rem; padding: .1rem .4rem; border-radius: 99px; color: #92400e; background: #fef3c7; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; vertical-align: middle; }
.entry-note { margin-top: .2rem; color: var(--slate); font-size: .82rem; }
.empty-state { padding: 1.2rem; text-align: center; color: var(--slate); background: rgba(255,255,255,.55); border: 2px dashed var(--line); border-radius: .9rem; }

.toast {
    position: fixed;
    left: 50%;
    bottom: max(1.2rem, env(safe-area-inset-bottom));
    z-index: 30;
    transform: translateX(-50%);
    width: min(calc(100% - 2rem), 520px);
    padding: .85rem 1rem;
    color: white;
    background: #166534;
    border-radius: .75rem;
    box-shadow: var(--shadow);
    text-align: center;
}
.toast.error { background: #991b1b; }

dialog { width: min(calc(100% - 1rem), 720px); max-height: 88vh; padding: 0; border: 0; border-radius: 1rem; box-shadow: 0 25px 70px rgba(0,0,0,.32); }
dialog::backdrop { background: rgba(15,23,42,.62); }
.dialog-card { padding: 1.2rem; overflow-y: auto; }
.dialog-heading { display: flex; justify-content: space-between; align-items: start; gap: 1rem; margin-bottom: 1rem; }
.icon-button { border: 0; background: transparent; font-size: 2rem; line-height: 1; cursor: pointer; }
.activity-editor { display: grid; gap: .65rem; margin-bottom: 1rem; }
.editor-row { display: grid; grid-template-columns: minmax(0, 1fr) 52px auto auto; gap: .45rem; }
.editor-name, .editor-colour { min-height: 44px; border: 1px solid #cbd5e1; border-radius: .55rem; }
.editor-name { min-width: 0; padding: .55rem .65rem; }
.editor-colour { width: 52px; padding: .2rem; }
.settings-panel { margin-top: 1.1rem; padding-top: 1rem; border-top: 1px solid var(--line); }
.setting-row { display: flex; align-items: center; gap: .55rem; margin-top: .45rem; }
.setting-row input { width: 82px; min-height: 44px; padding: .5rem; border: 1px solid #cbd5e1; border-radius: .55rem; }
.field-label { display: block; margin: .9rem 0 .35rem; font-weight: 750; }
.field-label span { color: var(--slate); font-weight: 400; }
#injectActivity, #injectCount, #injectComment, #activeCommentInput { width: 100%; min-height: 46px; padding: .65rem; border: 1px solid #cbd5e1; border-radius: .6rem; background: white; }
#injectComment, #activeCommentInput { resize: vertical; }
.inject-summary { margin-top: .55rem; padding: .7rem; color: #92400e; background: #fffbeb; border-radius: .55rem; font-weight: 750; text-align: center; }
.dialog-actions { display: flex; justify-content: flex-end; gap: .65rem; margin-top: 1.2rem; }

.review-container { display: grid; gap: 1rem; }
.active-review { padding: 1rem; background: #fff7ed; border: 1px solid #fdba74; border-radius: 1rem; }
.active-review h2 { margin-bottom: .7rem; color: #9a3412; }
.review-filter { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 1rem; background: white; border-radius: 1rem; box-shadow: var(--shadow); }
.date-fields { display: flex; align-items: end; gap: .55rem; }
.date-fields label { display: grid; gap: .25rem; color: var(--slate); font-size: .8rem; font-weight: 700; }
.date-fields input, #editActivity, #editStartedAt, #editEndedAt, #editNotes { min-height: 44px; padding: .55rem .65rem; border: 1px solid #cbd5e1; border-radius: .55rem; background: white; }
#editActivity, #editStartedAt, #editEndedAt, #editNotes { width: 100%; }
#editNotes { resize: vertical; }
.field-help { margin-top: .35rem; font-size: .82rem; }
.review-list { display: grid; gap: .6rem; }
.review-card { display: grid; grid-template-columns: 10px minmax(0, 1fr) auto; gap: .8rem; align-items: center; padding: .9rem 1rem; background: white; border-radius: .85rem; box-shadow: 0 5px 14px rgba(15,23,42,.06); }
.active-entry-card { box-shadow: none; }
.review-colour { width: 10px; height: 100%; min-height: 58px; border-radius: 99px; }
.review-card-heading { font-weight: 800; }
.running-badge { display: inline-block; margin-left: .45rem; padding: .1rem .4rem; border-radius: 99px; color: #166534; background: #dcfce7; font-size: .68rem; text-transform: uppercase; letter-spacing: .06em; vertical-align: middle; }
.review-times, .review-note { margin-top: .2rem; color: var(--slate); font-size: .84rem; }
.review-warning { width: fit-content; margin-top: .35rem; padding: .18rem .45rem; color: #991b1b; background: #fee2e2; border-radius: .4rem; font-size: .75rem; font-weight: 750; }
.review-side { display: grid; justify-items: end; gap: .4rem; font-variant-numeric: tabular-nums; }
.split-actions { justify-content: space-between; align-items: center; }
.split-actions > div { display: flex; gap: .5rem; }

.report-container { display: grid; gap: 1rem; }
.report-heading { display: flex; align-items: end; justify-content: space-between; gap: 1rem; padding: 1rem; background: white; border-radius: 1rem; box-shadow: var(--shadow); }
.report-alert { padding: .8rem 1rem; color: #9a3412; background: #fff7ed; border: 1px solid #fdba74; border-radius: .75rem; font-weight: 700; }
.report-actions { display: flex; justify-content: flex-end; gap: .6rem; }
.report-section { padding: 1rem; background: white; border-radius: 1rem; box-shadow: var(--shadow); }
.report-section > h2 { margin-bottom: .8rem; }
.table-scroll { overflow-x: auto; }
.report-table { width: 100%; border-collapse: collapse; font-size: .9rem; }
.report-table th, .report-table td { padding: .65rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
.report-table th { color: var(--slate); font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
.report-table .numeric { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.timesheet-value { font-weight: 800; }
.activity-dot { display: inline-block; width: .7rem; height: .7rem; margin-right: .45rem; border-radius: 99px; vertical-align: middle; }
.totals-table { max-width: 650px; }
.totals-table tfoot th { color: var(--navy); font-size: .9rem; border-top: 2px solid var(--navy); }
.report-detail-list { display: grid; gap: .45rem; }
.report-detail { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; gap: .4rem; padding: .65rem 0; border-bottom: 1px solid var(--line); }
.report-detail .activity-dot { margin-top: .35rem; }
.report-detail-times, .report-detail-note { margin-top: .15rem; color: var(--slate); font-size: .82rem; }
.print-footer { color: var(--slate); font-size: .75rem; text-align: center; }

@media (min-width: 680px) {
    .activity-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 520px) {
    .container { width: min(100% - 1rem, 920px); margin-top: .6rem; }
    .timer-card { border-radius: .9rem; margin-bottom: 1.4rem; }
    .editor-row { grid-template-columns: minmax(0, 1fr) 50px; }
    .editor-row .button { grid-column: span 1; }
    .timer-actions { gap: .4rem; }
    .timer-actions .button { padding-inline: .45rem; font-size: .92rem; }
    .app-header { align-items: flex-start; }
    .header-actions { flex-wrap: wrap; justify-content: flex-end; }
    .connection-status { flex-wrap: wrap; }
    .last-contact { width: 100%; margin-left: 1.1rem; }
    .failed-save { align-items: stretch; flex-direction: column; }
    .failed-save-dismiss { align-self: end; }
    .review-filter { align-items: stretch; flex-direction: column; }
    .date-fields { display: grid; grid-template-columns: 1fr 1fr; }
    .date-fields .button { grid-column: 1 / -1; }
    .review-card { grid-template-columns: 8px minmax(0, 1fr); }
    .review-colour { width: 8px; grid-row: 1 / span 2; }
    .review-side { grid-column: 2; display: flex; align-items: center; justify-content: space-between; }
    .split-actions { align-items: stretch; flex-direction: column-reverse; }
    .split-actions > div { display: grid; grid-template-columns: 1fr 1fr; }
    .report-heading { align-items: stretch; flex-direction: column; }
    .report-actions { display: grid; grid-template-columns: 1fr 1fr; }
}

@media print {
    @page { margin: 12mm; }
    body { background: white; color: black; font-size: 10pt; }
    .no-print { display: none !important; }
    .container { width: 100%; max-width: none; margin: 0; }
    .report-container { display: block; }
    .report-heading, .report-section { margin: 0 0 8mm; padding: 0; box-shadow: none; break-inside: avoid; }
    .report-heading { display: block; }
    .report-table { font-size: 8.5pt; }
    .report-table th, .report-table td { padding: 4px; }
    .table-scroll { overflow: visible; }
    .detail-section { break-before: page; }
    .report-detail { break-inside: avoid; }
    .print-footer { margin-top: 8mm; }
}
