/* ============================================================
   AeroRef - Aircraft Maintenance AI
   Premium Dark Theme for Hangar Use
   ============================================================ */

:root {
    --bg-primary: #0a0e1a;
    --bg-secondary: #111827;
    --bg-card: #1a2236;
    --bg-input: #1e293b;
    --bg-hover: #243049;

    --accent-blue: #3b82f6;
    --accent-cyan: #06b6d4;
    --accent-green: #10b981;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;
    --accent-purple: #8b5cf6;

    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;

    --border: #1e293b;
    --border-light: #334155;

    --glow-blue: rgba(59, 130, 246, 0.15);
    --glow-cyan: rgba(6, 182, 212, 0.1);

    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 16px;

    --safe-top: env(safe-area-inset-top, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);

    --header-height: 64px;
    --input-height: 72px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

html,
body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    display: flex;
    flex-direction: column;
    -webkit-font-smoothing: antialiased;
}

/* ============================================================
   Login Screen
   ============================================================ */
.login-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: var(--bg-primary);
    display: flex;
    align-items: center;
    justify-content: center;
}

.login-overlay.hidden {
    display: none !important;
}

.login-card {
    text-align: center;
    padding: 40px 32px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    width: 320px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5);
}

.login-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

.login-card h2 {
    font-size: 22px;
    font-weight: 700;
    margin-bottom: 4px;
    background: linear-gradient(135deg, #fff, var(--accent-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-card p {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 24px;
}

.login-card form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.login-card input {
    padding: 14px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 18px;
    font-family: 'JetBrains Mono', monospace;
    text-align: center;
    letter-spacing: 4px;
    outline: none;
    transition: border-color 0.2s;
}

.login-card input:focus {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--glow-cyan);
}

.login-error {
    margin-top: 12px;
    padding: 10px;
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    color: var(--accent-red);
    font-size: 13px;
}

/* ============================================================
   Header
   ============================================================ */
#app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(10, 14, 26, 0.85);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    padding-top: var(--safe-top);
}

.header-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    height: var(--header-height);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    box-shadow: 0 0 20px var(--glow-blue);
}

.logo-text h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.5px;
    background: linear-gradient(135deg, #fff, var(--accent-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 11px;
    color: var(--text-muted);
    font-weight: 500;
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
}

.icon-btn:hover,
.icon-btn.active {
    background: var(--bg-hover);
    color: var(--accent-cyan);
    border-color: var(--accent-cyan);
}

/* Panels */
.panel {
    padding: 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    animation: slideDown 0.2s ease;
}

.hidden {
    display: none !important;
}

/* Filter Panel */
.filter-panel {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    animation: slideDown 0.2s ease;
}

.filter-panel.hidden {
    display: none;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.filter-row {
    flex: 1;
}

.filter-row label {
    display: block;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 4px;
}

.filter-row select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
    appearance: none;
    -webkit-appearance: none;
    cursor: pointer;
}

/* ============================================================
   Chat Area
   ============================================================ */
#chat-area {
    flex: 1;
    overflow-y: auto;
    padding-top: calc(var(--header-height) + var(--safe-top));
    padding-bottom: calc(var(--input-height) + var(--safe-bottom) + 8px);
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

/* Welcome Screen */
.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px 20px 20px;
    min-height: calc(100vh - var(--header-height) - var(--input-height) - var(--safe-top) - var(--safe-bottom));
}

.welcome-icon {
    font-size: 56px;
    margin-bottom: 16px;
    animation: float 3s ease-in-out infinite;
}

@keyframes float {

    0%,
    100% {
        transform: translateY(0px);
    }

    50% {
        transform: translateY(-10px);
    }
}

.welcome h2 {
    font-size: 24px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-cyan));
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.welcome p {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 32px;
    max-width: 300px;
}

/* Panel Header */
.panel-header h3 {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-light);
}

/* Form Styles */
.part-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 16px;
}

.part-form input,
.part-form select {
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Inter', sans-serif;
}

.btn-primary {
    padding: 12px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    border: none;
    border-radius: var(--radius-sm);
    color: white;
    font-weight: 600;
    cursor: pointer;
}

/* Parts List */
.parts-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 4px;
}

.part-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px;
    background: var(--bg-input);
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-blue);
}

.part-item.component {
    border-left-color: var(--accent-blue);
}

.part-item.expendable {
    border-left-color: var(--accent-green);
}

.part-item.chemical {
    border-left-color: var(--accent-amber);
}

.part-item.tool {
    border-left-color: var(--accent-purple);
}

.part-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.part-number {
    font-family: 'JetBrains Mono', monospace;
    font-size: 13px;
    color: var(--text-primary);
    font-weight: 600;
}

.part-desc {
    font-size: 11px;
    color: var(--text-muted);
}

.part-cat {
    font-size: 9px;
    text-transform: uppercase;
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    align-self: flex-start;
}

.btn-delete {
    background: none;
    border: none;
    color: var(--accent-red);
    cursor: pointer;
    padding: 4px;
    opacity: 0.7;
}

.btn-delete:hover {
    opacity: 1;
}

.parts-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border-light);
}

.parts-actions .btn-secondary {
    flex: 1;
    text-align: center;
    font-size: 11px;
    padding: 8px;
    background: var(--bg-hover);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.2s;
    font-weight: 500;
}

.parts-actions .btn-secondary:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: var(--accent-blue);
    color: var(--accent-cyan);
}

/* FAQ List */
.faq-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-height: 50vh;
    overflow-y: auto;
    padding-right: 4px;
}

.faq-item {
    padding: 12px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    text-align: left;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.faq-item:hover {
    border-color: var(--accent-cyan);
    background: var(--bg-hover);
}

/* Quick actions removed */

/* Stats Bar */
.stats-bar {
    display: flex;
    gap: 16px;
    padding: 12px 16px;
    background: var(--bg-card);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    font-size: 11px;
    color: var(--text-muted);
    width: 100%;
    max-width: 400px;
    justify-content: center;
}

.stat-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-value {
    color: var(--accent-cyan);
    font-weight: 600;
    font-family: 'JetBrains Mono', monospace;
}

/* ============================================================
   Messages
   ============================================================ */
#messages {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.msg {
    max-width: 100%;
    animation: msgIn 0.3s ease;
}

@keyframes msgIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* User Message */
.msg-user {
    align-self: flex-end;
    max-width: 85%;
}

.msg-user .msg-bubble {
    background: linear-gradient(135deg, var(--accent-blue), #2563eb);
    border-radius: var(--radius-lg) var(--radius-lg) 4px var(--radius-lg);
    padding: 12px 16px;
    font-size: 14px;
    line-height: 1.5;
    box-shadow: 0 2px 12px rgba(59, 130, 246, 0.3);
}

/* AI Message */
.msg-ai {
    align-self: flex-start;
}

.msg-ai .msg-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border-light);
    border-radius: 4px var(--radius-lg) var(--radius-lg) var(--radius-lg);
    padding: 16px;
    font-size: 14px;
    line-height: 1.7;
}

.msg-ai .msg-bubble h1,
.msg-ai .msg-bubble h2,
.msg-ai .msg-bubble h3 {
    color: var(--accent-cyan);
    margin: 16px 0 8px 0;
    font-size: 15px;
}

.msg-ai .msg-bubble h1:first-child,
.msg-ai .msg-bubble h2:first-child,
.msg-ai .msg-bubble h3:first-child {
    margin-top: 0;
}

.msg-ai .msg-bubble p {
    margin-bottom: 8px;
}

.msg-ai .msg-bubble ul,
.msg-ai .msg-bubble ol {
    padding-left: 20px;
    margin-bottom: 8px;
}

.msg-ai .msg-bubble li {
    margin-bottom: 4px;
}

.msg-ai .msg-bubble strong {
    color: var(--accent-amber);
}

.msg-ai .msg-bubble code {
    background: var(--bg-primary);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 12px;
    color: var(--accent-green);
}

.msg-ai .msg-bubble blockquote {
    border-left: 3px solid var(--accent-cyan);
    padding-left: 12px;
    margin: 8px 0;
    color: var(--text-secondary);
}

/* References */
.references {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--border);
}

.references-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.ref-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    background: var(--bg-primary);
    border: 1px solid var(--border-light);
    border-radius: 20px;
    font-size: 11px;
    font-family: 'JetBrains Mono', monospace;
    color: var(--accent-cyan);
    margin: 2px 4px 2px 0;
    white-space: nowrap;
}

.ref-tag .ref-type {
    font-size: 9px;
    padding: 1px 5px;
    border-radius: 10px;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
}

.ref-type.amm-sds {
    background: rgba(139, 92, 246, 0.2);
    color: var(--accent-purple);
}

.ref-type.amm-pp {
    background: rgba(16, 185, 129, 0.2);
    color: var(--accent-green);
}

.ref-type.fim {
    background: rgba(245, 158, 11, 0.2);
    color: var(--accent-amber);
}

/* Loading */
.msg-loading .msg-bubble {
    display: flex;
    align-items: center;
    gap: 8px;
}

.loading-dots {
    display: flex;
    gap: 4px;
}

.loading-dots span {
    width: 8px;
    height: 8px;
    background: var(--accent-cyan);
    border-radius: 50%;
    animation: bounce 1.4s infinite ease-in-out both;
}

.loading-dots span:nth-child(1) {
    animation-delay: -0.32s;
}

.loading-dots span:nth-child(2) {
    animation-delay: -0.16s;
}

@keyframes bounce {

    0%,
    80%,
    100% {
        transform: scale(0.4);
        opacity: 0.4;
    }

    40% {
        transform: scale(1);
        opacity: 1;
    }
}

/* ============================================================
   Input Area
   ============================================================ */
#input-area {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: rgba(10, 14, 26, 0.9);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-input);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 16px;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--accent-cyan);
    box-shadow: 0 0 0 3px var(--glow-cyan);
}

#question-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: 'Inter', sans-serif;
    resize: none;
    max-height: 120px;
    line-height: 1.5;
    padding: 8px 0;
    outline: none;
}

#question-input::placeholder {
    color: var(--text-muted);
    font-size: 13px;
}

.send-btn {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-blue), var(--accent-cyan));
    border: none;
    border-radius: var(--radius);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

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

.send-btn:not(:disabled):hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px var(--glow-blue);
}

/* ============================================================
   Scrollbar
   ============================================================ */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-light);
    border-radius: 2px;
}

/* ============================================================
   Responsive
   ============================================================ */
@media (max-width: 380px) {
    .quick-actions {
        grid-template-columns: 1fr;
    }

    @keyframes pulse {
        0% {
            transform: scale(1);
            opacity: 1;
        }

        50% {
            transform: scale(1.2);
            opacity: 0.7;
        }

        100% {
            transform: scale(1);
            opacity: 1;
        }
    }

    .pulse {
        animation: pulse 1s infinite;
    }

    .quick-btn {
        padding: 12px;
    }
}