/**
 * OTEC Tenant - Consolidated Frontend CSS
 *
 * This file consolidates EstimatorTool.css and ServiceTypeSelector.css
 * for easy testing and modification of the OTEC tenant theme.
 *
 * USAGE: Make any style overrides here - this loads AFTER bundled CSS
 */

/* ========================================
   CSS VARIABLES (from EstimatorTool.css)
   ======================================== */
:root {
    /* Brand Colors */
    --tme-color-primary-1: #006a84; /* dark teal */
    --tme-color-primary-2: #76b7bd; /* light teal */
    --tme-color-primary-3: #fad02c;
    --tme-color-secondary-1: #c4c38d;
    --tme-color-secondary-2: #0a5a9c;
    --tme-color-secondary-3: #095284;
    --tme-color-danger: #d73348;
    --tme-color-info: #006a84;
    --tme-color-dark: #001825;
    --tme-color-white: #fff;

    /* Text Colors */
    --tme-color-text-primary: #2d2d2d;
    --tme-color-text-secondary: #374151;
    --tme-color-text: #111827;
    --tme-color-text-muted: #333;
    --tme-color-text-darker: #0a0a0a;

    /* Backgrounds */
    --tme-color-bg-page: #f5f5f5;

    /* Borders */
    --tme-color-border: #ccc;
    --tme-color-border-light: #e5e7eb;

    /* Cards */
    --card-radius: 12px;
    --card-padding: 16px;
    --card-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);

    /* Fonts - Updated to use Poppins + Playfair Display (loaded via Google Fonts in index.html) */
    --tme-ff-inter: "Poppins", system-ui, sans-serif;
    --tme-ff-heading: "Playfair Display", Georgia, serif;

    /* Headings */
    --heading-size: clamp(18px, 1.6vw, 22px);
}

/* ========================================
   ESTIMATOR TOOL OVERRIDES
   ======================================== */

/* Reset/baseline */
*,
*::before,
*::after {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--tme-ff-inter);
    background: var(--tme-color-bg-page);
    color: var(--tme-color-text);
}

/* Shell */
.appContainer {
    padding: 16px;
    gap: 12px;
    min-width: 0;
    height: 100%;
}

/* Cards & panels */
.card {
    border-radius: var(--card-radius);
    box-shadow: var(--card-shadow);
    padding: var(--card-padding);
    background: #fff;
}

.leftPanel {
    display: flex;
    flex-direction: column;
    min-width: 0;
    min-height: 0;
    overflow: hidden;
}

.rightPanel {
    display: grid;
    grid-template-rows: auto 1fr;
    gap: 12px;
    min-width: 0;
    min-height: 0;
    position: relative;
}

/* Map */
.mapWrapper {
    position: relative;
    width: 100%;
    min-height: 240px;
    border: 1px solid var(--tme-color-border);
    border-radius: var(--card-radius);
    background: #fff;
    overflow: hidden;
}

.mapDiv {
    position: absolute;
    inset: 0;
    z-index: 0;
    touch-action: none;
    overscroll-behavior: contain;
}

.mapDiv .esri-view,
.mapDiv .esri-view-root,
.mapDiv .esri-view-surface {
    touch-action: none;
    overscroll-behavior: contain;
}

.mapDiv canvas {
    min-width: 0 !important;
    min-height: 0 !important;
}

/* Overlay (spinner) */
.mapOverlay {
    position: absolute;
    inset: 0;
    z-index: 10;
    pointer-events: all;
    background: rgba(255, 255, 255, 0.55);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 12px;
}

.spinner {
    width: 56px;
    height: 56px;
    border: 3px solid rgba(0, 0, 0, 0.15);
    border-top-color: rgba(0, 0, 0, 0.6);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

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

.overlayText {
    font: 600 14px/1.2 var(--tme-ff-inter);
    color: var(--tme-color-text-darker);
}

/* Map controls */
.mapControls {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 30;
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

.mapButton {
    appearance: none;
    border: 1px solid rgba(0, 0, 0, 0.25);
    background: rgba(255, 255, 255, 0.96);
    color: var(--tme-color-text-darker);
    padding: 6px 12px;
    border-radius: 12px;
    font: 600 12px/1 var(--tme-ff-inter);
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.18);
    cursor: pointer;
}

.mapButton:hover {
    background: #f6f6f6;
}

.mapButton:active {
    background: #eee;
}

.mapButton:focus-visible {
    outline: 2px solid rgba(66, 115, 131, 0.9);
    outline-offset: 2px;
}

.mapButton[aria-pressed="true"] {
    border-color: rgba(66, 115, 131, 0.7);
    background: rgba(255, 255, 255, 0.98);
}

/* Headings */
.sectionTitle,
.subcardTitle,
.rightPanel h3,
.instructionsCard h3,
.card h2 {
    font-family: var(--tme-ff-heading);
    font-weight: 700;
    letter-spacing: 0.01em;
    color: var(--tme-color-text);
    font-size: var(--heading-size);
    margin: 0 0 8px 0;
}

/* Instructions */
.instructionsCard {
    margin-bottom: 12px;
    width: 100%;
    font-family: var(--tme-ff-heading);
    color: var(--tme-color-text-primary);
}

/* Forms */
.formRow {
    display: grid;
    grid-template-columns: 140px 1fr;
    gap: 10px;
    align-items: center;
    margin-bottom: 10px;
}

.formGrid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 10px;
}

.formGrid > *,
.formRow > * {
    min-width: 0;
}

.label,
.formLabel {
    color: var(--tme-color-text-muted);
    font-weight: 600;
    font-family: var(--tme-ff-inter);
    font-size: 14px;
}

.input,
.formInput,
.formGrid input,
.formGrid select,
.formGrid textarea,
.formRow input,
.formRow select,
.formRow textarea {
    width: 100%;
    max-width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--tme-color-border-light);
    border-radius: 8px;
    font: 14px var(--tme-ff-inter);
    color: var(--tme-color-text);
    background: #fff;
    outline: none;
}

.formInput:focus-visible,
.formRow input:focus-visible,
.formRow select:focus-visible,
.formGrid input:focus-visible,
.formGrid select:focus-visible {
    outline: 2px solid rgba(66, 115, 131, 0.9);
    outline-offset: 1px;
}

/* Map search overlay */
.map-overlay {
    position: absolute;
    top: 12px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 40;
    display: flex;
    gap: 8px;
    align-items: center;
    pointer-events: none;
    width: 100%;
    max-width: 600px;
    padding: 0 12px;
}

.map-search {
    pointer-events: auto;
    flex: 1;
    background: #fff;
    border: 1px solid var(--tme-color-border-light);
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    gap: 8px;
    align-items: center;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}

.map-search input {
    border: none;
    outline: none;
    flex: 1;
    font-size: 14px;
    font-family: var(--tme-ff-inter);
}

/* Subcards + right body */
.subcard {
    border: 1px solid var(--tme-color-border-light);
    border-radius: 12px;
    padding: 12px;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.rightBody {
    overflow: auto;
    min-height: 0;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Buttons */
.summary-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn {
    padding: 10px 14px;
    border-radius: 10px;
    border: 1px solid var(--tme-color-border-light);
    background: #fff;
    cursor: pointer;
    font-size: 14px;
    font-family: var(--tme-ff-inter);
}

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

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

/* Banners */
.inline-error {
    color: #b00020;
    margin: 0.4rem 0 0.6rem;
    font-size: 0.92rem;
}

.banner {
    margin-top: 0.75rem;
    padding: 0.6rem 0.8rem;
    border-radius: 0.35rem;
}

.banner-ok {
    background: #e8f9f0;
    border: 1px solid #9dd8b3;
    color: #1f6b3b;
}

.banner-err {
    background: #fdeaea;
    border: 1px solid #ef9a9a;
    color: #8a1f1f;
}

/* Link-style button */
.btn-link {
    background: transparent;
    border: none;
    color: #1f6b8a;
    cursor: pointer;
    font: inherit;
    padding: 0;
    text-decoration: underline;
}

.btn-link:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    text-decoration: none;
}

/* Unified button feedback */
.btn,
.btn.btn-primary {
    background: #fff;
    color: #1f1f1f;
    border: 1px solid #d0d0d0;
    padding: 8px 14px;
    border-radius: 8px;
    line-height: 1.15;
    cursor: pointer;
    transition:
        background-color 0.12s ease,
        color 0.12s ease,
        border-color 0.12s ease,
        transform 0.06s ease;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.btn:hover:not(:disabled) {
    border-color: #9a9a9a;
}

.btn:active:not(:disabled) {
    background: #000;
    color: #fff;
    border-color: #000;
    transform: translateY(1px);
}

.btn:focus-visible {
    outline: 2px solid #0a84ff;
    outline-offset: 2px;
}

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

@media (hover: none) {
    .btn:active:not(:disabled) {
        transform: none;
    }
}

.btn[aria-busy="true"] {
    cursor: progress;
}

.btn-row {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Step circles */
.stepsList-circles li {
    display: flex;
    gap: 0.5rem;
    align-items: flex-start;
}

.step-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.6rem;
    height: 1.6rem;
    margin-right: 0.5rem;
    border-radius: 50%;
    border: 2px solid #3a6ea5;
    color: #3a6ea5;
    font-weight: 700;
}

/* AOI label */
.aoi-label {
    margin: 0 0 0.25rem 0;
    font-weight: 600;
    font-size: 0.95rem;
    color: #334;
}

/* Popovers */
.panel.card,
.subcard,
.leftPanel,
.rightPanel,
.instructionsCard {
    overflow: visible;
}

.infobtn-wrap {
    position: relative;
    display: inline-block;
    margin-left: 0.4rem;
}

.infobtn {
    width: 1.1rem;
    height: 1.1rem;
    border-radius: 50%;
    border: 1px solid #3a6ea5;
    font-weight: bold;
    font-size: 0.8rem;
    line-height: 1rem;
    text-align: center;
    background: #e8f2ff;
    color: #3a6ea5;
    cursor: pointer;
}

.infobtn:focus-visible {
    outline: 2px solid rgba(66, 115, 131, 0.9);
    outline-offset: 2px;
}

.infobtn-pop {
    position: absolute;
    top: 1.6rem;
    left: 0;
    z-index: 9999;
    display: block;
    padding: 0.55rem 0.7rem;
    border-radius: 0.4rem;
    border: 1px solid #c8d5e6;
    background: #fff;
    box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
    font-size: 0.95rem;
    line-height: 1.35;
    white-space: normal;
    min-width: 18rem;
    width: clamp(18rem, 70vw, 32rem);
    max-width: calc(100vw - 2rem);
    overflow-wrap: break-word;
    word-break: normal;
    hyphens: auto;
}

/* Card Animations */
@keyframes slideDown {
    0% {
        opacity: 0;
        transform: translateY(-20px);
    }
    100% {
        opacity: 1;
        transform: translateY(0);
    }
}

.subcard,
.card.requestAssistanceCard {
    animation: slideDown 0.6s ease-out;
    animation-fill-mode: backwards;
}

@media (prefers-reduced-motion: no-preference) {
    .subcard,
    .card.requestAssistanceCard {
        animation: slideDown 0.6s ease-out;
    }
}

@media (prefers-reduced-motion: reduce) {
    .subcard,
    .card.requestAssistanceCard {
        animation: none;
    }
    .spinner {
        animation: none;
    }
}

/* ========================================
   SERVICE TYPE SELECTOR OVERRIDES
   ======================================== */

/* Page container */
.serviceSelector,
.service-selector-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 40px;
    font-family: var(--tme-ff-inter), system-ui, sans-serif;
}

/* Title (bold slab) */
.serviceTypeTitle,
.service-selector-title {
    font-family: var(--tme-ff-heading), "Roboto Slab", "Merriweather", serif;
    font-weight: 700;
    letter-spacing: 0.01em;
    font-size: clamp(22px, 2.2vw, 32px);
    margin: 0 0 8px 0;
    color: var(--tme-color-text-primary, #2d2d2d);
}

/* Lede/Subtitle */
.serviceTypeLede,
.service-selector-subtitle {
    font-family: var(--tme-ff-inter), system-ui, sans-serif;
    font-weight: 400;
    line-height: 1.5;
    font-size: 16px;
    color: var(--tme-color-text-secondary, #374151);
    margin: 0 0 16px 0;
}

/* Choice buttons */
.svcTypeBtn,
.service-button {
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: var(--tme-color-primary-2);
    color: var(--tme-color-white, #fff);
    border: 1px solid transparent;
    border-radius: 16px;
    padding: 12px 18px;
    font-size: 1rem;
    font-family: var(--tme-ff-inter), system-ui, sans-serif;
    font-weight: 700;
    letter-spacing: 0.02em;
    cursor: pointer;
    box-shadow: 0 1px 6px rgba(0, 0, 0, 0.12);
    transition:
        background-color 0.15s ease,
        transform 0.05s ease;
}

.svcTypeBtn:hover,
.svcTypeBtn:focus-visible,
.service-button:hover,
.service-button:focus-visible {
    background: var(--tme-color-primary-1);
    outline: none;
}

.svcTypeBtn:active,
.service-button:active {
    transform: translateY(1px);
}

/* Button layout */
.svcTypeGrid,
.service-button-group {
    display: grid;
    grid-auto-rows: minmax(44px, auto);
    grid-template-columns: repeat(3, minmax(160px, 1fr));
    gap: 12px;
}

/* ========================================
   RESPONSIVE DESIGN
   ======================================== */

/* Tablets & down (≤1023px) */
@media (max-width: 1023px) {
    .appContainer {
        display: flex;
        flex-direction: column;
        height: auto;
        min-height: 100dvh;
    }

    .rightPanel {
        display: block;
    }

    .rightBody {
        display: block;
        overflow: visible;
        min-height: auto;
    }

    .leftPanel .mapWrapper {
        display: block;
        min-height: 360px;
        height: 72vh !important;
        max-height: 90vh;
    }

    @supports (height: 1svh) {
        .leftPanel .mapWrapper {
            height: clamp(360px, 72svh, 90svh) !important;
            max-height: none;
        }
    }

    @supports (height: 1dvh) {
        .leftPanel .mapWrapper {
            height: clamp(360px, 68dvh, 88dvh) !important;
        }
    }

    .leftPanel .mapDiv,
    .leftPanel .mapDiv .esri-view,
    .leftPanel .mapDiv .esri-view-root,
    .leftPanel .mapDiv .esri-view-surface {
        width: 100% !important;
        height: 100% !important;
        min-height: 100% !important;
    }
}

/* Desktop (≥1024px) */
@media (min-width: 1024px) {
    .appContainer {
        display: grid;
        grid-template-columns: 65% 35%;
        grid-template-rows: auto minmax(0, 1fr);
        gap: 12px;
        align-items: stretch;
        justify-items: stretch;
    }

    .instructionsCard {
        grid-column: 1 / -1;
        grid-row: 1;
    }

    .leftPanel {
        grid-column: 1;
        grid-row: 2;
        min-height: 0;
        display: flex;
        flex-direction: column;
    }

    .rightPanel {
        grid-column: 2;
        grid-row: 2;
        min-height: 0;
    }

    .leftPanel .mapWrapper {
        flex: 1 1 auto;
        min-height: 0;
        height: auto;
    }

    .leftPanel .mapDiv,
    .leftPanel .mapDiv .esri-view,
    .leftPanel .mapDiv .esri-view-root,
    .leftPanel .mapDiv .esri-view-surface {
        width: 100%;
        height: 100%;
        min-height: 100%;
    }
}

/* Mobile (≤640px) */
@media (max-width: 640px) {
    .map-overlay {
        top: 60px;
        left: 96px;
        right: 16px;
        transform: none;
        max-width: none;
    }

    .map-search {
        width: 100%;
        min-width: 0;
    }

    .map-search input {
        width: 100%;
        min-width: 0;
    }
}

/* Service selector mobile */
@media (max-width: 900px) {
    .svcTypeGrid,
    .service-button-group {
        grid-template-columns: 1fr;
    }
}
