/* CSS Variables for Theming */
:root {
    /* Dark mode (default) - warm, soft, nurturing - inspired by digital lavender & serene pastels */
    /* Based on research: soft blues, gentle greens, warm beiges, pastel palette */
    --bg-primary: #2a2528;
    --bg-secondary: #352f35;
    --bg-card: #3d3740;
    --text-primary: #f2f2f2;
    --text-secondary: #d0d0d0;
    --accent: #b88cd8;
    --accent-hover: #c89ce8;
    --shadow: rgba(0, 0, 0, 0.18);
    --border: #4a444a;
    --alert-info: #a8c8d8;
    --alert-warning: #e8b8a8;
    --active-button: #e8b8c8;
    --active-button-hover: #f8c8d8;
}

[data-theme="light"] {
    /* Light mode - warm beige & soft pastels - inspired by birth plan templates & wellness apps */
    /* Based on research: beige, soft peach, pale sky blue, mint green, digital lavender */
    --bg-primary: #faf5f8;
    --bg-secondary: #fff8fb;
    --bg-card: #ffffff;
    --text-primary: #000000;
    --text-secondary: #4a4a4a;
    --accent: #b88cd8;
    --accent-hover: #a87cc8;
    --shadow: rgba(200, 168, 184, 0.08);
    --border: #e8d8e0;
    --alert-info: #a8c8d8;
    --alert-warning: #e8b8a8;
    --active-button: #e8b8c8;
    --active-button-hover: #d8a8b8;
    --pastel-peach: #f4d4c4;
    --pastel-lavender: #e8d8f0;
    --pastel-mint: #d8f0e8;
}

/* Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    min-height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    transition: background-color 0.3s ease, background 0.3s ease, color 0.3s ease;
    /* Safe area support for iPhone notch and home indicator */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* Dark mode radial gradient background */
[data-theme="dark"] body {
    background: radial-gradient(
        circle at 50% 30%,
        rgba(231, 170, 210, 0.15),
        rgba(40, 20, 60, 1) 70%
    );
    background-attachment: fixed;
    color: #f2f2f2;
}

/* Light mode gradient background */
[data-theme="light"] body {
    background: linear-gradient(
        to bottom,
        #f7d7f0 0%,
        #e6d9ff 100%
    );
    background-attachment: fixed;
    color: #2a2a2a;
}

.hidden {
    display: none !important;
}

/* Screen reader only - visually hidden but accessible to assistive tech */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border-width: 0;
}

/* Header */
header {
    padding: 1.5rem 1rem;
    padding-top: max(1.5rem, env(safe-area-inset-top));
    text-align: center;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    border-radius: 0 0 16px 16px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

/* Alert Banner */
.alert-banner {
    padding: 1rem 3rem 1rem 1rem;
    margin: 0;
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 2px 8px var(--shadow);
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: transform 0.3s ease, opacity 0.3s ease;
    flex-wrap: wrap;
}

/* Adjust padding when share button is visible */
.alert-banner.established-pattern {
    padding-right: 8rem; /* Make room for acknowledge and share buttons */
}

/* Adjust padding when acknowledge button is visible */
.alert-banner.established-pattern {
    padding-right: 8rem; /* Make room for acknowledge button */
}

.alert-banner.hidden {
    display: none;
}

.alert-banner:not(.hidden) {
    transform: translateY(0);
    opacity: 1;
}

.alert-banner.slide-in {
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        transform: translateY(-100%);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.alert-banner p {
    font-size: 0.95rem;
    line-height: 1.5;
    color: var(--text-primary);
    flex: 1;
    margin: 0;
}

.alert-banner.info {
    background-color: var(--alert-info);
    color: var(--text-primary);
    border-left: 4px solid var(--accent);
    border-radius: 0 0 12px 12px;
}

.alert-banner.warning {
    background-color: var(--alert-warning);
    color: var(--text-primary);
    border-left: 4px solid #e8b8a8;
    border-radius: 0 0 12px 12px;
}

/* Established pattern - more prominent */
.alert-banner.established-pattern {
    padding: 1.25rem 8rem 1.25rem 1.25rem;
    border-left-width: 6px;
    box-shadow: 0 4px 16px rgba(232, 184, 168, 0.3);
    font-weight: 500;
}

.alert-banner.established-pattern p {
    font-size: 1rem;
    font-weight: 500;
}

/* Pulsing animation for established pattern */
.alert-banner.pulsing {
    animation: pulseAlert 2s ease-in-out infinite;
}

@keyframes pulseAlert {
    0%, 100% {
        box-shadow: 0 4px 16px rgba(232, 184, 168, 0.3);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 6px 24px rgba(232, 184, 168, 0.5);
        transform: scale(1.01);
    }
}

/* Ensure pulsing works with slide-in */
.alert-banner.pulsing.slide-in {
    animation: slideDown 0.3s ease-out, pulseAlert 2s ease-in-out 0.3s infinite;
}

.alert-banner-icon {
    font-size: 1.25rem;
    flex-shrink: 0;
    line-height: 1;
}

.alert-banner-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: 0.25rem;
    border-radius: 4px;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    transition: opacity 0.2s ease, background-color 0.2s ease;
    touch-action: manipulation;
    z-index: 10;
}

/* Acknowledge button for established patterns */
.alert-banner-acknowledge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background-color: var(--accent);
    color: var(--text-primary);
    border: none;
    font-size: 0.85rem;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
    z-index: 10;
    white-space: nowrap;
}

.alert-banner-acknowledge:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.alert-banner-acknowledge:active {
    transform: translateY(0);
}

.alert-banner-acknowledge:focus {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

.alert-banner-acknowledge:disabled {
    opacity: 0.7;
    cursor: not-allowed;
    transform: none;
}

.alert-banner-acknowledge.hidden {
    display: none;
}

.alert-banner-close:hover {
    opacity: 1;
    background-color: rgba(0, 0, 0, 0.1);
}

.alert-banner-close:focus {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
    opacity: 1;
}

/* Main Content */
main {
    flex: 1;
    padding: 1.5rem 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    max-width: 600px;
    margin: 0 auto;
    width: 100%;
}

/* Timer Container */
.timer-container {
    text-align: center;
    margin-bottom: 2rem;
    padding: 2.5rem 1rem;
    background-color: var(--bg-secondary);
    border-radius: 20px;
    box-shadow: 0 4px 16px var(--shadow);
    border: 1px solid var(--border);
}

.timer-display {
    font-size: 4rem;
    font-weight: 300;
    font-variant-numeric: tabular-nums;
    color: var(--text-primary);
    margin-bottom: 2rem;
    min-height: 5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.timer-display.updating {
    transform: scale(1.05);
    opacity: 0.8;
}

/* Timer glow effect in dark mode - soft lavender glow */
[data-theme="dark"] .timer-display {
    text-shadow: 0 0 24px rgba(200, 168, 216, 0.4);
}

/* Main Button - Round design */
.btn-main {
    width: 200px;
    height: 200px;
    padding: 0;
    font-size: 1.1rem;
    font-weight: 500;
    background-color: var(--accent);
    color: var(--text-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
    transition: background-color 0.3s ease, transform 0.2s ease, box-shadow 0.3s ease;
    box-shadow: 0 4px 16px rgba(184, 140, 216, 0.4);
    touch-action: manipulation;
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    margin: 0 auto;
    gap: 0.5rem;
}

.wave-icon {
    width: 80px;
    height: 80px;
    display: block;
}

.button-text {
    font-size: 1.1rem;
    font-weight: 500;
    margin-top: 0.25rem;
}

/* Wave animation - gentle, reassuring flow like a contraction wave */
.wave {
    transform-origin: center;
    animation: waveFlow 4s ease-in-out infinite;
}

.wave1 {
    animation-delay: 0s;
}

.wave2 {
    animation-delay: 0.3s;
}

.wave3 {
    animation-delay: 0.6s;
}

@keyframes waveFlow {
    0% {
        transform: translateX(0) scaleY(0.9);
        opacity: 0.7;
    }
    25% {
        transform: translateX(3px) scaleY(1);
        opacity: 0.9;
    }
    50% {
        transform: translateX(0) scaleY(1.15);
        opacity: 1;
    }
    75% {
        transform: translateX(-3px) scaleY(1);
        opacity: 0.9;
    }
    100% {
        transform: translateX(0) scaleY(0.9);
        opacity: 0.7;
    }
}

/* Active state - waves become more pronounced and faster */
.btn-main.active .wave {
    animation-duration: 2.5s;
    animation-timing-function: ease-in-out;
}

.btn-main.active .wave1 {
    stroke-width: 3.5;
}

.btn-main.active .wave2 {
    stroke-width: 3;
    opacity: 0.9;
}

.btn-main.active .wave3 {
    stroke-width: 2.5;
    opacity: 0.7;
}

/* Disable animation for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .wave {
        animation: none;
    }
}

.btn-main:hover:not(.active) {
    background-color: var(--accent-hover);
    box-shadow: 0 6px 20px rgba(184, 140, 216, 0.5);
    transform: scale(1.02);
}

.btn-main:active {
    transform: scale(0.96);
}

.btn-main:focus {
    outline: 3px solid var(--accent);
    outline-offset: 4px;
}

/* Active state - when contraction is being timed - stronger pastel purple */
.btn-main.active {
    background-color: var(--accent);
    box-shadow: 0 6px 24px rgba(184, 140, 216, 0.6);
    animation: pulse-gentle 3s ease-in-out infinite;
}

.btn-main.active:hover {
    background-color: var(--accent-hover);
}

/* Subtle pulsing animation for active button - calming */
@keyframes pulse-gentle {
    0%, 100% {
        box-shadow: 0 6px 24px rgba(184, 140, 216, 0.6);
        transform: scale(1);
    }
    50% {
        box-shadow: 0 8px 28px rgba(184, 140, 216, 0.75);
        transform: scale(1.02);
    }
}

/* Disable animation for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .btn-main.active {
        animation: none;
    }
}

/* Stats Section */
.stats-section {
    margin-bottom: 2rem;
}

.stats-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.stat-card {
    background-color: var(--bg-card);
    padding: 1.25rem;
    border-radius: 16px;
    box-shadow: 0 2px 12px var(--shadow);
    border: 1px solid var(--border);
    transition: transform 0.2s ease, box-shadow 0.2s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px var(--shadow);
}

.stat-card.highlight {
    border: 2px solid var(--accent);
    background-color: var(--bg-secondary);
}

.stat-label {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Recent Section */
.recent-section {
    margin-bottom: 2rem;
}

.recent-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Removed section-header styles - no longer needed */

.recent-list {
    background-color: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 2px 8px var(--shadow);
    border: 1px solid var(--border);
    overflow: hidden;
}

.recent-item {
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.recent-item:last-child {
    border-bottom: none;
}

.recent-item-time {
    font-size: 0.9rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
}

.recent-item-content {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex: 1;
    justify-content: flex-end;
}

.recent-item-details {
    text-align: right;
}

.recent-item-delete {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
    font-size: 1.1rem;
    font-weight: 400;
    line-height: 1;
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 6px;
    transition: all 0.2s ease;
    flex-shrink: 0;
    min-width: 36px;
    min-height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    touch-action: manipulation;
    position: relative;
}

.recent-item-delete::before {
    content: '🗑️';
    font-size: 1rem;
    display: block;
    line-height: 1;
}

.recent-item-delete:hover {
    background-color: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.5);
    color: #dc2626;
    transform: scale(1.05);
}

.recent-item-delete:active {
    transform: scale(0.95);
    background-color: rgba(239, 68, 68, 0.3);
}

.recent-item-delete:focus {
    outline: 2px solid #ef4444;
    outline-offset: 2px;
    background-color: rgba(239, 68, 68, 0.2);
}

/* Tooltip for delete button */
.recent-item-delete::after {
    content: attr(aria-label);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%) translateY(-4px);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    border: 1px solid var(--border);
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 10;
}

.recent-item-delete:hover::after {
    opacity: 1;
    transform: translateX(-50%) translateY(-8px);
}

/* Hide tooltip on touch devices to avoid sticky tooltips */
@media (hover: none) {
    .recent-item-delete::after {
        display: none;
    }
}

.recent-item-duration {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

.recent-item-gap {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.25rem;
    font-variant-numeric: tabular-nums;
}

.empty-state {
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
}

.empty-state-icon {
    font-size: 4rem;
    line-height: 1;
    opacity: 0.6;
    filter: grayscale(0.3);
    animation: float-gentle 3s ease-in-out infinite;
}

@keyframes float-gentle {
    0%, 100% {
        transform: translateY(0);
    }
    50% {
        transform: translateY(-8px);
    }
}

.empty-state-content {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-width: 280px;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.empty-state-message {
    font-size: 0.9rem;
    line-height: 1.6;
    color: var(--text-secondary);
    margin: 0;
}

/* Success Toast Notification */
.success-toast {
    position: fixed;
    bottom: max(2rem, calc(2rem + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--bg-card);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1000;
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 90%;
    pointer-events: none;
    margin-left: env(safe-area-inset-left);
    margin-right: env(safe-area-inset-right);
}

.success-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.success-toast-icon {
    font-size: 1.25rem;
    line-height: 1;
}

.success-toast-message {
    font-size: 0.9rem;
    margin: 0;
}

/* Undo Toast Notification */
.undo-toast {
    position: fixed;
    bottom: max(2rem, calc(2rem + env(safe-area-inset-bottom)));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background-color: var(--bg-card);
    color: var(--text-primary);
    padding: 1rem 1.5rem;
    border-radius: 12px;
    box-shadow: 0 4px 16px var(--shadow);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    z-index: 1001; /* Above success toast */
    opacity: 0;
    transition: transform 0.3s ease, opacity 0.3s ease;
    max-width: 90%;
    pointer-events: auto; /* Allow interaction */
    margin-left: env(safe-area-inset-left);
    margin-right: env(safe-area-inset-right);
}

.undo-toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.undo-toast-icon {
    font-size: 1.25rem;
    line-height: 1;
    flex-shrink: 0;
}

.undo-toast-message {
    font-size: 0.9rem;
    margin: 0;
    flex: 1;
}

.undo-button {
    background-color: var(--accent);
    color: var(--text-primary);
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
    white-space: nowrap;
    flex-shrink: 0;
}

.undo-button:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.undo-button:active {
    transform: translateY(0);
}

.undo-button:focus {
    outline: 2px solid var(--text-primary);
    outline-offset: 2px;
}

.undo-button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none;
}

.undo-countdown {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    min-width: 2.5rem;
    text-align: right;
}

/* Disable animation for users who prefer reduced motion */
@media (prefers-reduced-motion: reduce) {
    .empty-state-icon {
        animation: none;
    }
    
    .alert-banner,
    .alert-banner.slide-in,
    .alert-banner.pulsing {
        animation: none;
        transform: scale(1);
        box-shadow: 0 4px 16px rgba(232, 184, 168, 0.3);
    }
    
    .timer-display.updating {
        transform: none;
        opacity: 1;
    }
    
    .success-toast,
    .undo-toast {
        transition: none;
    }
}

/* Clear Session Confirmation Modal */
.clear-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    padding-top: max(1.5rem, env(safe-area-inset-top));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }
    to {
        opacity: 1;
    }
}

.clear-modal.hidden {
    display: none;
}

.clear-modal-content {
    max-width: 420px;
    width: 100%;
    background-color: var(--bg-card);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border);
    text-align: center;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.clear-modal-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.8;
}

.clear-modal-content h2 {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.clear-modal-warning {
    font-size: 0.95rem;
    color: var(--text-secondary);
    margin-bottom: 1.5rem;
    line-height: 1.6;
}

.clear-modal-checkbox {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    border: 2px solid var(--border);
    transition: border-color 0.2s ease;
}

.clear-modal-checkbox input[type="checkbox"]:checked + label {
    color: var(--accent);
}

/* Style the checkbox container when checked - using class toggle in JS if :has() not supported */
.clear-modal-checkbox.checked {
    border-color: var(--accent);
    background-color: rgba(184, 140, 216, 0.1);
}

.clear-modal-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.clear-modal-checkbox label {
    font-size: 0.95rem;
    color: var(--text-primary);
    cursor: pointer;
    user-select: none;
    flex: 1;
    text-align: left;
}

.clear-modal-buttons {
    display: flex;
    gap: 0.75rem;
    flex-direction: row-reverse; /* Cancel on left, Clear on right */
}

.clear-confirm-btn {
    background-color: #ef4444;
    color: #ffffff;
    border: none;
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    touch-action: manipulation;
    flex: 1;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.clear-confirm-btn:hover:not(:disabled) {
    background-color: #dc2626;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
}

.clear-confirm-btn:active:not(:disabled) {
    transform: translateY(0);
}

.clear-confirm-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
    transform: none;
    box-shadow: none;
}

.clear-cancel-btn {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border);
    padding: 0.875rem 1.5rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
    flex: 1;
}

.clear-cancel-btn:hover {
    background-color: var(--bg-primary);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.clear-cancel-btn:active {
    transform: translateY(0);
}

/* Emergency Modal */
.emergency-modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    overflow-y: auto;
    animation: fadeIn 0.2s ease;
}

.emergency-modal.hidden {
    display: none;
}

.emergency-modal-content {
    max-width: 600px;
    width: 100%;
    background-color: var(--bg-card);
    padding: 2rem;
    border-radius: 20px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border);
    position: relative;
    animation: slideUp 0.3s ease;
    max-height: 90vh;
    overflow-y: auto;
}

.emergency-modal-close {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 2rem;
    line-height: 1;
    cursor: pointer;
    width: 2.5rem;
    height: 2.5rem;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: background-color 0.2s ease, color 0.2s ease;
    z-index: 10;
}

.emergency-modal-close:hover {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
}

.emergency-modal-content h2 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
    font-weight: 600;
    padding-right: 3rem;
}

.emergency-section,
.midwife-section,
.nhs111-section,
.general-advice-section {
    margin-bottom: 2rem;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
}

.emergency-section:last-child,
.midwife-section:last-child,
.nhs111-section:last-child,
.general-advice-section:last-child {
    border-bottom: none;
}

.emergency-modal-content h3 {
    font-size: 1.25rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    font-weight: 600;
}

.emergency-modal-content h4 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    margin-top: 1rem;
    color: var(--text-primary);
    font-weight: 600;
}

.emergency-list {
    list-style: none;
    padding: 0;
    margin: 0 0 1.25rem 0;
}

.emergency-list li {
    padding: 0.5rem 0 0.5rem 1.5rem;
    color: var(--text-secondary);
    line-height: 1.6;
    position: relative;
}

.emergency-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--accent);
    font-weight: bold;
    font-size: 1.2rem;
}

/* Emergency Buttons */
.btn-emergency {
    background-color: #ef4444;
    color: #ffffff;
    border: none;
    padding: 1rem 2rem;
    border-radius: 12px;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    touch-action: manipulation;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.3);
}

.btn-emergency:hover {
    background-color: #dc2626;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(239, 68, 68, 0.4);
}

.btn-emergency:active {
    transform: translateY(0);
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.3);
}

.btn-nhs111 {
    background-color: var(--accent);
    color: #ffffff;
    border: none;
    padding: 0.875rem 1.75rem;
    border-radius: 12px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    width: 100%;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    touch-action: manipulation;
}

.btn-nhs111:hover {
    background-color: var(--accent-hover);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(184, 140, 216, 0.3);
}

.btn-nhs111:active {
    transform: translateY(0);
}

.nhs111-description {
    color: var(--text-secondary);
    margin-bottom: 1rem;
    font-size: 0.95rem;
    line-height: 1.6;
}

/* Maternity Unit Phone Input */
.maternity-unit-container {
    margin-top: 1.5rem;
    padding: 1.25rem;
    background-color: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.maternity-unit-input-container {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 0;
}

.maternity-unit-input {
    flex: 1;
    padding: 0.75rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    background-color: var(--bg-card);
    color: var(--text-primary);
    font-size: 1rem;
    transition: border-color 0.2s ease;
}

.maternity-unit-input:focus {
    outline: none;
    border-color: var(--accent);
}

.btn-save-phone {
    background-color: var(--accent);
    color: #ffffff;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
    white-space: nowrap;
}

.btn-save-phone:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-save-phone:active {
    transform: translateY(0);
}

.saved-maternity-unit {
    margin-top: 1rem;
}

.saved-maternity-unit.hidden {
    display: none;
}

.saved-phone-label {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.saved-phone-number {
    font-size: 1.1rem;
    color: var(--text-primary);
    font-weight: 600;
    margin-bottom: 1rem;
    word-break: break-all;
}

.maternity-unit-buttons {
    display: flex;
    gap: 0.75rem;
}

.btn-call-phone {
    flex: 1;
    background-color: var(--accent);
    color: #ffffff;
    border: none;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
}

.btn-call-phone:hover {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-call-phone:active {
    transform: translateY(0);
}

.btn-edit-phone {
    background-color: var(--bg-secondary);
    color: var(--text-primary);
    border: 2px solid var(--border);
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
}

.btn-edit-phone:hover {
    background-color: var(--bg-card);
    border-color: var(--accent);
    transform: translateY(-1px);
}

.btn-edit-phone:active {
    transform: translateY(0);
}

.general-advice-section p {
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 0.75rem;
}

.disclaimer-text {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
    color: var(--text-primary) !important;
}

/* Safety Screen Emergency Info */
.safety-emergency-info {
    margin: 1.5rem 0;
    padding: 1.25rem;
    background-color: rgba(184, 140, 216, 0.1);
    border-radius: 12px;
    border: 1px solid var(--accent);
}

.safety-emergency-info h3 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
    color: var(--text-primary);
    font-weight: 600;
}

.safety-emergency-info p {
    margin-bottom: 0.5rem;
    line-height: 1.6;
    color: var(--text-secondary);
}

.safety-emergency-info p:last-child {
    margin-bottom: 0;
}

/* Alert Banner Emergency Button */
.alert-banner-emergency {
    position: absolute;
    top: 0.75rem;
    right: 3.5rem; /* Position to left of share button */
    background-color: var(--alert-warning);
    color: #ffffff;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease;
    touch-action: manipulation;
    z-index: 5;
}

.alert-banner-emergency:hover {
    background-color: #d97706;
    transform: translateY(-1px);
}

.alert-banner-emergency:active {
    transform: translateY(0);
}

.alert-banner-emergency.hidden {
    display: none;
}

/* Footer */
footer {
    padding: 1.5rem 1rem;
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border);
    margin-top: auto;
}

.footer-links {
    display: flex;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.footer-version {
    margin-top: 1rem;
    text-align: center;
}

.version-text {
    font-size: 0.75rem;
    color: var(--text-secondary);
    opacity: 0.7;
    margin: 0;
}

.link-button {
    background: none;
    border: none;
    color: var(--accent);
    font-size: 0.9rem;
    cursor: pointer;
    padding: 0.5rem;
    text-decoration: underline;
    text-underline-offset: 3px;
    transition: color 0.2s ease;
    touch-action: manipulation;
}

.link-button:hover {
    color: var(--accent-hover);
}

.link-button:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
}

/* Emergency Button in Footer */
.emergency-button {
    font-weight: 600;
    color: var(--alert-warning) !important;
    position: relative;
}

.emergency-button:hover {
    color: var(--active-button) !important;
}

.emergency-button:focus {
    outline: 2px solid var(--alert-warning);
}

/* Safety Intro Overlay */
.safety-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-primary);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
    padding-top: max(1.5rem, env(safe-area-inset-top));
    padding-bottom: max(1.5rem, env(safe-area-inset-bottom));
    padding-left: max(1.5rem, env(safe-area-inset-left));
    padding-right: max(1.5rem, env(safe-area-inset-right));
    overflow-y: auto;
}

.safety-content {
    max-width: 500px;
    width: 100%;
    background-color: var(--bg-secondary);
    padding: 2rem;
    border-radius: 16px;
    box-shadow: 0 8px 24px var(--shadow);
    border: 1px solid var(--border);
}

.safety-content h1 {
    font-size: 1.75rem;
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--text-primary);
}

.safety-content h2 {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.safety-text {
    margin-bottom: 2rem;
}

.safety-text p {
    margin-bottom: 1rem;
    color: var(--text-primary);
    line-height: 1.7;
}

.safety-text p:last-child {
    margin-bottom: 0;
}

.safety-text strong {
    color: var(--accent);
    font-weight: 600;
}

/* Primary Button */
.btn-primary {
    width: 100%;
    padding: 1.25rem;
    font-size: 1.1rem;
    font-weight: 600;
    background-color: var(--accent);
    color: var(--text-primary);
    border: none;
    border-radius: 16px;
    cursor: pointer;
    transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
    box-shadow: 0 4px 16px rgba(184, 140, 216, 0.3);
    touch-action: manipulation;
}

.btn-primary:hover {
    background-color: var(--accent-hover);
}

.btn-primary:active {
    transform: scale(0.98);
}

.btn-primary:focus {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Responsive Design */
@media (max-width: 480px) {
    .timer-display {
        font-size: 3rem;
    }
    
    .btn-main {
        width: 180px;
        height: 180px;
        font-size: 1rem;
    }

    .stats-grid {
        grid-template-columns: 1fr;
    }

    .footer-links {
        flex-direction: column;
        gap: 1rem;
        align-items: center;
    }

    .safety-content {
        padding: 1.5rem;
    }

    .clear-modal-content {
        padding: 1.5rem;
    }

    .clear-modal-content h2 {
        font-size: 1.25rem;
    }

    .share-view {
        padding: 1.5rem;
    }

    .share-summary {
        grid-template-columns: 1fr;
        padding: 1rem;
    }

    .share-view-header h2 {
        font-size: 1.25rem;
    }

    .share-table th,
    .share-table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.85rem;
    }


    /* Alert banner mobile adjustments */
    .alert-banner.established-pattern {
        padding-right: 1rem;
        padding-bottom: 3.5rem; /* Make room for acknowledge button on mobile */
    }

    .alert-banner-acknowledge {
        top: auto;
        bottom: 0.75rem;
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
    }

    /* Alert banner share button mobile */
    .alert-banner-share {
        top: auto;
        bottom: 3.5rem; /* Position above acknowledge button */
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
    }

    /* Undo toast mobile adjustments */
    .undo-toast {
        flex-wrap: wrap;
        gap: 0.5rem;
    }

    .undo-toast-message {
        width: 100%;
        order: 1;
    }

    .undo-button {
        order: 2;
        flex: 1;
        min-width: 80px;
    }

    .undo-countdown {
        order: 3;
        text-align: left;
    }

    /* Emergency modal mobile adjustments */
    .emergency-modal-content {
        padding: 1.5rem;
        max-height: 95vh;
    }

    .emergency-modal-content h2 {
        font-size: 1.5rem;
        padding-right: 2.5rem;
    }

    .emergency-modal-content h3 {
        font-size: 1.1rem;
    }

    .maternity-unit-input-container {
        flex-direction: column;
    }

    .maternity-unit-buttons {
        flex-direction: column;
    }

    /* Alert banner emergency button mobile */
    .alert-banner-emergency {
        top: auto;
        bottom: 3.5rem; /* Position above share button */
        right: 0.75rem;
        left: 0.75rem;
        width: auto;
    }
}

@media (min-width: 481px) {
    .timer-display {
        font-size: 4.5rem;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    :root {
        --border: #555555;
    }

    [data-theme="light"] {
        --border: #aaaaaa;
    }
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    * {
        transition: none !important;
        animation: none !important;
    }
}

