/* 
 * Metacloud - Katana Aesthetic
 * Sharp. Minimal. Timeless.
 */

:root {
    /* Core palette - restrained, purposeful */
    --ink: #1a1a1a;
    --ink-light: #3d3d3d;
    --ink-muted: #6b6b6b;
    --paper: #fafafa;
    --paper-warm: #f5f4f0;
    --steel: #e8e8e8;
    --steel-dark: #d0d0d0;
    
    /* Accent - a single, deliberate color */
    --accent: #2563eb;
    --accent-hover: #1d4ed8;
    --accent-light: #eff6ff;
    
    /* Danger */
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    
    /* Typography scale */
    --font-xs: 0.75rem;
    --font-sm: 0.875rem;
    --font-base: 1rem;
    --font-lg: 1.125rem;
    --font-xl: 1.5rem;
    --font-2xl: 2rem;
    --font-3xl: 2.5rem;
    
    /* Spacing scale */
    --space-1: 0.25rem;
    --space-2: 0.5rem;
    --space-3: 0.75rem;
    --space-4: 1rem;
    --space-5: 1.5rem;
    --space-6: 2rem;
    --space-8: 3rem;
    --space-10: 4rem;
    --space-12: 6rem;
    
    /* Effects - subtle */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04);
    --shadow-md: 0 2px 8px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.08);
    --radius: 4px;
    --transition: 150ms ease;
}

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

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-x: hidden;  /* Single place to prevent horizontal scroll */
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    font-size: var(--font-base);
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper-warm);
    min-height: 100vh;
}

/* Typography */
h1, h2, h3, h4, h5, h6 {
    font-weight: 600;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

h1 { font-size: var(--font-2xl); }
h2 { font-size: var(--font-xl); }
h3 { font-size: var(--font-lg); }

p {
    color: var(--ink-light);
}

/* Links */
a {
    color: var(--accent);
    text-decoration: none;
    transition: color var(--transition);
}

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

/* Header - clean bar */
.header {
    display: flex;
    align-items: center;
    padding: 0 var(--space-6);
    height: 64px;
    background: rgba(250, 250, 250, 0.95);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--steel);
    position: sticky;
    top: 0;
    z-index: 100;
    transform: translateZ(0);  /* GPU layer for smooth scroll with backdrop-filter */
}

.header a {
    color: var(--ink);
    font-weight: 500;
}

.header a:hover {
    color: var(--accent);
}

.header img {
    width: 32px;
    height: 32px;
}

.header .d-flex {
    width: 100%;
    display: flex;
    align-items: center;
}

.header .p-2 {
    padding: var(--space-3);
}

.header .me-auto {
    margin-right: auto;
}

/* Container */
.container {
    max-width: 720px;
    margin: 0 auto;
    padding: var(--space-8) var(--space-6);
}

/* Buttons */
button, .btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-family: inherit;
    font-size: var(--font-sm);
    font-weight: 500;
    line-height: 1;
    padding: var(--space-3) var(--space-5);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    transition: all var(--transition);
    background: var(--ink);
    color: var(--paper);
}

button:hover, .btn:hover {
    background: var(--ink-light);
    transform: translateY(-1px);
}

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

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

.btn-secondary {
    background: var(--steel);
    color: var(--ink);
}

.btn-secondary:hover {
    background: var(--steel-dark);
}

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

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

.btn-link {
    background: transparent;
    color: var(--accent);
    padding: 0;
    box-shadow: none;
}

.btn-link:hover {
    background: transparent;
    color: var(--accent-hover);
    transform: none;
}

.btn-sm {
    padding: var(--space-2) var(--space-3);
    font-size: var(--font-xs);
}

.btn-lg {
    padding: var(--space-4) var(--space-6);
    font-size: var(--font-base);
}

.btn-outline-secondary {
    background: transparent;
    border: 1px solid var(--steel-dark);
    color: var(--ink);
}

.btn-outline-secondary:hover {
    background: var(--steel);
}

.btn-outline-danger {
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
}

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

/* Forms */
.form-control {
    display: block;
    width: 100%;
    padding: var(--space-3) var(--space-4);
    font-family: inherit;
    font-size: var(--font-base);
    line-height: 1.5;
    color: var(--ink);
    background: var(--paper);
    border: 1px solid var(--steel-dark);
    border-radius: var(--radius);
    transition: border-color var(--transition), box-shadow var(--transition);
}

.form-control:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.form-control::placeholder {
    color: var(--ink-muted);
}

.form-label {
    display: block;
    margin-bottom: var(--space-2);
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--ink-light);
}

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

/* Cards */
.card {
    background: var(--paper);
    border: 1px solid var(--steel);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    transition: box-shadow var(--transition), border-color var(--transition);
}

.card-body {
    padding: var(--space-5);
}

/* Flash messages */
#messages {
    position: fixed;
    top: 80px;
    right: var(--space-6);
    width: 320px;
    z-index: 1000;
}

.flashes {
    list-style: none;
}

.flashes li {
    padding: var(--space-4);
    margin-bottom: var(--space-3);
    background: var(--ink);
    color: var(--paper);
    border-radius: var(--radius);
    font-size: var(--font-sm);
    box-shadow: var(--shadow-lg);
}

.flashes li.success, .flashes li[class*="success"] {
    background: #22c55e;
}

.flashes li.error, .flashes li[class*="error"], .flashes li[class*="danger"] {
    background: var(--danger);
}

.flashes li.warning, .flashes li[class*="warning"] {
    background: #f59e0b;
}

/* Loading state for buttons */
button:disabled {
    opacity: 0.7;
    cursor: wait;
}

/* Smooth focus states */
*:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* Skip to content link for accessibility */
.skip-link {
    position: absolute;
    top: -40px;
    left: 0;
    padding: 8px 16px;
    background: var(--accent);
    color: white;
    z-index: 10000;
    transition: top 0.2s;
}

.skip-link:focus {
    top: 0;
}

/* Page transitions - REMOVED (unnecessary) */

.card:hover {
    border-color: var(--steel-dark);
}

.task-list .card:hover {
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    transform: translateY(-1px);
}

/* Subtask cards with numbered border */
.subtask-card {
    transition: all var(--transition);
}

.subtask-card:hover {
    border-left-color: var(--accent) !important;
    background: var(--accent-light);
}

/* REMOVED: back-to-top, checkmark, glow, typing animations - dead code */

/* Reduced motion for accessibility */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    html {
        scroll-behavior: auto;
    }
}

.card:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

/* Details/summary polish */
details summary {
    user-select: none;
}

details[open] summary {
    margin-bottom: var(--space-2);
}

/* HTMX loading indicator */
.htmx-request {
    opacity: 0.5;
    transition: opacity 200ms;
}

.htmx-request::after {
    content: ' ⏳';
}

/* Spinner animation */
.spinner {
    width: 16px;
    height: 16px;
    border: 2px solid var(--steel);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* Progress bar */
.progress-bar-container {
    height: 4px;
    background: var(--steel);
    border-radius: 2px;
    overflow: hidden;
}

.progress-bar-indeterminate {
    height: 100%;
    width: 30%;
    background: var(--accent);
    border-radius: 2px;
    animation: indeterminate 1.5s ease-in-out infinite;
}

@keyframes indeterminate {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(400%); }
}

/* Action item animations */
.action-item {
    transition: all var(--transition);
}

/* Global progress bar */
.global-progress {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: transparent;
    z-index: 9999;
    pointer-events: none;
}

.global-progress.active {
    background: linear-gradient(90deg, var(--accent), var(--accent-light, #818cf8));
    animation: progress-slide 1s ease-in-out infinite;
}

@keyframes progress-slide {
    0% { transform: translateX(-100%); }
    100% { transform: translateX(100%); }
}

/* Removed bloat: skeleton loaders, pulse, copy buttons, toasts */

/* Status badges */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: var(--font-xs);
    font-weight: 500;
}

.badge-running {
    background: var(--accent-light);
    color: var(--accent);
}

.badge-pending {
    background: #fef3c7;
    color: #92400e;
}

.badge-completed {
    background: #dcfce7;
    color: #166534;
}

.badge-failed {
    background: #fee2e2;
    color: var(--danger);
}

/* Count badges */
.count-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    background: var(--steel);
    border-radius: 10px;
    font-size: var(--font-xs);
    font-weight: 600;
}

/* Responsive improvements */
@media (max-width: 480px) {
    .d-flex.gap-2 {
        gap: var(--space-1) !important;
    }
    
    .btn-sm {
        padding: 4px 8px;
        font-size: var(--font-xs);
    }
    
    /* Stack action buttons on mobile */
    .d-flex.flex-wrap {
        flex-direction: column;
        align-items: stretch;
    }
    
    .d-flex.flex-wrap .btn {
        width: 100%;
        justify-content: center;
    }
}

/* ============================================
   ONBOARDING - The hero moment
   ============================================ */

.onboarding {
    max-width: 600px;
    margin: var(--space-12) auto;
    text-align: center;
}

.onboarding-hero h1 {
    font-size: var(--font-3xl);
    font-weight: 700;
    letter-spacing: -0.03em;
    margin-bottom: var(--space-3);
}

.onboarding-subtitle {
    font-size: var(--font-lg);
    color: var(--ink-muted);
    margin-bottom: var(--space-8);
}

.onboarding-form {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.vision-input {
    width: 100%;
    padding: var(--space-5);
    font-size: var(--font-lg);
    line-height: 1.6;
    color: var(--ink);
    background: var(--paper);
    border: 2px solid var(--steel);
    border-radius: var(--radius);
    resize: none;
    transition: border-color var(--transition), box-shadow var(--transition);
}

.vision-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-light);
}

.vision-input::placeholder {
    color: var(--ink-muted);
}

.onboarding-form .btn {
    align-self: flex-end;
}

/* Recent tasks */
.recent-tasks {
    margin-top: var(--space-12);
    text-align: left;
}

.recent-tasks h2 {
    font-size: var(--font-sm);
    font-weight: 500;
    color: var(--ink-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: var(--space-4);
}

.task-cards {
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.task-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--space-4);
    background: var(--paper);
    border: 1px solid var(--steel);
    border-radius: var(--radius);
    color: var(--ink);
    transition: all var(--transition);
}

.task-card:hover {
    border-color: var(--accent);
    background: var(--accent-light);
    transform: translateX(4px);
    color: var(--ink);
}

.task-card::after {
    content: '→';
    opacity: 0;
    transform: translateX(-8px);
    transition: all var(--transition);
}

.task-card:hover::after {
    opacity: 1;
    transform: translateX(0);
}

.task-card-title {
    font-weight: 500;
}

.task-card-meta {
    font-size: var(--font-xs);
    color: var(--ink-muted);
}

.view-all-link {
    display: inline-block;
    margin-top: var(--space-4);
    font-size: var(--font-sm);
    color: var(--ink-muted);
}

.view-all-link:hover {
    color: var(--accent);
}

/* ============================================
   TASK PAGES
   ============================================ */

.task-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-3);
}

.task-list .card {
    transition: border-color var(--transition);
}

.task-list .card:hover {
    border-color: var(--ink-muted);
}

.task-list .card-body {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: var(--space-4);
}

.task-list .card-body > div:first-child {
    flex: 1;
    min-width: 0;
}

.task-list .card-body a.fw-bold {
    color: var(--ink);
    font-weight: 600;
}

.task-list .card-body a.fw-bold:hover {
    color: var(--accent);
}

/* Task view page */
pre {
    background: var(--paper-warm);
    padding: var(--space-5);
    border-radius: var(--radius);
    overflow-x: auto;
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: var(--font-sm);
    line-height: 1.7;
    border: 1px solid var(--steel);
}

code {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
}

/* Inline code */
p code, li code {
    background: var(--paper-warm);
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.9em;
}

/* Diff highlighting */
pre .diff-add, pre .line-add {
    background: #dcfce7;
    color: #166534;
}

pre .diff-del, pre .line-del {
    background: #fee2e2;
    color: #b91c1c;
}

pre .diff-header {
    color: var(--ink-muted);
    font-weight: 500;
}

/* Version history */
.list-group {
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--steel);
}

.list-group-item {
    padding: var(--space-3) var(--space-4);
    background: var(--paper);
    border-bottom: 1px solid var(--steel);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.list-group-item:last-child {
    border-bottom: none;
}

.list-group-item.active {
    background: var(--ink);
    color: var(--paper);
}

/* ============================================
   ACCOUNT PAGE - Tabs & Tables
   ============================================ */

/* Tab navigation */
.nav {
    display: flex;
    flex-wrap: wrap;
    padding-left: 0;
    margin-bottom: 0;
    list-style: none;
}

.nav-tabs {
    border-bottom: 1px solid var(--steel);
    gap: var(--space-1);
}

.nav-item {
    margin-bottom: -1px;
}

.nav-link {
    display: block;
    padding: var(--space-3) var(--space-4);
    color: var(--ink-muted);
    text-decoration: none;
    border: 1px solid transparent;
    border-top-left-radius: var(--radius);
    border-top-right-radius: var(--radius);
    transition: all var(--transition);
}

.nav-link:hover {
    color: var(--ink);
    background: var(--paper-warm);
}

.nav-link.active {
    color: var(--ink);
    background: var(--paper);
    border-color: var(--steel) var(--steel) var(--paper);
}

/* Tab content */
.tab-content {
    padding-top: var(--space-4);
}

.tab-pane {
    display: none;
}

.tab-pane.show.active {
    display: block;
}

/* Tables */
.table {
    width: 100%;
    margin-bottom: var(--space-4);
    border-collapse: collapse;
}

.table th,
.table td {
    padding: var(--space-3) var(--space-4);
    text-align: left;
    border-bottom: 1px solid var(--steel);
}

.table th {
    font-weight: 600;
    color: var(--ink-muted);
    font-size: var(--font-sm);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.table tbody tr:hover {
    background: var(--paper-warm);
}

.align-middle {
    vertical-align: middle;
}

/* Status text colors */
.text-success { color: #16a34a; }
.text-warning { color: #ca8a04; }
.text-danger { color: var(--danger); }
.text-info { color: var(--accent); }

/* Form utilities */
.form-text {
    display: block;
    margin-top: var(--space-1);
    font-size: var(--font-xs);
    color: var(--ink-muted);
}

.form-check-input {
    margin-right: var(--space-1);
}

/* Grid utilities */
.col-auto {
    flex: 0 0 auto;
    width: auto;
}

.g-2 {
    gap: var(--space-2);
}

/* Form row layout */
.row {
    display: flex;
    flex-wrap: wrap;
    margin-left: calc(-1 * var(--space-3));
    margin-right: calc(-1 * var(--space-3));
}

.row > * {
    padding-left: var(--space-3);
    padding-right: var(--space-3);
}

.col-sm-2 {
    flex: 0 0 auto;
    width: 16.666667%;
}

.col-sm-10 {
    flex: 0 0 auto;
    width: 83.333333%;
}

.col-form-label {
    padding-top: calc(var(--space-3) + 1px);
    padding-bottom: calc(var(--space-3) + 1px);
    font-weight: 500;
    color: var(--ink);
}

/* Responsive table */
.responsive-table {
    width: 100%;
    overflow-x: auto;
}

/* Margin utilities */
.me-2 { margin-right: var(--space-2); }
.me-3 { margin-right: var(--space-3); }
.flex-wrap { flex-wrap: wrap; }

/* Mobile form layout */
@media (max-width: 576px) {
    .col-sm-2,
    .col-sm-10 {
        flex: 0 0 auto;
        width: 100%;
    }
    
    .col-form-label {
        padding-top: 0;
        padding-bottom: var(--space-1);
    }
    
    .table th,
    .table td {
        padding: var(--space-2);
        font-size: var(--font-sm);
    }
    
    /* Stack table on mobile */
    .responsive-table thead {
        display: none;
    }
    
    .responsive-table tr {
        display: block;
        margin-bottom: var(--space-4);
        border: 1px solid var(--steel);
        border-radius: var(--radius);
    }
    
    .responsive-table td {
        display: block;
        text-align: right;
        border-bottom: 1px solid var(--steel);
    }
    
    .responsive-table td:last-child {
        border-bottom: none;
    }
    
    .responsive-table td::before {
        content: attr(data-label);
        float: left;
        font-weight: 600;
        color: var(--ink-muted);
    }
}

/* ============================================
   UTILITIES
   ============================================ */

.d-flex { display: flex; }
.flex-column { flex-direction: column; }
.align-items-center { align-items: center; }
.align-self-center { align-self: center; }
.justify-content-between { justify-content: space-between; }
.justify-content-center { justify-content: center; }

.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }

.m-0 { margin: 0; }
.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-6); }
.mb-1 { margin-bottom: var(--space-1); }
.mb-2 { margin-bottom: var(--space-2); }
.mb-3 { margin-bottom: var(--space-3); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-5 { margin-bottom: var(--space-6); }
.me-auto { margin-right: auto; }

.p-2 { padding: var(--space-2); }
.p-3 { padding: var(--space-3); }
.p-4 { padding: var(--space-4); }
.p-5 { padding: var(--space-6); }
.py-5 { padding-top: var(--space-6); padding-bottom: var(--space-6); }

.text-center { text-align: center; }
.text-muted { color: var(--ink-muted); }
.fw-bold { font-weight: 600; }

.col-4 {
    flex: 0 0 33.333%;
    padding: 0 var(--space-3);
}

/* ============================================
   RESPONSIVE
   ============================================ */

@media (max-width: 640px) {
    :root {
        --font-3xl: 1.75rem;
        --font-2xl: 1.5rem;
    }
    
    .container {
        padding: var(--space-6) var(--space-4);
    }
    
    .onboarding {
        margin: var(--space-8) auto;
    }
    
    .header {
        padding: 0 var(--space-4);
    }
    
    #messages {
        right: var(--space-4);
        left: var(--space-4);
        width: auto;
    }
    
    .task-list .card-body {
        flex-direction: column;
        align-items: flex-start;
    }
    
    .task-list .card-body > div:last-child {
        margin-top: var(--space-3);
    }
    
    .col-4 {
        flex: 0 0 100%;
        margin-bottom: var(--space-4);
    }
}
