/*
 * Snarf - Dark Theme (Obsidian-inspired)
 *
 * Color palette based on dark mode aesthetics with
 * purple/violet accents.
 */

/* =============================================================================
   CSS Custom Properties
   ============================================================================= */

:root {
    /* Background colors */
    --bg-primary: #1e1e2e;
    --bg-secondary: #181825;
    --bg-tertiary: #11111b;
    --bg-hover: #313244;
    --bg-active: #45475a;

    /* Text colors */
    --text-primary: #cdd6f4;
    --text-secondary: #a6adc8;
    --text-muted: #6c7086;
    --text-accent: #cba6f7;

    /* Accent colors */
    --accent-primary: #cba6f7;
    --accent-secondary: #f5c2e7;
    --accent-tertiary: #89b4fa;

    /* Syntax highlighting */
    --syntax-keyword: #cba6f7;
    --syntax-string: #a6e3a1;
    --syntax-comment: #6c7086;
    --syntax-function: #89b4fa;
    --syntax-variable: #f5c2e7;
    --syntax-number: #fab387;
    --syntax-operator: #89dceb;
    --syntax-heading: #f38ba8;
    --syntax-link: #89b4fa;
    --syntax-code: #f9e2af;

    /* UI elements */
    --border-color: #313244;
    --selection-bg: rgba(203, 166, 247, 0.2);
    --cursor-color: #f5e0dc;
    --line-number-color: #6c7086;
    --active-line-bg: rgba(69, 71, 90, 0.3);

    /* Status indicators */
    --status-connected: #a6e3a1;
    --status-disconnected: #f38ba8;
    --status-saving: #f9e2af;

    /* Spacing */
    --header-height: 48px;
    --footer-height: 28px;
    --gutter-width: 60px;

    /* Typography */
    --font-mono: 'JetBrains Mono', 'Fira Code', 'SF Mono', Consolas, monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-base: 14px;
    --line-height: 1.6;
}

/* =============================================================================
   Reset & Base
   ============================================================================= */

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

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: var(--font-sans);
    font-size: var(--font-size-base);
    line-height: var(--line-height);
    background-color: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

#app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.header {
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.logo {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-size: 18px;
    font-weight: 600;
    color: var(--accent-primary);
    letter-spacing: -0.5px;
}

.logo-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

.status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    transition: background-color 0.2s ease;
}

.status-indicator.connected {
    background-color: var(--status-connected);
}

.status-indicator.disconnected {
    background-color: var(--status-disconnected);
}

.status-indicator.saving {
    background-color: var(--status-saving);
}

/* Save indicator (checkmark/spinner) */
.save-indicator {
    display: none;
    font-size: 14px;
    line-height: 1;
}

.save-indicator.saving {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--text-muted);
    border-top-color: var(--status-saving);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.save-indicator.saved {
    display: inline-block;
    color: var(--status-connected);
}

.save-indicator.saved::before {
    content: '\2713';
}

.editor-container {
    flex: 1;
    overflow: hidden;
    position: relative;
}

#editor {
    height: 100%;
    width: 100%;
}

.footer {
    height: var(--footer-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    flex-shrink: 0;
    font-family: var(--font-mono);
    font-size: 12px;
}

.vim-status {
    color: var(--accent-primary);
    font-weight: 600;
    min-width: 80px;
}

.cursor-position {
    color: var(--text-muted);
}

/* =============================================================================
   CodeMirror Theme Overrides
   ============================================================================= */

.cm-editor {
    height: 100%;
    font-family: var(--font-mono);
    font-size: var(--font-size-base);
    background-color: var(--bg-primary);
}

.cm-editor.cm-focused {
    outline: none;
}

.cm-scroller {
    overflow: auto;
    font-family: var(--font-mono);
    line-height: var(--line-height);
}

.cm-content {
    padding: 16px 0;
    caret-color: var(--cursor-color);
}

.cm-line {
    padding: 0 16px 0 8px;
}

/* Gutters (line numbers) */
.cm-gutters {
    background-color: var(--bg-primary);
    border-right: 1px solid var(--border-color);
    color: var(--line-number-color);
}

.cm-gutter.cm-lineNumbers {
    min-width: var(--gutter-width);
}

.cm-gutterElement {
    padding: 0 8px 0 16px;
    text-align: right;
}

/* Active line */
.cm-activeLine {
    background-color: var(--active-line-bg);
}

.cm-activeLineGutter {
    background-color: var(--active-line-bg);
    color: var(--text-primary);
}

/* Selection */
.cm-selectionBackground {
    background-color: var(--selection-bg) !important;
}

.cm-focused .cm-selectionBackground {
    background-color: var(--selection-bg) !important;
}

/* Cursor */
.cm-cursor {
    border-left-color: var(--cursor-color);
    border-left-width: 2px;
}

/* Vim cursor styles */
.cm-fat-cursor {
    background-color: var(--accent-primary) !important;
    color: var(--bg-primary) !important;
}

.cm-fat-cursor-mark {
    background-color: var(--accent-primary);
}

.cm-animate-fat-cursor {
    animation: none;
    background-color: var(--accent-primary);
}

/* Search match highlighting */
.cm-searchMatch {
    background-color: rgba(249, 226, 175, 0.3);
    border-radius: 2px;
}

.cm-searchMatch.cm-searchMatch-selected {
    background-color: rgba(249, 226, 175, 0.5);
}

/* =============================================================================
   Markdown Syntax Highlighting
   ============================================================================= */

/* Headings */
.cm-header-1 {
    font-size: 1.6em;
    font-weight: 700;
    color: var(--syntax-heading);
}

.cm-header-2 {
    font-size: 1.4em;
    font-weight: 600;
    color: var(--syntax-heading);
}

.cm-header-3 {
    font-size: 1.2em;
    font-weight: 600;
    color: var(--syntax-heading);
}

.cm-header-4,
.cm-header-5,
.cm-header-6 {
    font-size: 1.1em;
    font-weight: 600;
    color: var(--syntax-heading);
}

/* Emphasis */
.cm-strong {
    font-weight: 700;
    color: var(--text-primary);
}

.cm-em {
    font-style: italic;
    color: var(--text-secondary);
}

/* Code */
.cm-monospace {
    font-family: var(--font-mono);
}

.cm-inline-code,
.cm-inlineCode {
    background-color: var(--bg-hover);
    color: var(--syntax-code);
    padding: 2px 4px;
    border-radius: 3px;
}

/* Links */
.cm-link {
    color: var(--syntax-link);
    text-decoration: underline;
}

.cm-url {
    color: var(--text-muted);
}

/* Lists */
.cm-list {
    color: var(--accent-tertiary);
}

/* Quotes */
.cm-quote {
    color: var(--text-secondary);
    font-style: italic;
}

/* Horizontal rule */
.cm-hr {
    color: var(--border-color);
}

/* Generic syntax tokens */
.cm-keyword {
    color: var(--syntax-keyword);
}

.cm-string {
    color: var(--syntax-string);
}

.cm-comment {
    color: var(--syntax-comment);
    font-style: italic;
}

.cm-variableName {
    color: var(--syntax-variable);
}

.cm-number {
    color: var(--syntax-number);
}

.cm-operator {
    color: var(--syntax-operator);
}

.cm-function {
    color: var(--syntax-function);
}

/* =============================================================================
   Vim Mode Specific Styles
   ============================================================================= */

/* Command line at bottom */
.cm-vim-panel {
    padding: 4px 8px;
    background-color: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-primary);
}

.cm-vim-panel input {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 12px;
    outline: none;
    width: 100%;
}

/* Visual mode selection */
.cm-vim-visual .cm-selectionBackground {
    background-color: rgba(203, 166, 247, 0.3) !important;
}

/* =============================================================================
   Scrollbar Styling
   ============================================================================= */

.cm-scroller::-webkit-scrollbar {
    width: 10px;
    height: 10px;
}

.cm-scroller::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

.cm-scroller::-webkit-scrollbar-thumb {
    background: var(--bg-active);
    border-radius: 5px;
    border: 2px solid var(--bg-primary);
}

.cm-scroller::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =============================================================================
   Animations
   ============================================================================= */

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

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

.status-indicator.saving {
    animation: pulse 1s ease-in-out infinite;
}

/* =============================================================================
   Responsive
   ============================================================================= */

@media (max-width: 768px) {
    :root {
        --font-size-base: 13px;
        --gutter-width: 48px;
    }

    .header {
        padding: 0 12px;
    }

    .footer {
        padding: 0 12px;
    }

    .cm-line {
        padding: 0 12px 0 4px;
    }
}

/* =============================================================================
   Button Components (shadcn-inspired)
   ============================================================================= */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 500;
    font-family: var(--font-sans);
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease, opacity 0.15s ease;
}

.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-primary), 0 0 0 4px var(--accent-primary);
}

.btn:disabled {
    opacity: 0.5;
    pointer-events: none;
}

/* Primary button */
.btn-primary {
    height: 40px;
    padding: 0 16px;
    background-color: var(--text-primary);
    color: var(--bg-primary);
    border: none;
}

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

/* Ghost button (icon button style) */
.btn-ghost {
    height: 36px;
    width: 36px;
    padding: 0;
    background-color: transparent;
    color: var(--text-muted);
    border: none;
}

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

/* Outline button */
.btn-outline {
    height: 40px;
    padding: 0 16px;
    background-color: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-outline:hover {
    background-color: var(--bg-hover);
    border-color: var(--text-muted);
}

/* Icon size inside buttons */
.btn-icon {
    height: 36px;
    width: 36px;
    padding: 0;
}

.btn svg {
    width: 16px;
    height: 16px;
    flex-shrink: 0;
}

.btn-full {
    width: 100%;
}

/* =============================================================================
   Form Components (shadcn-inspired)
   ============================================================================= */

.form-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
}

.form-field label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.form-field input {
    height: 40px;
    width: 100%;
    padding: 0 12px;
    font-size: 14px;
    font-family: var(--font-sans);
    background-color: transparent;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.form-field input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(203, 166, 247, 0.15);
}

.form-field input::placeholder {
    color: var(--text-muted);
}

/* =============================================================================
   Login Page (shadcn-inspired card)
   ============================================================================= */

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 16px;
    background-color: var(--bg-primary);
}

.login-card {
    width: 100%;
    max-width: 400px;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2), 0 1px 2px rgba(0, 0, 0, 0.1);
}

.login-card-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 24px 24px 0;
    text-align: center;
}

.login-logo {
    width: 96px;
    height: 96px;
    border-radius: 50%;
}

.login-title {
    font-size: 24px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.025em;
}

.login-description {
    font-size: 14px;
    color: var(--text-muted);
}

.login-card-content {
    padding: 24px;
}

.error-message {
    display: none;
    padding: 12px;
    margin-bottom: 16px;
    font-size: 14px;
    color: var(--status-disconnected);
    background-color: rgba(243, 139, 168, 0.1);
    border: 1px solid rgba(243, 139, 168, 0.2);
    border-radius: 6px;
}

/* =============================================================================
   Logout Button (header)
   ============================================================================= */

.logout-form {
    display: inline-flex;
    margin-left: 8px;
}

.logout-button {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 32px;
    width: 32px;
    padding: 0;
    background-color: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-muted);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.logout-button:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.logout-button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-secondary), 0 0 0 4px var(--accent-primary);
}

.logout-button svg {
    width: 16px;
    height: 16px;
}

/* =============================================================================
   Install Button (header) - matches logout button style
   ============================================================================= */

.install-button {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    padding: 0;
    background-color: transparent;
    color: var(--text-muted);
    border: none;
    border-radius: var(--radius-md, 6px);
    cursor: pointer;
    transition: background-color 0.15s ease, color 0.15s ease;
}

.install-button:hover {
    background-color: var(--bg-hover);
    color: var(--text-primary);
}

.install-button:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg-secondary), 0 0 0 4px var(--accent-primary);
}

.install-button svg {
    width: 16px;
    height: 16px;
}
