/* ============ Design tokens ============ */
:root {
    color-scheme: light;
    --brand-blue: #005ec9;
    --brand-blue-hover: #004fa8;
    --brand-green: #34a853;

    --bg: #f4f6fa;
    --surface: #ffffff;
    --surface-muted: #f8f9fc;
    --border: #e2e6ee;
    --border-strong: #cdd3df;
    --text: #172033;
    --text-muted: #5b667a;
    --text-faint: #8a93a6;
    --focus: rgba(0, 94, 201, 0.35);

    --danger: #c9302c;
    --danger-bg: #fdecec;
    --danger-border: #f3c2c0;
    --warn: #9a5b00;
    --warn-bg: #fff5e0;
    --warn-border: #f5d9a3;

    /* Event feed */
    --console-bg: #f6f8fb;
    --console-row: #ffffff;
    --console-row-hover: #eef3fb;
    --console-border: #e2e6ee;
    --console-text: #1f2a3d;
    --console-muted: #6b7489;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 4px 16px rgba(16, 24, 40, 0.06);

    --font: "Segoe UI", -apple-system, BlinkMacSystemFont, "Helvetica Neue", Roboto, Arial, sans-serif;
    --mono: ui-monospace, "Cascadia Code", "SF Mono", Consolas, "Liberation Mono", monospace;
}

/* ============ Base ============ */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

h1,
h2,
p {
    margin: 0;
}

code {
    font-family: var(--mono);
    font-size: 0.9em;
}

button {
    font: inherit;
    cursor: pointer;
}

button:disabled {
    cursor: not-allowed;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

[hidden] {
    display: none !important;
}

/* ============ Top bar ============ */
.topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
}

.topbar-inner {
    max-width: 1240px;
    margin: 0 auto;
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.brand-logo {
    height: 22px;
    width: auto;
    display: block;
}

.brand-divider {
    width: 1px;
    height: 20px;
    background: var(--border-strong);
}

.brand-product {
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.01em;
}

/* ============ Layout ============ */
.page {
    flex: 1;
    width: 100%;
    max-width: 1240px;
    margin: 0 auto;
    padding: 32px 24px 24px;
}

.intro {
    max-width: 760px;
    margin-bottom: 28px;
}

.intro h1 {
    font-size: 28px;
    line-height: 1.25;
    font-weight: 700;
    letter-spacing: -0.01em;
    margin-bottom: 8px;
}

.intro p {
    color: var(--text-muted);
}

.steps {
    list-style: none;
    padding: 0;
    margin: 18px 0 0;
    display: flex;
    flex-wrap: wrap;
    gap: 8px 22px;
    color: var(--text-muted);
    font-size: 14px;
}

.steps li {
    display: flex;
    align-items: center;
    gap: 8px;
}

.step-num {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: var(--brand-blue);
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
    gap: 20px;
    align-items: start;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px;
}

.panel-title {
    font-size: 16px;
    font-weight: 650;
}

/* ============ Provider tabs ============ */
.provider-tabs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 16px 0 20px;
}

.provider-tab {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 2px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text);
    text-align: left;
    transition: border-color 0.15s, background 0.15s;
}

.provider-tab:hover:not(:disabled) {
    border-color: var(--border-strong);
}

.provider-tab[aria-selected="true"] {
    border-color: var(--brand-blue);
    background: var(--surface);
    box-shadow: inset 0 0 0 1px var(--brand-blue);
}

.provider-tab:disabled {
    opacity: 0.55;
}

.provider-name {
    font-weight: 600;
    font-size: 14px;
}

.provider-service {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============ Form ============ */
.field {
    margin-bottom: 16px;
    min-width: 0;
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    margin-bottom: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
textarea {
    width: 100%;
    padding: 9px 12px;
    font: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--surface);
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    transition: border-color 0.15s, box-shadow 0.15s;
}

textarea {
    font-family: var(--mono);
    font-size: 12.5px;
    resize: vertical;
    min-height: 72px;
    word-break: break-all;
}

input::placeholder,
textarea::placeholder {
    color: var(--text-faint);
}

input:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand-blue);
    box-shadow: 0 0 0 3px var(--focus);
}

.field.invalid input,
.field.invalid textarea,
.field.invalid .dropzone {
    border-color: var(--danger);
}

.hint {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.field-error {
    margin-top: 6px;
    font-size: 12.5px;
    color: var(--danger);
}

.input-with-action {
    position: relative;
}

.input-with-action input {
    padding-right: 64px;
}

.input-action {
    position: absolute;
    top: 50%;
    right: 6px;
    transform: translateY(-50%);
    border: 0;
    background: transparent;
    color: var(--brand-blue);
    font-size: 13px;
    font-weight: 600;
    padding: 4px 8px;
    border-radius: 6px;
}

.dropzone {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 64px;
    padding: 12px;
    border: 1.5px dashed var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 400;
    font-size: 14px;
    text-align: center;
    cursor: pointer;
    margin: 0;
    transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.dragover {
    border-color: var(--brand-blue);
}

.dropzone.has-file {
    border-style: solid;
    border-color: var(--brand-green);
    color: var(--text);
}

.dropzone input {
    position: absolute;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.form-error {
    margin: 4px 0 16px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
    background: var(--danger-bg);
    border: 1px solid var(--danger-border);
    color: var(--danger);
    font-size: 13.5px;
}

.actions {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 10px;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 18px;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    font-weight: 600;
    font-size: 14px;
    transition: background 0.15s, border-color 0.15s, opacity 0.15s;
}

.btn-primary {
    background: var(--brand-blue);
    color: #fff;
}

.btn-primary:hover:not(:disabled) {
    background: var(--brand-blue-hover);
}

.btn-danger {
    background: var(--surface);
    color: var(--danger);
    border-color: var(--danger-border);
}

.btn-danger:hover:not(:disabled) {
    background: var(--danger-bg);
}

.btn:disabled {
    opacity: 0.5;
}

.btn.loading .btn-label::before {
    content: "";
    display: inline-block;
    width: 13px;
    height: 13px;
    margin-right: 8px;
    vertical-align: -2px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.link-button {
    display: block;
    margin: 14px auto 0;
    border: 0;
    background: none;
    color: var(--brand-blue);
    font-size: 13px;
    padding: 4px;
}

.link-button:hover {
    text-decoration: underline;
}

/* ============ Console ============ */
.console {
    display: flex;
    flex-direction: column;
    min-height: 620px;
}

.console-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
}

.console-target {
    margin-top: 2px;
    font-size: 13px;
    color: var(--text-muted);
    word-break: break-all;
}

.status-pill {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 4px 11px;
    border-radius: 999px;
    font-size: 12.5px;
    font-weight: 650;
    background: var(--surface-muted);
    color: var(--text-muted);
    border: 1px solid var(--border);
}

.status-pill::before {
    content: "";
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: currentColor;
}

.status-pill[data-status="connecting"],
.status-pill[data-status="stopping"] {
    color: var(--brand-blue);
}

.status-pill[data-status="streaming"] {
    color: var(--brand-green);
    border-color: color-mix(in srgb, var(--brand-green) 40%, transparent);
}

.status-pill[data-status="streaming"]::before {
    animation: pulse 1.6s ease-in-out infinite;
}

.status-pill[data-status="waiting"] {
    color: var(--warn);
}

.status-pill[data-status="failed"] {
    color: var(--danger);
    border-color: var(--danger-border);
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
    margin: 18px 0 14px;
}

.metric {
    padding: 10px 12px;
    background: var(--surface-muted);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    min-width: 0;
}

.metric-label {
    display: block;
    font-size: 12px;
    color: var(--text-muted);
}

.metric-value {
    display: block;
    margin-top: 2px;
    font-size: 19px;
    font-weight: 650;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.alert {
    margin-bottom: 14px;
    padding: 12px 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface-muted);
    font-size: 14px;
}

.alert[data-kind="user"] {
    background: var(--warn-bg);
    border-color: var(--warn-border);
}

.alert[data-kind="server"] {
    background: var(--danger-bg);
    border-color: var(--danger-border);
}

.alert-title {
    font-weight: 650;
    margin-bottom: 2px;
}

.alert[data-kind="user"] .alert-title {
    color: var(--warn);
}

.alert[data-kind="server"] .alert-title {
    color: var(--danger);
}

.alert-reference {
    margin-top: 8px;
    font-size: 13px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
    word-break: break-all;
}

.alert-detail {
    margin-top: 8px;
    font-size: 12.5px;
    color: var(--text-muted);
}

.alert-detail summary {
    cursor: pointer;
}

.alert-detail code {
    display: block;
    margin-top: 6px;
    white-space: pre-wrap;
    word-break: break-word;
}

.chip-button {
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    border-radius: 6px;
    font-size: 12px;
    padding: 2px 8px;
}

.feed-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    margin-bottom: 8px;
    font-size: 13px;
}

.feed-caption {
    font-weight: 600;
}

.feed-hint {
    font-weight: 400;
    color: var(--text-muted);
}

.toggle {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin: 0;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    white-space: nowrap;
}

.feed {
    flex: 1;
    min-height: 360px;
    max-height: 560px;
    overflow-y: auto;
    background: var(--console-bg);
    border: 1px solid var(--console-border);
    border-radius: var(--radius-sm);
    padding: 6px;
    font-family: var(--mono);
    font-size: 12.5px;
    color: var(--console-text);
}

.feed-empty {
    height: 100%;
    min-height: 340px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 4px;
    color: var(--console-muted);
    font-family: var(--font);
    font-size: 14px;
    padding: 20px;
}

.feed-empty-sub {
    font-size: 12.5px;
    opacity: 0.8;
}

.event {
    border-radius: 6px;
    margin-bottom: 3px;
    background: var(--console-row);
    border: 1px solid var(--console-border);
}

.event.new {
    animation: flash 1.2s ease-out;
}

.event-summary {
    display: grid;
    grid-template-columns: auto auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    background: none;
    color: inherit;
    font: inherit;
    text-align: left;
    border-radius: 6px;
}

.event-summary:hover {
    background: var(--console-row-hover);
}

.event-time {
    color: var(--console-muted);
}

.event-seq {
    color: var(--console-muted);
    min-width: 5ch;
}

.event-main {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.event-type {
    flex-shrink: 0;
    padding: 1px 8px;
    border-radius: 4px;
    font-weight: 600;
    background: #e7f0fc;
    color: #0b56b3;
}

.event-type[data-group="purchase"] {
    background: #e5f5ea;
    color: #1d7a38;
}

.event-type[data-group="cart"] {
    background: #fff2d9;
    color: #8a5800;
}

.event-type[data-group="auth"] {
    background: #f0eafe;
    color: #6034c7;
}

.event-ids {
    color: var(--console-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.event-chevron {
    color: var(--console-muted);
    transition: transform 0.15s;
}

.event.open .event-chevron {
    transform: rotate(90deg);
}

.event-body {
    position: relative;
    padding: 0 10px 10px;
}

.event-body pre {
    margin: 0;
    padding: 10px 12px;
    background: var(--console-bg);
    border: 1px solid var(--console-border);
    border-radius: 6px;
    overflow-x: auto;
    white-space: pre;
    color: var(--console-text);
    font-family: var(--mono);
    font-size: 12px;
    line-height: 1.55;
}

.event-body .chip-button {
    position: absolute;
    top: 8px;
    right: 18px;
    background: var(--console-row-hover);
    color: var(--console-text);
    border-color: var(--console-border);
}

/* ============ Footer & toasts ============ */
.footer {
    text-align: center;
    padding: 20px 24px 28px;
    font-size: 12.5px;
    color: var(--text-faint);
}

.toast-stack {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
    max-width: min(380px, calc(100vw - 40px));
}

.toast {
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    background: #172033;
    color: #fff;
    font-size: 14px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    border-left: 4px solid var(--brand-blue);
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.2s, transform 0.2s;
}

.toast.show {
    opacity: 1;
    transform: none;
}

.toast[data-kind="success"] {
    border-left-color: var(--brand-green);
}

.toast[data-kind="error"] {
    border-left-color: #f07a76;
}

/* ============ Animations ============ */
@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.35;
    }
}

@keyframes flash {
    from {
        background: #e2f4e7;
    }

    to {
        background: var(--console-row);
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before {
        animation: none !important;
        transition: none !important;
    }
}

/* ============ Responsive ============ */
@media (max-width: 960px) {
    .workspace {
        grid-template-columns: 1fr;
    }

    .console {
        min-height: 0;
    }
}

@media (max-width: 600px) {
    .page {
        padding: 22px 16px 16px;
    }

    .topbar-inner {
        padding: 12px 16px;
    }

    .intro h1 {
        font-size: 23px;
    }

    .panel {
        padding: 16px;
    }

    .provider-tab {
        padding: 8px 9px;
    }

    .field-row,
    .metrics {
        grid-template-columns: 1fr 1fr;
    }

    .feed-hint {
        display: none;
    }

    .event-summary {
        grid-template-columns: auto minmax(0, 1fr) auto;
        gap: 8px;
    }

    .event-seq {
        display: none;
    }

    .event-ids {
        display: none;
    }
}
