/* ========================================
   TradeBot — Design Tokens & Global Styles
   Based on Pencil design: source/docs/pencil-new.pen
   ======================================== */

:root {
    /* Colors */
    --bg-primary: #0A0F1C;
    --surface: #1E293B;
    --inset: #0F172A;
    --accent: #22D3EE;
    --foreground: #FFFFFF;
    --muted-foreground: #94A3B8;
    --tertiary: #64748B;
    --muted: #475569;
    --border: #0F172A;
    --destructive: #EF4444;
    --destructive-foreground: #FFFFFF;
    --success: #22C55E;
    --accent-text: #0A0F1C;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 8px;
    --radius-lg: 12px;

    /* Fonts */
    --font-sans: 'Inter', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;

    /* Sidebar */
    --sidebar-width: 260px;
}

/* ========================================
   Reset & Base
   ======================================== */

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

html, body {
    height: 100%;
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--foreground);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

#app {
    height: 100%;
}

#blazor-error-ui {
    background: var(--destructive);
    color: var(--foreground);
    padding: 8px 16px;
    position: fixed;
    bottom: 0;
    width: 100%;
    z-index: 9999;
    text-align: center;
    display: none;
}

#blazor-error-ui a {
    color: var(--foreground);
    text-decoration: underline;
}

/* ========================================
   Loading Screen
   ======================================== */

.loading-screen {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100vh;
    gap: 16px;
    color: var(--muted-foreground);
    font-size: 14px;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* ========================================
   App Layout
   ======================================== */

.app-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ========================================
   Sidebar (Desktop)
   ======================================== */

.sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--surface);
    display: flex;
    flex-direction: column;
    gap: 8px;
    padding: 24px 16px;
    overflow-y: auto;
}

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 8px;
}

.sidebar-logo svg {
    color: var(--accent);
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.sidebar-logo span {
    font-family: var(--font-mono);
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.sidebar-sep {
    height: 1px;
    background: var(--border);
    width: 100%;
}

.sidebar-label {
    font-family: var(--font-sans);
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--radius-md);
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 400;
    color: var(--muted);
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.nav-item:hover {
    color: var(--muted-foreground);
    background: var(--inset);
}

.nav-item.active {
    color: var(--accent);
    font-weight: 500;
    background: var(--inset);
}

.nav-item.active svg {
    color: var(--accent);
}

.nav-item svg {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    color: var(--muted);
}

/* ========================================
   Mobile Header
   ======================================== */

.mobile-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    height: 56px;
    padding: 0 20px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-primary);
}

.mobile-header-logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.mobile-header-logo svg {
    color: var(--accent);
    width: 22px;
    height: 22px;
}

.mobile-header-logo span {
    font-family: var(--font-mono);
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
}

.mobile-header button {
    background: none;
    border: none;
    cursor: pointer;
    padding: 4px;
}

.mobile-header button svg {
    width: 24px;
    height: 24px;
    color: var(--muted-foreground);
}

/* ========================================
   Main Content Area
   ======================================== */

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 32px;
    padding: 32px 40px;
    overflow-y: auto;
    min-width: 0;
}

/* ========================================
   Page Header
   ======================================== */

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 16px;
}

.page-header-left {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.page-title {
    font-family: var(--font-sans);
    font-size: 24px;
    font-weight: 600;
    color: var(--foreground);
}

.page-desc {
    font-family: var(--font-sans);
    font-size: 14px;
    font-weight: 400;
    color: var(--muted-foreground);
}

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-family: var(--font-sans);
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: all 0.15s ease;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--accent);
    color: var(--accent-text);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
}

.btn-primary:hover:not(:disabled) {
    opacity: 0.9;
}

.btn-primary svg {
    width: 18px;
    height: 18px;
}

.btn-outline {
    background: transparent;
    color: var(--muted-foreground);
    padding: 10px 20px;
    border-radius: var(--radius-md);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--border);
}

.btn-outline:hover:not(:disabled) {
    border-color: var(--muted);
}

.btn-icon-delete {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 34px;
    height: 34px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.btn-icon-delete:hover {
    border-color: var(--destructive);
    background: rgba(239, 68, 68, 0.1);
}

.btn-icon-delete svg {
    width: 16px;
    height: 16px;
    color: var(--destructive);
}

/* ========================================
   Table Card
   ======================================== */

.table-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    width: 100%;
}

.table-header {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    background: var(--inset);
    border-bottom: 1px solid var(--border);
}

.table-header span {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 2px;
    text-transform: uppercase;
}

.th-name { flex: 1; }
.th-wallets { width: 200px; }
.th-status { width: 140px; }
.th-actions { width: 100px; }

.table-row {
    display: flex;
    align-items: center;
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    transition: background 0.1s ease;
}

.table-row:last-child {
    border-bottom: none;
}

.table-row:hover {
    background: rgba(255, 255, 255, 0.02);
}

.td-name {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 0;
}

.td-wallets {
    width: 200px;
    font-family: var(--font-mono);
    font-size: 14px;
    font-weight: 500;
    color: var(--muted-foreground);
}

.td-status {
    width: 140px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.td-actions {
    width: 100px;
}

.exchange-icon {
    width: 36px;
    height: 36px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 14px;
    color: var(--accent-text);
    background: var(--accent);
    flex-shrink: 0;
}

.exchange-name {
    font-family: var(--font-sans);
    font-size: 15px;
    font-weight: 500;
    color: var(--foreground);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}

.status-text {
    font-family: var(--font-mono);
    font-size: 12px;
    font-weight: 500;
    color: var(--success);
}

.table-footer {
    display: flex;
    align-items: center;
    padding: 14px 24px;
    background: var(--inset);
}

.table-footer span {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--muted);
}

/* ========================================
   Mobile Cards
   ======================================== */

.cards-container {
    display: none;
    flex-direction: column;
    gap: 12px;
}

.exchange-card {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.card-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

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

.card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 14px;
    color: var(--accent-text);
    background: var(--accent);
    flex-shrink: 0;
}

.card-info {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.card-name {
    font-family: var(--font-sans);
    font-size: 16px;
    font-weight: 600;
    color: var(--foreground);
}

.card-status {
    display: flex;
    align-items: center;
    gap: 6px;
}

.card-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
}

.card-status-text {
    font-family: var(--font-mono);
    font-size: 11px;
    font-weight: 500;
    color: var(--success);
}

.card-delete-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: transparent;
    cursor: pointer;
    transition: all 0.15s ease;
}

.card-delete-btn:hover {
    border-color: var(--destructive);
    background: rgba(239, 68, 68, 0.1);
}

.card-delete-btn svg {
    width: 16px;
    height: 16px;
    color: var(--destructive);
}

.card-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--inset);
    border-radius: var(--radius-md);
    padding: 10px 12px;
}

.card-label {
    font-family: var(--font-mono);
    font-size: 10px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: 1.5px;
    text-transform: uppercase;
}

.card-value {
    font-family: var(--font-mono);
    font-size: 13px;
    font-weight: 500;
    color: var(--muted-foreground);
}

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

/* ========================================
   Modal
   ======================================== */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}

.modal {
    background: var(--surface);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    overflow: hidden;
    animation: modalIn 0.2s ease;
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to { opacity: 1; transform: scale(1); }
}

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

.modal-title {
    font-family: var(--font-sans);
    font-size: 18px;
    font-weight: 600;
    color: var(--foreground);
}

.modal-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
    cursor: pointer;
    transition: background 0.15s ease;
}

.modal-close:hover {
    background: var(--inset);
}

.modal-close svg {
    width: 18px;
    height: 18px;
    color: var(--muted-foreground);
}

.modal-body {
    padding: 24px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-label {
    font-family: var(--font-sans);
    font-size: 13px;
    font-weight: 500;
    color: var(--muted-foreground);
}

.form-input {
    height: 44px;
    background: var(--inset);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 0 16px;
    font-family: var(--font-sans);
    font-size: 14px;
    color: var(--foreground);
    outline: none;
    transition: border-color 0.15s ease;
    width: 100%;
}

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

.form-input:focus {
    border-color: var(--accent);
}

.form-error {
    font-family: var(--font-sans);
    font-size: 12px;
    color: var(--destructive);
}

.form-hint {
    font-family: var(--font-sans);
    font-size: 12px;
    color: var(--muted);
    line-height: 1.5;
}

.modal-footer {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 24px 20px;
    border-top: 1px solid var(--border);
}

/* ========================================
   Alert / Messages
   ======================================== */

.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    font-size: 13px;
    font-family: var(--font-sans);
}

.alert-error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--destructive);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.alert-success {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
}

/* ========================================
   Loading States
   ======================================== */

.loading-overlay {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px;
}

.loading-inline {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--muted-foreground);
    font-size: 13px;
}

.loading-inline .loading-spinner {
    width: 16px;
    height: 16px;
    border-width: 2px;
}

.table-empty {
    padding: 48px 24px;
    text-align: center;
    color: var(--muted);
    font-size: 14px;
}

/* ========================================
   Mobile Page (Full-page form for mobile add)
   ======================================== */

.mobile-form-page {
    display: none;
}

/* ========================================
   Responsive — Mobile < 768px
   ======================================== */

@media (max-width: 767px) {
    .sidebar {
        display: none;
    }

    .mobile-header {
        display: flex;
    }

    .main-content {
        padding: 24px 20px;
        gap: 20px;
    }

    .page-title {
        font-size: 22px;
    }

    .page-desc {
        font-size: 13px;
    }

    .btn-primary {
        padding: 8px 14px;
        font-size: 13px;
    }

    .btn-primary svg {
        width: 14px;
        height: 14px;
    }

    .table-card {
        display: none;
    }

    .cards-container {
        display: flex;
    }

    .modal {
        max-width: 100%;
        margin: 0;
        border-radius: var(--radius-lg);
    }
}
