:root {
    --bg: #081120;
    --bg-2: #0d1a2f;
    --panel: #121f36;
    --panel-2: #182841;
    --line: #273a59;
    --text: #e8effa;
    --muted: #95aac6;
    --accent: #38bdf8;
    --good: #22c55e;
    --warn: #facc15;
    --danger: #ef4444;
    --radius: 14px;
    --shadow: 0 16px 40px rgba(0, 0, 0, 0.28);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text);
    background: radial-gradient(circle at 30% -10%, rgba(56, 189, 248, 0.12), transparent 38%),
    radial-gradient(circle at 100% 0, rgba(34, 197, 94, 0.08), transparent 26%),
    linear-gradient(180deg, var(--bg), var(--bg-2));
    font-family: "Inter", "Segoe UI", Arial, sans-serif;
}

.app-shell {
    min-height: 100vh;
}

.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
    padding: 18px 24px;
    border-bottom: 1px solid var(--line);
    background: rgba(8, 17, 32, 0.72);
    backdrop-filter: blur(7px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    color: var(--accent);
    text-decoration: none;
    font-size: 26px;
    font-weight: 800;
    letter-spacing: 0;
}

.top-nav {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.top-nav a {
    text-decoration: none;
    color: var(--text);
    font-weight: 600;
    padding: 9px 12px;
    border-radius: 10px;
}

.top-nav a:hover {
    background: rgba(255, 255, 255, 0.06);
}

.inline-form {
    margin: 0;
}

.page {
    max-width: 1600px;
    margin: 0 auto;
    padding: 24px 18px 40px;
}

.panel {
    background: linear-gradient(180deg, rgba(18, 31, 54, 0.98), rgba(13, 24, 44, 0.98));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 18px;
}

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

.panel-header-stacked {
    align-items: flex-start;
}

.panel-subtitle {
    margin: 6px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.35;
}

.panel h2,
.auth-card h1 {
    margin: 0;
    font-size: 24px;
    letter-spacing: 0;
}

.count {
    color: var(--muted);
    font-size: 13px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 14px;
    margin-bottom: 18px;
}

.summary-card {
    background: linear-gradient(180deg, rgba(18, 32, 56, 0.98), rgba(14, 23, 42, 0.98));
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 16px;
}

.summary-label {
    color: var(--muted);
    display: block;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.summary-value {
    font-size: 24px;
    font-weight: 700;
}

.controls-bar {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.stack-form {
    display: grid;
    gap: 10px;
}

.action-panel {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.ticker-form {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

input,
select,
button {
    border-radius: 10px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--text);
    font-size: 14px;
    padding: 11px 12px;
}

input:focus,
select:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

label {
    color: var(--muted);
    font-size: 13px;
}

.primary-btn,
.secondary-btn,
.ghost-btn,
.danger-btn {
    cursor: pointer;
    font-weight: 700;
}

.primary-btn {
    background: linear-gradient(180deg, #22c55e, #16934f);
    border-color: #1f9d55;
    color: white;
}

.secondary-btn {
    background: #1d2e4d;
}

.ghost-btn {
    background: transparent;
}

.danger-btn {
    background: rgba(239, 68, 68, 0.2);
    border-color: rgba(239, 68, 68, 0.45);
    color: #fecaca;
}

button:hover {
    filter: brightness(1.06);
}

.alert {
    border: 1px solid transparent;
    padding: 12px 14px;
    border-radius: 12px;
    font-weight: 700;
    margin-bottom: 14px;
}

.alert-success {
    color: #4ade80;
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.4);
}

.alert-error {
    color: #fca5a5;
    background: rgba(239, 68, 68, 0.14);
    border-color: rgba(239, 68, 68, 0.4);
}

.alert-info {
    color: #7dd3fc;
    background: rgba(56, 189, 248, 0.12);
    border-color: rgba(56, 189, 248, 0.35);
}

.table-wrap {
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: rgba(9, 17, 31, 0.55);
}

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

th, td {
    border-bottom: 1px solid var(--line);
    padding: 12px 12px;
    text-align: left;
    vertical-align: middle;
    font-size: 13px;
    line-height: 1.3;
}

th {
    color: var(--muted);
    text-transform: uppercase;
    font-size: 12px;
    letter-spacing: 0;
    position: sticky;
    top: 0;
    z-index: 2;
    background: rgba(12, 24, 44, 0.96);
    backdrop-filter: blur(6px);
}

tbody tr {
    transition: background-color 140ms ease;
}

tbody tr:hover td {
    background: rgba(56, 189, 248, 0.08);
}

.ticker {
    font-weight: 800;
    letter-spacing: 0;
}

.company-cell {
    min-width: 240px;
}

.badge {
    display: inline-block;
    border-radius: 999px;
    padding: 5px 12px;
    font-size: 11px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0;
    border: 1px solid transparent;
    box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07);
}

.badge-strong-buy {
    background: linear-gradient(180deg, rgba(22, 163, 74, 0.38), rgba(22, 163, 74, 0.2));
    color: #bbf7d0;
    border-color: rgba(34, 197, 94, 0.52);
}

.badge-buy {
    background: linear-gradient(180deg, rgba(22, 163, 74, 0.28), rgba(22, 163, 74, 0.14));
    color: #86efac;
    border-color: rgba(34, 197, 94, 0.42);
}

.badge-hold {
    background: linear-gradient(180deg, rgba(250, 204, 21, 0.24), rgba(250, 204, 21, 0.12));
    color: #fef08a;
    border-color: rgba(250, 204, 21, 0.45);
}

.badge-watch {
    background: linear-gradient(180deg, rgba(251, 146, 60, 0.26), rgba(251, 146, 60, 0.13));
    color: #fdba74;
    border-color: rgba(251, 146, 60, 0.42);
}

.badge-avoid,
.badge-sell {
    background: linear-gradient(180deg, rgba(239, 68, 68, 0.24), rgba(239, 68, 68, 0.12));
    color: #fecaca;
    border-color: rgba(239, 68, 68, 0.42);
}

.badge-unknown {
    background: rgba(148, 163, 184, 0.15);
    color: #cbd5e1;
    border-color: rgba(148, 163, 184, 0.33);
}

.net-strong {
    color: #4ade80;
    font-weight: 800;
}

.net-medium {
    color: #facc15;
    font-weight: 800;
}

.net-weak {
    color: #fca5a5;
    font-weight: 800;
}

.pos-change {
    color: #4ade80;
    font-weight: 700;
}

.neg-change {
    color: #fca5a5;
    font-weight: 700;
}

.neutral-change,
.muted,
.muted-text,
.small-text {
    color: var(--muted);
}

.pagination-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-top: 12px;
}

.pagination-controls {
    display: flex;
    gap: 8px;
    align-items: center;
}

.page-link,
.sort-link,
.link {
    color: var(--accent);
    text-decoration: none;
    font-weight: 600;
}

.sort-link:hover,
.page-link:hover,
.link:hover {
    text-decoration: underline;
}

.auth-card {
    max-width: 460px;
    margin: 40px auto;
    background: linear-gradient(180deg, rgba(18, 31, 54, 0.98), rgba(13, 24, 44, 0.98));
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

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

.chart-panel {
    overflow-x: auto;
}

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

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

.watchlist-controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.watchlist-tools {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.watchlist-tools input[type="text"] {
    min-width: 280px;
}

.watchlist-tools .ghost-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    padding: 11px 12px;
}

.watchlist-table-wrap {
    max-height: min(68vh, 760px);
}

.watchlist-table {
    min-width: 1040px;
}

.watchlist-table th {
    z-index: 3;
}

.watchlist-table .sticky-col {
    position: sticky;
    left: 0;
}

.watchlist-table th.sticky-col {
    z-index: 5;
    background: rgba(12, 24, 44, 0.98);
    box-shadow: 1px 0 0 rgba(39, 58, 89, 0.95);
}

.watchlist-table td.sticky-col {
    z-index: 2;
    background: rgba(10, 20, 36, 0.98);
    box-shadow: 1px 0 0 rgba(39, 58, 89, 0.95);
}

.watchlist-table tbody tr:hover td.sticky-col {
    background: rgba(20, 40, 68, 0.98);
}

.watchlist-table tbody tr:last-child td {
    border-bottom: 0;
}

.sort-trigger {
    color: var(--muted);
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    white-space: nowrap;
}

.sort-trigger.is-active {
    color: #d3e8ff;
}

.sort-trigger:hover {
    color: var(--accent);
}

.sort-indicator {
    color: var(--accent);
    font-size: 11px;
}

.th-with-info {
    white-space: nowrap;
}

.th-label-row {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.info-tip {
    width: 17px;
    height: 17px;
    border-radius: 999px;
    border: 1px solid rgba(125, 211, 252, 0.4);
    background: rgba(56, 189, 248, 0.15);
    color: #bae6fd;
    font-size: 10px;
    font-weight: 700;
    line-height: 1;
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    position: relative;
}

.info-tip:hover {
    filter: none;
}

.info-tip:focus-visible {
    outline: 2px solid rgba(125, 211, 252, 0.85);
    outline-offset: 2px;
}

.info-tip::before {
    content: "";
    position: absolute;
    top: calc(100% + 3px);
    left: 50%;
    transform: translateX(-50%);
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid rgba(15, 27, 47, 0.98);
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
    z-index: 14;
}

.info-tip::after {
    content: attr(data-tooltip);
    position: absolute;
    top: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%);
    width: min(240px, 48vw);
    background: rgba(15, 27, 47, 0.98);
    color: #dbeafe;
    border: 1px solid rgba(148, 163, 184, 0.38);
    border-radius: 8px;
    padding: 7px 9px;
    text-transform: none;
    font-size: 11px;
    line-height: 1.3;
    letter-spacing: 0;
    text-align: left;
    white-space: normal;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms ease;
    z-index: 13;
}

.info-tip:hover::before,
.info-tip:hover::after,
.info-tip:focus-visible::before,
.info-tip:focus-visible::after,
.info-tip:active::before,
.info-tip:active::after {
    opacity: 1;
}

.sparkline {
    width: 110px;
    height: 32px;
    display: block;
}

.sparkline polyline {
    fill: none;
    stroke-width: 2;
    vector-effect: non-scaling-stroke;
}

.sparkline-up polyline {
    stroke: #34d399;
}

.sparkline-down polyline {
    stroke: #f87171;
}

.sparkline-flat polyline {
    stroke: #94a3b8;
}

@media (max-width: 1200px) {
    .summary-grid {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 900px) {
    .app-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

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

    .watchlist-tools input[type="text"] {
        min-width: 220px;
    }

    .info-tip::after {
        width: min(220px, 56vw);
    }
}

@media (max-width: 620px) {
    .summary-grid {
        grid-template-columns: 1fr;
    }

    .page {
        padding: 14px 10px 28px;
    }

    .panel {
        padding: 14px;
    }

    table {
        min-width: 100%;
    }

    .watchlist-table-wrap {
        max-height: none;
    }

    .watchlist-table thead {
        display: none;
    }

    .watchlist-table,
    .watchlist-table tbody,
    .watchlist-table tr,
    .watchlist-table td {
        display: block;
        width: 100%;
    }

    .watchlist-table tr {
        border-bottom: 1px solid var(--line);
        padding: 8px 0;
    }

    .watchlist-table td {
        border-bottom: 0;
        padding: 7px 4px;
        display: grid;
        grid-template-columns: minmax(80px, 96px) 1fr;
        gap: 8px;
        align-items: center;
    }

    .watchlist-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: 11px;
        text-transform: uppercase;
    }

    .watchlist-table .sticky-col {
        position: static;
        left: auto;
        box-shadow: none;
    }

    .watchlist-table .company-cell {
        min-width: 0;
    }

    .watchlist-table .action-cell {
        justify-content: flex-start;
    }

    .watchlist-table .action-cell form {
        width: auto;
    }

    .watchlist-controls {
        align-items: stretch;
    }

    .watchlist-tools {
        width: 100%;
    }

    .watchlist-tools input[type="text"] {
        min-width: 0;
        width: 100%;
    }

    .watchlist-tools select,
    .watchlist-tools button,
    .watchlist-tools a {
        flex: 1 1 auto;
    }
}
