:root {
    --primary: #007aff;
    --primary-dark: #005fc4;
    --success: #218739;
    --danger: #d92d20;
    --warning: #c76d00;
    --teal: #176f72;
    --purple: #764ba2;
    --text: #242424;
    --muted: #68707a;
    --border: #e3e5e8;
    --surface: #ffffff;
    --surface-soft: #f7f8fb;
    --shadow: 0 12px 35px rgba(27, 36, 50, 0.12);
}

* {
    box-sizing: border-box;
}

html {
    min-height: 100%;
    background: #eef1f6;
}

body {
    min-height: 100vh;
    margin: 0;
    padding: max(20px, env(safe-area-inset-top)) 12px max(24px, env(safe-area-inset-bottom));
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    color: var(--text);
    background: linear-gradient(150deg, #eef1f6 0%, #f8f9fc 100%);
    overflow-y: auto;
}

button,
input {
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
a:focus-visible {
    outline: 3px solid rgba(0, 122, 255, 0.28);
    outline-offset: 2px;
}

.page-shell {
    width: 100%;
    display: flex;
    justify-content: center;
}

.container {
    width: min(100%, 560px);
    background: var(--surface);
    padding: 24px;
    border-radius: 22px;
    box-shadow: var(--shadow);
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Authentication */
.auth-container {
    max-width: 430px;
    color: #fff;
    background: linear-gradient(140deg, #176f72 0%, #4f6db8 55%, #764ba2 100%);
    box-shadow: 0 18px 44px rgba(71, 70, 151, 0.35);
    text-align: center;
}

.brand-mark {
    width: 70px;
    height: 70px;
    margin: 0 auto 12px;
    display: grid;
    place-items: center;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.17);
    font-size: 38px;
}

.auth-container h1 {
    margin: 0;
    font-size: 30px;
}

.auth-subtitle {
    margin: 8px 0 24px;
    color: rgba(255, 255, 255, 0.82);
}

.input-group {
    margin-bottom: 16px;
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 7px;
    font-size: 14px;
    font-weight: 600;
}

.input-group input,
.activity-input,
.date-input,
#unlockPin {
    width: 100%;
    min-height: 46px;
    padding: 11px 13px;
    border: 1px solid var(--border);
    border-radius: 11px;
    color: var(--text);
    background: #fff;
}

.auth-container .input-group input {
    color: #fff;
    border-color: rgba(255, 255, 255, 0.35);
    background: rgba(255, 255, 255, 0.14);
}

.auth-container .input-group input::placeholder {
    color: rgba(255, 255, 255, 0.63);
}

.btn-primary,
.btn-toggle,
.btn-finish-small,
.btn-add-activity,
.btn-apply-date,
.btn-stop-alarm,
.btn-unlock-open,
.btn-unlock-cancel {
    border: 0;
    border-radius: 11px;
    cursor: pointer;
    font-weight: 700;
    transition: transform 0.15s ease, opacity 0.15s ease, background 0.15s ease;
}

button:disabled {
    cursor: wait;
    opacity: 0.62;
}

button:not(:disabled):active {
    transform: scale(0.98);
}

.full-width {
    width: 100%;
}

.btn-primary {
    min-height: 48px;
    padding: 12px 18px;
    color: var(--purple);
    background: #fff;
}

.btn-link {
    margin-top: 13px;
    padding: 4px;
    border: 0;
    color: rgba(255, 255, 255, 0.9);
    background: transparent;
    cursor: pointer;
    text-decoration: underline;
}

.auth-switch {
    margin: 18px 0 0;
    color: rgba(255, 255, 255, 0.82);
    font-size: 14px;
}

.auth-switch a {
    color: #fff;
    font-weight: 700;
}

.auth-message,
.status-message {
    margin: 0 0 14px;
    padding: 10px 12px;
    border-radius: 10px;
    font-size: 13px;
    text-align: left;
}

.auth-message.error {
    color: #fff;
    background: rgba(126, 18, 18, 0.55);
}

.auth-message.success {
    color: #fff;
    background: rgba(14, 93, 46, 0.55);
}

.status-message {
    color: #25405f;
    background: #edf5ff;
}

.status-message.error {
    color: #7a271a;
    background: #fff0ed;
}

.status-message.success {
    color: #176b32;
    background: #ecf9ef;
}

/* App header */
.app-container {
    min-height: 300px;
}

.app-header {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: start;
    margin-bottom: 18px;
}

.tabs {
    display: flex;
    padding: 5px;
    border-radius: 12px;
    background: #f0f2f6;
}

.tab-btn {
    flex: 1;
    min-height: 42px;
    padding: 9px 12px;
    border: 0;
    border-radius: 9px;
    color: #727985;
    background: transparent;
    cursor: pointer;
    font-weight: 700;
}

.tab-btn.active {
    color: var(--text);
    background: #fff;
    box-shadow: 0 2px 7px rgba(0, 0, 0, 0.08);
}

.account-actions {
    display: grid;
    justify-items: end;
    gap: 6px;
}

.btn-darken,
.btn-logout {
    border: 0;
    background: transparent;
    cursor: pointer;
    font-weight: 700;
}

.btn-darken {
    padding: 7px 9px;
    border-radius: 8px;
    color: #fff;
    background: #151515;
    font-size: 12px;
}

.btn-logout {
    padding: 2px;
    color: var(--danger);
}

.user-email {
    max-width: 145px;
    color: var(--muted);
    font-size: 11px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Timer cards */
.activity-card {
    padding: 15px;
    margin-bottom: 14px;
    border: 1px solid var(--border);
    border-radius: 15px;
    background: var(--surface-soft);
    box-shadow: 0 3px 9px rgba(24, 39, 75, 0.04);
}

.autocomplete {
    position: relative;
}

.activity-input {
    font-size: 16px;
    font-weight: 600;
}

.autocomplete-items {
    position: absolute;
    z-index: 20;
    top: calc(100% + 2px);
    right: 0;
    left: 0;
    max-height: 190px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: #fff;
    box-shadow: 0 10px 25px rgba(25, 38, 58, 0.16);
}

.autocomplete-items:empty {
    display: none;
}

.autocomplete-items div {
    padding: 11px 12px;
    border-bottom: 1px solid #eff0f2;
    cursor: pointer;
    text-align: left;
    font-size: 14px;
}

.autocomplete-items div:last-child {
    border-bottom: 0;
}

.autocomplete-items div:hover,
.autocomplete-items div:focus {
    background: #edf5ff;
}

.timer-controls {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    grid-template-areas:
        "display display display"
        "toggle alarm finish";
    gap: 9px;
    align-items: center;
    margin-top: 12px;
}

.timer-display-small {
    grid-area: display;
    padding: 8px;
    color: #111;
    font-size: clamp(28px, 8vw, 38px);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
    letter-spacing: 1px;
    text-align: center;
}

.btn-toggle {
    grid-area: toggle;
    min-height: 44px;
    padding: 10px 12px;
    color: #fff;
    background: var(--success);
}

.btn-toggle.paused {
    background: var(--warning);
}

.btn-finish-small {
    grid-area: finish;
    min-height: 44px;
    padding: 10px 12px;
    color: #fff;
    background: var(--primary);
}

.btn-alarm {
    grid-area: alarm;
    width: 46px;
    height: 44px;
    display: grid;
    place-items: center;
    padding: 0;
    border: 1px solid #d6a800;
    border-radius: 10px;
    background: #fffdf1;
    cursor: pointer;
    font-size: 20px;
}

.btn-alarm.active {
    color: #000;
    background: #ffcc00;
    animation: pulse 1.8s infinite;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.06); }
}

.btn-add-activity {
    width: 100%;
    min-height: 48px;
    padding: 11px;
    border: 2px dashed var(--primary);
    color: var(--primary);
    background: rgba(0, 122, 255, 0.035);
}

.btn-add-activity:hover {
    background: rgba(0, 122, 255, 0.09);
}

/* Reports */
.filter-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.filter-btn {
    flex: 1 1 100px;
    min-height: 38px;
    padding: 7px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: #555e68;
    background: #fff;
    cursor: pointer;
    font-size: 13px;
    font-weight: 700;
}

.filter-btn.active {
    color: #fff;
    border-color: var(--primary);
    background: var(--primary);
}

.date-picker-group {
    display: grid;
    grid-template-columns: 1fr auto 1fr auto;
    gap: 7px;
    align-items: center;
    margin-bottom: 20px;
}

.date-input {
    min-width: 0;
    min-height: 40px;
    padding: 7px;
    font-size: 13px;
}

.btn-apply-date {
    min-height: 40px;
    padding: 8px 12px;
    color: #fff;
    background: var(--teal);
}

.report-heading-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 10px;
}

.report-heading-row h2,
.report-block h2 {
    margin: 0;
    font-size: 17px;
}

.report-total {
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.chart-container {
    position: relative;
    height: 285px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: #fff;
}

.report-block {
    margin-top: 28px;
}

.report-block h2 {
    padding-bottom: 9px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.table-scroll {
    overflow-x: auto;
}

.summary-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

.summary-table th,
.summary-table td {
    padding: 10px;
    border-bottom: 1px solid #eceef1;
    text-align: left;
}

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

.summary-table td:last-child,
.summary-table th:last-child {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.empty-table-cell,
.empty-state {
    padding: 18px;
    color: var(--muted);
    text-align: center !important;
    font-size: 13px;
}

.empty-state.error {
    color: var(--danger);
}

.history-list {
    padding: 0;
    margin: 0;
    list-style: none;
}

.history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 12px 13px;
    margin-bottom: 9px;
    border: 1px solid var(--border);
    border-radius: 11px;
    background: var(--surface-soft);
}

.history-info {
    min-width: 0;
    text-align: left;
}

.history-info strong {
    display: block;
    overflow-wrap: anywhere;
}

.history-date {
    display: block;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

.btn-delete {
    flex: 0 0 auto;
    padding: 8px 11px;
    border: 0;
    border-radius: 8px;
    color: #fff;
    background: var(--danger);
    cursor: pointer;
    font-size: 12px;
    font-weight: 700;
}

/* Alarm modal */
.modal-overlay {
    position: fixed;
    z-index: 9999;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 16px;
    background: rgba(0, 0, 0, 0.86);
}

.modal-content {
    width: min(100%, 340px);
    padding: 28px;
    border-radius: 20px;
    background: #fff;
    box-shadow: 0 12px 45px rgba(0, 0, 0, 0.5);
    text-align: center;
    animation: popIn 0.25s ease-out;
}

.modal-icon {
    font-size: 62px;
    animation: shake 0.55s infinite;
}

.modal-content h2 {
    margin: 8px 0;
    color: var(--danger);
}

.btn-stop-alarm {
    width: 100%;
    min-height: 50px;
    margin-top: 10px;
    color: #fff;
    background: var(--danger);
    font-size: 18px;
}

@keyframes popIn {
    from { transform: scale(0.88); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

@keyframes shake {
    0%, 100% { transform: rotate(-12deg); }
    50% { transform: rotate(12deg); }
}

/* OLED screen */
.oled-saver-overlay {
    position: fixed;
    z-index: 9998;
    inset: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: #000;
}

.unlock-hint {
    width: 100%;
    height: 100%;
    border: 0;
    color: #696969;
    background: #000;
    cursor: pointer;
}

.unlock-form {
    width: min(90%, 280px);
    flex-direction: column;
    align-items: center;
    color: #9c9c9c;
    text-align: center;
}

.unlock-form p {
    margin-top: 0;
}

#unlockPin {
    width: 150px;
    color: #fff;
    border: 1px solid #333;
    background: #181818;
    font-size: 24px;
    letter-spacing: 8px;
    text-align: center;
}

.unlock-actions {
    display: flex;
    gap: 12px;
    margin-top: 16px;
}

.btn-unlock-cancel,
.btn-unlock-open {
    min-width: 100px;
    padding: 10px 16px;
}

.btn-unlock-cancel {
    color: #ff625a;
    border: 1px solid #ff625a;
    background: transparent;
}

.btn-unlock-open {
    color: #fff;
    background: #218739;
}

.unlock-form small {
    margin-top: 16px;
    color: #555;
}

@media (min-width: 560px) {
    .timer-controls {
        grid-template-columns: auto minmax(130px, 1fr) auto auto;
        grid-template-areas: "toggle display alarm finish";
    }

    .timer-display-small {
        font-size: 28px;
    }
}

@media (max-width: 430px) {
    body {
        padding-inline: 8px;
    }

    .container {
        padding: 17px;
        border-radius: 17px;
    }

    .app-header {
        grid-template-columns: 1fr;
    }

    .account-actions {
        grid-template-columns: auto auto 1fr;
        justify-items: start;
        align-items: center;
    }

    .user-email {
        max-width: 100%;
        justify-self: end;
    }

    .date-picker-group {
        grid-template-columns: 1fr auto 1fr;
    }

    .btn-apply-date {
        grid-column: 1 / -1;
    }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
