/* Kaibernetic Web Interface Styles */

:root {
    --primary-color: #2563eb;
    --secondary-color: #64748b;
    --success-color: #10b981;
    --danger-color: #ef4444;
    --warning-color: #f59e0b;
    --bg-color: #f8fafc;
    --sidebar-bg: #ffffff;
    --text-color: #1e293b;
    --border-color: #e2e8f0;
    --shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06);
}

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

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

/* Navigation */
.navbar {
    background: white;
    border-bottom: 1px solid var(--border-color);
    padding: 1rem 0;
    box-shadow: var(--shadow);
}

.nav-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    display: flex;
    align-items: center;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--primary-color);
}

.nav-brand i {
    margin-right: 0.5rem;
}

.nav-menu {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Auth Container */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100vh - 70px);
    padding: 2rem;
}

.auth-box {
    background: white;
    padding: 2rem;
    border-radius: 8px;
    box-shadow: var(--shadow);
    width: 100%;
    max-width: 400px;
}

.auth-box h2 {
    margin-bottom: 1.5rem;
    text-align: center;
    color: var(--primary-color);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 1rem;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary:hover {
    background: #1d4ed8;
}

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

.btn-secondary:hover {
    background: #475569;
}

.btn-disabled {
    background: var(--border-color);
    color: var(--secondary-color);
    cursor: not-allowed;
    opacity: 0.7;
}

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

.btn-sm {
    padding: 0.25rem 0.75rem;
    font-size: 0.875rem;
}

.goal-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    font-size: 0.75rem;
}

.goal-badge.shared {
    background: rgba(14, 165, 233, 0.15);
    color: #0284c7;
}

.goal-badge.claimed-self {
    background: rgba(16, 185, 129, 0.15);
    color: var(--success-color);
}

.goal-badge.claimed-other {
    background: rgba(148, 163, 184, 0.25);
    color: var(--secondary-color);
}

/* Main Container */
.main-container {
    display: flex;
    height: calc(100vh - 70px);
}

/* Sidebar */
.sidebar {
    width: clamp(320px, 30vw, 600px);
    background: var(--sidebar-bg);
    border-left: 1px solid var(--border-color);
    overflow-y: auto;
    order: 2;
}

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

.search-box {
    position: relative;
    padding: 1.5rem;
}

.search-box input {
    width: 100%;
    padding: 0.5rem 2.25rem 0.5rem 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 4px;
}

.search-loading {
    position: absolute;
    top: calc(50% - 0.625rem);
    right: 2rem;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    transform: translateY(-50%);
    display: none;
}

.search-loading.active {
    display: block;
}

.search-status {
    padding: 0 1.5rem 0.5rem 1.5rem;
    font-size: 0.85rem;
    color: var(--secondary-color);
}

.search-results {
    display: none;
    margin: 0 1.5rem 1rem 1.5rem;
    background: #ffffff;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    max-height: 320px;
    overflow-y: auto;
}

.search-result {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s ease;
}

.search-result:last-child {
    border-bottom: none;
}

.search-result:hover {
    background: var(--bg-color);
}

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

.search-result .result-title {
    font-weight: 600;
    flex: 1;
}

.search-result .result-hierarchy {
    font-size: 0.75rem;
    padding: 0.15rem 0.4rem;
    border-radius: 999px;
    background: var(--bg-color);
    text-transform: uppercase;
}

.search-result .result-rank {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--secondary-color);
}

.search-result .result-path {
    font-size: 0.75rem;
    color: var(--secondary-color);
    margin-top: 0.35rem;
}

.search-result .result-snippet {
    margin-top: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-color);
}

.search-result .result-snippet mark {
    background: rgba(37, 99, 235, 0.12);
    color: var(--primary-color);
}

.search-result .result-scores {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: var(--secondary-color);
    display: flex;
    gap: 1rem;
}

/* Filter buttons */
.filter-buttons {
    padding: 0 1.5rem 1rem 1.5rem;
    display: flex;
    gap: 0.5rem;
    justify-content: center;
}

.filter-btn {
    flex: 1;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    border: 1px solid var(--border-color);
    background: white;
    color: var(--text-color);
    border-radius: 4px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.25rem;
}

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

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

.filter-btn.active:hover {
    background: #1e40af;
    border-color: #1e40af;
}

/* Goal Tree */
.goal-tree {
    padding: 1.5rem;
}

.goal-item {
    padding: 0.75rem;
    cursor: pointer;
    border-radius: 4px;
    margin-bottom: 0.5rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    position: relative;
}

.goal-item .expand-toggle {
    width: 16px;
    height: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--secondary-color);
    font-size: 12px;
    flex-shrink: 0;
}

.goal-item .expand-toggle:hover {
    color: var(--primary-color);
}

.goal-item .expand-toggle.empty {
    visibility: hidden;
}

.goal-item:hover {
    background: var(--bg-color);
}

.goal-item.active {
    background: #e0e7ff;
    color: var(--primary-color);
}

.goal-item i {
    font-size: 0.875rem;
    width: 1rem;
    text-align: center;
}

.goal-children {
    margin-left: 1.5rem;
    overflow: hidden;
    transition: max-height 0.3s ease-out;
}

.goal-children.collapsed {
    max-height: 0;
    margin-bottom: 0;
}

/* Content Area */
.content {
    flex: 1;
    overflow-y: auto;
    padding: 2rem;
    order: 1;
}

.goal-detail {
    max-width: 800px;
    margin: 0 auto;
}

.goal-header {
    margin-bottom: 2rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.goal-header h1 {
    margin-bottom: 0.5rem;
}

.goal-meta {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    color: var(--secondary-color);
    font-size: 0.875rem;
}

.goal-actions {
    margin-top: 1rem;
    display: flex;
    gap: 0.5rem;
}

.goal-section {
    margin-bottom: 2rem;
}

.goal-section h3 {
    margin-bottom: 1rem;
    color: var(--secondary-color);
}

/* Status badges */
.status-badge {
    display: inline-block;
    padding: 0.25rem 0.75rem;
    border-radius: 12px;
    font-size: 0.875rem;
    font-weight: 500;
}

.status-badge.active {
    background: #dbeafe;
    color: #1e40af;
}

.status-badge.completed {
    background: #d1fae5;
    color: #065f46;
}

.status-badge.archived {
    background: #f3f4f6;
    color: #6b7280;
}

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

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: white;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    border-radius: 8px;
    box-shadow: var(--shadow);
}

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

.modal-header h3 {
    margin: 0;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--secondary-color);
}

.modal-footer {
    padding: 1rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* Loading */
.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 2000;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* Error Messages */
.error-message {
    color: var(--danger-color);
    font-size: 0.875rem;
    margin-top: 0.5rem;
}

/* Auth switch */
.auth-switch {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.875rem;
}

.auth-switch a {
    color: var(--primary-color);
    text-decoration: none;
}

.auth-switch a:hover {
    text-decoration: underline;
}

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

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
}

/* Responsive */
@media (max-width: 1024px) {
    .sidebar {
        width: clamp(280px, 25vw, 400px);
    }
    
    .sidebar-header,
    .search-box,
    .goal-tree {
        padding: 1rem;
    }
    
    .filter-buttons {
        padding: 0 1rem 0.75rem 1rem;
    }
    
    .goal-item {
        padding: 0.5rem;
        gap: 0.5rem;
    }
}

@media (max-width: 768px) {
    .main-container {
        flex-direction: column;
    }
    
    .sidebar {
        width: 100%;
        height: 40vh;
        border-left: none;
        border-top: 1px solid var(--border-color);
        order: 2;
    }
    
    .content {
        padding: 1rem;
        order: 1;
    }
    
    .sidebar-header,
    .search-box,
    .goal-tree {
        padding: 0.75rem;
    }
    
    .filter-buttons {
        padding: 0 0.75rem 0.5rem 0.75rem;
    }
}

/* Markdown rendering styles - integrated with goal content */
.goal-section h1, .goal-section h2, .goal-section h3, .goal-section h4, .goal-section h5, .goal-section h6 {
    margin-top: 2rem;
    margin-bottom: 1rem;
    font-weight: 600;
    color: var(--text-color);
}

.goal-section h1 { 
    font-size: 1.75rem; 
    border-bottom: 2px solid var(--border-color); 
    padding-bottom: 0.5rem; 
}

.goal-section h2 { 
    font-size: 1.5rem; 
    border-bottom: 1px solid var(--border-color); 
    padding-bottom: 0.25rem; 
}

.goal-section h3 { 
    font-size: 1.25rem; 
}

.goal-section h4 { 
    font-size: 1.125rem; 
}

.goal-section h5 { 
    font-size: 1rem; 
    font-weight: 600; 
}

.goal-section h6 { 
    font-size: 0.875rem; 
    font-weight: 600; 
    color: var(--secondary-color);
}

/* Override the first header to not have top margin */
.goal-section > h1:first-child,
.goal-section > h2:first-child,
.goal-section > h3:first-child,
.goal-section > h4:first-child,
.goal-section > h5:first-child,
.goal-section > h6:first-child {
    margin-top: 0;
}

.goal-section p {
    margin-bottom: 1rem;
    line-height: 1.6;
}

.goal-section ul, .goal-section ol {
    margin-bottom: 1rem;
    padding-left: 1.5rem;
}

.goal-section li {
    margin-bottom: 0.25rem;
    line-height: 1.5;
}

.goal-section blockquote {
    border-left: 4px solid var(--primary-color);
    margin: 1.5rem 0;
    padding-left: 1rem;
    color: var(--secondary-color);
    font-style: italic;
}

.goal-section code {
    background: #e2e8f0;
    padding: 0.125rem 0.375rem;
    border-radius: 3px;
    font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
    font-size: 0.875rem;
}

.goal-section pre {
    background: #1e293b;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 6px;
    overflow-x: auto;
    margin: 1.5rem 0;
    line-height: 1.4;
}

.goal-section pre code {
    background: none;
    padding: 0;
    color: inherit;
    font-size: 0.875rem;
}

.goal-section strong {
    font-weight: 600;
}

.goal-section em {
    font-style: italic;
}

.goal-section a {
    color: var(--primary-color);
    text-decoration: none;
}

.goal-section a:hover {
    text-decoration: underline;
}

.goal-section hr {
    border: none;
    border-top: 1px solid var(--border-color);
    margin: 2rem 0;
}

.goal-section table {
    width: 100%;
    border-collapse: collapse;
    margin: 1rem 0;
}

.goal-section th,
.goal-section td {
    border: 1px solid var(--border-color);
    padding: 0.5rem;
    text-align: left;
}

.goal-section th {
    background: var(--bg-color);
    font-weight: 600;
}
