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

:root {
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --success: #16a34a;
    --danger: #dc2626;
    --warning: #f59e0b;
    --bg: #f8fafc;
    --surface: #ffffff;
    --border: #e2e8f0;
    --text: #1e293b;
    --text-muted: #64748b;
    --radius: 6px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Navigation progress bar */
.nav-progress {
    position: fixed;
    top: 0;
    left: 0;
    height: 3px;
    width: 0;
    background: var(--primary);
    z-index: 9999;
    pointer-events: none;
    transition: none;
}

.nav-progress.active {
    width: 90%;
    transition: width 8s cubic-bezier(0.1, 0.5, 0.3, 1);
}

/* Navbar */
.navbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 1.5rem;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand a {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    text-decoration: none;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.nav-link {
    padding: 0.5rem 0.75rem;
    color: var(--text-muted);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    transition: color 0.15s, background 0.15s;
}

.nav-link:hover {
    color: var(--text);
    background: var(--bg);
}

.nav-link.active {
    color: var(--primary);
    font-weight: 600;
}

.nav-user {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-left: 1rem;
    padding-left: 1rem;
    border-left: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-muted);
}

.badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--danger);
    color: white;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    margin-left: 4px;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Cards */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.card-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--text);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.15s;
    gap: 0.375rem;
}

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

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

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

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

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

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

.btn-sm {
    padding: 0.25rem 0.625rem;
    font-size: 0.8125rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    margin-bottom: 0.375rem;
    color: var(--text);
}

.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text);
    background: var(--surface);
    transition: border-color 0.15s;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

select.form-control {
    appearance: auto;
}

textarea.form-control {
    min-height: 200px;
    font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
    font-size: 0.8125rem;
    resize: vertical;
}

/* Tables */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

thead th {
    text-align: left;
    padding: 0.625rem 0.75rem;
    background: var(--bg);
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8125rem;
    text-transform: uppercase;
    letter-spacing: 0.025em;
}

tbody td {
    padding: 0.625rem 0.75rem;
    border-bottom: 1px solid var(--border);
}

tbody tr:hover {
    background: var(--bg);
}

/* Status badges */
.status {
    display: inline-block;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-draft { background: #e2e8f0; color: #475569; }
.status-pending_review { background: #fef3c7; color: #92400e; }
.status-approved { background: #d1fae5; color: #065f46; }
.status-declined { background: #fecaca; color: #991b1b; }
.status-executed { background: #dbeafe; color: #1e40af; }
.status-failed { background: #fecaca; color: #991b1b; }
.status-executing { background: #e0e7ff; color: #3730a3; }

/* Login page */
.login-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 3rem;
    text-align: center;
    max-width: 400px;
    width: 100%;
}

.login-card h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
    margin-bottom: 0.5rem;
}

.login-card p {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

.btn-login {
    width: 100%;
    padding: 0.75rem;
    font-size: 1rem;
}

/* Suggestions panel */
.suggestions-panel {
    background: #fffbeb;
    border: 1px solid #fde68a;
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 1rem;
}

.suggestions-panel h3 {
    font-size: 0.9375rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: #92400e;
}

.suggestion-text {
    font-size: 0.875rem;
    margin-bottom: 0.75rem;
    white-space: pre-wrap;
}

.corrected-sql {
    background: #1e293b;
    color: #e2e8f0;
    padding: 0.75rem;
    border-radius: var(--radius);
    font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
    font-size: 0.8125rem;
    margin-bottom: 0.75rem;
    white-space: pre-wrap;
    overflow-x: auto;
}

.reseller-id-info {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0.75rem;
}

/* Results panel */
.results-panel {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-top: 1rem;
}

.results-panel.success {
    border-color: var(--success);
    background: #f0fdf4;
}

.results-panel.error {
    border-color: var(--danger);
    background: #fef2f2;
}

.results-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-top: 0.5rem;
}

.result-item {
    font-size: 0.875rem;
}

.result-item .label {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.result-item .value {
    font-size: 1rem;
    font-weight: 500;
}

.error-message {
    margin-top: 0.5rem;
    padding: 0.75rem;
    background: #fecaca;
    border-radius: var(--radius);
    font-family: monospace;
    font-size: 0.8125rem;
    color: #991b1b;
    white-space: pre-wrap;
}

.error-container {
    text-align: center;
    padding: 3rem;
}

.error-container h1 {
    color: var(--danger);
    margin-bottom: 1rem;
}

.error-container pre {
    text-align: left;
    background: var(--bg);
    padding: 1rem;
    border-radius: var(--radius);
    overflow-x: auto;
    margin-bottom: 1.5rem;
    font-size: 0.8125rem;
}

/* Query editor toolbar */
.editor-toolbar {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.editor-toolbar select {
    min-width: 200px;
}

/* Review detail */
.sql-readonly {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: var(--radius);
    font-family: "SF Mono", "Monaco", "Menlo", "Consolas", monospace;
    font-size: 0.8125rem;
    white-space: pre-wrap;
    overflow-x: auto;
    margin-bottom: 1rem;
}

.review-meta {
    display: flex;
    gap: 2rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.review-comment {
    margin-bottom: 1rem;
}

.review-comment textarea {
    min-height: 100px;
}

/* Review history */
.review-history {
    margin-top: 1.5rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.review-entry {
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}

.review-entry:last-child {
    border-bottom: none;
}

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

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

.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Utility */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: 0.875rem; }
.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.5rem; }
.gap-2 { gap: 1rem; }

/* Empty state */
.empty-state {
    text-align: center;
    padding: 3rem;
    color: var(--text-muted);
}

/* CodeMirror overrides */
.CodeMirror {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    height: auto;
    min-height: 200px;
    max-height: 500px;
}

/* Filter form */
.filter-form {
    display: flex;
    gap: 0.75rem;
    align-items: end;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.filter-form .form-group {
    margin-bottom: 0;
}
