:root {
    --color-bg: #f5f7fa;
    --color-surface: #ffffff;
    --color-border: #e3e8ef;
    --color-text: #1a2233;
    --color-text-muted: #6b7688;
    --color-primary: #2563eb;
    --color-primary-dark: #1d4ed8;
    --color-primary-light: #eaf1ff;
    --color-positive: #0f9d58;
    --color-positive-bg: #e8f7ee;
    --color-negative: #d93025;
    --color-negative-bg: #fdecea;
    --color-sidebar-bg: #101828;
    --color-sidebar-text: #cbd5e1;
    --color-sidebar-text-active: #ffffff;
    --radius: 10px;
    --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06);
    --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08);
    --sidebar-width: 240px;
}

* {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: var(--color-bg);
    color: var(--color-text);
    font-size: 14px;
    line-height: 1.5;
}

a {
    color: var(--color-primary);
    text-decoration: none;
}

button, input, select, textarea {
    font-family: inherit;
    font-size: inherit;
}

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #101828 0%, #1e293b 100%);
}

.login-card {
    background: var(--color-surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 40px;
    width: 100%;
    max-width: 380px;
}

.login-card h1 {
    margin: 0 0 4px;
    font-size: 22px;
}

.login-card p.subtitle {
    margin: 0 0 24px;
    color: var(--color-text-muted);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 600;
    font-size: 13px;
    color: var(--color-text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    background: var(--color-surface);
    color: var(--color-text);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid transparent;
    background: var(--color-primary);
    color: #fff;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s ease;
}

.btn:hover {
    background: var(--color-primary-dark);
}

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

.btn-block {
    width: 100%;
}

.btn-secondary {
    background: var(--color-surface);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover {
    background: var(--color-bg);
}

.btn-danger {
    background: var(--color-negative);
}

.btn-danger:hover {
    background: #b8271e;
}

.error-message {
    background: var(--color-negative-bg);
    color: var(--color-negative);
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 13px;
    margin-bottom: 16px;
}

/* ---------- App shell ---------- */
.app-shell {
    display: flex;
    min-height: 100vh;
}

.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--color-sidebar-bg);
    color: var(--color-sidebar-text);
    display: flex;
    flex-direction: column;
    padding: 20px 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 20;
}

.sidebar .brand {
    font-size: 18px;
    font-weight: 700;
    color: #fff;
    padding: 0 24px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    margin-bottom: 12px;
}

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

.sidebar nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 24px;
    color: var(--color-sidebar-text);
    font-weight: 500;
    border-left: 3px solid transparent;
}

.sidebar nav a:hover {
    background: rgba(255,255,255,0.06);
    color: #fff;
}

.sidebar nav a.active {
    background: rgba(37, 99, 235, 0.18);
    color: var(--color-sidebar-text-active);
    border-left-color: var(--color-primary);
}

.sidebar .icon {
    width: 18px;
    text-align: center;
}

.sidebar-footer {
    padding: 16px 24px 0;
    border-top: 1px solid rgba(255,255,255,0.08);
}

.sidebar-footer .user-name {
    font-size: 13px;
    color: #fff;
    margin-bottom: 8px;
}

.logout-link {
    background: none;
    border: none;
    color: var(--color-sidebar-text);
    cursor: pointer;
    padding: 0;
    font-weight: 600;
    font-size: 13px;
}

.logout-link:hover {
    color: #fff;
}

.main {
    margin-left: var(--sidebar-width);
    flex: 1;
    padding: 28px 32px 60px;
    max-width: 1400px;
}

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

.page-header h1 {
    margin: 0;
    font-size: 24px;
}

.page-header .subtitle {
    color: var(--color-text-muted);
    margin-top: 4px;
}

/* ---------- Cards / grid ---------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 20px;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat-card .label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: 8px;
}

.stat-card .value {
    font-size: 26px;
    font-weight: 700;
}

.stat-card .delta {
    margin-top: 6px;
    font-size: 13px;
    font-weight: 600;
}

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

.pill {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
}

.pill.positive { background: var(--color-positive-bg); color: var(--color-positive); }
.pill.negative { background: var(--color-negative-bg); color: var(--color-negative); }

/* ---------- Tables ---------- */
.table-wrap {
    overflow-x: auto;
}

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

thead th {
    text-align: left;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--color-text-muted);
    font-weight: 600;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

tbody td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--color-border);
    white-space: nowrap;
}

tbody tr:last-child td {
    border-bottom: none;
}

tbody tr:hover {
    background: var(--color-bg);
}

.text-right { text-align: right; }
.text-muted { color: var(--color-text-muted); }

/* ---------- Forms inline ---------- */
.inline-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
    align-items: flex-end;
    margin-bottom: 20px;
}

.inline-form .form-group {
    margin-bottom: 0;
    min-width: 140px;
}

/* ---------- Stock cards grid ---------- */
.stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 14px;
}

.stock-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 18px;
    text-align: left;
    cursor: pointer;
    transition: box-shadow 0.15s ease, transform 0.15s ease;
    box-shadow: var(--shadow-sm);
}

.stock-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
}

.stock-card .ticker {
    font-size: 18px;
    font-weight: 700;
}

.stock-card .name {
    color: var(--color-text-muted);
    font-size: 12px;
    margin: 4px 0 12px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stock-card .price {
    font-size: 20px;
    font-weight: 700;
}

/* ---------- Section headings ---------- */
.section-title {
    font-size: 16px;
    font-weight: 700;
    margin: 0 0 16px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.grid-cols-4 {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
}

.mb-24 { margin-bottom: 24px; }

.back-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    color: var(--color-text-muted);
    font-weight: 600;
    margin-bottom: 12px;
}

.back-link:hover { color: var(--color-text); }

.loading, .empty-state {
    padding: 40px;
    text-align: center;
    color: var(--color-text-muted);
}

.kv-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.kv-list .kv-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--color-border);
}

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

.kv-list .kv-label { color: var(--color-text-muted); }
.kv-list .kv-value { font-weight: 600; }

canvas.chart {
    width: 100%;
    height: 260px;
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
    .grid-cols-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
    .sidebar {
        position: static;
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        padding: 10px 0;
    }
    .sidebar .brand { display: none; }
    .sidebar nav { flex-direction: row; }
    .sidebar nav a { padding: 10px 14px; border-left: none; border-bottom: 3px solid transparent; white-space: nowrap; }
    .sidebar nav a.active { border-left-color: transparent; border-bottom-color: var(--color-primary); }
    .sidebar-footer { display: none; }
    .app-shell { flex-direction: column; }
    .main { margin-left: 0; padding: 20px 16px 40px; }
    .grid-cols-4 { grid-template-columns: 1fr 1fr; }
}

@media (max-width: 480px) {
    .grid-cols-4 { grid-template-columns: 1fr; }
}
