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

:root {
    --bg:         #0d1117;
    --surface:    #161b22;
    --surface2:   #1f2937;
    --border:     #30363d;
    --text:       #e6edf3;
    --text-muted: #8b949e;
    --accent:     #58a6ff;
    --accent-dim: #1f3a5f;
    --success:    #3fb950;
    --danger:     #f85149;
    --warning:    #d29922;
    --radius:     8px;
    --sidebar-w:  220px;
    --font-mono:  'SFMono-Regular', Consolas, 'Liberation Mono', monospace;
}

html, body { height: 100%; background: var(--bg); color: var(--text); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif; font-size: 14px; line-height: 1.6; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── App Shell ─────────────────────────────────────────────────────── */
.app-shell { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ───────────────────────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    padding: 16px 0;
    transition: width 0.2s ease;
    overflow: hidden;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px 20px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 12px;
}

.logo-icon { font-size: 22px; color: var(--accent); flex-shrink: 0; }
.logo-text  { font-size: 18px; font-weight: 600; color: var(--text); }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 2px; padding: 0 8px; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 12px;
    border-radius: var(--radius);
    color: var(--text-muted);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    text-decoration: none;
    white-space: nowrap;
}
.nav-item:hover, .nav-item.active { background: var(--surface2); color: var(--text); text-decoration: none; }
.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.nav-label { overflow: hidden; text-overflow: ellipsis; transition: opacity 0.2s ease; }

.sidebar-footer {
    padding: 16px 8px 0;
    border-top: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.user-email {
    display: block;
    padding: 4px 12px;
    color: var(--text-muted);
    font-size: 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.logout-btn { color: var(--danger) !important; }
.logout-btn:hover { background: rgba(248, 81, 73, 0.1) !important; }

.sidebar-toggle {
    background: none;
    border: none;
    font-size: 14px;
    margin-top: 4px;
}
.toggle-icon { transition: transform 0.2s ease; }

/* ── Collapsed sidebar ────────────────────────────────────────────── */
.sidebar-collapsed .sidebar {
    width: 56px;
}
.sidebar-collapsed .nav-label {
    opacity: 0;
    width: 0;
    overflow: hidden;
}
.sidebar-collapsed .sidebar-logo {
    padding: 0 17px 20px;
    justify-content: center;
}
.sidebar-collapsed .nav-item {
    justify-content: center;
    padding: 9px 0;
}
.sidebar-collapsed .user-email {
    display: none;
}

/* ── Main Content ──────────────────────────────────────────────────── */
.main-content { flex: 1; overflow: hidden; display: flex; flex-direction: column; }

/* ── Chat Page ─────────────────────────────────────────────────────── */
.chat-page { display: flex; flex-direction: column; height: 100%; }

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

.chat-title { font-size: 15px; font-weight: 600; }

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    scroll-behavior: smooth;
}

.message {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    max-width: 820px;
}

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

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 600;
    flex-shrink: 0;
    color: var(--accent);
}

.user-avatar { background: var(--accent-dim); color: var(--accent); }

.message-bubble {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 16px;
    line-height: 1.7;
}

.message-user .message-bubble {
    background: var(--accent-dim);
    border-color: #2d5a9e;
    color: var(--text);
}

/* Markdown content inside bubbles */
.message-bubble p { margin-bottom: 8px; }
.message-bubble p:last-child { margin-bottom: 0; }
.message-bubble h1, .message-bubble h2, .message-bubble h3 { margin: 12px 0 6px; font-size: 15px; }
.message-bubble ul, .message-bubble ol { padding-left: 20px; margin-bottom: 8px; }
.message-bubble li { margin-bottom: 2px; }
.message-bubble code { font-family: var(--font-mono); background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 5px; font-size: 13px; }
.message-bubble pre { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; overflow-x: auto; margin: 8px 0; }
.message-bubble pre code { background: none; border: none; padding: 0; }
.message-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 13px; font-family: var(--font-mono); }
.message-bubble th, .message-bubble td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.message-bubble th { background: var(--surface2); font-weight: 600; }
.message-bubble tr:nth-child(even) { background: rgba(255,255,255,0.02); }
.message-bubble td:first-child { width: 32px; padding: 4px 8px; text-align: center; }
.message-bubble th:first-child { width: 32px; padding: 4px 8px; }
.message-bubble img { width: 22px; height: 22px; border-radius: 50%; vertical-align: middle; object-fit: cover; background: var(--surface2); }
.message-bubble strong { font-weight: 600; color: #fff; }
.message-bubble blockquote { border-left: 3px solid var(--accent); padding-left: 12px; color: var(--text-muted); margin: 8px 0; }

/* Usage metrics */
.usage-metrics {
    display: flex;
    gap: 12px;
    margin-top: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    font-size: 11px;
    font-family: var(--font-mono);
    color: var(--text-muted);
    opacity: 0.6;
}
.usage-metrics span {
    cursor: default;
}
.usage-metrics span:hover {
    opacity: 1;
    color: var(--text);
}

.context-bar-wrap {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}
.context-bar {
    display: inline-block;
    width: 60px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    vertical-align: middle;
}
.context-bar-fill {
    display: block;
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* Streaming */
.message-bubble.streaming { min-width: 60px; }

.thinking-dots { display: flex; gap: 4px; align-items: center; height: 20px; }
.thinking-dots span {
    display: inline-block;
    width: 6px;
    height: 6px;
    background: var(--text-muted);
    border-radius: 50%;
    animation: bounce 1.2s infinite;
}
.thinking-dots span:nth-child(2) { animation-delay: 0.2s; }
.thinking-dots span:nth-child(3) { animation-delay: 0.4s; }

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

/* Empty state */
.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 60px 24px;
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
}

.empty-icon { font-size: 40px; color: var(--accent); opacity: 0.6; }
.empty-state p { font-size: 16px; }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 8px; }

.suggestion-chip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 6px 16px;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}
.suggestion-chip:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-dim); }

/* Chat input */
.chat-input-area {
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: flex-end;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    overflow: hidden;
    transition: border-color 0.15s;
}
.input-wrapper:focus-within { border-color: var(--accent); }

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text);
    font-size: 14px;
    padding: 12px 16px;
    resize: none;
    outline: none;
    font-family: inherit;
    min-height: 44px;
    max-height: 200px;
    line-height: 1.5;
}

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

.send-btn {
    background: var(--accent);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 8px;
    margin: 4px;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity 0.15s;
    flex-shrink: 0;
}
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.send-btn:not(:disabled):hover { opacity: 0.85; }

/* ── Wallets Page ──────────────────────────────────────────────────── */
.page-content { padding: 32px; overflow-y: auto; height: 100%; }

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.page-header h1 { font-size: 22px; font-weight: 600; }

.metrics-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    margin-bottom: 24px;
}

.metric-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.metric-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.metric-value  { font-size: 20px; font-weight: 600; font-family: var(--font-mono); }
.positive { color: var(--success); }
.negative { color: var(--danger); }

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}

.add-wallet-form h3 { margin-bottom: 16px; font-size: 16px; }

.form-row {
    display: grid;
    grid-template-columns: 2fr 1fr 1fr;
    gap: 12px;
    margin-bottom: 16px;
}

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 12px; color: var(--text-muted); }

.form-input {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 8px 12px;
    font-size: 13px;
    outline: none;
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-input:focus { border-color: var(--accent); }

.wallets-table-wrapper { overflow-x: auto; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.data-table th {
    text-align: left;
    padding: 10px 14px;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 1px solid var(--border);
}

.data-table td {
    padding: 12px 14px;
    border-bottom: 1px solid rgba(48, 54, 61, 0.5);
    vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }

.network-badge {
    display: inline-block;
    background: var(--accent-dim);
    color: var(--accent);
    border-radius: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
}

.address { font-family: var(--font-mono); color: var(--text-muted); font-size: 12px; }

/* ── Buttons ───────────────────────────────────────────────────────── */
.btn-primary {
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius);
    padding: 8px 16px;
    font-size: 13px;
    cursor: pointer;
    font-weight: 500;
    transition: opacity 0.15s;
}
.btn-primary:hover:not(:disabled) { opacity: 0.85; }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-full { width: 100%; padding: 11px; font-size: 14px; }

.btn-ghost {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 6px 14px;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-ghost:hover { border-color: var(--text-muted); color: var(--text); }

.btn-danger-sm {
    background: transparent;
    color: var(--danger);
    border: 1px solid transparent;
    border-radius: 4px;
    padding: 3px 10px;
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.btn-danger-sm:hover { border-color: var(--danger); background: rgba(248,81,73,0.08); }

/* ── Auth Pages ────────────────────────────────────────────────────── */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 40px;
    width: 100%;
    max-width: 380px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-logo { font-size: 20px; font-weight: 700; color: var(--accent); text-align: center; letter-spacing: -0.5px; }
.auth-card h2 { font-size: 18px; text-align: center; color: var(--text); }

.auth-footer { text-align: center; color: var(--text-muted); font-size: 13px; margin-top: 4px; }

/* ── Alerts ────────────────────────────────────────────────────────── */
.alert-error {
    background: rgba(248, 81, 73, 0.1);
    border: 1px solid rgba(248, 81, 73, 0.3);
    color: var(--danger);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
}
.alert-success {
    background: rgba(63, 185, 80, 0.1);
    border: 1px solid rgba(63, 185, 80, 0.3);
    color: var(--success);
    border-radius: var(--radius);
    padding: 10px 14px;
    font-size: 13px;
}

/* ── Loading ───────────────────────────────────────────────────────── */
.loading { color: var(--text-muted); padding: 40px; text-align: center; }

/* ── FluentUI dark theme (replaces FluentDesignTheme component) ───── */
:root {
    --neutral-fill-rest: var(--surface);
    --neutral-fill-stealth-rest: transparent;
    --neutral-fill-stealth-hover: var(--surface2);
    --neutral-foreground-rest: var(--text);
    --neutral-stroke-rest: var(--border);
    --accent-fill-rest: var(--accent);
    --neutral-layer-1: var(--bg);
    --neutral-layer-2: var(--surface);
    --neutral-fill-input-rest: var(--bg);
    --neutral-fill-input-hover: var(--surface);
    --base-layer-luminance: 0.1;
}

/* ── FluentDataGrid in chat ────────────────────────────────────────── */
.chat-data-grid,
.chat-data-grid [role="gridcell"],
.chat-data-grid [role="columnheader"],
.chat-data-grid td,
.chat-data-grid th {
    font-family: 'Inter', 'SF Pro Display', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif !important;
    font-size: 13.5px !important;
    letter-spacing: -0.01em;
    font-feature-settings: 'tnum';
    text-align: left !important;
    justify-content: flex-start !important;
    color: var(--text) !important;
    background: transparent !important;
}
.chat-data-grid [role="columnheader"] {
    color: var(--text-muted) !important;
}

/* ── Token Chips ──────────────────────────────────────────────────── */
.token-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: var(--accent-dim);
    border: 1px solid rgba(88, 166, 255, 0.3);
    border-radius: 20px;
    padding: 5px 10px 5px 14px;
    font-size: 13px;
    font-weight: 500;
    color: var(--accent);
}

.token-chip-remove {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 2px;
    line-height: 1;
    transition: color 0.15s;
}

.token-chip-remove:hover {
    color: var(--danger);
}

/* ── Mobile top bar (hidden on desktop) ───────────────────────────── */
.mobile-topbar {
    display: none;
    align-items: center;
    gap: 12px;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
.mobile-topbar-title {
    font-size: 16px;
    font-weight: 600;
    color: var(--text);
}
.mobile-hamburger {
    background: none;
    border: none;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 4px;
}
.mobile-hamburger span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text);
    border-radius: 1px;
    transition: transform 0.2s ease, opacity 0.2s ease;
}
/* Overlay backdrop */
.sidebar-overlay {
    display: none;
}

/* ── Scrollbar ─────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #484f58; }

/* ══════════════════════════════════════════════════════════════════════
   Responsive — Tablet (≤ 768px)
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 768px) {
    /* Show mobile top bar, hide sidebar by default */
    .mobile-topbar { display: flex; }

    .app-shell {
        flex-direction: column;
    }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        z-index: 100;
        width: var(--sidebar-w) !important;
        transform: translateX(-100%);
        transition: transform 0.25s ease;
    }

    /* When open */
    .sidebar-mobile-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-overlay {
        display: block;
        position: fixed;
        inset: 0;
        z-index: 99;
        background: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(2px);
    }

    /* Hide desktop collapse toggle on mobile */
    .sidebar-toggle { display: none !important; }

    /* Collapsed class should not affect mobile */
    .sidebar-collapsed .sidebar {
        width: var(--sidebar-w) !important;
    }
    .sidebar-collapsed .nav-label {
        opacity: 1;
        width: auto;
    }
    .sidebar-collapsed .sidebar-logo {
        padding: 0 20px 20px;
        justify-content: flex-start;
    }
    .sidebar-collapsed .nav-item {
        justify-content: flex-start;
        padding: 9px 12px;
    }
    .sidebar-collapsed .user-email {
        display: block;
    }

    /* Main content takes full height minus topbar */
    .main-content {
        height: calc(100vh - 48px);
        overflow: hidden;
    }

    /* Chat adjustments */
    .chat-header { padding: 12px 16px; }
    .messages { padding: 16px; gap: 12px; }
    .message { max-width: 100%; }
    .message-avatar { width: 28px; height: 28px; font-size: 10px; }
    .message-bubble { padding: 10px 14px; font-size: 13px; }

    .chat-input-area { padding: 12px 16px 16px; }
    .chat-input { padding: 10px 14px; font-size: 16px; }

    /* Prevent iOS zoom on all inputs */
    input, textarea, select { font-size: 16px !important; }

    /* Page content */
    .page-content { padding: 20px 16px; }
    .page-header h1 { font-size: 18px; }

    /* Form rows stack on mobile */
    .form-row {
        grid-template-columns: 1fr !important;
        gap: 10px;
    }

    /* Metrics row */
    .metrics-row {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
    .metric-card { padding: 12px 14px; }
    .metric-value { font-size: 16px; }

    /* Cards */
    .card { padding: 16px; }

    /* Constrain bubble width so inner table wrapper can scroll */
    .message-bubble { max-width: calc(100vw - 80px); overflow: hidden; }
    .wallets-table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* Usage metrics wrap */
    .usage-metrics {
        flex-wrap: wrap;
        gap: 6px 12px;
        font-size: 10px;
    }

    /* Suggestion chips */
    .suggestions { gap: 6px; }
    .suggestion-chip { font-size: 12px; padding: 5px 12px; }

    /* Empty state */
    .empty-state { padding: 40px 16px; }
    .empty-icon { font-size: 32px; }
    .empty-state p { font-size: 14px; }

    /* Auth pages */
    .auth-card { padding: 28px 20px; margin: 0 16px; }
}

/* ══════════════════════════════════════════════════════════════════════
   Responsive — Small phone (≤ 480px)
   ══════════════════════════════════════════════════════════════════════ */
@media (max-width: 480px) {
    .metrics-row {
        grid-template-columns: 1fr;
    }

    .message-avatar { display: none; }
    .message { gap: 0; }
    .message-bubble { border-radius: 12px; max-width: calc(100vw - 32px); }

    .chat-title { font-size: 13px; }
    .btn-ghost { padding: 5px 10px; font-size: 12px; }

    .page-content { padding: 16px 12px; }

    .token-chip { font-size: 12px; padding: 4px 8px 4px 12px; }

    /* Data table font size */
    .data-table { font-size: 12px; }
    .data-table th { font-size: 10px; padding: 8px 10px; }
    .data-table td { padding: 10px; }

    .chat-data-grid,
    .chat-data-grid [role="gridcell"],
    .chat-data-grid [role="columnheader"],
    .chat-data-grid td,
    .chat-data-grid th {
        font-size: 12px !important;
    }
}
