:root {
    --bg: #0f172a;
    --card: #111827;
    --accent: #22d3ee;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --danger: #ef4444;
    --success: #22c55e;
    --border: #1f2937;
}

* { box-sizing: border-box; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
    margin: 0;
    background: var(--bg);
    color: var(--text);
}

.modal-open {
    overflow: hidden;
}

.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 24px;
}

header h1 {
    margin: 0;
    font-size: 28px;
}

.user-meta {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
    color: var(--muted);
    margin-top: 6px;
}

.subtitle {
    margin: 4px 0 20px;
    color: var(--muted);
}

.debug-panel {
    border: 1px dashed var(--accent);
    background: #0b1221;
    border-radius: 12px;
    padding: 14px 16px;
    margin-bottom: 18px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.15);
}

.debug-title {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--muted);
    margin: 0 0 8px;
}

.debug-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 6px;
}

.debug-list code {
    background: #0f172a;
    padding: 6px 8px;
    border-radius: 8px;
    display: inline-block;
    border: 1px solid var(--border);
}

.debug-label {
    color: var(--muted);
    margin-right: 6px;
    font-weight: 600;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 18px 20px;
    margin-bottom: 18px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
}

.card h2 {
    margin-top: 0;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px 16px;
    align-items: end;
}

.form-control {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-control label {
    font-weight: 600;
}

.form-control input,
.form-control select,
.pill-group label {
    background: #0b1221;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    color: var(--text);
}

.form-control input:focus,
.form-control select:focus {
    outline: 2px solid var(--accent);
}

.input-inline {
    display: flex;
    gap: 8px;
    align-items: center;
    margin: 8px 0 4px;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 6px;
}

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

.summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.stat {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: #0b1221;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.02);
}

#liveStatus.error { color: var(--danger); }

.report-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.currency-switcher {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 180px;
}

.currency-switcher select {
    width: 100%;
}

.btn {
    background: #1f2937;
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 600;
}

.btn.primary { background: var(--accent); color: #0f172a; border-color: var(--accent); }
.btn.secondary { background: #334155; }
.btn.danger { background: var(--danger); border-color: var(--danger); }
.btn.ghost { background: transparent; }

.btn:hover { filter: brightness(1.05); }

.icon-button {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: #1f2937;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
}

.alert {
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 16px;
}

.alert.success { background: rgba(34, 197, 94, 0.15); border: 1px solid #22c55e33; }
.alert.error { background: rgba(239, 68, 68, 0.15); border: 1px solid #ef444433; }

.filters .filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    align-items: flex-end;
}

.pill-group {
    display: flex;
    gap: 12px;
}

.pill-group input {
    margin-right: 6px;
}

.price-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.live-pill {
    padding: 6px 10px;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(34, 211, 238, 0.12);
    color: var(--accent);
    font-weight: 700;
    letter-spacing: 0.06em;
    box-shadow: 0 0 0 0 rgba(34, 211, 238, 0.4);
    transition: box-shadow 0.3s ease;
}

.live-pill.active {
    box-shadow: 0 0 0 6px rgba(34, 211, 238, 0.08);
}

.price-actions {
    display: flex;
    align-items: center;
    gap: 10px;
}

.order-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 14px;
    margin-top: 14px;
}

.asset-average-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 12px;
    margin-top: 12px;
}

.asset-average-card {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
    background: #0b1221;
    display: grid;
    gap: 8px;
}

.order-card {
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 16px;
    background: #0b1221;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.order-card__header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
}

.order-card__live {
    text-align: right;
}

.order-card__live .order-live-price {
    font-size: 18px;
    font-weight: 700;
}

.order-card__body {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 10px;
}

.order-card__actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.order-card__preview {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--border);
    display: grid;
    gap: 10px;
}

.preview-row {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.preview-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.order-card.status-open { border-left: 3px solid var(--accent); }
.order-card.status-closed { border-left: 3px solid var(--success); }

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

.is-hidden {
    display: none !important;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 10px 8px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

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

.badge {
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.badge.open { background: rgba(34, 211, 238, 0.12); color: var(--accent); }
.badge.closed { background: rgba(34, 197, 94, 0.12); color: var(--success); }

.status-open td { border-left: 3px solid var(--accent); }
.status-closed td { border-left: 3px solid var(--success); }

.profit.positive { color: var(--success); }
.profit.negative { color: var(--danger); }

.unrealized { color: var(--muted); }

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

.cell-stack {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.chip {
    display: inline-flex;
    align-items: center;
    padding: 4px 8px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid var(--border);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.mono {
    font-variant-numeric: tabular-nums;
}

.hint { color: var(--muted); margin: 4px 0 0; }

.eyebrow {
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 12px;
    color: var(--muted);
    margin: 0 0 4px;
}

.input-with-addon {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: stretch;
}

.input-addon {
    display: inline-flex;
    align-items: center;
    padding: 0 12px;
    background: #0b1221;
    border: 1px solid var(--border);
    border-left: none;
    border-radius: 0 8px 8px 0;
    font-weight: 700;
}

.input-with-addon input {
    border-radius: 8px 0 0 8px;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: none;
    justify-content: center;
    align-items: center;
    padding: 16px;
    z-index: 10;
}

.modal.open {
    display: flex;
}

.modal-dialog {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    max-width: 480px;
    width: 100%;
    box-shadow: 0 24px 48px rgba(0,0,0,0.35);
    padding: 18px 20px;
    animation: pop 160ms ease;
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.modal-form .form-control {
    margin-bottom: 10px;
}

.modal-actions {
    justify-content: space-between;
    gap: 8px;
}

@keyframes pop {
    from { transform: translateY(8px) scale(0.98); opacity: 0; }
    to { transform: translateY(0) scale(1); opacity: 1; }
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 8px;
}

.muted { color: var(--muted); }

.text-right { text-align: right; }

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

@media (max-width: 760px) {
    .form-actions { justify-content: flex-start; }
    .price-row { flex-direction: column; align-items: flex-start; }

    .table-wrapper { overflow: visible; }
    table { border: 0; }
    thead { display: none; }
    tbody { display: flex; flex-direction: column; gap: 12px; }
    tr { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 6px 12px; border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; }
    td { padding: 6px 0; border: none; }
    td::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: uppercase; letter-spacing: 0.08em; }
    td.actions { grid-column: 1 / -1; flex-direction: row; flex-wrap: wrap; gap: 8px; }
    .cell-stack { flex-direction: column; align-items: flex-start; }
}
