:root {
    --ink: #0f2027;
    --text: #1e293b;
    --muted: #64748b;
    --line: #e2e8f0;
    --panel: #ffffff;
    --bg: #f8fafc;
    --accent: #0f766e;
    --accent-ink: #ffffff;
    --warn-bg: #fffbeb;
    --warn-line: #fcd34d;
    --info-bg: #eff6ff;
    --info-line: #bfdbfe;
    --err-bg: #fef2f2;
    --err-line: #fecaca;
    --up: #15803d;
    --down: #b91c1c;
    --radius: 12px;
    font-family: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    color: var(--text);
    background: var(--bg);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-size: 14px;
    line-height: 1.45;
}

[hidden] {
    display: none !important;
}

a {
    color: #1d4ed8;
}

code {
    background: #f1f5f9;
    padding: 0 .3em;
    border-radius: 4px;
    font-size: .92em;
}

hr {
    border: 0;
    border-top: 1px solid var(--line);
    margin: 1.2rem 0;
}

/* Layout */
.layout {
    display: grid;
    grid-template-columns: 330px minmax(0, 1fr);
    min-height: 100vh;
}

.sidebar {
    background: #f1f5f9;
    border-right: 1px solid var(--line);
    padding: 1rem 1rem 3rem;
    overflow-y: auto;
    max-height: 100vh;
    position: sticky;
    top: 0;
}

.main {
    padding: 1.4rem 1.8rem 2rem;
    max-width: 1560px;
    width: 100%;
}

.admin {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.4rem 1.8rem 3rem;
}

.footer {
    color: var(--muted);
    font-size: .75rem;
    margin-top: 2rem;
}

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

    .sidebar {
        position: static;
        max-height: none;
        border-right: 0;
        border-bottom: 1px solid var(--line);
    }

    .main {
        padding: 1rem;
    }
}

/* Hero and status */
.hero {
    background: linear-gradient(120deg, #0f2027 0%, #203a43 55%, #2c5364 100%);
    border-radius: 14px;
    padding: 1.3rem 1.8rem;
    margin-bottom: 1rem;
    color: #f3f6f9;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: flex-start;
    flex-wrap: wrap;
}

.hero h1 {
    margin: 0;
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: -.5px;
}

.hero p {
    margin: .35rem 0 0;
    opacity: .85;
    font-size: .93rem;
}

.hero.small {
    padding: 1rem 1.2rem;
}

.hero.small h1 {
    font-size: 1.5rem;
}

.user-menu {
    display: flex;
    gap: .5rem;
    align-items: center;
    font-size: .85rem;
}

.user-menu .btn.ghost {
    color: #f3f6f9;
    border-color: rgba(255, 255, 255, .35);
}

.statusbar {
    background: #f1f5f9;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .45rem .8rem;
    margin: -.4rem 0 .9rem;
    font-size: .8rem;
    color: #334155;
    white-space: pre-wrap;
}

.progress {
    margin: 0 0 .9rem;
}

.progress-text {
    font-size: .85rem;
    color: #334155;
    margin-bottom: .3rem;
}

.progress progress {
    width: 100%;
    height: .6rem;
    accent-color: var(--accent);
}

/* Banners */
.banner,
.info,
.error {
    border-radius: 8px;
    padding: .65rem .9rem;
    margin: 0 0 .7rem;
    font-size: .88rem;
}

.banner.warn {
    background: var(--warn-bg);
    border: 1px solid var(--warn-line);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.info {
    background: var(--info-bg);
    border: 1px solid var(--info-line);
}

.error {
    background: var(--err-bg);
    border: 1px solid var(--err-line);
}

.error-text {
    color: var(--down);
    font-size: .85rem;
    min-height: 1.2em;
}

.ok {
    color: var(--up);
    font-size: .85rem;
}

.caption {
    color: var(--muted);
    font-size: .8rem;
    margin: .3rem 0 .6rem;
}

/* Buttons and inputs */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .3rem;
    border: 1px solid #cbd5e1;
    background: #fff;
    color: var(--text);
    border-radius: 8px;
    padding: .45rem .85rem;
    font: inherit;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover {
    border-color: #94a3b8;
}

.btn:disabled {
    opacity: .6;
    cursor: wait;
}

.btn.primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--accent-ink);
}

.btn.primary:hover {
    filter: brightness(1.08);
}

.btn.ghost {
    background: transparent;
}

.btn.danger {
    color: var(--down);
    border-color: var(--err-line);
}

.btn.small {
    padding: .2rem .55rem;
    font-size: .8rem;
}

.btn.block {
    width: 100%;
    margin: .5rem 0;
}

.linkish {
    background: none;
    border: 0;
    color: #1d4ed8;
    cursor: pointer;
    padding: .3rem 0;
    font: inherit;
    font-size: .8rem;
    text-decoration: underline;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
select {
    width: 100%;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    padding: .42rem .6rem;
    font: inherit;
    background: #fff;
}

input:focus-visible,
select:focus-visible,
.btn:focus-visible {
    outline: 2px solid #2563eb;
    outline-offset: 1px;
}

/* Sidebar */
.side-section {
    border-bottom: 1px solid var(--line);
    padding: .6rem 0 .8rem;
}

.side-section h3 {
    font-size: .95rem;
    margin: .2rem 0 .5rem;
    color: var(--ink);
}

.field {
    display: block;
    margin: .45rem 0;
}

.field-label {
    display: block;
    font-size: .78rem;
    color: #334155;
    margin-bottom: .2rem;
    font-weight: 600;
}

.slider {
    display: flex;
    align-items: center;
    gap: .5rem;
}

.slider input {
    flex: 1;
    accent-color: var(--accent);
}

.slider output {
    min-width: 2.6rem;
    text-align: right;
    font-variant-numeric: tabular-nums;
    font-weight: 600;
}

.toggle {
    display: flex;
    align-items: center;
    gap: .5rem;
    margin: .35rem 0;
    cursor: pointer;
    font-size: .85rem;
}

.toggle input {
    accent-color: var(--accent);
    width: 1rem;
    height: 1rem;
}

.check {
    display: flex;
    align-items: center;
    gap: .45rem;
    font-size: .84rem;
    padding: .12rem 0;
    cursor: pointer;
}

.check input {
    accent-color: var(--accent);
}

.issuer-search {
    margin-bottom: .35rem;
}

.issuer-list {
    max-height: 230px;
    overflow-y: auto;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: .3rem .55rem;
}

.rating-checks {
    max-height: 200px;
    overflow-y: auto;
}

.range-pair {
    display: flex;
    align-items: center;
    gap: .4rem;
}

details {
    margin: .3rem 0;
}

summary {
    cursor: pointer;
    font-weight: 600;
    font-size: .85rem;
    padding: .25rem 0;
}

/* Tiles */
.tiles {
    display: grid;
    gap: .7rem;
}

.tile-row {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: .7rem;
    margin-bottom: .2rem;
}

@media (max-width: 1100px) {
    .tile-row {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

.metric {
    background: var(--panel);
    border: 1px solid #e6eaef;
    border-radius: var(--radius);
    padding: .75rem .9rem;
    box-shadow: 0 1px 2px rgba(16, 24, 40, .04);
}

.metric-label {
    font-size: .7rem;
    color: var(--muted);
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .03em;
    line-height: 1.2;
}

.metric-value {
    font-size: 1.3rem;
    line-height: 1.3;
    margin-top: .15rem;
    font-variant-numeric: tabular-nums;
    overflow-wrap: anywhere;
}

.metric-delta {
    font-size: .75rem;
    color: var(--muted);
    margin-top: .1rem;
}

.metric-delta.up {
    color: var(--up);
}

.metric-delta.down {
    color: var(--down);
}

/* Cards and pills */
.sectionhead {
    font-size: 1.12rem;
    font-weight: 700;
    color: var(--ink);
    margin: .5rem 0 .15rem;
}

.sectionhead.small {
    font-size: .95rem;
}

.picks {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .8rem;
}

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

.card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: .9rem 1rem;
    display: flex;
    flex-direction: column;
    gap: .5rem;
}

.card.deal {
    margin: .8rem 0;
}

.cardhead {
    min-height: 5.6rem;
}

.tickerline {
    display: flex;
    align-items: flex-start;
}

.rank {
    display: inline-block;
    flex: none;
    width: 1.5rem;
    height: 1.5rem;
    line-height: 1.5rem;
    border-radius: 50%;
    background: var(--ink);
    color: #fff;
    text-align: center;
    font-size: .8rem;
    font-weight: 700;
    margin-right: .45rem;
}

.ticker {
    font-size: .98rem;
    font-weight: 700;
    color: var(--ink);
    overflow-wrap: anywhere;
}

.ticker.big {
    font-size: 1.15rem;
    margin-bottom: .4rem;
}

.sub {
    color: var(--muted);
    font-size: .78rem;
    margin-top: .2rem;
}

.why {
    color: #475569;
    font-size: .8rem;
    font-style: italic;
    min-height: 2.4rem;
}

.pills {
    display: flex;
    flex-wrap: wrap;
    gap: .3rem;
}

.pill {
    display: inline-block;
    padding: .14rem .6rem;
    border-radius: 999px;
    font-size: .74rem;
    background: #eef2ff;
    color: #3730a3;
    font-weight: 600;
}

.facts {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: .4rem 1rem;
}

.facts ul {
    margin: 0;
    padding-left: 1.1rem;
    font-size: .84rem;
}

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

/* Tabs */
.tabs {
    display: flex;
    gap: .2rem;
    border-bottom: 1px solid var(--line);
    margin: 1rem 0 .8rem;
    overflow-x: auto;
}

.tabs button {
    border: 0;
    background: none;
    padding: .55rem .9rem;
    font: inherit;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
}

.tabs button.active {
    color: var(--ink);
    border-bottom-color: #ef4444;
}

.issuer-checks .checks {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: .1rem .8rem;
    margin-bottom: .6rem;
}

.two-col {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
    align-items: start;
}

@media (max-width: 1000px) {
    .two-col {
        grid-template-columns: 1fr;
    }
}

.chart {
    width: 100%;
    min-height: 120px;
}

.symbol-buttons {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: .35rem;
    margin: .3rem 0 .6rem;
}

@media (max-width: 900px) {
    .symbol-buttons {
        grid-template-columns: repeat(3, minmax(0, 1fr));
    }
}

.orderbook {
    margin: .9rem 0;
}

.orderbook h4 {
    margin: .2rem 0 .4rem;
}

/* Tables */
.table-wrap {
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fff;
    margin: .4rem 0 .8rem;
}

table.data {
    border-collapse: collapse;
    width: 100%;
    font-size: .82rem;
    font-variant-numeric: tabular-nums;
}

table.data th,
table.data td {
    padding: .38rem .6rem;
    border-bottom: 1px solid #f1f5f9;
    text-align: left;
    white-space: nowrap;
}

table.data th {
    position: sticky;
    top: 0;
    background: #f8fafc;
    z-index: 1;
    cursor: pointer;
    user-select: none;
    font-weight: 700;
    color: #334155;
}

table.data th.sorted {
    color: var(--accent);
}

table.data td.wide {
    white-space: normal;
    min-width: 260px;
}

table.data td.clip {
    max-width: 380px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

table.data th.sticky,
table.data td.sticky {
    position: sticky;
    left: 0;
    background: inherit;
    z-index: 2;
}

table.data tbody tr {
    background: #fff;
}

table.data tr.clickable {
    cursor: pointer;
}

table.data tr.clickable:hover {
    background: #f0fdfa;
}

table.data tr.selected {
    background: #ccfbf1;
}

table.data.plain th {
    cursor: default;
    position: static;
}

/* Dialogs */
.dialog {
    border: 0;
    border-radius: 14px;
    padding: 0;
    width: min(1100px, 96vw);
    max-height: 92vh;
    box-shadow: 0 20px 60px rgba(15, 32, 39, .35);
}

.dialog::backdrop {
    background: rgba(15, 32, 39, .45);
}

.dialog>div {
    padding: 0 1.3rem;
}

.dialog-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: #fff;
    border-bottom: 1px solid var(--line);
    padding: .7rem 1.3rem !important;
    z-index: 3;
}

.dialog-head h2 {
    margin: 0;
    font-size: 1.1rem;
}

.dialog-head .btn.ghost {
    color: var(--text);
}

#bond-body,
#deal-body {
    padding: 1rem 1.3rem 1.2rem;
    display: flex;
    flex-direction: column;
    gap: .55rem;
}

.dialog-actions {
    display: flex;
    gap: .6rem;
    padding: .8rem 1.3rem 1.2rem !important;
    border-top: 1px solid var(--line);
    position: sticky;
    bottom: 0;
    background: #fff;
}

/* Login */
.login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 1rem;
}

.login-card {
    width: min(420px, 100%);
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 1.2rem;
    box-shadow: 0 10px 30px rgba(15, 32, 39, .08);
}

/* Admin */
.admin-section {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 1rem 1.2rem;
    margin: 1rem 0;
}

.admin-section h3 {
    margin: 0 0 .3rem;
}

.admin-form {
    display: flex;
    flex-wrap: wrap;
    gap: .5rem;
    align-items: center;
    margin: .6rem 0;
}

.admin-form input,
.admin-form select {
    width: auto;
    flex: 1 1 160px;
}

.admin-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: .4rem 1rem;
    align-items: end;
}

/* Methodology */
.prose {
    max-width: 900px;
}

.prose h4 {
    margin: 1.2rem 0 .3rem;
    color: var(--ink);
}

.prose math {
    font-size: 1.15rem;
    margin: .6rem 0;
}

/* Vega embed: keep the export menu compact */
.vega-embed {
    width: 100%;
}

.vega-embed summary {
    font-weight: normal;
}