/* === Custom Properties === */
:root {
    --color-bg: #ffffff;
    --color-bg-secondary: #f8f9fa;
    --color-bg-tertiary: #e9ecef;
    --color-text: #212529;
    --color-text-secondary: #495057;
    --color-text-muted: #5a6268;
    --color-primary: #0b5ed7;
    --color-primary-hover: #0a4fc4;
    --color-success: #198754;
    --color-warning: #ffc107;
    --color-error: #dc3545;
    --color-info: #0dcaf0;
    --color-border: #dee2e6;
    --color-focus: #0b5ed7;
    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
    --max-width: 1200px;
    --spacing-xs: 0.25rem;
    --spacing-sm: 0.5rem;
    --spacing-md: 1rem;
    --spacing-lg: 1.5rem;
    --spacing-xl: 2rem;
    --spacing-xxl: 3rem;
    --radius: 6px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.1);
}

/* === Reset === */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

/* === Base === */
html {
    font-size: 16px;
    line-height: 1.6;
}

body {
    font-family: var(--font-family);
    color: var(--color-text);
    background: var(--color-bg);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1;
    max-width: var(--max-width);
    width: 100%;
    margin: 0 auto;
    padding: var(--spacing-xl) var(--spacing-lg);
}

/* === Skip Link === */
.skip-link {
    position: absolute;
    top: -100%;
    left: var(--spacing-md);
    background: var(--color-primary);
    color: #fff;
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius);
    z-index: 1000;
    text-decoration: none;
    font-weight: 600;
}

.skip-link:focus {
    top: var(--spacing-sm);
}

/* === Focus === */
:focus-visible {
    outline: 2px solid var(--color-focus);
    outline-offset: 2px;
}

:focus:not(:focus-visible) {
    outline: none;
}

/* === Typography === */
h1, h2, h3, h4, h5, h6 {
    line-height: 1.3;
    margin-bottom: var(--spacing-md);
    color: var(--color-text);
}

h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.25rem; }

p { margin-bottom: var(--spacing-md); }

a {
    color: var(--color-primary);
    text-decoration: underline;
}

a:hover {
    color: var(--color-primary-hover);
}

/* === Header/Nav === */
header {
    background: var(--color-bg);
    border-bottom: 1px solid var(--color-border);
    padding: var(--spacing-md) var(--spacing-lg);
}

header nav {
    max-width: var(--max-width);
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--color-text);
    text-decoration: none;
}

.nav-links {
    list-style: none;
    display: flex;
    gap: var(--spacing-lg);
    align-items: center;
}

.nav-links a {
    color: var(--color-text-secondary);
    text-decoration: none;
    font-size: 0.9rem;
}

.nav-links a:hover {
    color: var(--color-primary);
}

.nav-user {
    display: flex;
    gap: var(--spacing-sm);
    align-items: center;
}

.nav-user span {
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* === Footer === */
footer {
    border-top: 1px solid var(--color-border);
    padding: var(--spacing-lg);
    text-align: center;
    color: var(--color-text-muted);
    font-size: 0.875rem;
}

/* === Messages === */
.messages {
    max-width: var(--max-width);
    margin: var(--spacing-md) auto;
    padding: 0 var(--spacing-lg);
}

.message {
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius);
    margin-bottom: var(--spacing-sm);
    font-size: 0.9rem;
}

.message-success { background: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }
.message-warning { background: #fff3cd; color: #664d03; border: 1px solid #ffecb5; }
.message-error { background: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }
.message-info { background: #cff4fc; color: #055160; border: 1px solid #b6effb; }

/* === Buttons === */
.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-lg);
    border: 1px solid transparent;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: background-color 0.15s, border-color 0.15s;
    line-height: 1.5;
}

.btn:disabled, .btn[disabled] {
    opacity: 0.65;
    cursor: not-allowed;
}

.btn-primary {
    background: var(--color-primary);
    color: #fff;
    border-color: var(--color-primary);
}

.btn-primary:hover:not(:disabled) {
    background: var(--color-primary-hover);
    border-color: var(--color-primary-hover);
}

.btn-secondary {
    background: var(--color-bg);
    color: var(--color-text);
    border-color: var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background: var(--color-bg-secondary);
}

.btn-danger {
    background: var(--color-error);
    color: #fff;
    border-color: var(--color-error);
}

.btn-danger:hover:not(:disabled) {
    background: #bb2d3b;
    border-color: #b02a37;
}

/* === Forms === */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-xs);
    font-weight: 500;
    font-size: 0.9rem;
}

.form-control {
    width: 100%;
    padding: var(--spacing-sm) var(--spacing-md);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    font-family: var(--font-family);
    font-size: 1rem;
    line-height: 1.5;
    color: var(--color-text);
    background: var(--color-bg);
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: 2px solid var(--color-primary);
    outline-offset: 2px;
    border-color: var(--color-primary);
    box-shadow: none;
}

textarea.form-control {
    resize: vertical;
    min-height: 100px;
}

.form-error {
    color: var(--color-error);
    font-size: 0.8rem;
    margin-top: var(--spacing-xs);
}

/* === Cards === */
.card {
    background: var(--color-bg);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: var(--spacing-lg);
    box-shadow: var(--shadow);
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: var(--spacing-lg);
}

/* === Status Indicators === */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: var(--spacing-xs);
    padding: 2px var(--spacing-sm);
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 500;
}

.status-running { background: #d1e7dd; color: #0f5132; }
.status-building { background: #fff3cd; color: #664d03; }
.status-failed { background: #f8d7da; color: #842029; }
.status-stopped { background: var(--color-bg-tertiary); color: var(--color-text-secondary); }
.status-drafting { background: #cff4fc; color: #055160; }
.status-queued { background: #e2e3e5; color: #41464b; }
.status-pending { background-color: #e9ecef; color: #495057; }
.status-completed { background: #d1e7dd; color: #0f5132; }

/* === Progress Steps === */
.progress-steps {
    list-style: none;
    counter-reset: step;
}

.progress-steps li {
    counter-increment: step;
    position: relative;
    padding: var(--spacing-sm) 0 var(--spacing-sm) 3rem;
    border-left: 2px solid var(--color-border);
    margin-left: 1rem;
}

.progress-steps li::before {
    content: counter(step);
    position: absolute;
    left: -1rem;
    width: 2rem;
    height: 2rem;
    border-radius: 50%;
    background: var(--color-bg-tertiary);
    color: var(--color-text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
}

.progress-steps li.step-active { border-left-color: var(--color-primary); }
.progress-steps li.step-active::before { background: var(--color-primary); color: #fff; }
.progress-steps li.step-complete { border-left-color: var(--color-success); }
.progress-steps li.step-complete::before { background: var(--color-success); color: #fff; }
.progress-steps li.step-failed { border-left-color: var(--color-error); }
.progress-steps li.step-failed::before { background: var(--color-error); color: #fff; }

/* === Tables (admin) === */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: var(--spacing-lg);
}

.table th, .table td {
    padding: var(--spacing-sm) var(--spacing-md);
    text-align: left;
    border-bottom: 1px solid var(--color-border);
}

.table th {
    font-weight: 600;
    color: var(--color-text-secondary);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* === Conversation / Chat === */
.conversation {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-md);
    margin-bottom: var(--spacing-lg);
}

.chat-message {
    padding: var(--spacing-md);
    border-radius: var(--radius);
    max-width: 80%;
}

.chat-message.user-message {
    background: var(--color-primary);
    color: #fff;
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.chat-message.assistant-message {
    background: var(--color-bg-secondary);
    color: var(--color-text);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.chat-message time {
    display: block;
    font-size: 0.75rem;
    margin-top: var(--spacing-xs);
    opacity: 0.7;
}

/* === Log Stream === */
.log-stream {
    background: #1e1e1e;
    color: #d4d4d4;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    padding: var(--spacing-md);
    border-radius: var(--radius);
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.4;
}

/* === HTMX Loading === */
.htmx-indicator {
    display: none;
}

.htmx-request .htmx-indicator {
    display: inline-block;
}

.htmx-request.htmx-indicator {
    display: inline-block;
}

/* Visual feedback while HTMX request is in-flight on a button */
button.htmx-request {
    opacity: 0.6;
    pointer-events: none;
    cursor: wait;
}

/* === Utility === */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.text-center { text-align: center; }
.text-muted { color: var(--color-text-muted); }
.mt-sm { margin-top: var(--spacing-sm); }
.mt-md { margin-top: var(--spacing-md); }
.mt-lg { margin-top: var(--spacing-lg); }
.mt-xl { margin-top: var(--spacing-xl); }
.mt-xxs { margin-top: var(--spacing-xs); }
.mb-md { margin-bottom: var(--spacing-md); }
.mb-lg { margin-bottom: var(--spacing-lg); }
.details-toggle { cursor: pointer; font-weight: 500; }
.empty-state { padding: 3rem; }
.btn-sm { font-size: 0.8rem; padding: 0.25rem 0.75rem; }
.text-small { font-size: 0.85rem; }

/* === Layout utilities === */
.max-w-md { max-width: 700px; margin-left: auto; margin-right: auto; }
.max-w-lg { max-width: 900px; margin-left: auto; margin-right: auto; }
.max-w-xl { max-width: 1200px; margin-left: auto; margin-right: auto; }

/* === Flex utilities === */
.d-flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.align-items-center { align-items: center; }
.align-items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.flex-column { flex-direction: column; }
.gap-xs { gap: 0.25rem; }
.gap-sm { gap: 0.5rem; }
.gap-md { gap: 1rem; }
.gap-lg { gap: 1.5rem; }

/* === Spacing utilities === */
.mt-auto { margin-top: auto; }
.mb-0 { margin-bottom: 0; }
.mb-xs { margin-bottom: 0.25rem; }
.mb-sm { margin-bottom: 0.5rem; }
.p-lg { padding: 3rem; }

/* === Typography utilities === */
.text-sm { font-size: 0.9rem; }

/* === Card layout utilities === */
.card-header-row { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 0.5rem; }
.card-actions { display: flex; gap: 0.5rem; margin-top: auto; }
.card-title { font-size: 1.1rem; margin-bottom: 0; }

/* === List utilities === */
.list-unstyled { list-style: none; padding: 0; }
.list-item-row { display: flex; justify-content: space-between; align-items: center; padding: 0.5rem 0; border-bottom: 1px solid var(--color-border); }

/* === Integration card === */
.integration-card { display: flex; justify-content: space-between; align-items: center; }
.integration-name { margin-bottom: 0.25rem; }

/* === Form row === */
.form-row { display: flex; align-items: center; gap: 0.5rem; }

/* === Action row === */
.action-row { display: flex; gap: 1rem; flex-wrap: wrap; }

/* === Auth layout === */
.auth-container { max-width: 400px; margin: var(--spacing-xxl) auto; text-align: center; }
.btn-full { width: 100%; justify-content: center; }

/* === Divider === */
.divider {
    display: flex;
    align-items: center;
    color: var(--color-text-muted);
}
.divider::before, .divider::after {
    content: "";
    flex: 1;
    border-bottom: 1px solid var(--color-border);
}
.divider span {
    padding: 0 var(--spacing-sm);
}

/* === Responsive === */
@media (max-width: 768px) {
    main {
        padding: var(--spacing-md);
    }

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

    header nav {
        flex-direction: column;
        gap: var(--spacing-sm);
    }

    .nav-links {
        flex-wrap: wrap;
        justify-content: center;
    }
}

/* === Expiry Banner === */
.expiry-banner {
    max-width: var(--max-width);
    margin: var(--spacing-md) auto;
    padding: 0;
}

.expiry-banner-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--spacing-sm) var(--spacing-md);
    background: #fff3cd;
    color: #664d03;
    border: 1px solid #ffecb5;
    border-radius: var(--radius);
    margin-bottom: var(--spacing-xs);
    font-size: 0.9rem;
}

.expiry-banner-item p {
    margin: 0;
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
    flex-wrap: wrap;
}

.expiry-banner-close {
    flex-shrink: 0;
    background: transparent;
    border: 1px solid #664d03;
    color: #664d03;
    font-size: 1.2rem;
    line-height: 1;
    padding: var(--spacing-xs) var(--spacing-sm);
}

.expiry-banner-close:hover {
    background: rgba(0, 0, 0, 0.1);
}

/* ================================================================
   Admin Dashboard Styles
   ================================================================ */

/* Admin Navigation */
.admin-nav {
    padding: 0.75rem 1.5rem;
    border-bottom: 1px solid var(--color-border, #e0e0e0);
    background: var(--color-bg-secondary, #f8f9fa);
}

.admin-nav ul {
    list-style: none;
    margin: 0;
    padding: 0;
    display: flex;
    gap: 1.5rem;
}

.admin-nav a {
    text-decoration: none;
    color: var(--color-text-secondary, #6c757d);
    padding: 0.25rem 0;
}

.admin-nav a.active {
    color: var(--color-text, #212529);
    font-weight: 600;
    border-bottom: 2px solid var(--color-primary, #0d6efd);
}

/* Stats Grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    padding: 1rem;
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 0.375rem;
    text-align: center;
}

.stat-card .stat-value {
    display: block;
    font-size: 1.5rem;
    font-weight: 700;
}

.stat-card .stat-label {
    display: block;
    font-size: 0.875rem;
    color: var(--color-text-secondary, #6c757d);
}

/* Health Check Indicators */
.health-checks ul {
    list-style: none;
    padding: 0;
    display: flex;
    gap: 1.5rem;
}

.health-ok::before {
    content: "";
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #198754;
    margin-right: 0.5rem;
}

.health-down::before {
    content: "";
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    background: #dc3545;
    margin-right: 0.5rem;
}

/* Admin Tables */
.admin-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
}

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

.admin-table th {
    font-weight: 600;
    background: var(--color-bg-secondary, #f8f9fa);
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 0.25rem;
    font-size: 0.75rem;
    font-weight: 600;
}

.badge-pending { background: #ffc107; color: #212529; }
.badge-in_progress { background: #0dcaf0; color: #212529; }
.badge-completed, .badge-ok { background: #198754; color: #fff; }
.badge-failed, .badge-down { background: #dc3545; color: #fff; }
.badge-queued { background: #6c757d; color: #fff; }
.badge-running { background: #0d6efd; color: #fff; }
.badge-stopped { background: #6c757d; color: #fff; }

/* Dashboard Status (polling container) */
.dashboard-status {
    margin-bottom: 2rem;
}

.dashboard-status.poll-error {
    opacity: 0.7;
}

/* Mutation Error */
.mutation-error {
    color: #dc3545;
    font-size: 0.75rem;
    display: block;
    margin-top: 0.25rem;
}

/* Admin Content */
.admin-content {
    padding: 1.5rem;
}

/* Filter Bar */
.filter-bar {
    margin-bottom: 1rem;
}

.filter-bar label {
    margin-right: 0.5rem;
    font-weight: 600;
}

.filter-bar select {
    padding: 0.375rem 0.75rem;
    border: 1px solid var(--color-border, #e0e0e0);
    border-radius: 0.25rem;
}

/* User Detail */
.user-header {
    margin-bottom: 1.5rem;
}

.infrastructure-section {
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--color-bg-secondary, #f8f9fa);
    border-radius: 0.375rem;
}

.infrastructure-section dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
    margin: 0;
}

.infrastructure-section dt {
    font-weight: 600;
}

.integration-status {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.5rem 1rem;
}

.integration-status dt {
    font-weight: 600;
}

.user-actions {
    margin-top: 1.5rem;
}
