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

:root {
    --primary: #003366;
    --primary-hover: #004080;
    --bg-app: #f7f8fa;
    --bg-sidebar: #ffffff;
    --bg-card: #ffffff;
    --bg-hover: #f3f4f6;
    --bg-active: #eff6ff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.04);
    --shadow: 0 1px 3px rgba(0,0,0,0.08);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --sidebar-width: 240px;
    --topbar-height: 56px;
    --radius: 6px;
    --radius-lg: 8px;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-app);
    -webkit-font-smoothing: antialiased;
}

/* ============================================
   APP LAYOUT
============================================ */
.app {
    display: flex;
    min-height: 100vh;
}

/* ============================================
   SIDEBAR
============================================ */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    transition: transform 0.2s ease;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-light);
}

.workspace {
    display: flex;
    align-items: center;
    gap: 10px;
}

.workspace-icon {
    font-size: 24px;
}

.workspace-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.nav-section {
    margin-bottom: 16px;
}

.nav-section-title {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 8px 12px 6px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    transition: all 0.15s ease;
    margin-bottom: 2px;
}

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

.nav-item.active {
    background: var(--bg-active);
    color: var(--primary);
}

.nav-icon {
    width: 18px;
    height: 18px;
    fill: currentColor;
    opacity: 0.7;
}

.nav-item.active .nav-icon {
    opacity: 1;
}

.sidebar-footer {
    padding: 12px 16px;
    border-top: 1px solid var(--border-light);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.user-avatar {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 13px;
    font-weight: 600;
}

.user-details {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
}

.user-role {
    font-size: 11px;
    color: var(--text-muted);
}

/* ============================================
   MAIN
============================================ */
.main {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

/* ============================================
   TOPBAR
============================================ */
.topbar {
    height: var(--topbar-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-secondary);
    border-radius: var(--radius);
}

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

.topbar-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.topbar-actions {
    margin-left: auto;
}

.today-date {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================
   CONTENT
============================================ */
.content {
    flex: 1;
    padding: 24px;
    max-width: 1200px;
    width: 100%;
    margin: 0 auto;
}

.section {
    display: none;
    animation: fadeIn 0.2s ease;
}

.section.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.section-header {
    margin-bottom: 24px;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.section-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.section-header p {
    font-size: 14px;
    color: var(--text-secondary);
}

/* ============================================
   METRICS
============================================ */
.metrics {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.metric-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    box-shadow: var(--shadow-sm);
}

.metric-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--text-primary);
    line-height: 1;
    margin-bottom: 4px;
}

.metric-label {
    font-size: 13px;
    color: var(--text-secondary);
}

/* ============================================
   CARDS
============================================ */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    margin-bottom: 16px;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
}

.card-header h3 {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.card-body {
    padding: 20px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 16px;
}

.link {
    font-size: 13px;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.link:hover {
    text-decoration: underline;
}

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 24px;
}

/* ============================================
   BUTTONS
============================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    cursor: pointer;
    transition: all 0.15s ease;
}

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

.btn-sm {
    padding: 6px 12px;
    font-size: 12px;
}

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

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

/* ============================================
   QUICK ACTIONS
============================================ */
.quick-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-app);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
    text-align: left;
}

.quick-action:hover {
    background: var(--bg-hover);
    border-color: var(--primary);
    color: var(--primary);
}

.quick-action-icon {
    width: 28px;
    height: 28px;
    background: var(--bg-card);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
}

/* ============================================
   TOOLBAR
============================================ */
.toolbar {
    margin-bottom: 16px;
}

.filter-group {
    display: flex;
    gap: 8px;
}

.filter-btn {
    padding: 6px 14px;
    font-size: 13px;
    font-weight: 500;
    font-family: inherit;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.15s ease;
}

.filter-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

/* ============================================
   TASKS
============================================ */
.tasks-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.task-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: all 0.15s ease;
}

.task-item:hover {
    border-color: var(--primary);
    box-shadow: var(--shadow);
}

.task-checkbox {
    width: 18px;
    height: 18px;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    color: white;
    transition: all 0.15s ease;
    flex-shrink: 0;
}

.task-checkbox:hover {
    border-color: var(--success);
}

.task-checkbox.completed {
    background: var(--success);
    border-color: var(--success);
}

.task-content {
    flex: 1;
    min-width: 0;
}

.task-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 2px;
}

.task-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.task-priority {
    padding: 4px 10px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 12px;
    flex-shrink: 0;
}

.priority-1 { background: #dbeafe; color: #2563eb; }
.priority-2 { background: #fef3c7; color: #d97706; }
.priority-3 { background: #fee2e2; color: #dc2626; }

/* ============================================
   SEARCH
============================================ */
.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    position: relative;
}

.search-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
}

#memory-search-input {
    flex: 1;
    padding: 10px 12px 10px 40px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
    transition: border-color 0.15s ease;
}

#memory-search-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============================================
   MEMORY
============================================ */
.memory-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.memory-item {
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
}

.memory-content {
    font-size: 14px;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.memory-meta {
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================
   RITUALS
============================================ */
.rituals-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 16px;
}

.ritual-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.ritual-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 16px;
    background: var(--primary);
    color: white;
}

.ritual-name {
    font-size: 14px;
    font-weight: 600;
}

.ritual-header .btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    font-size: 12px;
    padding: 6px 10px;
}

.ritual-header .btn:hover {
    background: rgba(255,255,255,0.3);
}

.ritual-steps {
    list-style: none;
}

.ritual-step {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-light);
    font-size: 13px;
    color: var(--text-secondary);
    display: flex;
    justify-content: space-between;
}

.ritual-step:last-child {
    border-bottom: none;
}

/* ============================================
   CHAT
============================================ */
.chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - var(--topbar-height) - 48px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 24px;
}

.chat-empty {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}

.chat-empty-icon {
    font-size: 40px;
    margin-bottom: 12px;
}

.chat-empty h3 {
    font-size: 16px;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.message {
    max-width: 70%;
    padding: 12px 16px;
    margin-bottom: 12px;
    border-radius: var(--radius-lg);
    font-size: 14px;
    line-height: 1.5;
}

.message.user {
    background: var(--primary);
    color: white;
    margin-left: auto;
    border-bottom-right-radius: 4px;
}

.message.assistant {
    background: var(--bg-app);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-input-area {
    display: flex;
    gap: 12px;
    padding: 16px;
    border-top: 1px solid var(--border);
}

#chat-input {
    flex: 1;
    padding: 10px 14px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    resize: none;
    background: var(--bg-app);
    color: var(--text-primary);
}

#chat-input:focus {
    outline: none;
    border-color: var(--primary);
}

/* ============================================
   MODAL
============================================ */
.modal-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-backdrop.active {
    display: flex;
}

.modal-dialog {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 440px;
    max-height: 85vh;
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

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

.modal-header h3 {
    font-size: 15px;
    font-weight: 600;
}

.modal-close {
    width: 28px;
    height: 28px;
    background: var(--bg-app);
    border: none;
    border-radius: 50%;
    font-size: 18px;
    cursor: pointer;
    color: var(--text-secondary);
}

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

.modal-body {
    padding: 20px;
    overflow-y: auto;
}

/* ============================================
   FORMS
============================================ */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 6px;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 10px 12px;
    font-size: 14px;
    font-family: inherit;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-card);
    color: var(--text-primary);
}

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

/* ============================================
   RESPONSIVE
============================================ */
@media (max-width: 1024px) {
    .metrics {
        grid-template-columns: repeat(2, 1fr);
    }
    
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .main {
        margin-left: 0;
    }
    
    .menu-toggle {
        display: block;
    }
    
    .content {
        padding: 16px;
    }
    
    .metrics {
        grid-template-columns: 1fr 1fr;
        gap: 12px;
    }
    
    .metric-card {
        padding: 16px;
    }
    
    .metric-value {
        font-size: 22px;
    }
    
    .quick-actions {
        grid-template-columns: 1fr;
    }
    
    .message {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .section-header {
        flex-direction: column;
        gap: 12px;
        align-items: flex-start;
    }
    
    .section-header .btn {
        width: 100%;
    }
}

/* ============================================
   LOGIN PAGE
============================================ */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f5f7fa 0%, #e4e8ec 100%);
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-card {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    padding: 40px;
}

.login-header {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo {
    font-size: 48px;
    display: block;
    margin-bottom: 16px;
}

.login-header h1 {
    font-size: 24px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.login-header p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form .form-group {
    margin-bottom: 20px;
}

.login-form input {
    width: 100%;
    padding: 12px 14px;
    font-size: 14px;
}

.btn-login {
    width: 100%;
    padding: 14px;
    font-size: 15px;
    font-weight: 600;
    margin-top: 8px;
}

.form-error {
    color: var(--danger);
    font-size: 13px;
    text-align: center;
    min-height: 20px;
    margin-bottom: 8px;
}

.login-footer {
    text-align: center;
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-muted);
}

/* ============================================
   LOGOUT BUTTON
============================================ */
.user-info {
    position: relative;
}

.logout-btn {
    background: none;
    border: none;
    padding: 8px;
    cursor: pointer;
    color: var(--text-muted);
    border-radius: var(--radius);
    transition: all 0.15s ease;
    margin-left: auto;
}

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

/* ============================================
   MEMORY ENHANCED
============================================ */
.memory-toolbar {
    margin-bottom: 16px;
}

.memory-toolbar .search-bar {
    margin-bottom: 0;
}

.memory-filters {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 16px;
}

.memory-stats {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    padding: 12px 16px;
    background: var(--bg-app);
    border-radius: var(--radius);
}

.memory-item {
    position: relative;
    padding: 16px;
    padding-right: 50px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    border-left: 3px solid var(--primary);
    transition: all 0.15s ease;
}

.memory-item:hover {
    box-shadow: var(--shadow);
}

.memory-item-actions {
    position: absolute;
    top: 12px;
    right: 12px;
    display: flex;
    gap: 4px;
    opacity: 0;
    transition: opacity 0.15s ease;
}

.memory-item:hover .memory-item-actions {
    opacity: 1;
}

.memory-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: var(--bg-app);
    border-radius: var(--radius);
    cursor: pointer;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s ease;
}

.memory-action-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.memory-action-btn.delete:hover {
    background: #fee2e2;
    color: var(--danger);
}

.memory-category-badge {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    background: var(--bg-app);
    border-radius: 10px;
    color: var(--text-secondary);
    margin-right: 8px;
}

/* Similar memories warning */
.similar-warning {
    background: #fef3c7;
    border: 1px solid #f59e0b;
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}

.similar-warning-title {
    font-weight: 600;
    color: #92400e;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.similar-item {
    background: white;
    padding: 12px;
    border-radius: var(--radius);
    margin-bottom: 8px;
    font-size: 13px;
}

.similar-item-score {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 4px;
}

.similar-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.similar-actions .btn {
    flex: 1;
    font-size: 12px;
    padding: 8px 12px;
}
