/* ============================================
   AMITEK AI CHAT — Premium Dark Theme
   ============================================ */

:root {
    /* Core Palette */
    --bg-primary: #0a0f1e;
    --bg-secondary: #111827;
    --bg-tertiary: #1a2236;
    --bg-glass: rgba(17, 24, 39, 0.85);

    /* Accent */
    --accent-blue: #3b82f6;
    --accent-purple: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #3b82f6, #8b5cf6);
    --accent-glow: rgba(59, 130, 246, 0.3);

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

    /* Borders */
    --border-subtle: rgba(148, 163, 184, 0.1);
    --border-accent: rgba(59, 130, 246, 0.3);

    /* Sizing */
    --header-height: 64px;
    --input-area-height: auto;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    /* Transitions */
    --transition-fast: 150ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-medium: 300ms cubic-bezier(0.4, 0, 0.2, 1);
    --transition-slow: 500ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ============ RESET & BASE ============ */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
}

/* ============ SCREENS ============ */
.screen {
    display: none;
    width: 100%;
    height: 100%;
}

.screen.active {
    display: flex;
}

/* ============ AUTH SCREEN ============ */
#auth-screen {
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    position: relative;
    overflow: hidden;
}

#auth-screen::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle at 50% 50%, rgba(59, 130, 246, 0.06) 0%, transparent 50%);
    animation: pulse-bg 8s ease-in-out infinite;
}

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

.auth-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.auth-logo {
    position: relative;
    width: 100px;
    height: 100px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 8px;
}

.logo-glow {
    position: absolute;
    inset: -20px;
    background: var(--accent-gradient);
    border-radius: 50%;
    opacity: 0.15;
    filter: blur(30px);
    animation: glow-pulse 3s ease-in-out infinite;
}

@keyframes glow-pulse {
    0%, 100% { opacity: 0.1; transform: scale(0.9); }
    50% { opacity: 0.2; transform: scale(1.1); }
}

.logo-icon {
    width: 80px;
    height: 80px;
    animation: spin-slow 20s linear infinite;
}

@keyframes spin-slow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.auth-title {
    font-size: 28px;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.5px;
}

.auth-subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 400;
    margin-top: -8px;
}

.pin-input-group {
    width: 100%;
}

.pin-input {
    width: 100%;
    padding: 14px 20px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-family: 'JetBrains Mono', monospace;
    font-size: 20px;
    text-align: center;
    letter-spacing: 8px;
    outline: none;
    transition: var(--transition-fast);
}

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

.pin-input::placeholder {
    letter-spacing: normal;
    font-size: 14px;
    font-family: 'Inter', sans-serif;
    color: var(--text-muted);
}

.pin-error {
    color: #ef4444;
    font-size: 13px;
    text-align: center;
    min-height: 20px;
    margin-top: 8px;
    opacity: 0;
    transition: var(--transition-fast);
}

.pin-error.visible {
    opacity: 1;
}

.btn-primary {
    width: 100%;
    padding: 14px 24px;
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-family: 'Inter', sans-serif;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: var(--transition-fast);
    position: relative;
    overflow: hidden;
}

.btn-primary::before {
    content: '';
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, rgba(255,255,255,0.1), transparent);
    opacity: 0;
    transition: var(--transition-fast);
}

.btn-primary:hover::before {
    opacity: 1;
}

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

/* ============ CHAT SCREEN ============ */
#chat-screen {
    flex-direction: column;
    background: var(--bg-primary);
}

/* ============ HEADER ============ */
.chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    height: var(--header-height);
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-subtle);
    position: relative;
    z-index: 10;
    flex-shrink: 0;
}

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

.avatar-ring {
    padding: 2px;
    background: var(--accent-gradient);
    border-radius: 50%;
}

.avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 13px;
    color: var(--accent-blue);
}

.header-info h2 {
    font-size: 15px;
    font-weight: 600;
    line-height: 1.2;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    font-size: 11px;
    color: var(--text-secondary);
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 6px rgba(34, 197, 94, 0.5);
}

.status-dot.thinking {
    background: #f59e0b;
    box-shadow: 0 0 6px rgba(245, 158, 11, 0.5);
    animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

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

.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* ============ MESSAGES ============ */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    -webkit-overflow-scrolling: touch;
}

.messages-inner {
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    min-height: 100%;
}

/* Welcome Card */
.welcome-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 32px 24px;
    text-align: center;
    margin: auto 0;
    animation: fadeInUp 0.5s ease;
}

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

.welcome-card h3 {
    font-size: 20px;
    font-weight: 600;
    margin-bottom: 8px;
}

.welcome-card p {
    color: var(--text-secondary);
    font-size: 14px;
    line-height: 1.6;
    max-width: 320px;
    margin: 0 auto 20px;
}

.quick-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: center;
}

.chip {
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 12px;
    cursor: pointer;
    transition: var(--transition-fast);
    white-space: nowrap;
}

.chip:hover {
    background: rgba(59, 130, 246, 0.1);
    border-color: var(--border-accent);
    color: var(--accent-blue);
}

/* Message Bubbles */
.message {
    display: flex;
    gap: 10px;
    max-width: 85%;
    animation: fadeInUp 0.3s ease;
}

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

.message.assistant {
    align-self: flex-start;
}

.msg-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    flex-shrink: 0;
    margin-top: 4px;
}

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

.message.assistant .msg-avatar {
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    color: var(--accent-blue);
}

.msg-content {
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    line-height: 1.6;
    font-size: 14px;
    position: relative;
}

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

.message.assistant .msg-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}

.msg-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 6px;
    display: block;
}

.message.user .msg-time {
    text-align: right;
    color: rgba(255,255,255,0.6);
}

/* Markdown in messages */
.msg-content h1, .msg-content h2, .msg-content h3 {
    margin: 12px 0 6px;
    font-weight: 600;
}

.msg-content h1 { font-size: 18px; }
.msg-content h2 { font-size: 16px; }
.msg-content h3 { font-size: 15px; }

.msg-content p {
    margin: 6px 0;
}

.msg-content ul, .msg-content ol {
    padding-left: 20px;
    margin: 6px 0;
}

.msg-content li {
    margin: 3px 0;
}

.msg-content code {
    font-family: 'JetBrains Mono', monospace;
    font-size: 12.5px;
    background: rgba(0, 0, 0, 0.3);
    padding: 2px 6px;
    border-radius: 4px;
}

.msg-content pre {
    margin: 10px 0;
    border-radius: var(--radius-sm);
    overflow: hidden;
    position: relative;
}

.msg-content pre code {
    display: block;
    padding: 14px;
    background: #0d1117;
    overflow-x: auto;
    line-height: 1.5;
    border-radius: var(--radius-sm);
}

.code-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 12px;
    background: #161b22;
    font-size: 11px;
    color: var(--text-muted);
    font-family: 'JetBrains Mono', monospace;
}

.btn-copy {
    padding: 3px 8px;
    background: transparent;
    border: 1px solid var(--border-subtle);
    border-radius: 4px;
    color: var(--text-muted);
    font-size: 11px;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-copy:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn-copy.copied {
    color: #22c55e;
    border-color: #22c55e;
}

.msg-content table {
    border-collapse: collapse;
    width: 100%;
    margin: 10px 0;
    font-size: 13px;
}

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

.msg-content th {
    background: var(--bg-tertiary);
    font-weight: 600;
}

.msg-content blockquote {
    border-left: 3px solid var(--accent-blue);
    padding: 8px 16px;
    margin: 10px 0;
    background: rgba(59, 130, 246, 0.05);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    color: var(--text-secondary);
}

.msg-content strong {
    color: var(--text-primary);
    font-weight: 600;
}

.msg-content a {
    color: var(--accent-blue);
    text-decoration: none;
}

.msg-content a:hover {
    text-decoration: underline;
}

.msg-content hr {
    border: none;
    border-top: 1px solid var(--border-subtle);
    margin: 12px 0;
}

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

.typing-indicator span {
    width: 7px;
    height: 7px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: typing-bounce 1.4s ease infinite;
}

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

@keyframes typing-bounce {
    0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
    40% { transform: translateY(-6px); opacity: 1; }
}

/* ============ INPUT AREA ============ */
.input-area {
    padding: 12px 16px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--bg-glass);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border-subtle);
    flex-shrink: 0;
}

.input-container {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    padding: 6px 6px 6px 16px;
    transition: var(--transition-fast);
}

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

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

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

.btn-send {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--accent-gradient);
    border-radius: var(--radius-md);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
    flex-shrink: 0;
    opacity: 0.4;
}

.btn-send:not(:disabled) {
    opacity: 1;
}

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

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

.input-footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 4px 0;
}

.model-badge {
    font-size: 11px;
    color: var(--text-muted);
    padding: 2px 8px;
    background: var(--bg-tertiary);
    border-radius: var(--radius-full);
}

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

/* ============ SIDE MENU ============ */
.menu-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 100;
    opacity: 0;
    visibility: hidden;
    transition: var(--transition-medium);
}

.menu-overlay.active {
    opacity: 1;
    visibility: visible;
}

.side-menu {
    position: fixed;
    top: 0;
    right: -320px;
    width: 300px;
    max-width: 80vw;
    height: 100%;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-subtle);
    z-index: 101;
    display: flex;
    flex-direction: column;
    transition: var(--transition-medium);
}

.side-menu.active {
    right: 0;
}

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

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

.chat-history-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.history-item {
    padding: 12px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition-fast);
    margin-bottom: 2px;
}

.history-item:hover {
    background: var(--bg-tertiary);
}

.history-item.active {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid var(--border-accent);
}

.history-item-title {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-item-date {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.menu-footer {
    padding: 12px;
    border-top: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.menu-action {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-family: 'Inter', sans-serif;
    font-size: 13px;
    cursor: pointer;
    transition: var(--transition-fast);
    width: 100%;
    text-align: left;
}

.menu-action:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ============ SCROLLBAR ============ */
.messages-container::-webkit-scrollbar {
    width: 4px;
}

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

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

.chat-history-list::-webkit-scrollbar {
    width: 3px;
}

.chat-history-list::-webkit-scrollbar-thumb {
    background: var(--border-subtle);
    border-radius: 3px;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 480px) {
    .welcome-card {
        padding: 24px 16px;
    }

    .welcome-card h3 {
        font-size: 18px;
    }

    .chip {
        font-size: 11px;
        padding: 6px 12px;
    }

    .message {
        max-width: 92%;
    }

    .msg-content {
        padding: 10px 14px;
        font-size: 13.5px;
    }
}

/* ============ SAFE AREA (Notched phones) ============ */
@supports (padding: env(safe-area-inset-top)) {
    .chat-header {
        padding-top: max(12px, env(safe-area-inset-top));
    }

    .input-area {
        padding-bottom: max(12px, env(safe-area-inset-bottom));
    }
}

/* ============ ERROR STATE ============ */
.msg-error {
    background: rgba(239, 68, 68, 0.1) !important;
    border-color: rgba(239, 68, 68, 0.3) !important;
}

.msg-error .error-text {
    color: #ef4444;
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 8px;
}

.btn-retry {
    padding: 4px 10px;
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    border-radius: var(--radius-sm);
    color: #ef4444;
    font-family: 'Inter', sans-serif;
    font-size: 11px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.btn-retry:hover {
    background: rgba(239, 68, 68, 0.25);
}
