/* =========================================
   1. Style & Global Settings
   ========================================= */
:root {
    --cal-navy: #002663;
    --cal-blue-hover: #003380;
    --cal-light-bg: #f5f7fa;
    --bg-gradient-top: #f0f4f8;
    --bg-gradient-bot: #dfe7ef;
    --card-bg: #ffffff;
    --text-primary: #1d1d1f;
    --text-secondary: #86868b;
    --error-color: #d32f2f;
    --card-shadow: 0 12px 40px rgba(0, 38, 99, 0.08);
    --btn-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);

    /* Toast Colors */
    --toast-success: #10b981;
    --toast-error: #ef4444;
    --toast-bg: #ffffff;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-font-smoothing: antialiased; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Microsoft JhengHei", "微軟正黑體", sans-serif;
    background: linear-gradient(180deg, var(--bg-gradient-top) 0%, var(--bg-gradient-bot) 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
}

a { text-decoration: none; }

/* --- Top Navigation --- */
.top-bar {
    position: absolute;
    top: 12px;
    left: 0;
    width: 100%;
    padding: 0 25px;
    display: flex;
    justify-content: space-between;
    font-size: 13px;
    color: var(--text-secondary);
    font-weight: 500;
    z-index: 10;
}
.top-bar a { color: var(--text-secondary); transition: color 0.2s; margin-left: 15px; }
.top-bar a:hover { color: var(--cal-navy); }

.logout-btn {
    color: #e67e22;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: opacity 0.2s;
}
.logout-btn:hover { opacity: 0.7; }

/* --- Main Card Container --- */
.main-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.card {
    position: relative;
    background: var(--card-bg);
    width: 100%;
    max-width: 900px;
    border-radius: 20px;
    box-shadow: var(--card-shadow);
    padding: 40px 32px;
    text-align: center;
    border-top: 6px solid var(--cal-navy);
    transition: max-width 0.3s;
}

.card-header h1 {
    font-size: 22px;
    color: var(--cal-navy);
    margin-bottom: 4px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-secondary);
    letter-spacing: 0.5px;
    text-transform: uppercase;
    margin-bottom: 25px;
    font-weight: 600;
}

/* --- Home Button --- */
.home-btn {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: color 0.2s;
}
.home-btn:hover {
    color: var(--cal-navy);
}

/* --- Search Area with Autocomplete --- */
.search-area {
    margin-bottom: 5px; /* Reduced for error message space */
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
    position: relative; /* For absolute positioning of suggestions */
}

.input-group {
    display: flex;
    gap: 10px;
}

.input-wrapper {
    position: relative;
    width: 100%;
}

.input-field {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 15px;
    color: var(--text-primary);
    background-color: #fff;
    outline: none;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 600;
    text-align: center;
}

.input-field:focus {
    border-color: var(--cal-navy);
    box-shadow: 0 0 0 2px rgba(0, 38, 99, 0.1);
}

.input-field.error {
    border-color: var(--error-color);
    box-shadow: 0 0 0 2px rgba(211, 47, 47, 0.1);
    animation: shake 0.4s cubic-bezier(.36,.07,.19,.97) both;
}

/* Autocomplete Suggestions */
.suggestions-list {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: white;
    border: 1px solid #e5e5ea;
    border-radius: 8px;
    margin-top: 5px;
    max-height: 250px;
    overflow-y: auto;
    box-shadow: 0 4px 15px rgba(0,0,0,0.1);
    z-index: 100;
    text-align: left;
    display: none; /* Hidden by default */
}

.suggestions-list.active {
    display: block;
}

.suggestion-item {
    padding: 10px 15px;
    cursor: pointer;
    font-size: 14px;
    border-bottom: 1px solid #f0f0f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.suggestion-item:last-child { border-bottom: none; }
.suggestion-item:hover, .suggestion-item.selected { background-color: #f0f7ff; }

.sug-icao { font-weight: 700; color: var(--cal-navy); }
.sug-name { color: #666; font-size: 12px; margin-left: 10px; }
.sug-country { color: #999; font-size: 11px; font-style: italic; }

/* Validation Message */
.validation-msg {
    height: 20px;
    font-size: 13px;
    color: var(--error-color);
    margin-bottom: 15px;
    opacity: 0;
    transition: opacity 0.2s;
    font-weight: 500;
}
.validation-msg.visible { opacity: 1; }

/* Buttons */
.sys-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 15px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.2s cubic-bezier(0.25, 0.8, 0.25, 1);
    cursor: pointer;
    text-align: center;
    border: none;
}

.primary-btn {
    background-color: var(--cal-navy);
    color: #fff;
    box-shadow: 0 4px 12px rgba(0, 38, 99, 0.2);
}
.primary-btn:hover {
    background-color: var(--cal-blue-hover);
    transform: translateY(-1px);
    box-shadow: 0 6px 15px rgba(0, 38, 99, 0.25);
}

/* --- Result Area --- */
.grid-stack { display: flex; flex-direction: column; gap: 10px; }
.grid-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.atis-result-card {
    background-color: #fcfcfd;
    border: 1px solid #eaeff5;
    border-radius: 12px;
    padding: 20px;
    text-align: left;
    box-shadow: var(--btn-shadow);
    height: 100%;
    display: flex;
    flex-direction: column;
}

.atis-title-badge {
    background-color: var(--cal-navy);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 12px;
    border-radius: 20px;
    display: inline-block;
    margin-bottom: 12px;
    align-self: flex-start;
}
.atis-title-badge.arr { background-color: #007aff; }

.atis-text-content {
    font-family: 'Monaco', 'Consolas', 'Courier New', monospace;
    white-space: pre-wrap;
    line-height: 1.6;
    color: #334155;
    font-size: 14px;
    flex: 1;
    word-wrap: break-word; 
    overflow-wrap: break-word;
}

.acars-header {
    color: #94a3b8;
    font-size: 12px;
    margin-bottom: 8px;
    display: block;
    padding-bottom: 5px;
    border-bottom: 1px dashed #e2e8f0;
}

.atis-meta-footer {
    margin-top: 15px;
    padding-top: 12px;
    border-top: 1px dashed #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    color: #64748b;
    background-color: #f8fafc;
    margin: 15px -20px -20px -20px;
    padding: 10px 20px;
    border-radius: 0 0 12px 12px;
}
.meta-item { display: flex; align-items: center; gap: 4px; }
.meta-icon { opacity: 0.6; }
.meta-value { font-family: 'Monaco', monospace; font-weight: 600; color: var(--cal-navy); }

.status-msg { color: var(--text-secondary); font-size: 14px; padding: 20px 0; line-height: 1.5; }
.status-msg.error { color: var(--error-color); }

.footer-warning {
    margin-top: 30px;
    font-size: 12px;
    color: #94a3b8;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    line-height: 1.4;
}
.warning-icon { font-size: 16px; margin-bottom: 2px; }

/* Highlighting */
.highlight-runway { color: #d9480f; font-weight: bold; background: rgba(217, 72, 15, 0.05); padding: 0 2px; border-radius: 2px;}
.highlight-wind { color: #0d9488; font-weight: bold; }
.highlight-visibility { color: #2563eb; font-weight: bold; }
.highlight-cloud { color: #9333ea; font-weight: bold; }
.highlight-qnh { color: #b91c1c; font-weight: bold; background: rgba(185, 28, 28, 0.05); padding: 0 2px; border-radius: 2px;}
.highlight-temp { color: #059669; font-weight: bold; }
.highlight-info { color: #c2410c; font-weight: bold; border-bottom: 2px solid #c2410c; }

/* Animation Keyframes */
@keyframes shake {
  10%, 90% { transform: translate3d(-1px, 0, 0); }
  20%, 80% { transform: translate3d(2px, 0, 0); }
  30%, 50%, 70% { transform: translate3d(-4px, 0, 0); }
  40%, 60% { transform: translate3d(4px, 0, 0); }
}

/* =========================================
   Toast Notification Styles (Optimized)
   ========================================= */
.toast-container {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    /* Desktop Default: Bottom Right */
}

.toast {
    background: var(--toast-bg);
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
    padding: 16px 20px 20px 20px;
    width: 300px;
    position: relative;
    overflow: hidden;
    animation: slideIn 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    border-left: 5px solid transparent;
    text-align: left;
}

.toast.success { border-left-color: var(--toast-success); }
.toast.error { border-left-color: var(--toast-error); }

.toast-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}

.toast-title {
    font-weight: 700;
    font-size: 14px;
    color: var(--text-primary);
}
.toast.success .toast-title { color: var(--toast-success); }
.toast.error .toast-title { color: var(--toast-error); }

.toast-body {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.4;
}

.toast-close {
    cursor: pointer;
    color: #94a3b8;
    font-size: 18px;
    line-height: 1;
    background: none;
    border: none;
    padding: 0;
}
.toast-close:hover { color: var(--text-primary); }

/* Progress Bar */
.toast-progress-bg {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 4px;
    background: #f1f5f9;
}

.toast-progress-bar {
    height: 100%;
    width: 100%;
    background-color: var(--cal-navy);
    transform-origin: left;
}

.toast.success .toast-progress-bar { background-color: var(--toast-success); }
.toast.error .toast-progress-bar { background-color: var(--toast-error); }

.animate-progress { animation: progressBar 60s linear forwards; }

@keyframes slideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes slideOut {
    from { transform: translateX(0); opacity: 1; }
    to { transform: translateX(120%); opacity: 0; }
}
@keyframes progressBar {
    from { transform: scaleX(1); }
    to { transform: scaleX(0); }
}

/* Loader */
.loader-container { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 40px 0; color: var(--cal-navy); }
.loader-plane { width: 50px; height: 50px; fill: var(--cal-navy); margin-bottom: 15px; animation: flyAcross 2.5s linear infinite; opacity: 0; }
@keyframes flyAcross {
    0% { transform: translateX(-180px) rotate(90deg); opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { transform: translateX(180px) rotate(90deg); opacity: 0; }
}
.loader-text { font-size: 15px; font-weight: 600; margin-bottom: 5px; letter-spacing: 0.5px; }
.loader-subtext { font-size: 12px; opacity: 0.7; margin-bottom: 8px; }
.loader-timer { font-size: 13px; color: var(--text-secondary); font-family: 'Monaco', monospace; background: #f1f5f9; padding: 4px 10px; border-radius: 12px; }

/* --- RWD & Mobile Optimization --- */
@media (max-width: 480px) {
    .card { padding: 30px 20px; box-shadow: none; border-top: none; }
    .grid-cols { grid-template-columns: 1fr; gap: 10px; }
    .top-bar { position: relative; margin-bottom: 10px; top: 0; padding: 0; }
    .atis-meta-footer { flex-direction: column; gap: 5px; align-items: flex-start; }
    
    /* Optimized Toast for Mobile: Centered Bottom */
    .toast-container {
        right: 0;
        left: 0;
        bottom: 20px;
        align-items: center; /* Center horizontally */
    }
    .toast {
        width: 90vw; /* Take up most of width */
        max-width: 350px;
        animation: slideUp 0.4s cubic-bezier(0.25, 1, 0.5, 1);
    }
    @keyframes slideUp {
        from { transform: translateY(100%); opacity: 0; }
        to { transform: translateY(0); opacity: 1; }
    }
    @keyframes slideOut {
        from { transform: translateY(0); opacity: 1; }
        to { transform: translateY(100%); opacity: 0; }
    }
}
