:root {
    --bg: #07101d;
    --bg-soft: #0d1a2d;
    --card: #111f33;
    --line: #2b3a53;
    --text: #e6edf7;
    --muted: #9caecc;
    --blue: #47a2ff;
    --green: #3bc779;
    --red: #ff6f6f;
}

[data-theme="light"] {
    --bg: #f5f8fc;
    --bg-soft: #ffffff;
    --card: #ffffff;
    --line: #ccd8ea;
    --text: #18202c;
    --muted: #617088;
    --blue: #2e7ed8;
    --green: #2c9f62;
    --red: #d85757;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
    color: var(--text);
    background:
        radial-gradient(900px 320px at 30% -80px, #173051 0%, transparent 70%),
        var(--bg);
    overflow-x: hidden;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: 54px;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 8px calc(12px + env(safe-area-inset-left, 0px));
    display: grid;
    grid-template-columns: auto 1fr auto;
    gap: 10px;
    align-items: center;
    background: color-mix(in srgb, var(--bg-soft) 88%, #10243d 12%);
    border-bottom: 1px solid var(--line);
}

.top-title {
    text-align: center;
    font-weight: 700;
}

.icon-btn {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    border-radius: 8px;
    width: 38px;
    height: 38px;
    cursor: pointer;
}

.side-menu {
    position: fixed;
    top: 58px;
    left: 12px;
    width: 190px;
    z-index: 35;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--bg-soft);
    padding: 8px;
    display: grid;
    gap: 6px;
}

.side-menu.hidden {
    display: none;
}

.side-menu a {
    text-decoration: none;
    color: var(--text);
    font-size: 0.92rem;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 8px 10px;
}

.page {
    min-height: 100vh;
    padding: 14px calc(12px + env(safe-area-inset-right, 0px)) calc(40px + env(safe-area-inset-bottom, 0px)) calc(12px + env(safe-area-inset-left, 0px));
}

.container {
    max-width: 1280px;
    margin: 0 auto;
    display: grid;
    gap: 14px;
}

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

.subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 0.93rem;
}

.theme-btn {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    border-radius: 8px;
    height: 36px;
    padding: 0 12px;
    cursor: pointer;
}

.panel {
    background: linear-gradient(180deg, color-mix(in srgb, var(--bg-soft) 92%, #1d3557 8%) 0%, var(--bg-soft) 100%);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 14px;
}

.panel-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}

h2 {
    margin: 0;
    font-size: 1.05rem;
}

.filters {
    display: grid;
    gap: 8px;
    grid-template-columns: 180px 1fr;
    align-items: center;
    margin-bottom: 12px;
}

label {
    color: var(--muted);
    font-size: 0.9rem;
}

#ticker-input,
#table-search {
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #0a1628;
    color: var(--text);
    padding: 0 12px;
}

[data-theme="light"] #ticker-input,
[data-theme="light"] #table-search {
    background: #f5f8ff;
}

.add-wrap {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

#add-ticker-btn {
    border: 1px solid #2f4f77;
    background: #173152;
    color: #d6e8ff;
    border-radius: 8px;
    padding: 0 14px;
    font-weight: 600;
    cursor: pointer;
}

.add-message {
    margin: 0;
    min-height: 20px;
    grid-column: 2;
    font-size: 0.84rem;
    color: var(--muted);
}

.checkbox-wrap {
    grid-column: 1 / -1;
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.risk-grid {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.risk-card {
    border: 1px solid var(--line);
    border-radius: 10px;
    background: rgba(6, 13, 24, 0.56);
    padding: 10px;
    display: grid;
    gap: 7px;
}

.risk-title {
    font-size: 0.9rem;
    color: var(--muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.help-wrap {
    position: relative;
    display: inline-flex;
}

.help-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    font-size: 11px;
    line-height: 1;
    padding: 0;
}

.help-pop {
    position: absolute;
    left: 22px;
    top: -4px;
    width: 220px;
    border: 1px solid var(--line);
    background: var(--bg-soft);
    color: var(--text);
    border-radius: 8px;
    padding: 7px 9px;
    font-size: 0.76rem;
    line-height: 1.4;
    opacity: 0;
    pointer-events: none;
    transform: translateY(4px);
    transition: opacity 0.14s ease, transform 0.14s ease;
    z-index: 4;
}

.help-wrap:hover .help-pop,
.help-wrap:focus-within .help-pop,
.help-wrap:active .help-pop {
    opacity: 1;
    transform: translateY(0);
}

.risk-value {
    font-size: 1.02rem;
    font-weight: 700;
}

.chart-wrap {
    position: relative;
}

.chart-tip {
    position: absolute;
    top: 8px;
    right: 8px;
    z-index: 2;
    border: 1px solid var(--line);
    background: color-mix(in srgb, var(--bg-soft) 84%, #0d1a2d 16%);
    color: var(--text);
    border-radius: 7px;
    font-size: 0.78rem;
    padding: 4px 6px;
    pointer-events: none;
    max-width: 75%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chart-tip.hidden {
    display: none;
}

.risk-chart,
.daily-chart {
    width: 100%;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: color-mix(in srgb, var(--bg-soft) 86%, #0f1b2f 14%);
}

.risk-chart {
    height: 150px;
}

.daily-chart {
    height: 340px;
}

.axis-line {
    stroke: #3a5072;
    stroke-width: 1;
}

.line-path {
    fill: none;
    stroke: var(--blue);
    stroke-width: 2;
}

.axis-text {
    fill: var(--muted);
    font-size: 11px;
}

.crosshair {
    stroke: #95b8e5;
    stroke-width: 1;
    stroke-dasharray: 3 3;
    opacity: 0;
}

.badge {
    display: inline-block;
    font-size: 0.78rem;
    border-radius: 999px;
    padding: 4px 9px;
    font-weight: 700;
}

.badge.neutral {
    background: #31435f;
    color: #dce7f9;
}

.badge.good {
    background: rgba(59, 199, 121, 0.17);
    color: #7debaf;
}

.badge.warn {
    background: rgba(245, 197, 95, 0.15);
    color: #f8d987;
}

.badge.danger {
    background: rgba(255, 111, 111, 0.2);
    color: #ff9e9e;
}

.table-wrap {
    overflow: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1060px;
}

th,
td {
    border-bottom: 1px solid #22314a;
    padding: 9px 8px;
    text-align: right;
    white-space: nowrap;
    font-size: 0.88rem;
}

th:nth-child(1),
th:nth-child(2),
td:nth-child(1),
td:nth-child(2) {
    text-align: left;
}

th {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 600;
}

tr:hover td {
    background: rgba(54, 84, 124, 0.14);
    cursor: pointer;
}

.table-remove-btn {
    border: 1px solid #7e3540;
    background: #55242b;
    color: #ffd4d4;
    border-radius: 7px;
    padding: 4px 9px;
    font-size: 0.8rem;
    cursor: pointer;
}

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

.pos {
    color: var(--green);
    font-weight: 600;
}

.neg {
    color: var(--red);
    font-weight: 600;
}

.entry {
    color: var(--green);
    font-weight: 700;
}

.modal {
    position: fixed;
    inset: 0;
    z-index: 40;
    display: grid;
    place-items: center;
}

.modal.hidden {
    display: none;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(4, 10, 18, 0.66);
}

.modal-card {
    position: relative;
    width: min(980px, 95vw);
    max-height: 88vh;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--bg-soft);
    padding: 14px;
}

.login-card {
    width: min(460px, 92vw);
}

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

.modal-head h3 {
    margin: 0;
    font-size: 1.05rem;
}

.modal-close-btn {
    border: 1px solid var(--line);
    background: var(--card);
    color: var(--text);
    border-radius: 7px;
    padding: 6px 10px;
    cursor: pointer;
}

.modal-subtitle {
    margin: 8px 0 10px;
    color: var(--muted);
    font-size: 0.9rem;
}

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

.auth-wrap button {
    border: 1px solid var(--line);
    background: #14263d;
    color: #dde8f8;
    border-radius: 8px;
    height: 34px;
    padding: 0 12px;
    cursor: pointer;
}

.content-panel p {
    margin: 10px 0 0;
    color: var(--muted);
    line-height: 1.65;
}

@media (max-width: 760px) {
    .hero {
        flex-direction: column;
        align-items: flex-start;
    }

    .risk-grid {
        grid-template-columns: 1fr;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .add-message {
        grid-column: auto;
    }

    table,
    thead,
    tbody,
    th,
    td,
    tr {
        display: block;
    }

    thead {
        display: none;
    }

    tbody tr {
        border: 1px solid #22314a;
        border-radius: 10px;
        margin-bottom: 10px;
        padding: 8px;
    }

    td {
        border-bottom: 1px dashed #22314a;
        text-align: right;
        padding: 7px 4px;
        white-space: normal;
    }

    td::before {
        content: attr(data-label);
        float: left;
        color: var(--muted);
        font-size: 0.78rem;
        margin-right: 8px;
    }

    .risk-chart {
        height: 190px;
    }

    .daily-chart {
        height: 260px;
    }
}
