:root {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --text: #f8fafc;
    --muted: #94a3b8;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #22c55e;
    --danger: #ef4444;
    --border: rgba(148, 163, 184, 0.2);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, sans-serif;
    background: linear-gradient(180deg, #0b1220 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100vh;
}

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

.container {
    width: min(1200px, 92%);
    margin: 0 auto;
}

.sensex-bar {
    background: linear-gradient(90deg, #1e3a5f 0%, #1e293b 50%, #312e81 100%);
    border-bottom: 1px solid var(--border);
}

.sensex-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 0;
    flex-wrap: wrap;
}

.sensex-title {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
}

.sensex-label {
    font-weight: 700;
    font-size: 0.95rem;
    letter-spacing: 0.04em;
}

.sensex-date {
    font-size: 0.75rem;
    color: var(--muted);
}

.sensex-metrics {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.sensex-metric {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
}

.sensex-metric.primary .metric-value {
    font-size: 1.35rem;
    font-weight: 700;
}

.sensex-metric.up .metric-value {
    color: var(--success);
}

.sensex-metric.down .metric-value {
    color: var(--danger);
}

.metric-label {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--muted);
}

.metric-value {
    font-weight: 600;
    font-size: 1rem;
}

.site-header {
    border-bottom: 1px solid var(--border);
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem 0;
}

.eyebrow {
    margin: 0;
    color: var(--primary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.site-header h1 {
    margin: 0.2rem 0;
    font-size: 1.6rem;
}

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

main {
    padding: 2rem 0 4rem;
}

.hero {
    margin-bottom: 2rem;
}

.hero h2 {
    margin: 0 0 0.5rem;
    font-size: 1.8rem;
}

.hero p,
.muted {
    color: var(--muted);
}

.btn {
    display: inline-block;
    border: none;
    border-radius: 10px;
    padding: 0.75rem 1.2rem;
    font-weight: 600;
    cursor: pointer;
}

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

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

.stock-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.25rem;
}

.stock-card,
.panel,
.empty-state {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.25rem;
}

.stock-card-header {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: start;
}

.stock-card h3 {
    margin: 0;
}

.badge {
    background: var(--surface-2);
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--muted);
}

.price-row {
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
    margin: 1rem 0;
}

.ltp {
    font-size: 1.8rem;
    font-weight: 700;
}

.ltp.large {
    font-size: 2.4rem;
}

.change.up {
    color: var(--success);
}

.change.down {
    color: var(--danger);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin: 0;
}

.metrics.wide {
    grid-template-columns: repeat(4, 1fr);
}

.metrics.compact {
    grid-template-columns: repeat(3, 1fr);
}

.metrics div {
    background: rgba(15, 23, 42, 0.45);
    border-radius: 10px;
    padding: 0.65rem 0.75rem;
}

.metrics dt {
    margin: 0;
    font-size: 0.75rem;
    color: var(--muted);
}

.metrics dd {
    margin: 0.2rem 0 0;
    font-weight: 600;
}

.latest-result {
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.latest-result h4 {
    margin: 0 0 0.75rem;
    font-size: 0.95rem;
}

.card-link {
    display: inline-block;
    margin-top: 1rem;
    color: var(--primary);
    font-weight: 600;
}

.panel {
    margin-bottom: 1.5rem;
}

.panel h3 {
    margin-top: 0;
}

.quote-banner {
    display: grid;
    gap: 1.5rem;
}

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

.data-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.data-table th,
.data-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    color: var(--muted);
    font-size: 0.85rem;
}

.detail-header {
    margin-bottom: 1.5rem;
}

.back-link {
    color: var(--primary);
    display: inline-block;
    margin-bottom: 0.75rem;
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
}

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

.errors {
    margin: 1rem 0;
    color: var(--danger);
}

.small {
    font-size: 0.85rem;
}

.site-footer {
    border-top: 1px solid var(--border);
    padding: 1.5rem 0 2rem;
    color: var(--muted);
    font-size: 0.9rem;
}

.analytics-section {
    margin-top: 2rem;
}

.analytics-controls {
    margin-top: 2rem;
}

.analytics-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 1rem;
    flex-wrap: wrap;
}

.analytics-toolbar-group {
    display: flex;
    align-items: end;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.analytics-field label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.analytics-toolbar input[type="date"] {
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 8px;
    padding: 0.55rem 0.75rem;
    font: inherit;
}

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

.btn-secondary:hover {
    background: #475569;
}

.analytics-section h3 {
    margin-bottom: 0.35rem;
}

.table-scroll {
    overflow-x: auto;
    margin-top: 1rem;
}

.analytics-table th,
.analytics-table td {
    white-space: nowrap;
    font-size: 0.85rem;
}

.analytics-table th[scope="row"] {
    position: sticky;
    left: 0;
    background: var(--surface);
    z-index: 1;
}

.fundamentals-table th[rowspan="2"] {
    vertical-align: bottom;
}

.fund-row-fy_end th[scope="row"] {
    font-weight: 700;
}

code {
    background: rgba(15, 23, 42, 0.6);
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    font-size: 0.85em;
}

@media (max-width: 768px) {
    .header-inner {
        flex-direction: column;
        align-items: stretch;
    }

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