/* Soak Web UI - Main Stylesheet */

/* Ancizar Sans Variable Font */
@font-face {
    font-family: 'Ancizar Sans';
    src: url('../fonts/AncizarSans-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: normal;
    font-display: swap;
}

@font-face {
    font-family: 'Ancizar Sans';
    src: url('../fonts/AncizarSans-Italic-VariableFont_wght.ttf') format('truetype');
    font-weight: 100 900;
    font-style: italic;
    font-display: swap;
}

:root {
    /* Brand colours from watercolor hero */
    --deep-twilight: #1A1753;
    --honey-bronze: #FBB75C;
    --vivid-tangerine: #F28126;
    --frosted-blue: #8CD6E5;
    --blue-green: #38A0C3;
    --razzmatazz: #DB2E70;

    /* Semantic colour mapping */
    --primary: var(--blue-green);
    --primary-dark: #2a7a94;
    --primary-light: #e0f4f8;
    --secondary: var(--deep-twilight);
    --secondary-light: #e8e7f0;
    --success: #319e8a;
    --success-dark: #257a6b;
    --success-light: #e0f5f1;
    --warning: var(--vivid-tangerine);
    --warning-dark: #c9691e;
    --warning-light: #fef0e3;
    --danger: var(--razzmatazz);
    --danger-dark: #b8255a;
    --danger-light: #fce4ec;
    --info: var(--frosted-blue);
    --info-light: #e8f7fa;

    /* Accent colours */
    --accent-warm: var(--honey-bronze);
    --accent-warm-light: #fef5e7;

    /* Grays - slightly tinted toward deep-twilight */
    --gray-50: #f8f8fa;
    --gray-100: #f0f0f4;
    --gray-200: #e6e6ec;
    --gray-300: #d8d8e0;
    --gray-400: #a8a8b8;
    --gray-500: #6c6c7d;
    --gray-600: #4a4a5a;
    --gray-700: #343445;
    --gray-800: #222230;
    --gray-900: var(--deep-twilight);

    --bg-secondary: var(--gray-50);
    --border-color: var(--gray-200);
    --radius: 0.375rem;
    --radius-sm: 0.25rem;
    --shadow: 0 1px 3px rgba(26, 23, 83, 0.08);
    --shadow-lg: 0 4px 12px rgba(26, 23, 83, 0.12);
    --header-height: 42px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'Ancizar Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: white;
    color: var(--gray-800);
    line-height: 1.5;
    font-size: 0.875rem;
}

code, pre, kbd {
    font-family: 'JetBrains Mono', 'SF Mono', Monaco, monospace;
}

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

/* ========================================
   Layout
   ======================================== */

.container { max-width: 1200px; margin: 0 auto; padding: 0 1rem; }
.container-narrow { max-width: 800px; margin: 0 auto; padding: 0 1rem; }

/* Header - Dark, thin */
header {
    background: var(--gray-900);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 1000;
    height: var(--header-height);
}
.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}
.logo {
    font-size: 0.9rem;
    font-weight: 600;
    color: white;
    text-decoration: none;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    letter-spacing: 0.3px;
}
.logo-img { width: 1.58rem; height: 1.58rem; }
.logo:hover { color: white; }

nav { display: flex; gap: 0; height: 100%; }
nav a {
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    padding: 0 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    height: 100%;
    border-bottom: 2px solid transparent;
}
nav a:hover { color: white; background: rgba(255,255,255,0.05); }
nav a.active { color: white; border-bottom-color: var(--primary); background: rgba(255,255,255,0.05); }
nav .btn {
    margin: 0.35rem 0;
    padding: 0.3rem 0.75rem;
    font-size: 0.75rem;
    background: var(--primary);
    border-radius: var(--radius-sm);
    height: auto;
    border-bottom: none;
}
nav .btn:hover { background: var(--primary-dark); }

.nav-right { display: flex; align-items: center; gap: 0.75rem; height: 100%; }
.user-info {
    font-size: 0.75rem;
    color: rgba(255,255,255,0.6);
}
.nav-right .btn-ghost {
    color: rgba(255,255,255,0.6);
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
}
.nav-right .btn-ghost:hover { color: white; background: rgba(255,255,255,0.1); }

main { padding: 1.5rem 0; min-height: calc(100vh - var(--header-height)); }

/* ========================================
   Cards
   ======================================== */

.card {
    background: white;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    padding: 1.25rem;
    margin-bottom: 1rem;
}
.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--gray-100);
}
.card-title { font-size: 1rem; font-weight: 600; margin: 0; }
.card-sm { padding: 0.875rem; }
.card-flush { padding: 0; }
.card-muted { background: var(--gray-50); border: 1px solid var(--gray-200); }

/* ========================================
   Typography
   ======================================== */

h1 { font-size: 1.5rem; font-weight: 600; margin-bottom: 1rem; letter-spacing: -0.01em; }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.75rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.5rem; }
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 0.8125rem; }
.text-xs { font-size: 0.7rem; }
.font-bold { font-weight: 700; }
.font-medium { font-weight: 500; }

/* ========================================
   Buttons
   ======================================== */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:hover { background: var(--primary-dark); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary { background: white; color: var(--gray-700); border: 1px solid var(--gray-300); }
.btn-secondary:hover { background: var(--gray-50); border-color: var(--gray-400); }
.btn-ghost { background: transparent; color: var(--gray-600); }
.btn-ghost:hover { background: var(--gray-100); color: var(--gray-900); }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: var(--danger-dark); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 1rem; }
.btn-icon { padding: 0.5rem; }
.opacity-50 { opacity: 0.5; }

/* ========================================
   Forms
   ======================================== */

.form-group { margin-bottom: 1.25rem; }
.form-label {
    display: block;
    font-weight: 500;
    margin-bottom: 0.375rem;
    font-size: 0.875rem;
}
.form-label-required::after { content: ' *'; color: var(--danger); }
.form-hint { font-size: 0.8125rem; color: var(--gray-500); margin-top: 0.25rem; }
.form-input, .form-select, .form-textarea {
    width: 100%;
    padding: 0.625rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    font-size: 0.9375rem;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: white;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.form-textarea { resize: vertical; min-height: 100px; }
.form-error { border-color: var(--danger); }
.form-error-message { color: var(--danger); font-size: 0.8125rem; margin-top: 0.25rem; }

/* ========================================
   Grid
   ======================================== */

.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 768px) {
    .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ========================================
   Flex utilities
   ======================================== */

.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.items-start { align-items: flex-start; }
.justify-between { justify-content: space-between; }
.justify-center { justify-content: center; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.gap-4 { gap: 1rem; }

/* ========================================
   Tables
   ======================================== */

.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
}
th {
    font-weight: 600;
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--gray-500);
    background: var(--gray-50);
}
tr:hover { background: var(--gray-50); }
.table-actions { white-space: nowrap; }

/* ========================================
   Status badges
   ======================================== */

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 500;
}
.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--blue-green); }
.badge-gray { background: var(--gray-100); color: var(--gray-600); }

/* ========================================
   Stats
   ======================================== */

.stat { text-align: center; padding: 1rem; }
.stat-value { font-size: 1.75rem; font-weight: 700; color: var(--primary); line-height: 1.2; }
.stat-label { font-size: 0.8125rem; color: var(--gray-500); margin-top: 0.25rem; }

/* ========================================
   Tabs
   ======================================== */

.tabs {
    display: flex;
    border-bottom: 1px solid var(--gray-200);
    gap: 0;
    margin-bottom: 1.5rem;
}
.tab {
    padding: 0.75rem 1rem;
    color: var(--gray-500);
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: all 0.15s;
    cursor: pointer;
    background: none;
    border-left: none;
    border-right: none;
    border-top: none;
}
.tab:hover { color: var(--gray-700); }
.tab.active, .tab[aria-selected="true"] {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab-panel { display: none; }
.tab-panel.active, .tab-panel[aria-hidden="false"] { display: block; }

/* ========================================
   Progress bars
   ======================================== */

.progress {
    height: 0.5rem;
    background: var(--gray-200);
    border-radius: 9999px;
    overflow: hidden;
}
.progress-bar {
    height: 100%;
    background: var(--primary);
    border-radius: 9999px;
    transition: width 0.3s ease;
}
.progress-bar-success { background: var(--success); }
.progress-bar-warning { background: var(--warning); }

/* ========================================
   Alerts
   ======================================== */

.alert {
    padding: 1rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1rem;
    font-size: 0.875rem;
}
.alert-info { background: var(--primary-light); color: var(--primary-dark); }
.alert-success { background: var(--success-light); color: var(--success-dark); }
.alert-warning { background: var(--warning-light); color: var(--warning-dark); }
.alert-danger { background: var(--danger-light); color: var(--danger-dark); }

/* ========================================
   File upload zone
   ======================================== */

.upload-zone {
    border: 2px dashed var(--gray-300);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    transition: all 0.15s;
    cursor: pointer;
}
.upload-zone:hover, .upload-zone.drag-over {
    border-color: var(--primary);
    background: var(--primary-light);
}
.upload-zone-icon { font-size: 2rem; color: var(--gray-400); margin-bottom: 0.5rem; }
.upload-zone-text { color: var(--gray-600); }
.upload-zone-hint { font-size: 0.8125rem; color: var(--gray-400); margin-top: 0.25rem; }

/* ========================================
   Document list
   ======================================== */

.doc-list { list-style: none; }
.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-sm);
    margin-bottom: 0.5rem;
    background: white;
}
.doc-item-info { display: flex; align-items: center; gap: 0.75rem; }
.doc-item-icon { color: var(--gray-400); }
.doc-item-name { font-weight: 500; }
.doc-item-meta { font-size: 0.8125rem; color: var(--gray-500); }
.doc-item-remove {
    color: var(--gray-400);
    cursor: pointer;
    padding: 0.25rem;
    border-radius: var(--radius-sm);
    background: transparent;
    border: none;
}
.doc-item-remove:hover { color: var(--danger); background: var(--danger-light); }

/* ========================================
   Offcanvas / Sidebar
   ======================================== */

.offcanvas {
    position: fixed;
    top: var(--header-height, 42px);
    right: -400px;
    width: 400px;
    max-width: 100%;
    height: calc(100vh - var(--header-height, 42px));
    background: white;
    box-shadow: var(--shadow-lg);
    transition: right 0.3s ease;
    z-index: 900;
    display: flex;
    flex-direction: column;
}
.offcanvas.open { right: 0; }
.offcanvas-lg { width: 600px; }
.offcanvas-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--gray-200);
}
.offcanvas-title { font-weight: 600; font-size: 1rem; }
.offcanvas-body { padding: 1.5rem; flex: 1; overflow-y: auto; }
.offcanvas-backdrop {
    position: fixed;
    top: var(--header-height, 42px);
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 899;
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
}
.offcanvas-backdrop.open { opacity: 1; visibility: visible; }

/* ========================================
   Modal
   ======================================== */

.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 999;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}
.modal-backdrop.open { opacity: 1; visibility: visible; }

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    background: white;
    border-radius: var(--radius);
    box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
    z-index: 1000;
    width: 100%;
    max-width: 400px;
    opacity: 0;
    visibility: hidden;
    transition: all 0.2s;
}
.modal.open {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, -50%) scale(1);
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--gray-200);
}
.modal-header h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.modal-body { padding: 1.25rem; }
.modal-body p { margin-bottom: 0.5rem; }
.modal-body p:last-child { margin-bottom: 0; }
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--gray-200);
    background: var(--gray-50);
    border-radius: 0 0 var(--radius) var(--radius);
}

/* ========================================
   Text colour utilities
   ======================================== */

.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warning { color: var(--warning); }

/* ========================================
   Empty state
   ======================================== */

.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 1rem; opacity: 0.5; }
.empty-state-title { font-size: 1.125rem; font-weight: 600; color: var(--gray-700); margin-bottom: 0.5rem; }

/* ========================================
   Cost display
   ======================================== */

.cost-display {
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
}
.cost-display-row {
    display: flex;
    justify-content: space-between;
    padding: 0.25rem 0;
}
.cost-display-label { color: var(--gray-600); }
.cost-display-value { font-weight: 600; }
.cost-display-primary { font-size: 1.25rem; color: var(--primary); }

/* ========================================
   Pipeline card
   ======================================== */

.pipeline-card {
    border: 2px solid var(--gray-200);
    border-radius: var(--radius);
    padding: 1rem;
    cursor: pointer;
    transition: all 0.15s;
}
.pipeline-card:hover { border-color: var(--gray-300); background: var(--gray-50); }
.pipeline-card.selected { border-color: var(--primary); background: var(--primary-light); }
.pipeline-card-name { font-weight: 600; margin-bottom: 0.25rem; }
.pipeline-card-desc { font-size: 0.875rem; color: var(--gray-600); }

/* ========================================
   Quote card
   ======================================== */

.quote-card {
    border-left: 3px solid var(--primary);
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    margin-bottom: 0.75rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}
.quote-text { font-style: italic; margin-bottom: 0.5rem; }
.quote-source { font-size: 0.8125rem; color: var(--gray-500); }

/* ========================================
   Code tag
   ======================================== */

.code-tag {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.5rem;
    background: var(--gray-100);
    border-radius: var(--radius-sm);
    font-size: 0.8125rem;
    margin: 0.125rem;
}

/* ========================================
   Theme card
   ======================================== */

.theme-card {
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 1rem;
}
.theme-card-header {
    padding: 1rem;
    background: var(--gray-50);
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.theme-card-header:hover { background: var(--gray-100); }
.theme-card-body { padding: 1rem; border-top: 1px solid var(--gray-200); }
.theme-card-name { font-weight: 600; }
.theme-card-codes { margin-top: 0.5rem; }

/* ========================================
   DAG Nodes (Pipeline Progress)
   ======================================== */

.dag-nodes {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}
.dag-node {
    padding: 0.75rem 1rem;
    background: white;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    cursor: pointer;
    transition: all 0.15s;
    min-width: 120px;
}
.dag-node:hover { border-color: var(--primary); }
.dag-node.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}
.dag-node-name { font-weight: 500; font-size: 0.875rem; }
.dag-node-type { font-size: 0.75rem; color: var(--gray-500); }

/* ========================================
   List filters
   ======================================== */

.list-filters {
    padding: 0.75rem 1rem;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}
.list-filters .form-input,
.list-filters .form-select {
    background: white;
    font-size: 0.8125rem;
    padding: 0.4rem 0.6rem;
}

/* ========================================
   UUID tag
   ======================================== */

.uuid-tag {
    font-size: 0.75rem;
    background: var(--gray-100);
    padding: 0.125rem 0.375rem;
    border-radius: 0.25rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--gray-600);
}

/* ========================================
   Result preview
   ======================================== */

.result-preview {
    max-height: 400px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 1rem;
    background: white;
}

/* ========================================
   Utilities
   ======================================== */

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-3 { margin-top: 0.75rem; }
.mt-4 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 0.25rem; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.p-0 { padding: 0; }
.p-1 { padding: 0.25rem; }
.p-2 { padding: 0.5rem; }
.p-3 { padding: 0.75rem; }
.p-4 { padding: 1rem; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }

/* ========================================
   HTMX loading indicator
   ======================================== */

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

/* ========================================
   Spinner
   ======================================== */

.spinner {
    display: inline-block;
    width: 1rem;
    height: 1rem;
    border: 2px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ========================================
   Alpine.js cloak
   ======================================== */

[x-cloak] { display: none !important; }

/* ========================================
   TomSelect overrides
   ======================================== */

.ts-wrapper { font-size: 0.9375rem; }
.ts-wrapper.multi .ts-control {
    padding: 0.375rem 0.5rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    background: white;
}
.ts-wrapper.multi .ts-control:focus,
.ts-wrapper.multi.focus .ts-control {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}
.ts-wrapper .ts-control .item {
    background: var(--primary-light);
    color: var(--primary);
    border: none;
    border-radius: var(--radius-sm);
    padding: 0.25rem 0.5rem;
    font-size: 0.8125rem;
}
.ts-wrapper .ts-dropdown {
    border: 1px solid var(--gray-300);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
}
.ts-wrapper .ts-dropdown .option {
    padding: 0.5rem 0.75rem;
}
.ts-wrapper .ts-dropdown .option.active {
    background: var(--primary-light);
    color: var(--primary);
}
.ts-wrapper .ts-dropdown .option .text-muted {
    color: var(--gray-500);
    font-size: 0.75rem;
}

/* Document processing status */
.doc-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.875rem;
}
.doc-status-processing {
    color: var(--warning);
}
.doc-status-ready {
    color: var(--success);
}
.doc-status-failed {
    color: var(--danger);
}
