/* ============================================================
   AutoMate by Delta Software — Design System
   Premium dark theme with glassmorphism and micro-animations
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ─── CSS Custom Properties ─────────────────────────────── */
:root {
    /* Brand colors (Red, Gray, Black Theme) */
    --am-primary: #DC2626; /* Red */
    --am-primary-light: #EF4444;
    --am-primary-dark: #991B1B;
    --am-accent: #9CA3AF; /* Gray */
    --am-accent-light: #D1D5DB;

    /* Surfaces */
    --am-bg-deep: #000000; /* Black */
    --am-bg: #111111;
    --am-bg-elevated: #1F1F1F;
    --am-bg-card: rgba(31, 31, 31, 0.7);
    --am-bg-hover: rgba(55, 55, 55, 0.5);
    --am-bg-input: rgba(17, 17, 17, 0.8);

    /* Text */
    --am-text: #F9FAFB;
    --am-text-secondary: #D1D5DB;
    --am-text-muted: #9CA3AF;
    --am-text-inverse: #000000;

    /* Borders */
    --am-border: rgba(156, 163, 175, 0.2);
    --am-border-light: rgba(156, 163, 175, 0.1);
    --am-border-focus: var(--am-primary-light);

    /* Status */
    --am-success: #10B981;
    --am-warning: #F59E0B;
    --am-error: #EF4444;
    --am-info: #3B82F6;

    /* Gradients */
    --am-gradient-primary: linear-gradient(135deg, #DC2626 0%, #991B1B 100%);
    --am-gradient-dark: linear-gradient(180deg, #111111 0%, #000000 100%);
    --am-gradient-card: linear-gradient(135deg, rgba(31,31,31,0.8) 0%, rgba(17,17,17,0.6) 100%);

    /* Glass */
    --am-glass-bg: rgba(31, 41, 55, 0.6);
    --am-glass-border: rgba(255, 255, 255, 0.08);
    --am-glass-blur: 20px;

    /* Shadows */
    --am-shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --am-shadow-md: 0 4px 12px rgba(0,0,0,0.4);
    --am-shadow-lg: 0 10px 40px rgba(0,0,0,0.5);
    --am-shadow-glow: 0 0 30px rgba(220, 38, 38, 0.2);

    /* Spacing */
    --am-radius-sm: 8px;
    --am-radius-md: 12px;
    --am-radius-lg: 16px;
    --am-radius-xl: 24px;
    --am-radius-full: 9999px;

    /* Sidebar */
    --am-sidebar-width: 280px;

    /* Transitions */
    --am-transition: 200ms cubic-bezier(0.4, 0, 0.2, 1);
    --am-transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ─── Reset & Base ──────────────────────────────────────── */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
    background: var(--am-bg-deep);
    color: var(--am-text);
    line-height: 1.6;
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

a { color: var(--am-primary-light); text-decoration: none; }
a:hover { color: var(--am-accent-light); }

::selection {
    background: var(--am-primary);
    color: white;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--am-border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--am-text-muted); }

/* ─── App Layout ────────────────────────────────────────── */
.am-app {
    display: flex;
    height: 100vh;
    width: 100vw;
    background: var(--am-gradient-dark);
}

/* ─── Login Screen ──────────────────────────────────────── */
.am-login {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100vh;
    width: 100vw;
    background: var(--am-gradient-dark);
}

.am-login-card {
    width: 100%;
    max-width: 420px;
    padding: 48px;
    background: var(--am-glass-bg);
    backdrop-filter: blur(var(--am-glass-blur));
    border: 1px solid var(--am-glass-border);
    border-radius: var(--am-radius-xl);
    box-shadow: var(--am-shadow-lg), var(--am-shadow-glow);
    animation: fadeInUp 0.6s ease-out;
}

.am-login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.am-login-logo h1 {
    font-size: 2rem;
    font-weight: 700;
    background: var(--am-gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.am-login-logo .am-company {
    font-size: 0.8rem;
    color: var(--am-text-muted);
    margin-top: 4px;
    letter-spacing: 2px;
    text-transform: uppercase;
}

/* ─── Sidebar ───────────────────────────────────────────── */
.am-sidebar {
    width: var(--am-sidebar-width);
    min-width: var(--am-sidebar-width);
    height: 100vh;
    background: var(--am-glass-bg);
    backdrop-filter: blur(var(--am-glass-blur));
    border-right: 1px solid var(--am-glass-border);
    display: flex;
    flex-direction: column;
    transition: transform var(--am-transition);
    z-index: 100;
}

.am-sidebar-header {
    padding: 20px 16px;
    border-bottom: 1px solid var(--am-border-light);
    display: flex;
    align-items: center;
    gap: 12px;
}

.am-sidebar-logo {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--am-gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.am-sidebar-version {
    font-size: 0.7rem;
    color: var(--am-text-muted);
    background: var(--am-bg-elevated);
    padding: 2px 8px;
    border-radius: var(--am-radius-full);
}

.am-new-chat-btn {
    margin: 12px 16px;
    padding: 12px;
    background: var(--am-gradient-primary);
    color: white;
    border: none;
    border-radius: var(--am-radius-md);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all var(--am-transition);
    font-family: inherit;
}

.am-new-chat-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--am-shadow-md), var(--am-shadow-glow);
}

/* Conversation List */
.am-conv-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.am-conv-group-label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--am-text-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
    padding: 12px 12px 6px;
}

.am-conv-item {
    padding: 10px 12px;
    border-radius: var(--am-radius-sm);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: all var(--am-transition);
    margin-bottom: 2px;
    position: relative;
}

.am-conv-item:hover {
    background: var(--am-bg-hover);
}

.am-conv-item.active {
    background: rgba(220, 38, 38, 0.15);
    border: 1px solid rgba(220, 38, 38, 0.3);
}

.am-conv-item .am-conv-title {
    flex: 1;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--am-text);
}

.am-conv-item .am-conv-time {
    font-size: 0.7rem;
    color: var(--am-text-muted);
    white-space: nowrap;
}

.am-conv-item .am-conv-delete {
    display: none;
    background: none;
    border: none;
    color: var(--am-error);
    cursor: pointer;
    padding: 4px;
    font-size: 0.85rem;
    border-radius: 4px;
}

.am-conv-item:hover .am-conv-delete {
    display: block;
}

/* Sidebar footer */
.am-sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--am-border-light);
    display: flex;
    gap: 8px;
}

.am-sidebar-footer button {
    flex: 1;
    padding: 8px;
    background: var(--am-bg-elevated);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-sm);
    color: var(--am-text-secondary);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: inherit;
    transition: all var(--am-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.am-sidebar-footer button:hover {
    background: var(--am-bg-hover);
    color: var(--am-text);
}

/* ─── Main Chat Area ────────────────────────────────────── */
.am-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
    position: relative;
}

/* Top bar */
.am-topbar {
    height: 56px;
    padding: 0 20px;
    border-bottom: 1px solid var(--am-border-light);
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(10px);
}

.am-topbar-menu {
    display: none;
    background: none;
    border: none;
    color: var(--am-text);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px;
}

.am-topbar-title {
    flex: 1;
    font-size: 0.95rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.am-topbar-model {
    font-size: 0.75rem;
    color: var(--am-text-muted);
    background: var(--am-bg-elevated);
    padding: 4px 10px;
    border-radius: var(--am-radius-full);
    border: 1px solid var(--am-border);
}

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

.am-messages-inner {
    max-width: 800px;
    margin: 0 auto;
    padding: 0 24px;
}

/* Welcome Screen */
.am-welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
    padding: 40px;
    animation: fadeIn 0.8s ease-out;
}

.am-welcome-icon {
    font-size: 4rem;
    margin-bottom: 24px;
    animation: float 3s ease-in-out infinite;
}

.am-welcome h2 {
    font-size: 1.8rem;
    font-weight: 700;
    background: var(--am-gradient-primary);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 12px;
}

.am-welcome p {
    color: var(--am-text-secondary);
    max-width: 500px;
    margin-bottom: 32px;
    line-height: 1.7;
}

.am-welcome-skills {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.am-skill-chip {
    padding: 10px 20px;
    background: var(--am-bg-card);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-full);
    font-size: 0.85rem;
    color: var(--am-text-secondary);
    cursor: pointer;
    transition: all var(--am-transition);
    font-family: inherit;
}

.am-skill-chip:hover {
    background: rgba(220, 38, 38, 0.15);
    border-color: var(--am-primary);
    color: var(--am-text);
    transform: translateY(-2px);
}

/* Message Bubbles */
.am-message {
    margin-bottom: 24px;
    animation: fadeInUp 0.3s ease-out;
}

.am-message-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
}

.am-message-avatar {
    width: 28px;
    height: 28px;
    border-radius: var(--am-radius-full);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 600;
}

.am-message.user .am-message-avatar {
    background: var(--am-gradient-primary);
    color: white;
}

.am-message.assistant .am-message-avatar {
    background: linear-gradient(135deg, #111111, #333333);
    border: 1px solid #555555;
    color: white;
}

.am-message-author {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--am-text);
}

.am-message-time {
    font-size: 0.7rem;
    color: var(--am-text-muted);
}

.am-message-content {
    padding: 0 36px;
    font-size: 0.92rem;
    line-height: 1.7;
    color: var(--am-text);
}

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

.am-message-content code {
    background: var(--am-bg-elevated);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.85em;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    color: var(--am-accent-light);
}

.am-message-content pre {
    background: var(--am-bg);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-sm);
    padding: 16px;
    overflow-x: auto;
    margin: 12px 0;
    position: relative;
}

.am-message-content pre code {
    background: none;
    padding: 0;
    color: var(--am-text);
    font-size: 0.85rem;
}

.am-message-content h1, .am-message-content h2, .am-message-content h3 {
    margin: 16px 0 8px;
    color: var(--am-text);
}

.am-message-content ul, .am-message-content ol {
    padding-left: 24px;
    margin: 8px 0;
}

.am-message-content li { margin-bottom: 4px; }

.am-message-content blockquote {
    border-left: 3px solid var(--am-primary);
    padding-left: 16px;
    margin: 12px 0;
    color: var(--am-text-secondary);
}

.am-message-content a {
    color: var(--am-primary-light);
    text-decoration: underline;
    text-decoration-color: rgba(167, 139, 250, 0.3);
}

/* Tool execution indicator */
.am-tool-indicator {
    margin: 8px 36px;
    padding: 10px 14px;
    background: rgba(6, 182, 212, 0.08);
    border: 1px solid rgba(6, 182, 212, 0.2);
    border-radius: var(--am-radius-sm);
    font-size: 0.8rem;
    color: var(--am-accent-light);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: fadeIn 0.3s ease-out;
}

.am-tool-indicator.success { border-color: rgba(16, 185, 129, 0.3); color: var(--am-success); }
.am-tool-indicator.error { border-color: rgba(239, 68, 68, 0.3); color: var(--am-error); }

.am-tool-spinner {
    width: 14px;
    height: 14px;
    border: 2px solid transparent;
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.am-typing-dot {
    width: 8px;
    height: 8px;
    background: var(--am-primary-light);
    border-radius: 50%;
    animation: typingBounce 1.4s infinite ease-in-out;
}

.am-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.am-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* ─── Input Area ────────────────────────────────────────── */
.am-input-area {
    padding: 16px 24px 24px;
    border-top: 1px solid var(--am-border-light);
    background: rgba(17, 24, 39, 0.5);
    backdrop-filter: blur(10px);
}

.am-input-wrapper {
    max-width: 800px;
    margin: 0 auto;
    position: relative;
}

.am-input-box {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--am-bg-input);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-lg);
    padding: 8px;
    transition: all var(--am-transition);
}

.am-input-box:focus-within {
    border-color: var(--am-primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

.am-input-textarea {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    color: var(--am-text);
    font-size: 0.95rem;
    font-family: inherit;
    line-height: 1.5;
    resize: none;
    min-height: 24px;
    max-height: 200px;
    padding: 8px 12px;
}

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

.am-send-btn {
    width: 40px;
    height: 40px;
    background: var(--am-gradient-primary);
    border: none;
    border-radius: var(--am-radius-md);
    color: white;
    font-size: 1.1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--am-transition);
    flex-shrink: 0;
}

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

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

.am-input-hint {
    font-size: 0.7rem;
    color: var(--am-text-muted);
    text-align: center;
    margin-top: 8px;
}

/* ─── Settings Panel ────────────────────────────────────── */
.am-settings-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    z-index: 200;
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.am-settings-overlay.visible { display: block; }

.am-settings-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 420px;
    max-width: 90vw;
    height: 100vh;
    background: var(--am-bg);
    border-left: 1px solid var(--am-border);
    z-index: 201;
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.3s ease-out;
}

.am-settings-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--am-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.am-settings-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.am-settings-close {
    background: none;
    border: none;
    color: var(--am-text-secondary);
    font-size: 1.3rem;
    cursor: pointer;
    padding: 4px;
}

.am-settings-body {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.am-settings-group {
    margin-bottom: 32px;
}

.am-settings-group h3 {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--am-primary-light);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 16px;
}

.am-field {
    margin-bottom: 16px;
}

.am-field label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--am-text);
    margin-bottom: 6px;
}

.am-field .am-field-desc {
    font-size: 0.75rem;
    color: var(--am-text-muted);
    margin-bottom: 6px;
}

.am-field input[type="text"],
.am-field input[type="password"],
.am-field input[type="number"],
.am-field select,
.am-field textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--am-bg-input);
    border: 1px solid var(--am-border);
    border-radius: var(--am-radius-sm);
    color: var(--am-text);
    font-size: 0.9rem;
    font-family: inherit;
    outline: none;
    transition: border-color var(--am-transition);
}

.am-field input:focus,
.am-field select:focus,
.am-field textarea:focus {
    border-color: var(--am-primary);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.1);
}

.am-field select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%239CA3AF' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.am-btn {
    padding: 10px 20px;
    background: var(--am-gradient-primary);
    color: white;
    border: none;
    border-radius: var(--am-radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--am-transition);
}

.am-btn:hover {
    transform: translateY(-1px);
    box-shadow: var(--am-shadow-md);
}

.am-btn-secondary {
    background: var(--am-bg-elevated);
    border: 1px solid var(--am-border);
    color: var(--am-text);
}

/* ─── Animations ────────────────────────────────────────── */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

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

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

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

@keyframes typingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
    40% { transform: scale(1); opacity: 1; }
}

@keyframes am-dot-pulse {
    0%, 100% { transform: scale(1); opacity: 0.5; }
    50% { transform: scale(1.5); opacity: 1; }
}

@keyframes am-pulse-glow {
    0%, 100% { box-shadow: 0 0 10px 0 rgba(220, 38, 38, 0.05); }
    50% { box-shadow: 0 0 20px 5px rgba(220, 38, 38, 0.15); }
}

/* ─── Thinking Indicator (replaces tool indicators for users) ── */
.am-thinking-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    color: var(--am-text-muted);
    font-size: 0.85rem;
    font-style: italic;
    animation: am-fade-in 0.3s ease;
}
.am-thinking-indicator .am-typing-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--am-text-muted);
    animation: am-dot-pulse 1.5s infinite;
}
.am-thinking-indicator .am-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.am-thinking-indicator .am-typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes am-fade-in { from { opacity: 0; } to { opacity: 1; } }

/* ─── Agent Selector ───────────────────────────────────── */
.am-agent-selector {
    border-bottom: 1px solid var(--am-glass-border);
    padding-bottom: 8px;
    margin-bottom: 4px;
}
.am-agent-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    cursor: pointer;
    color: var(--am-text-secondary);
    font-size: 0.85rem;
    transition: all 0.2s;
    border-left: 3px solid transparent;
}
.am-agent-option:hover { background: rgba(255,255,255,0.03); color: var(--am-text-primary); }
.am-agent-option.active {
    background: rgba(220, 38, 38, 0.08);
    color: var(--am-primary-light);
    border-left-color: var(--am-primary-light);
    font-weight: 500;
}

/* ─── Responsive ────────────────────────────────────────── */
@media (max-width: 768px) {
    .am-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        transform: translateX(-100%);
    }
    .am-sidebar.open {
        transform: translateX(0);
        box-shadow: var(--am-shadow-lg);
    }
    .am-topbar-menu { display: block; }
    .am-messages-inner { padding: 0 16px; }
    .am-input-area { padding: 12px 16px 16px; }
    .am-welcome-skills { flex-direction: column; align-items: center; }
}
