/* LoRaWAN Sensor Expert - Emergent Connext Branding */
/* Brand Colors from Emergent Connext Guidelines */

:root {
    /* Primary Brand Colors */
    --brand-green: #6b8e23;          /* Olive Green - Primary */
    --brand-blue: #2a7ca0;           /* Blue - Primary */
    --brand-brown: #40351e;          /* Dark Brown - Primary */

    /* Secondary Brand Colors */
    --brand-cream: #f9eddc;          /* Cream - Secondary */
    --brand-gold: #ba7c2b;           /* Gold - Secondary */
    --brand-burgundy: #440008;       /* Dark Red/Burgundy - Secondary */

    /* UI Colors */
    --bg-dark: #40351e;              /* Dark brown background */
    --bg-sidebar: #2d2518;           /* Darker brown sidebar */
    --bg-card: #f9eddc;              /* Cream card background */
    --bg-input: #352d1c;             /* Input background */
    --text-light: #f9eddc;           /* Cream text - for dark backgrounds */
    --text-card: #2a7ca0;            /* Blue text - for cards/boxes */
    --text-white: #ffffff;           /* White text */
    --text-muted: #c5b89a;           /* Muted cream text */
    --border-color: #5a4d36;         /* Brown border */

    /* Status Colors */
    --status-online: #6b8e23;
    --status-warning: #ba7c2b;
    --status-critical: #440008;
    --status-offline: #999999;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    min-height: 100vh;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    background-color: var(--bg-dark);
}

/* Header */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 20px;
    background: var(--brand-blue);
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.3);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 15px;
}

.header-logo {
    height: 40px;
    object-fit: contain;
    background: white;
    padding: 4px 8px;
    border-radius: 4px;
}

.header-title h1 {
    font-size: 20px;
    font-weight: 600;
    color: var(--text-white);
}

.header-subtitle {
    font-size: 12px;
    opacity: 0.9;
    color: var(--brand-cream);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 16px;
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-white);
}

.logout-btn {
    background: rgba(255, 255, 255, 0.2);
    color: white;
    padding: 8px 16px;
    border-radius: 4px;
    text-decoration: none;
    font-size: 13px;
    border: none;
    cursor: pointer;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Main Chat Area */
.chat-main {
    display: flex;
    flex-direction: column;
    flex: 1;
    overflow: hidden;
    background: var(--bg-dark);
}

/* Chat Messages */
.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    scroll-behavior: smooth;
}

/* Welcome Message */
.welcome-message {
    max-width: 700px;
    margin: 40px auto;
    text-align: center;
    padding: 40px;
    background: var(--bg-card);
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
}

.welcome-icon {
    margin-bottom: 24px;
}

.welcome-icon svg {
    stroke: var(--brand-blue);
}

.welcome-message h2 {
    font-size: 28px;
    font-weight: 700;
    color: var(--brand-blue);
    margin-bottom: 12px;
}

.welcome-message p {
    font-size: 16px;
    color: var(--text-card);
    margin-bottom: 32px;
}

.quick-actions h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.quick-action-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    justify-content: center;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-card);
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    cursor: pointer;
    transition: all 0.2s ease;
}

.quick-action:hover {
    background-color: var(--brand-green);
    color: white;
    border-color: var(--brand-green);
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(107, 142, 35, 0.3);
}

.quick-icon {
    font-size: 16px;
}

/* Message Styles */
.message {
    max-width: 800px;
    margin: 16px auto;
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 14px;
    font-weight: 600;
}

.message.user .message-avatar {
    background-color: var(--brand-blue);
    color: white;
}

.message.assistant .message-avatar {
    background-color: var(--brand-green);
    color: white;
}

.message-content {
    padding: 12px 16px;
    border-radius: 18px;
    max-width: calc(100% - 60px);
    line-height: 1.6;
    text-align: left;
}

.message.user .message-content {
    background-color: var(--brand-blue);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.assistant .message-content {
    background-color: var(--bg-card);
    color: var(--brand-brown);
    border-bottom-left-radius: 4px;
}

.message-content p {
    margin-bottom: 8px;
}

.message-content p:last-child {
    margin-bottom: 0;
}

.message-content ul, .message-content ol {
    margin-left: 20px;
    margin-bottom: 8px;
}

.message-content code {
    background-color: rgba(0, 0, 0, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 13px;
}

.message-content pre {
    background-color: #1E1E1E;
    color: #D4D4D4;
    padding: 12px;
    border-radius: 8px;
    overflow-x: auto;
    margin: 8px 0;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.message-content a {
    color: var(--brand-blue);
    text-decoration: underline;
}

.message.user .message-content a {
    color: #B3D9FF;
}

/* Typing Indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 8px 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background-color: var(--brand-blue);
    border-radius: 50%;
    animation: typing 1.4s infinite ease-in-out;
}

.typing-indicator span:nth-child(1) {
    animation-delay: 0s;
}

.typing-indicator span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-indicator span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typing {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.4;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

/* Chat Input */
.chat-input-container {
    padding: 16px 24px 24px;
    background-color: var(--bg-dark);
    border-top: 1px solid var(--border-color);
}

.chat-input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    gap: 12px;
    align-items: flex-end;
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 8px;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.chat-input-wrapper:focus-within {
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px rgba(42, 124, 160, 0.2);
}

.chat-input {
    flex: 1;
    padding: 8px 12px;
    font-size: 15px;
    font-family: inherit;
    color: var(--brand-brown);
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    line-height: 1.5;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.send-button {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--brand-green);
    color: white;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    flex-shrink: 0;
}

.send-button:hover {
    background-color: #5a7a1e;
}

.send-button:disabled {
    background-color: var(--text-muted);
    cursor: not-allowed;
}

.input-hint {
    max-width: 800px;
    margin: 8px auto 0;
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
}

.input-hint kbd {
    display: inline-block;
    padding: 2px 6px;
    font-size: 11px;
    font-family: inherit;
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-light);
}

/* Sidebar */
.sidebar {
    position: fixed;
    top: 0;
    right: -320px;
    width: 320px;
    height: 100vh;
    background-color: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: -4px 0 20px rgba(0, 0, 0, 0.3);
    transition: right 0.3s ease;
    z-index: 100;
}

.sidebar.open {
    right: 0;
}

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--brand-blue);
    color: white;
}

.sidebar-header h3 {
    font-size: 16px;
    font-weight: 600;
}

.sidebar-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 24px;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    border-radius: 4px;
}

.sidebar-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.sidebar-content {
    padding: 20px;
}

.filter-group {
    margin-bottom: 20px;
}

.filter-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-card);
    margin-bottom: 8px;
}

.filter-group select {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    color: var(--brand-brown);
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    cursor: pointer;
    outline: none;
}

.filter-group select:focus {
    border-color: var(--brand-blue);
}

.apply-filters-btn {
    width: 100%;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    color: white;
    background-color: var(--brand-green);
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.2s ease;
}

.apply-filters-btn:hover {
    background-color: #5a7a1e;
}

/* Loading Overlay */
.loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(64, 53, 30, 0.95);
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    z-index: 200;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 4px solid var(--border-color);
    border-top-color: var(--brand-green);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

.loading-overlay p {
    font-size: 14px;
    color: var(--text-light);
}

/* Source Cards */
.source-card {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background-color: rgba(42, 124, 160, 0.15);
    border-radius: 20px;
    font-size: 12px;
    color: var(--brand-blue);
    margin: 4px 4px 4px 0;
    text-decoration: none;
    transition: background-color 0.2s ease;
}

.source-card:hover {
    background-color: rgba(42, 124, 160, 0.25);
}

.sources-list {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid rgba(42, 124, 160, 0.2);
}

.sources-list h4 {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Error Message */
.error-message {
    background-color: rgba(68, 0, 8, 0.2);
    border: 1px solid var(--brand-burgundy);
    color: #ff6b6b;
    padding: 12px 16px;
    border-radius: 8px;
    margin: 16px auto;
    max-width: 800px;
}

/* Responsive */
@media (max-width: 768px) {
    .app-header {
        padding: 12px 16px;
    }

    .header-title h1 {
        font-size: 16px;
    }

    .header-subtitle {
        display: none;
    }

    .chat-messages {
        padding: 16px;
    }

    .welcome-message {
        padding: 20px;
        margin: 20px auto;
    }

    .welcome-message h2 {
        font-size: 22px;
    }

    .quick-action-buttons {
        flex-direction: column;
    }

    .quick-action {
        width: 100%;
        justify-content: center;
    }

    .chat-input-container {
        padding: 12px 16px 16px;
    }

    .message {
        max-width: 100%;
    }

    .message-content {
        max-width: calc(100% - 50px);
    }
}

/* Scrollbar */
.chat-messages::-webkit-scrollbar {
    width: 8px;
}

.chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

.chat-messages::-webkit-scrollbar-thumb {
    background-color: var(--border-color);
    border-radius: 4px;
}

.chat-messages::-webkit-scrollbar-thumb:hover {
    background-color: var(--text-muted);
}

/* Markdown Tables */
.message-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 12px 0;
    font-size: 14px;
}

.message-content th,
.message-content td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.message-content th {
    background-color: rgba(42, 124, 160, 0.1);
    font-weight: 600;
    color: var(--brand-blue);
}

/* Device Cards */
.device-card {
    background-color: white;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    margin: 12px 0;
    border-left: 4px solid var(--brand-green);
}

.device-card h4 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--brand-blue);
}

.device-card .vendor {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.device-card .specs {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 8px;
}

.device-card .spec-item {
    font-size: 13px;
}

.device-card .spec-label {
    font-weight: 500;
    color: var(--text-muted);
}

.device-card .spec-value {
    color: var(--brand-brown);
}

/* Login Page Styles */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--bg-dark) 0%, var(--brand-brown) 100%);
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
}

.login-logos {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    margin-bottom: 30px;
}

.logo {
    max-height: 50px;
    max-width: 120px;
    object-fit: contain;
}

.login-card h1 {
    text-align: center;
    color: var(--brand-blue);
    margin-bottom: 8px;
    font-size: 28px;
}

.subtitle {
    text-align: center;
    color: var(--brand-blue);
    margin-bottom: 30px;
}

.oauth-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 20px;
}

.btn-oauth {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 14px 20px;
    border-radius: 6px;
    font-size: 15px;
    font-weight: 500;
    text-decoration: none;
    transition: all 0.2s;
    cursor: pointer;
}

.btn-microsoft {
    background: #ffffff;
    color: #5e5e5e;
    border: 1px solid #8c8c8c;
}

.btn-microsoft:hover {
    background: #f3f3f3;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.login-footer {
    margin-top: 30px;
    text-align: center;
    color: var(--brand-blue);
    font-size: 12px;
}
