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

:root {
    --bg: #0f1014;
    --bg-card: #1a1b23;
    --bg-card-hover: #22232e;
    --bg-input: #14151c;
    --border: #2a2b35;
    --text: #e8e8ed;
    --text-dim: #8b8c9a;
    --text-muted: #5b5c6e;
    --green: #00d46a;
    --green-bg: rgba(0, 212, 106, 0.08);
    --red: #ff4444;
    --red-bg: rgba(255, 68, 68, 0.08);
    --blue: #ff2d78;
    --blue-bg: rgba(255, 45, 120, 0.08);
    --radius: 10px;
    --radius-sm: 6px;
}

html { font-size: 16px; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

a { color: inherit; text-decoration: none; }

.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 32px;
}

.logo {
    font-size: 1.3rem;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.logo span { color: var(--blue); }

.nav { display: flex; gap: 8px; flex: 1; }

.nav-link {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    color: var(--text-dim);
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover { color: var(--text); background: rgba(255,255,255,0.04); }
.nav-link.active { color: var(--text); background: rgba(255,255,255,0.06); }

.user-badge {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-dim);
}

.user-avatar {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--blue);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

.main {
    max-width: 1200px;
    margin: 0 auto;
    padding: 32px 24px;
}

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

h1 { font-size: 1.5rem; font-weight: 700; }

.page-subtitle {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 20px;
    margin-top: -8px;
}

.filters { display: flex; gap: 8px; }

.filter-select {
    background: var(--bg-input);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
}
.filter-select:focus { border-color: var(--blue); }

.market-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 12px;
}

.market-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: border-color 0.15s, background 0.15s;
}

.market-card:hover {
    border-color: var(--text-muted);
    background: var(--bg-card-hover);
}

.market-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.78rem;
}

.market-category {
    background: var(--blue-bg);
    color: var(--blue);
    padding: 3px 10px;
    border-radius: 100px;
    font-weight: 500;
}

.market-end {
    color: var(--text-muted);
}

.market-question {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
    color: var(--text);
}

.market-footer {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

.market-prices {
    display: flex;
    gap: 16px;
}

.price-block {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.price-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.price-block.yes .price-label { color: var(--green); }
.price-block.no .price-label { color: var(--red); }

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

.market-volume {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 2px;
}

.volume-label {
    font-size: 0.7rem;
    color: var(--text-muted);
}

.volume-value {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-dim);
}

/* --- Market Detail --- */

.back-link {
    display: inline-block;
    color: var(--text-dim);
    font-size: 0.85rem;
    margin-bottom: 20px;
    transition: color 0.15s;
}
.back-link:hover { color: var(--text); }

.market-detail {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 24px;
    align-items: start;
}

@media (max-width: 820px) {
    .market-detail { grid-template-columns: 1fr; }
}

.market-detail-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 12px;
}

.market-end-countdown {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.market-outcome-badge {
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 0.8rem;
    font-weight: 600;
}
.market-outcome-badge.yes { background: var(--green-bg); color: var(--green); }
.market-outcome-badge.no { background: var(--red-bg); color: var(--red); }

.market-detail-main .market-question {
    font-size: 1.4rem;
    margin-bottom: 8px;
}

.market-description {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 24px;
}

.user-position-info {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 20px;
}

.user-position-info h4 {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 8px;
    font-weight: 500;
}

.position-summary {
    display: flex;
    gap: 12px;
}

.position-item {
    padding: 6px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
}

.position-item.yes { background: var(--green-bg); color: var(--green); }
.position-item.no { background: var(--red-bg); color: var(--red); }

/* --- Trade Panels --- */

.trade-panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 8px;
}

@media (max-width: 600px) {
    .trade-panels { grid-template-columns: 1fr; }
}

.trade-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
}

.yes-panel { border-top: 3px solid var(--green); }
.no-panel { border-top: 3px solid var(--red); }

.trade-panel h3 {
    font-size: 1rem;
    margin-bottom: 4px;
}

.yes-panel h3 { color: var(--green); }
.no-panel h3 { color: var(--red); }

.trade-hint {
    font-size: 0.8rem;
    color: var(--text-dim);
    margin-bottom: 14px;
}

.trade-price-display {
    font-size: 0.9rem;
    color: var(--text-dim);
    margin-bottom: 14px;
}

.trade-price-display strong {
    color: var(--text);
    font-size: 1.1rem;
}

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

.trade-form label {
    display: flex;
    flex-direction: column;
    gap: 4px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.trade-input {
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 10px 12px;
    font-size: 1rem;
    outline: none;
    transition: border-color 0.15s;
}
.trade-input:focus { border-color: var(--blue); }

.btn {
    padding: 10px 20px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s, transform 0.1s;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn:active:not(:disabled) { transform: scale(0.98); }

.btn-yes { background: var(--green); color: #000; }
.btn-no { background: var(--red); color: #fff; }
.btn-primary { background: var(--blue); color: #fff; }

/* --- Sidebar --- */

.sidebar-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
}

.sidebar-card h4 {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin-bottom: 12px;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.orderbook-header {
    display: grid;
    grid-template-columns: 1fr 1fr;
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 6px;
}
.orderbook-header span:last-child { text-align: right; }

.orderbook-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    font-size: 0.85rem;
    padding: 4px 0;
    font-variant-numeric: tabular-nums;
}

.ob-price { font-weight: 600; }
.ob-shares { text-align: right; color: var(--text-dim); }

.empty-hint {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-align: center;
    padding: 8px 0;
}

.trades-list { max-height: 300px; overflow-y: auto; }

.trade-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    padding: 3px 0;
    font-variant-numeric: tabular-nums;
}

.trade-side {
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.7rem;
    padding: 1px 6px;
    border-radius: 4px;
}

.trade-side.yes { background: var(--green-bg); color: var(--green); }
.trade-side.no { background: var(--red-bg); color: var(--red); }

.trade-shares { color: var(--text-dim); flex: 1; text-align: right; }
.trade-price { font-weight: 600; }

/* --- Toast --- */

.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    z-index: 1000;
    animation: toastIn 0.3s ease;
}

@keyframes toastIn {
    from { opacity: 0; transform: translateX(-50%) translateY(10px); }
    to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.toast-success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); }
.toast-error { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); }

/* --- Portfolio --- */

.portfolio-summary {
    display: flex;
    gap: 12px;
    margin-bottom: 24px;
}

.summary-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    min-width: 200px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.summary-label { font-size: 0.78rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.03em; }
.summary-value { font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums; }

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

.position-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
}

.position-card.resolved { opacity: 0.7; }

.position-link {
    font-weight: 600;
    font-size: 0.95rem;
    flex: 1;
    min-width: 200px;
}

.position-link:hover { color: var(--blue); }

.position-details {
    display: flex;
    align-items: center;
    gap: 10px;
}

.pos-badge {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    font-size: 0.8rem;
    font-weight: 600;
}

.pos-badge.yes { background: var(--green-bg); color: var(--green); }
.pos-badge.no { background: var(--red-bg); color: var(--red); }

.pos-resolution {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
}

.pos-resolution.yes { background: var(--green-bg); color: var(--green); }
.pos-resolution.no { background: var(--red-bg); color: var(--red); }

.empty-state {
    text-align: center;
    padding: 64px 24px;
    color: var(--text-dim);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
}

.empty-state p { font-size: 1rem; }

/* --- Login --- */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}

.login-container {
    width: 100%;
    max-width: 380px;
    padding: 40px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
}

.login-logo { margin-bottom: 8px; font-size: 1.6rem; }

.login-subtitle {
    color: var(--text-dim);
    font-size: 0.9rem;
    margin-bottom: 28px;
}

.login-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
    text-align: left;
}

.login-form label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 0.85rem;
    color: var(--text-dim);
}

.form-error {
    background: var(--red-bg);
    color: var(--red);
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
}
