:root {
    --bg-dark: #050508;
    --bg-surface: rgba(18, 18, 29, 0.7);
    --bg-surface-hover: rgba(30, 30, 46, 0.85);
    --primary: #00d2ff;
    --primary-gradient: linear-gradient(135deg, #00d2ff, #0066ff);
    --accent: #00e676;
    --accent-gradient: linear-gradient(135deg, #00e676, #00b0ff);
    --border: rgba(255, 255, 255, 0.08);
    --border-glow: rgba(0, 210, 255, 0.3);
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --radius-lg: 16px;
    --radius-md: 12px;
    --radius-sm: 8px;
    --shadow-glow: 0 0 15px rgba(0, 210, 255, 0.2);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: 'Inter', sans-serif;
    -webkit-font-smoothing: antialiased;
}

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    background-image: 
        radial-gradient(circle at 10% 20%, rgba(0, 230, 118, 0.05) 0%, transparent 40%),
        radial-gradient(circle at 90% 80%, rgba(0, 210, 255, 0.05) 0%, transparent 40%);
    background-attachment: fixed;
}

/* Header */
header {
    background: rgba(5, 5, 8, 0.85);
    backdrop-filter: blur(15px);
    border-bottom: 1px solid var(--border);
    padding: 12px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
}

.brand-icon {
    width: 32px;
    height: 32px;
    background: var(--primary-gradient);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #050508;
    font-weight: 800;
    box-shadow: var(--shadow-glow);
}

.brand-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.brand-text p {
    font-size: 0.65rem;
    color: var(--primary);
    text-transform: uppercase;
    font-weight: bold;
    letter-spacing: 0.5px;
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border);
    color: var(--text-main);
    text-decoration: none;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

.btn-back:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: var(--primary);
}

/* App Container Layout */
.app-layout {
    display: flex;
    flex: 1;
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    gap: 20px;
    padding: 20px;
    height: calc(100vh - 57px);
    height: calc(100dvh - 57px);
    overflow: hidden;
}

/* Sidebar monitor (systems / subdomains) */
.sidebar-panel {
    width: 300px;
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}

.panel-header {
    padding: 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.panel-header h2 {
    font-size: 0.95rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--primary);
}

.systems-list {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.system-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-main);
    transition: all 0.2s ease;
}

.system-item:hover {
    background: rgba(255, 255, 255, 0.06);
    border-color: rgba(0, 210, 255, 0.2);
}

.system-info {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.82rem;
    font-weight: 500;
}

.system-info i {
    width: 16px;
    text-align: center;
    color: var(--primary);
}

.system-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.72rem;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #555;
}

.status-dot.online {
    background: var(--accent);
    box-shadow: 0 0 8px var(--accent);
}

/* Central Robot / Chat Room */
.chat-panel {
    flex: 1.2;
    display: flex;
    flex-direction: column;
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
}

.robot-workspace {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    overflow-y: auto;
    position: relative;
}

/* Cyber Robot Face Animation */
.robot-avatar-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Shrunken robot state when answers are active */
.chat-panel.has-answers .robot-avatar-container {
    transform: scale(0.65);
    margin-bottom: 5px;
}

.robot-sphere {
    position: relative;
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: radial-gradient(circle at 30% 30%, #1e293b, #0f172a);
    border: 3px solid var(--border);
    box-shadow: 0 8px 32px rgba(0,0,0,0.5), inset 0 0 20px rgba(255,255,255,0.05);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

/* Robot face lines/circuits */
.robot-sphere::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 10%;
    right: 10%;
    height: 2px;
    background: rgba(255, 255, 255, 0.05);
}

.robot-eyes {
    display: flex;
    gap: 24px;
    z-index: 2;
}

.robot-eye {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #00d2ff;
    box-shadow: 0 0 15px #00d2ff, 0 0 30px #00d2ff;
    position: relative;
    animation: robot-blink 4s infinite;
    transition: all 0.3s ease;
}

.robot-eye::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: white;
}

/* Glowing Halo Circle */
.robot-halo {
    position: absolute;
    width: 140px;
    height: 140px;
    border-radius: 50%;
    border: 2px dashed rgba(0, 210, 255, 0.25);
    animation: robot-spin 20s linear infinite;
    pointer-events: none;
}

/* Robot states */
.robot-sphere.listening {
    border-color: var(--accent);
    box-shadow: 0 0 25px rgba(0, 230, 118, 0.4);
}
.robot-sphere.listening .robot-eye {
    background: var(--accent);
    box-shadow: 0 0 15px var(--accent), 0 0 30px var(--accent);
}
.robot-sphere.listening .robot-halo {
    border-color: rgba(0, 230, 118, 0.4);
    animation-duration: 8s;
}

.robot-sphere.thinking {
    border-color: #ffd600;
    box-shadow: 0 0 25px rgba(255, 214, 0, 0.4);
}
.robot-sphere.thinking .robot-eye {
    background: #ffd600;
    box-shadow: 0 0 15px #ffd600, 0 0 30px #ffd600;
    animation: robot-pulse-eye 0.8s infinite alternate;
}
.robot-sphere.thinking .robot-halo {
    border-color: rgba(255, 214, 0, 0.4);
    animation-duration: 4s;
}

.robot-sphere.speaking {
    border-color: #00e5ff;
    box-shadow: 0 0 25px rgba(0, 229, 255, 0.4);
}
.robot-sphere.speaking .robot-eye {
    background: #00e5ff;
    box-shadow: 0 0 15px #00e5ff, 0 0 30px #00e5ff;
    animation: robot-talk-eye 0.15s infinite alternate;
}
.robot-sphere.speaking .robot-halo {
    border-color: rgba(0, 229, 255, 0.4);
    animation-duration: 12s;
}

.robot-label {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--primary);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Chat display areas */
.answers-container {
    width: 100%;
    flex: 1;
    display: none;
    flex-direction: column;
    gap: 16px;
    overflow-y: auto;
    padding: 10px 0;
    scroll-behavior: smooth;
}

.chat-panel.has-answers .answers-container {
    display: flex;
}

.message-bubble {
    max-width: 85%;
    padding: 14px 18px;
    border-radius: var(--radius-md);
    line-height: 1.5;
    font-size: 0.9rem;
    word-wrap: break-word;
}

.message-bubble.incoming {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    color: var(--text-main);
    align-self: flex-start;
}

.message-bubble.outgoing {
    background: var(--primary-gradient);
    color: #ffffff;
    align-self: flex-end;
    box-shadow: 0 4px 12px rgba(0, 102, 255, 0.2);
}

.message-bubble.incoming p {
    margin-bottom: 8px;
}
.message-bubble.incoming p:last-child {
    margin-bottom: 0;
}

.message-bubble strong {
    color: var(--primary);
}
.message-bubble.outgoing strong {
    color: #fff;
}

.message-bubble pre {
    background: rgba(0,0,0,0.3);
    padding: 10px;
    border-radius: 6px;
    overflow-x: auto;
    font-family: monospace;
    font-size: 0.82rem;
    margin: 8px 0;
    border: 1px solid var(--border);
}

/* Floating quick suggestions */
.suggestions-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
    margin-top: 15px;
    width: 100%;
}

.chat-panel.has-answers .suggestions-grid {
    margin-top: 5px;
    justify-content: flex-start;
}

.suggestion-pill {
    padding: 8px 14px;
    border-radius: 20px;
    background: rgba(255,255,255,0.03);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.76rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.suggestion-pill:hover {
    background: rgba(0, 210, 255, 0.08);
    border-color: var(--primary);
    color: white;
}

/* Chat Input Bar */
.input-dock {
    padding: 15px 20px;
    border-top: 1px solid var(--border);
    background: rgba(5, 5, 8, 0.4);
    display: flex;
    gap: 10px;
    align-items: center;
}

.input-container {
    flex: 1;
    position: relative;
    display: flex;
    align-items: center;
}

.chat-input {
    width: 100%;
    padding: 14px 45px 14px 16px;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border);
    color: white;
    border-radius: 24px;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.25s ease;
}

.chat-input:focus {
    border-color: var(--primary);
    background: rgba(255, 255, 255, 0.04);
    box-shadow: 0 0 10px rgba(0, 210, 255, 0.15);
}

.mic-btn {
    position: absolute;
    right: 12px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 1.1rem;
    cursor: pointer;
    padding: 6px;
    transition: all 0.2s ease;
}

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

.mic-btn.active {
    color: var(--accent);
    animation: mic-pulse 1.2s infinite alternate;
}

.send-btn {
    width: 46px;
    height: 46px;
    border-radius: 50%;
    background: var(--primary-gradient);
    border: none;
    color: #050508;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    cursor: pointer;
    box-shadow: var(--shadow-glow);
    transition: all 0.2s ease;
}

.send-btn:hover {
    transform: scale(1.05);
    opacity: 0.95;
}

.send-btn:active {
    transform: scale(0.95);
}

/* Right Panel: Integrated Tools suite */
.tools-panel {
    width: 420px;
    background: var(--bg-surface);
    backdrop-filter: blur(10px);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: all 0.3s ease;
}

.tab-nav {
    display: flex;
    background: rgba(0,0,0,0.2);
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 14px 10px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    transition: all 0.2s ease;
}

.tab-btn i {
    font-size: 1rem;
}

.tab-btn:hover {
    color: var(--text-main);
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
    background: rgba(255, 255, 255, 0.01);
}

.tab-viewport {
    flex: 1;
    overflow-y: auto;
    position: relative;
}

.tab-content {
    display: none;
    padding: 16px;
    flex-direction: column;
    gap: 15px;
    height: 100%;
}

.tab-content.active {
    display: flex;
}

/* Tool Forms */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
}

.form-control {
    padding: 10px 12px;
    background: rgba(0,0,0,0.25);
    border: 1px solid var(--border);
    color: white;
    border-radius: 8px;
    font-size: 0.88rem;
    outline: none;
}

.form-control:focus {
    border-color: var(--primary);
}

.btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    padding: 12px;
    border-radius: 8px;
    font-size: 0.88rem;
    font-weight: bold;
    cursor: pointer;
    border: none;
    transition: all 0.15s ease;
}

.btn-primary {
    background: var(--primary-gradient);
    color: #050508;
}

.btn-accent {
    background: var(--accent-gradient);
    color: #050508;
}

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-main);
}

.btn-outline:hover {
    background: rgba(255,255,255,0.03);
    border-color: var(--primary);
}

.btn:active {
    transform: scale(0.98);
}

/* Contract & BOQ Previews */
.preview-box {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 12px;
    font-size: 0.8rem;
    overflow-y: auto;
    max-height: 250px;
    white-space: pre-wrap;
    word-break: break-all;
    line-height: 1.5;
    color: #e2e8f0;
}

.contract-preview-editable {
    outline: none;
    border: 1px dashed rgba(0, 210, 255, 0.3);
}

.contract-preview-editable:focus {
    border-color: var(--primary);
    box-shadow: inset 0 0 10px rgba(0, 210, 255, 0.1);
}

/* BOQ discipline table */
.boq-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    max-height: 250px;
}

.boq-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.76rem;
    text-align: left;
}

.boq-table th {
    background: rgba(0,0,0,0.4);
    padding: 8px 10px;
    color: var(--primary);
    font-weight: bold;
    border-bottom: 1px solid var(--border);
}

.boq-table td {
    padding: 8px 10px;
    border-bottom: 1px solid rgba(255,255,255,0.03);
    color: #e2e8f0;
}

.boq-table tr:last-child td {
    border-bottom: none;
}

/* 3D Design results styles */
.render-frame {
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
    background: #000;
    min-height: 200px;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

.render-img {
    width: 100%;
    height: auto;
    object-fit: cover;
    display: block;
}

/* Photo Measure tool Canvas styles */
.canvas-wrapper {
    width: 100%;
    position: relative;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #000;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}

.measure-canvas {
    max-width: 100%;
    max-height: 400px;
    display: block;
    cursor: crosshair;
}

/* Toggle Controls for HUD */
.hud-toggles {
    display: flex;
    gap: 8px;
}

.hud-toggle-btn {
    flex: 1;
    padding: 8px;
    font-size: 0.72rem;
    border-radius: 6px;
    font-weight: 700;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.02);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.2s ease;
}

.hud-toggle-btn.active {
    background: rgba(0, 210, 255, 0.1);
    border-color: var(--primary);
    color: var(--primary);
}

/* =============================================
   MOBILE MEDIA QUERY (Max-width: 768px)
   For smartphones:
   - Header is compact
   - App Layout is single column, scrolling vertically
   - Sidebar is hidden or accessible via top drawer
   - Tools panel is collapsed, tab/tool buttons appear
     as a modal or drawer
   ============================================= */
@media (max-width: 900px) {
    .app-layout {
        flex-direction: column;
        height: auto;
        overflow-y: auto;
        padding: 10px;
        gap: 15px;
    }
    
    .sidebar-panel {
        width: 100%;
        max-height: 220px;
    }
    
    .systems-list {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
        gap: 6px;
    }
    
    .system-item {
        padding: 8px 10px;
    }
    
    .chat-panel {
        height: calc(100vh - 120px);
        height: calc(100dvh - 120px);
    }
    
    .tools-panel {
        width: 100%;
        height: auto;
    }
}

/* Animations */
@keyframes robot-blink {
    0%, 45%, 55%, 100% {
        transform: scaleY(1);
    }
    50% {
        transform: scaleY(0.1);
    }
}

@keyframes robot-spin {
    100% {
        transform: rotate(360deg);
    }
}

@keyframes robot-pulse-eye {
    0% {
        transform: scale(0.9);
        opacity: 0.8;
    }
    100% {
        transform: scale(1.1);
        opacity: 1;
    }
}

@keyframes robot-talk-eye {
    0% {
        transform: scaleY(0.6) scaleX(1);
    }
    100% {
        transform: scaleY(1.2) scaleX(1.1);
    }
}

@keyframes mic-pulse {
    0% {
        transform: scale(1);
        text-shadow: 0 0 5px rgba(0, 230, 118, 0.5);
    }
    100% {
        transform: scale(1.1);
        text-shadow: 0 0 15px rgba(0, 230, 118, 0.9);
    }
}

/* Global Speech Bubble custom styling */
.text-speech-bubble {
    position: absolute;
    top: -45px;
    background: var(--accent);
    color: black;
    padding: 6px 12px;
    border-radius: 12px;
    font-size: 0.72rem;
    font-weight: 700;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    white-space: nowrap;
    animation: bounce 1.5s infinite alternate;
}

.text-speech-bubble::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px 6px 0;
    border-style: solid;
    border-color: var(--accent) transparent;
}

@keyframes bounce {
    0% { transform: translateY(0) translateX(-50%); }
    100% { transform: translateY(-4px) translateX(-50%); }
}
