/* ==========================================================================
   FluidGuide — App Styles
   ========================================================================== */

/* --- Custom Properties --- */
:root {
    --deep-blue: #003B5C;
    --bright-teal: #00B2A9;
    --white: #FFFFFF;
    --light-grey: #F5F5F5;
    --warm-sand: #F4E9D9;
    --alert-red: #D94F4F;
    --soft-green: #4CAF50;

    --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --tab-bar-height: 56px;
    --header-height: 56px;
    --max-content-width: 480px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: var(--font-stack);
    font-size: 16px;
    line-height: 1.5;
    color: var(--deep-blue);
    background: var(--white);
    -webkit-font-smoothing: antialiased;
    overscroll-behavior: none;
}

img, svg {
    display: block;
    max-width: 100%;
    height: auto;
}

button {
    font-family: inherit;
    font-size: inherit;
    cursor: pointer;
    border: none;
    background: none;
    -webkit-tap-highlight-color: transparent;
}

a {
    color: var(--bright-teal);
    text-decoration: none;
}

fieldset {
    border: none;
}

legend {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

textarea {
    font-family: var(--font-stack);
    font-size: 16px;
}

/* --- Loading Screen --- */
.loading-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--deep-blue);
    color: var(--white);
    z-index: 1000;
    gap: 1.5rem;
}

.loading-screen[hidden] {
    display: none;
}

.loading-logo {
    filter: brightness(0) invert(1);
}

.loading-text {
    font-size: 1rem;
    opacity: 0.8;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--bright-teal);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Error Screen --- */
.error-screen {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--white);
    padding: 2rem;
    z-index: 999;
    text-align: center;
    gap: 1.5rem;
}

.error-screen[hidden] {
    display: none;
}

.error-message {
    max-width: var(--max-content-width);
}

.error-message h2 {
    margin-bottom: 0.5rem;
    color: var(--deep-blue);
}

.error-message p {
    color: #666;
    margin-bottom: 0.5rem;
}

/* --- App Layout --- */
.app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
}

.app[hidden] {
    display: none;
}

.app.checked-out .tab-panel {
    opacity: 0.6;
    pointer-events: none;
}

/* --- Header --- */
.header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: var(--deep-blue);
    flex-shrink: 0;
}

.header-brand {
    display: flex;
    align-items: center;
    justify-content: center;
    height: var(--header-height);
    padding: 0 1rem;
}

.header-brand img {
    filter: brightness(0) invert(1);
}

/* --- Location Banner --- */
.location-banner {
    background: var(--warm-sand);
    padding: 0.625rem 1rem;
    text-align: center;
    font-size: 0.875rem;
}

.location-state {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.location-state[hidden] {
    display: none;
}

.location-state p {
    flex: 1 1 100%;
    margin-bottom: 0.25rem;
}

.location-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    display: inline-block;
    flex-shrink: 0;
}

.location-indicator--on {
    background: var(--soft-green);
    box-shadow: 0 0 4px var(--soft-green);
}

.location-indicator--off {
    background: #999;
}

@keyframes pulse-green {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* --- Offline Bar --- */
.offline-bar {
    background: var(--alert-red);
    color: var(--white);
    text-align: center;
    padding: 0.375rem 1rem;
    font-size: 0.8125rem;
    font-weight: 500;
}

.offline-bar[hidden] {
    display: none;
}

/* --- Main Content --- */
.main {
    flex: 1;
    padding-bottom: calc(var(--tab-bar-height) + var(--safe-area-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-panel {
    max-width: var(--max-content-width);
    margin: 0 auto;
    width: 100%;
}

.tab-panel[hidden] {
    display: none;
}

.tab-content {
    padding: 1rem;
}

.tab-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
}

/* --- Bottom Tab Bar --- */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: calc(var(--tab-bar-height) + var(--safe-area-bottom));
    padding-bottom: var(--safe-area-bottom);
    background: var(--white);
    border-top: 1px solid #E0E0E0;
    display: flex;
    z-index: 100;
}

.tab-btn {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.125rem;
    min-height: 44px;
    min-width: 44px;
    color: #999;
    font-size: 0.6875rem;
    font-weight: 500;
    transition: color 0.15s;
}

.tab-btn--active {
    color: var(--bright-teal);
}

.tab-icon {
    width: 24px;
    height: 24px;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 44px;
    padding: 0.625rem 1.25rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9375rem;
    transition: background 0.15s, opacity 0.15s;
    text-decoration: none;
}

.btn:active {
    opacity: 0.8;
}

.btn-teal {
    background: var(--bright-teal);
    color: var(--white);
}

.btn-outline {
    background: transparent;
    color: var(--deep-blue);
    border: 1.5px solid var(--deep-blue);
}

.btn-sm {
    min-height: 36px;
    padding: 0.375rem 0.875rem;
    font-size: 0.8125rem;
}

.btn-lg {
    min-height: 50px;
    font-size: 1rem;
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* --- Route Tab --- */
.route-hero {
    width: 100%;
    aspect-ratio: 16 / 9;
    background: var(--light-grey);
    overflow: hidden;
}

.route-hero:empty {
    display: none;
}

.route-hero img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.route-name {
    font-size: 1.375rem;
    margin-bottom: 0.25rem;
}

.route-summary {
    color: #555;
    margin-bottom: 1rem;
}

.confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.5rem;
}

.confidence-badge--green {
    background: #E8F5E9;
    color: #2E7D32;
}

.confidence-badge--amber {
    background: #FFF8E1;
    color: #F57F17;
}

.confidence-badge--red {
    background: #FFEBEE;
    color: #C62828;
}

.confidence-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.confidence-badge--green .confidence-dot { background: var(--soft-green); }
.confidence-badge--amber .confidence-dot { background: #FFC107; }
.confidence-badge--red .confidence-dot { background: var(--alert-red); }

.route-duration {
    font-size: 0.875rem;
    color: #555;
    margin-bottom: 1.5rem;
}

/* --- Directions --- */
.directions {
    margin-bottom: 1.5rem;
}

.direction-segment {
    margin-bottom: 1rem;
}

.direction-segment h3 {
    font-size: 0.9375rem;
    color: var(--deep-blue);
    margin-bottom: 0.25rem;
    padding-bottom: 0.25rem;
    border-bottom: 2px solid var(--bright-teal);
}

.direction-segment p {
    font-size: 0.9375rem;
    color: #444;
    line-height: 1.6;
}

/* --- Advice Cards --- */
.advice-cards {
    margin-bottom: 1.5rem;
}

.advice-card {
    background: #E0F7FA;
    border-left: 4px solid var(--bright-teal);
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
    font-size: 0.875rem;
}

.advice-card h4 {
    font-size: 0.875rem;
    margin-bottom: 0.25rem;
}

/* --- Map --- */
.map-wrapper {
    position: relative;
    margin-bottom: 1.5rem;
    border-radius: 12px;
    overflow: hidden;
}

.route-map {
    width: 100%;
    height: 280px;
    background: var(--light-grey);
    z-index: 1;
}

.btn-centre-map {
    position: absolute;
    bottom: 12px;
    right: 12px;
    width: 40px;
    height: 40px;
    background: var(--white);
    border-radius: 8px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 2;
}

/* --- Safety Card --- */
.safety-card {
    background: #FFF3E0;
    border-left: 4px solid #FF9800;
    border-radius: 0 8px 8px 0;
    padding: 1rem;
    margin-bottom: 1rem;
}

.safety-card:empty {
    display: none;
}

.safety-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
    color: #E65100;
}

.safety-card p, .safety-card li {
    font-size: 0.875rem;
    line-height: 1.6;
}

/* --- Conditions Tab --- */
.conditions-updated {
    font-size: 0.8125rem;
    color: #888;
    margin-bottom: 1rem;
}

.conditions-card {
    background: var(--light-grey);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.conditions-card h3 {
    font-size: 1rem;
    margin-bottom: 0.75rem;
    color: var(--deep-blue);
}

.conditions-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
    gap: 0.75rem;
}

.condition-item {
    text-align: center;
}

.condition-label {
    display: block;
    font-size: 0.75rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.25rem;
}

.condition-value {
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--deep-blue);
}

.wind-compass {
    transition: transform 0.3s;
}

/* --- Warnings --- */
.warnings:empty {
    display: none;
}

.warning-card {
    background: #FFEBEE;
    border-left: 4px solid var(--alert-red);
    border-radius: 0 8px 8px 0;
    padding: 0.75rem 1rem;
    margin-bottom: 0.75rem;
}

.warning-card h4 {
    color: var(--alert-red);
    font-size: 0.9375rem;
    margin-bottom: 0.25rem;
}

.warning-card p {
    font-size: 0.875rem;
    color: #444;
}

/* --- Info Tab --- */
.info-card {
    background: var(--light-grey);
    border-radius: 12px;
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.info-card--emergency {
    background: #FFF3E0;
}

.info-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.info-coming-soon {
    text-align: center;
    color: #888;
    font-size: 1rem;
    padding: 1rem 0;
}

.emergency-link {
    display: inline-flex;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--deep-blue);
    margin-top: 0.5rem;
}

.safety-list {
    list-style: none;
    padding: 0;
}

.safety-list li {
    position: relative;
    padding-left: 1.25rem;
    margin-bottom: 0.5rem;
    font-size: 0.9375rem;
    line-height: 1.5;
}

.safety-list li::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0.5em;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--bright-teal);
}

/* --- A2HS Prompt --- */
.a2hs-prompt {
    position: fixed;
    bottom: calc(var(--tab-bar-height) + var(--safe-area-bottom) + 8px);
    left: 0.5rem;
    right: 0.5rem;
    z-index: 200;
    animation: slide-up 0.3s ease-out;
}

.a2hs-prompt[hidden] {
    display: none;
}

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

.a2hs-content {
    position: relative;
    background: var(--deep-blue);
    color: var(--white);
    border-radius: 12px;
    padding: 1rem 2.5rem 1rem 1rem;
    max-width: var(--max-content-width);
    margin: 0 auto;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
}

.a2hs-content h3 {
    font-size: 1rem;
    margin-bottom: 0.375rem;
}

.a2hs-content p {
    font-size: 0.8125rem;
    line-height: 1.5;
    opacity: 0.9;
}

.a2hs-close {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--white);
    font-size: 1.5rem;
    opacity: 0.7;
}

.a2hs-indicator {
    margin-top: 0.5rem;
}

.a2hs-indicator svg {
    animation: bounce 1s ease-in-out 3;
}

@keyframes bounce {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

/* --- Modal --- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
    padding: 1rem;
}

.modal-overlay[hidden] {
    display: none;
}

.modal {
    background: var(--white);
    border-radius: 16px;
    padding: 1.5rem;
    max-width: 360px;
    width: 100%;
}

.modal h3 {
    font-size: 1.125rem;
    margin-bottom: 0.75rem;
}

.modal p {
    font-size: 0.9375rem;
    color: #555;
    margin-bottom: 1rem;
    line-height: 1.5;
}

.modal-actions {
    display: flex;
    gap: 0.75rem;
}

.modal-actions .btn {
    flex: 1;
}

/* --- Post-Session Overlay --- */
.post-session-overlay {
    position: fixed;
    inset: 0;
    background: var(--white);
    z-index: 250;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.post-session-overlay[hidden] {
    display: none;
}

.post-session-content {
    max-width: var(--max-content-width);
    margin: 0 auto;
    padding: 2rem 1rem;
    text-align: center;
}

.post-session-content h2 {
    font-size: 1.5rem;
    margin: 1rem 0 0.25rem;
}

.post-session-content > p {
    color: #666;
    margin-bottom: 2rem;
}

/* --- Feedback Form --- */
.feedback-form {
    text-align: left;
}

.feedback-section {
    margin-bottom: 1.5rem;
}

.feedback-textarea {
    width: 100%;
    border: 1.5px solid #DDD;
    border-radius: 8px;
    padding: 0.75rem;
    resize: vertical;
    min-height: 80px;
}

.feedback-textarea:focus {
    outline: none;
    border-color: var(--bright-teal);
}

.feedback-hint {
    font-size: 0.8125rem;
    color: #888;
    margin-bottom: 0.75rem;
}

/* --- Star Rating --- */
.star-rating {
    display: flex;
    gap: 0.25rem;
    justify-content: center;
}

.star {
    font-size: 2.5rem;
    color: #DDD;
    transition: color 0.15s;
    min-width: 44px;
    min-height: 44px;
}

.star.active {
    color: #FFC107;
}

/* --- Video Capture --- */
.video-capture {
    position: relative;
    background: var(--light-grey);
    border-radius: 12px;
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.video-preview,
.video-playback {
    width: 100%;
    border-radius: 8px;
    background: #000;
    aspect-ratio: 4 / 3;
    margin-bottom: 0.75rem;
}

.video-preview[hidden],
.video-playback[hidden] {
    display: none;
}

.video-controls {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    flex-wrap: wrap;
}

.video-controls button[hidden] {
    display: none;
}

.video-countdown {
    text-align: center;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--alert-red);
    margin-top: 0.5rem;
}

.video-countdown[hidden] {
    display: none;
}

.video-countdown.countdown-large {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 4rem;
    color: #fff;
    text-shadow: 0 2px 8px rgba(0, 0, 0, 0.6);
    z-index: 10;
}

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 0.5rem;
    font-size: 0.875rem;
    line-height: 1.4;
    cursor: pointer;
    margin-top: 0.5rem;
}

.checkbox-label[hidden] {
    display: none;
}

.checkbox-label input[type="checkbox"] {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    margin-top: 0.125rem;
    accent-color: var(--bright-teal);
}

/* --- Feedback Progress --- */
.feedback-progress {
    margin-bottom: 1rem;
    text-align: center;
}

.feedback-progress[hidden] {
    display: none;
}

.progress-bar {
    height: 6px;
    background: #E0E0E0;
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--bright-teal);
    border-radius: 3px;
    width: 0%;
    transition: width 0.3s;
}

.feedback-progress p {
    font-size: 0.8125rem;
    color: #888;
}

/* --- Feedback Thanks --- */
.feedback-thanks {
    text-align: center;
    padding: 2rem 0;
}

.feedback-thanks[hidden] {
    display: none;
}

.feedback-thanks h3 {
    font-size: 1.375rem;
    color: var(--soft-green);
    margin-bottom: 0.5rem;
}

.feedback-thanks p {
    color: #666;
    margin-bottom: 1.5rem;
}

/* --- Session Ended Notice --- */
.session-ended-notice {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background: var(--deep-blue);
    color: var(--white);
    text-align: center;
    padding: 1rem;
    z-index: 400;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    animation: slide-down 0.3s ease-out;
}

.session-ended-notice[hidden] {
    display: none;
}

@keyframes slide-down {
    from { transform: translateY(-100%); }
    to { transform: translateY(0); }
}

.session-ended-notice p {
    font-size: 0.875rem;
}

/* --- Accessibility --- */
:focus-visible {
    outline: 2px solid var(--bright-teal);
    outline-offset: 2px;
}

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

/* --- Responsive --- */
@media (min-width: 481px) {
    .main {
        display: flex;
        justify-content: center;
    }
}
