/* ==========================================================================
   Design Tokens & Base Setup
   ========================================================================== */
:root {
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --primary-color: #72b2dc;
    --primary-hover: #5fa3cf;
    --text-color: #1e293b;
    --text-muted: #64748b;
    --border-color: #e2e8f0;
    --border-radius: 24px;
    --shadow: 0 20px 40px rgba(0, 0, 0, 0.03);
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1); /* Smoother expansion curves */
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: #cbd5e1;
    color: var(--text-color);
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    padding: 0 10px;
}

/* ==========================================================================
   App Container & Base Page Structure
   ========================================================================== */
.app-container {
    background-color: var(--card-bg);
    padding: 30px 20px 90px 20px;
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 360px;
    min-height: 560px;
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
    overflow: hidden;
}

.app-header {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 14px;
    width: 100%;
    margin-bottom: 35px;
}

.app-header-icon {
    width: 44px;
    height: 44px;
    object-fit: contain;
    border-radius: 8px;
    filter: drop-shadow(0 4px 6px rgba(0, 0, 0, 0.06));
}

.app-title {
    font-size: 1.8rem;
    font-weight: 500;
    color: #1a5f8c;
    letter-spacing: -0.5px;
}

.app-page {
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    animation: fadeIn 0.2s ease-out;
}

/* ==========================================================================
   Buttons & Form-Inputs
   ========================================================================== */
.track-btn {
    width: 100%;
    max-width: 280px;
    padding: 14px 0;
    font-size: 0.95rem;
    font-weight: 600;
    letter-spacing: 0.5px;
    color: white;
    background-color: var(--primary-color);
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 6px rgba(114, 178, 220, 0.15);
    margin-bottom: 20px;
}

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

.settings-input {
    width: 100%;
    padding: 12px;
    font-size: 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background-color: #f8fafc;
    color: var(--text-color);
    transition: var(--transition);
}

.settings-input:focus {
    outline: none;
    border-color: var(--primary-color);
    background-color: #ffffff;
}

/* ==========================================================================
   Status Indicators & Info-Cards
   ========================================================================== */
.status-container {
    min-height: 24px;
    margin-bottom: 25px;
}

#status {
    font-size: 0.9rem;
    font-weight: 500;
}

.status-ready { color: #0284c7; }
.status-loading { color: #d97706; animation: pulse 1.5s infinite; }
.status-success { color: #16a34a; }
.status-error { color: #dc2626; }

@keyframes pulse {
    0% { opacity: 0.6; }
    50% { opacity: 1; }
    100% { opacity: 0.6; }
}

.response-card, .settings-card {
    width: 100%;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    background-color: #ffffff;
}

.card-header {
    font-size: 1rem;
    font-weight: 500;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    color: #000000;
}

#res-time-span {
    color: var(--primary-hover);
    font-weight: 600;
}

.flex-rows { display: flex; flex-direction: column; }
.row-split { display: flex; justify-content: space-between; width: 100%; }
.row-full { width: 100%; }
.cell { padding: 14px 16px; display: flex; flex-direction: column; }
.border-bottom { border-bottom: 1px solid var(--border-color); }
.text-right { align-items: flex-end; text-align: right; }

.label {
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 4px;
    text-transform: uppercase;
}

.value { font-size: 0.95rem; font-weight: 600; color: #000000; }
.address-text { font-size: 0.85rem; font-weight: 400; line-height: 1.4; }

.temp-display-wrapper {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 2px;
}

.embedded-weather-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    vertical-align: middle;
}

/* ==========================================================================
   History Log Card List (Actionable Expandable Cards Layout)
   ========================================================================== */
.history-list {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    height: 400px; /* Fixed viewport height to guarantee scrolling metrics */
    overflow-y: auto; /* Active local scrolling behavior */
    padding-right: 4px;
    padding-bottom: 20px; /* Safe padding anchor at bottom of list */
}

.history-list::-webkit-scrollbar { width: 4px; }
.history-list::-webkit-scrollbar-thumb { background-color: var(--border-color); border-radius: 4px; }

/* The Accordion Container */
.log-card {
    background-color: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: var(--transition);
    cursor: pointer;
    flex-shrink: 0; /* 🔥 CRITICAL FIX: Stops browser from shrinking cards inside flex containers */
}

.log-card:hover {
    border-color: var(--primary-color);
}

/* Active Open Card State Layout tweaks */
.log-card.expanded {
    border-color: var(--primary-color);
    box-shadow: 0 4px 12px rgba(114, 178, 220, 0.08);
}

/* Safe clickable wrapper enclosing passive textual info */
.log-card-clickable-area {
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    width: 100%;
}

.log-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.75rem;
    color: var(--text-muted);
    border-bottom: 1px dashed var(--border-color);
    padding-bottom: 6px;
}

.log-card-id { color: var(--text-color); font-weight: 700; }
.log-card-user { background-color: #f1f5f9; padding: 2px 6px; border-radius: 4px; font-weight: 500; }
.log-card-body { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.log-card-address { font-size: 0.85rem; line-height: 1.4; color: var(--text-color); flex-grow: 1; word-break: break-word; }

.log-card-temp {
    font-size: 0.85rem;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 6px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

/* Animated Action Tray (Accordion Drawer) */
.log-card-action-tray {
    max-height: 0;
    opacity: 0;
    background-color: #f8fafc;
    border-top: 1px solid transparent;
    display: flex;
    justify-content: flex-start;
    align-items: center;
    gap: 12px; /* Adjusted to hold two triggers cleanly */
    padding: 0 14px;
    transition: max-height 0.25s cubic-bezier(0.4, 0, 0.2, 1), 
                opacity 0.2s linear, 
                padding 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Expanded Dynamic Target State overrides via JavaScript */
.log-card.expanded .log-card-action-tray {
    max-height: 52px; /* Fixed height accommodating internal action elements */
    opacity: 1;
    padding: 10px 14px;
    border-top-color: var(--border-color);
}

/* Action Trigger Elements (Option 2 Mini UI Design Engine) */
.tray-action-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    font-size: 0.78rem;
    font-weight: 600;
    border-radius: 6px;
    border: 1px solid transparent;
    cursor: pointer;
    background: none;
    transition: var(--transition);
}

/* Maps Button Styling Rule Setup */
.btn-action-maps {
    color: #1a5f8c;
    background-color: #e0f2fe;
    text-decoration: none; /* Strips text link underline semantics */
}
.btn-action-maps:hover {
    background-color: #bae6fd;
}
.btn-action-maps .action-icon {
    stroke: #1a5f8c;
}

/* Delete Specific Trigger Styling Rules */
.btn-action-delete {
    color: #dc2626;
    background-color: #fee2e2;
}
.btn-action-delete:hover {
    background-color: #fecaca;
}
.btn-action-delete .action-icon {
    stroke: #dc2626;
}

.action-icon {
    width: 14px;
    height: 14px;
}

/* Animation trigger class for API completion logic */
.card-leave-animate {
    animation: slideOutLeft 0.3s cubic-bezier(0.4, 0, 1, 1) forwards;
}

@keyframes slideOutLeft {
    to {
        transform: translateX(-105%);
        opacity: 0;
        margin-bottom: -70px; /* Pulls subsequent logs up nicely while destroying node */
    }
}

/* Temperature context badging matching */
.temp-blue { color: #1d4ed8; background-color: #dbeafe; }
.temp-blue .embedded-weather-icon { stroke: #1d4ed8; }
.temp-lightblue { color: #1a5f8c; background-color: #e0f2fe; }
.temp-lightblue .embedded-weather-icon { stroke: #1a5f8c; }
.temp-orange { color: #b45309; background-color: #fef3c7; }
.temp-orange .embedded-weather-icon { stroke: #b45309; }
.temp-red { color: #b91c1c; background-color: #fee2e2; }
.temp-red .embedded-weather-icon { stroke: #b91c1c; }
.temp-none { color: var(--text-muted); background-color: #f1f5f9; }
.temp-none .embedded-weather-icon { stroke: var(--text-muted); }

/* ==========================================================================
   Settings Page Configuration
   ========================================================================== */
.settings-card { padding: 20px 16px; }
.settings-title { font-size: 1.1rem; font-weight: 600; margin-bottom: 20px; color: #1a5f8c; }
.form-group { width: 100%; margin-bottom: 20px; display: flex; flex-direction: column; }
.help-text { font-size: 0.75rem; color: var(--text-muted); margin-top: 6px; }
.settings-status { font-size: 0.85rem; text-align: center; font-weight: 500; min-height: 18px; }

/* ==========================================================================
   Bottom Navigation Bar
   ========================================================================== */
.bottom-nav {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 70px;
    background-color: #f8fafc;
    border-top: 1px solid var(--border-color);
    border-bottom-left-radius: var(--border-radius);
    border-bottom-right-radius: var(--border-radius);
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding-bottom: 5px;
}

.nav-item {
    background: none;
    border: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    cursor: pointer;
    width: 33.33%;
    height: 100%;
    transition: var(--transition);
}

.nav-icon {
    width: 22px;
    height: 22px;
    margin-bottom: 4px;
    transition: var(--transition);
}

.nav-item.active { color: #1a5f8c; }
.nav-item.active .nav-icon { transform: translateY(-2px); stroke: #1a5f8c; }
.nav-label { font-size: 0.75rem; font-weight: 500; }

.hidden { display: none !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: translateY(0); } }