:root {
    --brand: #EF2B2D;
    --muted: #666;
    --border: #eee;
    --mono: "SF Mono", Monaco, Consolas, monospace;
}

* {
    box-sizing: border-box;
}

body {
    font-family: system-ui, sans-serif;
    line-height: 1.6;
    margin: 0;
    padding: 2rem;
}

button {
    cursor: pointer;
}

.container {
    max-width: 48rem;
    margin: 0 auto;
}

h1 {
    font-size: 1.5rem;
    margin: 0 0 0.5rem;
}

p {
    margin: 0 0 1.5rem;
    color: #444;
}

/* Auth */

#auth {
    text-align: center;
    padding: 4rem 1rem;
}

#auth p {
    max-width: 28rem;
    margin: 0 auto 2rem;
}

#auth .subtitle {
    font-size: 0.875rem;
    margin-top: -1rem;
}

/* App */

#app {
    display: none;
}

#app.visible {
    display: block;
}

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Status pill */

.status {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 999px;
    border: none;
    cursor: pointer;
}

.status .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status.hidden {
    visibility: hidden;
}

.status.loading {
    background: #fef3c7;
    color: #92400e;
}

.status.loading .dot {
    background: #f59e0b;
    animation: pulse 1s infinite;
}

.status.ready {
    background: #dcfce7;
    color: #166534;
}

.status.ready .dot {
    background: #22c55e;
}

.status.running {
    background: #dbeafe;
    color: #1e40af;
}

.status.running .dot {
    background: #3b82f6;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    50% { opacity: 0.4; }
}

/* Buttons */

.btn {
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 4px;
}

.btn-primary {
    background: var(--brand);
    color: white;
    padding: 0.75rem 1.5rem;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: white;
    border: 1px solid #ddd;
    color: var(--muted);
}

.btn-icon {
    width: 2rem;
    height: 2rem;
    background: white;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-family: var(--mono);
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

/* Selectors */

.selector {
    margin: 1.5rem 0;
}

.selector label {
    display: block;
    font-size: 0.875rem;
    color: var(--muted);
    margin-bottom: 0.5rem;
}

.selector select,
.selector input[type="date"] {
    font-size: 1rem;
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    width: 100%;
    max-width: 400px;
}

/* Multiple selectors in a row */

.selectors {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin: 1.5rem 0;
    width: 100%;
    box-sizing: border-box;
}

.selectors .selector {
    margin: 0;
    flex: 1 1 120px;
    min-width: 120px;
    max-width: 100%;
    box-sizing: border-box;
}

.selectors .selector select,
.selectors .selector input[type="date"] {
    max-width: 100%;
    box-sizing: border-box;
}

.selectors .selector-action {
    display: flex;
    align-items: flex-end;
    flex: 0 0 auto;
    min-width: 0;
}

#run-btn-wrapper {
    display: inline-block;
}

#run-btn-wrapper .btn:disabled {
    pointer-events: none;
}

/* Output */

.output-panel {
    display: none;
    background: #fafafa;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.output-panel.visible {
    display: block;
}

#output-status,
#output {
    font-family: var(--mono);
    font-size: 14px;
    padding: 1rem;
}

#output-status {
    color: var(--muted);
    padding-bottom: 0;
}

#output-status:empty {
    display: none;
}

#output > * {
    margin-bottom: 1rem;
    max-width: 100%;
    overflow-x: auto;
}

#output > *:last-child {
    margin-bottom: 0;
}

#output pre {
    background: white;
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.75rem 1rem;
    margin: 0;
    white-space: pre-wrap;
}

#output table {
    border-collapse: collapse;
    font-size: 13px;
}

#output th,
#output td {
    border: 1px solid #ddd;
    padding: 0.5rem 0.75rem;
    text-align: right;
}

#output th {
    background: #f5f5f5;
    font-weight: 600;
}

#output img {
    max-width: 100%;
    height: auto;
}

/* Code modal */

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    padding: 1rem;
    overflow-y: auto;
    box-sizing: border-box;
}

.modal.visible {
    display: flex;
    justify-content: center;
    align-items: flex-start;
}

.modal-content {
    background: white;
    border-radius: 8px;
    width: 100%;
    max-width: 52rem;
    margin: 2rem 0;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
    background: #fafafa;
}

.modal-title {
    font-family: var(--mono);
    font-size: 0.875rem;
    color: var(--muted);
}

.modal-close {
    width: 1.75rem;
    height: 1.75rem;
    border: none;
    background: none;
    font-size: 1.25rem;
    color: var(--muted);
}

.modal-close:hover {
    background: var(--border);
}

.modal-content-sm {
    max-width: 28rem;
    align-self: center;
    margin: 0;
}

.modal-body {
    padding: 1rem;
    line-height: 1.6;
}

.modal-body p {
    margin: 0 0 1rem;
}

.modal-body p:last-child {
    margin-bottom: 0;
}

.modal-body a {
    color: var(--muted);
}

#code-view {
    margin: 0;
    max-height: 70vh;
    overflow: auto;
}

#code-view code {
    display: block;
    font-size: 13px;
    line-height: 1.6;
    padding: 1rem;
}

footer {
    color: var(--muted);
    font-size: 0.875rem;
    text-align: center;
    margin-top: 3rem;
    padding-top: 2rem;
    border-top: 1px solid var(--border);
}

footer a {
    color: var(--muted);
}

@media (max-width: 480px) {
    body {
        padding: 1rem;
    }
    .modal-content {
        margin: 0;
        height: calc(100vh - 2rem);
    }
}
