:root {
    --bg-primary: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #334155;
    --text-primary: #f1f5f9;
    --text-secondary: #cbd5e1;
    --text-muted: #94a3b8;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --accent-blue: #3b82f6;
    --border-color: #475569;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.3);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 16px;
    line-height: 1.5;
    overflow-x: hidden;
}

/* Compact Container */
.compact-container {
    margin: 0;
    padding: 8px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    width: 100%;
}

/* Compact Header */
.compact-header {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: 16px;
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
}

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

.header-left h1 {
    font-size: 18px;
    font-weight: 600;
    margin: 0;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.status-indicator {
    font-size: 10px;
}

.status-indicator.online {
    color: var(--accent-green);
}

.status-indicator.offline {
    color: var(--text-muted);
}

.poll-interval-display {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
}

.poll-label {
    color: var(--text-muted);
}

.poll-value {
    color: var(--accent-blue);
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.2s;
}

.poll-value.editable {
    cursor: pointer;
}

.poll-value.editable:hover {
    background: var(--bg-card);
}

.poll-interval-input {
    width: 50px;
    padding: 2px 6px;
    background: var(--bg-card);
    border: 1px solid var(--accent-blue);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 12px;
    font-weight: 600;
    text-align: center;
}

.poll-interval-input:focus {
    outline: none;
    border-color: var(--accent-green);
}

.header-center {
    text-align: center;
}

.compact-price {
    display: flex;
    align-items: baseline;
    gap: 12px;
    justify-content: center;
}

.price-label {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.price-value {
    font-size: 24px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.price-change {
    font-size: 14px;
    font-weight: 600;
}

.price-change.positive {
    color: var(--accent-green);
}

.price-change.negative {
    color: var(--accent-red);
}

.price-up {
    animation: priceUp 0.5s ease;
}

.price-down {
    animation: priceDown 0.5s ease;
}

@keyframes priceUp {
    0%, 100% { background: transparent; }
    50% { background: rgba(16, 185, 129, 0.2); }
}

@keyframes priceDown {
    0%, 100% { background: transparent; }
    50% { background: rgba(239, 68, 68, 0.2); }
}

.header-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.header-balances {
    display: flex;
    gap: 12px;
}

.balance-display {
    display: flex;
    align-items: baseline;
    gap: 4px;
    font-size: 14px;
}

.balance-amount {
    font-size: 21px;
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.balance-ticker {
    font-size: 14px;
    font-weight: 500;
    opacity: 0.8;
}

.mon-balance .balance-amount {
    color: #00ff88;
}

.usdc-balance .balance-amount {
    color: #3b82f6;
}

.total-balance .balance-amount {
    color: #f59e0b;
    font-size: 24px;
}

.usd-value {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
}

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

/* Main Grid Layout */
.main-grid {
    display: grid;
    grid-template-columns: 1fr 371px;
    gap: 10px;
    flex: 1;
    min-height: 0;
}

/* Left Column: Chart + History */
.left-column {
    display: flex;
    flex-direction: column;
    gap: 10px;
    min-height: 0;
}

/* Sidebars */
.sidebar-left,
.sidebar-right {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.sidebar-right {
    width: 371px;
    min-width: 371px;
    max-width: 371px;
}

.main-content {
    min-height: 0;
    display: flex;
    flex-direction: column;
    flex: 1;
}

/* Cards */
.card {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 12px;
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
}

.compact-card {
    padding: 10px;
}

/* Chart Card */
.chart-card {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chart-card h3 {
    font-size: 10.5px;
    margin-bottom: 7px;
}

.tradingview-widget-container {
    flex: 1;
    overflow: hidden;
    background: #0a0e27;
    border-radius: 6px;
    min-height: 0;
}

#tradingview_widget {
    width: 100%;
    height: 100%;
}

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

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    margin: 0;
}

.card h3 {
    font-size: 15px;
    font-weight: 600;
    margin-bottom: 10px;
}

/* Balance List */
.balance-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.balance-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 6px 8px;
    background: var(--bg-card);
    border-radius: 4px;
}

.balance-label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.balance-value {
    font-size: 15px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* Compact Forms */
.compact-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 8px;
}

.compact-form:last-child {
    margin-bottom: 0;
}

.compact-form input,
.compact-form select {
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
}

.compact-form input:focus,
.compact-form select:focus {
    outline: none;
    border-color: var(--accent-blue);
}

/* Hide number input spinners */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

input[type="number"] {
    -moz-appearance: textfield;
}

/* Highlight filled inputs */
input[type="number"]:not(:placeholder-shown) {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

/* Buttons */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 4px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 13px;
}

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-icon {
    background: transparent;
    border: none;
    cursor: pointer;
    font-size: 14px;
    padding: 4px;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-icon:hover {
    opacity: 1;
}

.btn-primary {
    background: var(--accent-blue);
    color: white;
}

.btn-primary:hover {
    background: #2563eb;
}

.btn-success {
    background: var(--accent-green);
    color: white;
    opacity: 0.6;
}

.btn-success:hover {
    background: #059669;
    opacity: 1;
}

.btn-danger {
    background: var(--accent-red);
    color: white;
    opacity: 0.6;
}

.btn-danger:hover {
    background: #dc2626;
    opacity: 1;
}

.btn-secondary {
    background: var(--bg-card);
    color: var(--text-primary);
}

.btn-secondary:hover {
    background: #475569;
}

/* Tables */
.table-container {
    overflow: auto;
    flex: 1;
    min-height: 0;
    /* Скрываем полосы прокрутки */
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none; /* IE and Edge */
}

/* Скрываем полосы прокрутки для WebKit (Chrome, Safari) */
.table-container::-webkit-scrollbar {
    display: none;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}

.compact-table {
    font-size: 14px;
}

thead {
    background: var(--bg-card);
    position: sticky;
    top: 0;
    z-index: 1;
}

th {
    padding: 8px;
    text-align: left;
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 14px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

td {
    padding: 8px;
    border-top: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 14px;
}

tbody tr {
    transition: background-color 0.2s ease;
}

tbody tr:hover {
    background: rgba(255, 255, 255, 0.05);
}

.no-data {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 20px;
}

.order-buy {
    color: var(--accent-green);
    font-weight: 600;
}

.order-sell {
    color: var(--accent-red);
    font-weight: 600;
}

/* Active Orders Card - fills remaining space */
.active-orders-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
}

.active-orders-card .card-header {
    margin-bottom: 9px;
}

.active-orders-card .card-header h3 {
    font-size: 15px;
}

.active-orders-card .table-container {
    flex: 1;
    min-height: 0;
}

.active-orders-card .compact-table {
    font-size: 11.9px;
}

.active-orders-card th {
    font-size: 11.9px;
    padding: 7.2px;
}

.active-orders-card th:nth-child(3),
.active-orders-card th:nth-child(4),
.active-orders-card th:nth-child(5) {
    text-align: center;
}

.active-orders-card td {
    font-size: 11.9px;
    padding: 7.2px;
}

/* Trade History */
.trade-history {
    height: 20vh;
    min-height: 20vh;
    max-height: 20vh;
}

.trade-history .card {
    height: 100%;
}

.trade-history th {
    font-size: 12.6px;
}

.trade-history td {
    font-size: 12.6px;
}

/* Toast Notifications */
#toast-container {
    position: fixed;
    bottom: 16px;
    right: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    background: var(--bg-card);
    padding: 12px 16px;
    border-radius: 6px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    min-width: 300px;
    animation: slideIn 0.3s ease;
    border-left: 3px solid var(--accent-blue);
}

.toast.success {
    border-left-color: var(--accent-green);
}

.toast.error {
    border-left-color: var(--accent-red);
}

@keyframes slideIn {
    from {
        transform: translateX(400px);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-secondary);
    padding: 24px;
    border-radius: 12px;
    max-width: 400px;
    width: 90%;
}

.modal-content h2 {
    margin-bottom: 12px;
    font-size: 20px;
}

.modal-content p {
    margin-bottom: 16px;
    color: var(--text-secondary);
    font-size: 14px;
}

.modal-content form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.modal-content input {
    padding: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
}

.api-key-hint {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 8px;
}

/* Responsive */
@media (max-width: 1200px) {
    .main-grid {
        grid-template-columns: 180px 1fr 200px;
    }
}

@media (max-width: 900px) {
    .main-grid {
        grid-template-columns: 1fr;
        grid-template-rows: auto auto 1fr;
    }

    .sidebar-left,
    .sidebar-right {
        flex-direction: row;
    }

    .sidebar-left .card,
    .sidebar-right .card {
        flex: 1;
    }

    .compact-header {
        grid-template-columns: 1fr;
        gap: 8px;
    }

    .header-left,
    .header-center,
    .header-right {
        justify-content: center;
        text-align: center;
    }
}

/* Quick Swap Form */
.quick-swap-form {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.swap-column {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.swap-column input {
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}

.swap-column input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.swap-column input:not(:placeholder-shown) {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

.swap-column .btn {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    width: 100%;
    box-sizing: border-box;
}

.estimated-info {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 4px 0;
    min-height: 20px;
}

/* Limit Order Grid */
.limit-order-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
}

.limit-column {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

.limit-column input {
    padding: 8px 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 14px;
    width: 100%;
    box-sizing: border-box;
}

.limit-column input:focus {
    outline: none;
    border-color: var(--accent-blue);
}

.limit-column input:not(:placeholder-shown) {
    border-color: var(--accent-blue);
    background: rgba(59, 130, 246, 0.1);
}

.limit-column .btn {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    width: 100%;
    box-sizing: border-box;
}

/* Grid Orders Panel */
.grid-panel {
    padding: 0.65rem 1.1rem 1.1rem 1.1rem;
}

.grid-panel h3 {
    font-size: 0.88rem;
    margin-bottom: 0.4rem;
    margin-top: 0;
}

.grid-container {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.grid-row {
    display: grid;
    grid-template-columns: 20px 1fr 1fr 1fr auto;
    gap: 0.3rem;
    align-items: center;
}

.grid-row-label {
    font-size: 0.75rem;
    color: #8b92a7;
    font-weight: 600;
    text-align: left;
}

.grid-input-wrapper {
    position: relative;
    width: 100%;
    min-width: 0;
}

.grid-input-wrapper .input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    padding-right: 1.5rem;
    background: #0a0e27;
    border: 1px solid #2a3447;
    border-radius: 6px;
    font-size: 0.875rem;
    color: #fff;
    outline: none;
    transition: border-color 0.2s;
}

.grid-input-wrapper .input:focus {
    border-color: #3b82f6;
}

.grid-percent {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.875rem;
    color: #8b92a7;
    pointer-events: none;
}

.grid-create-btn,
.grid-delete-btn {
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    white-space: nowrap;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.75rem;
}

/* Volatility Metrics */
.volatility-metrics {
    display: flex;
    gap: 12px;
    margin-top: 4px;
    font-size: 16.5px;
}

.volatility-metric {
    color: #94a3b8;
    font-weight: 500;
}

.volatility-value {
    color: #e2e8f0;
    font-weight: 600;
}


/* Refresh Button */
.btn-refresh {
    background: none;
    border: none;
    color: #94a3b8;
    cursor: pointer;
    padding: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.btn-refresh:hover {
    color: #e2e8f0;
    background: rgba(148, 163, 184, 0.1);
}

.btn-refresh:active {
    transform: rotate(180deg);
}

.btn-refresh svg {
    transition: transform 0.3s ease;
}

.btn-refresh:hover svg {
    transform: rotate(180deg);
}

