/**
 * Project Obsidian — Stylesheet
 * Dark obsidian theme, responsive, self-contained.
 */

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

:root {
    --bg-primary: #0d0d0d;
    --bg-secondary: #161616;
    --bg-tertiary: #1e1e1e;
    --bg-hover: #262626;
    --bg-active: #2a2a2a;
    --border: #333;
    --border-light: #444;
    --text-primary: #e0e0e0;
    --text-secondary: #999;
    --text-muted: #666;
    --accent: #7c8aff;
    --accent-hover: #9aa3ff;
    --accent-dim: rgba(124, 138, 255, 0.15);
    --danger: #ff4d4d;
    --danger-hover: #ff6666;
    --warning: #ffaa33;
    --warning-hover: #ffbb55;
    --success: #4dff88;
    --success-bg: rgba(77, 255, 136, 0.1);
    --radius: 6px;
    --radius-lg: 10px;
    --shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    --transition: 0.15s ease;
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-mono: 'SF Mono', 'Fira Code', 'Cascadia Code', Consolas, monospace;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--bg-primary);
    -webkit-font-smoothing: antialiased;
}

/* ─── Views ───────────────────────────────────────────────────── */
.view {
    display: none;
    height: 100%;
}

.view.active {
    display: flex;
    flex-direction: column;
}

/* ─── Auth Pages (Login / Setup / Emergency) ──────────────────── */
.auth-container {
    max-width: 400px;
    width: 100%;
    margin: auto;
    padding: 40px 24px;
}

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

.auth-header h1 {
    font-size: 28px;
    font-weight: 600;
    color: var(--text-primary);
    letter-spacing: -0.5px;
}

.auth-header .subtitle {
    color: var(--text-secondary);
    margin-top: 8px;
    font-size: 14px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.auth-footer {
    text-align: center;
    margin-top: 24px;
}

/* ─── Forms ───────────────────────────────────────────────────── */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.form-group label {
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

input[type="text"],
input[type="password"],
input[type="email"] {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 14px;
    outline: none;
    transition: border-color var(--transition);
}

input:focus {
    border-color: var(--accent);
}

/* ─── Buttons ─────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    font-family: var(--font);
    font-size: 14px;
    font-weight: 500;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-tertiary);
    color: var(--text-primary);
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

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

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #000;
    font-weight: 600;
}

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

.btn-danger {
    color: var(--danger);
    border-color: rgba(255, 77, 77, 0.3);
}

.btn-danger:hover {
    background: rgba(255, 77, 77, 0.1);
    border-color: var(--danger);
}

.btn-warning {
    color: var(--warning);
    border-color: rgba(255, 170, 51, 0.3);
}

.btn-warning:hover {
    background: rgba(255, 170, 51, 0.1);
    border-color: var(--warning);
}

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

.btn-full {
    width: 100%;
}

.btn-link {
    background: none;
    border: none;
    color: var(--accent);
    padding: 4px 0;
    font-size: 13px;
}

.btn-link:hover {
    color: var(--accent-hover);
    background: none;
    border: none;
    text-decoration: underline;
}

.btn-cancel {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ─── App Header ──────────────────────────────────────────────── */
.app-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.header-left {
    flex-shrink: 0;
}

.app-title {
    font-size: 18px;
    font-weight: 600;
    letter-spacing: -0.5px;
}

.header-center {
    flex: 1;
    display: flex;
    justify-content: center;
}

.search-bar {
    width: 100%;
    max-width: 400px;
}

.search-bar input {
    width: 100%;
    padding: 8px 14px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 20px;
    color: var(--text-primary);
    font-family: var(--font);
    font-size: 13px;
    outline: none;
    transition: border-color var(--transition);
}

.search-bar input:focus {
    border-color: var(--accent);
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-shrink: 0;
}

/* ─── Key Indicator ───────────────────────────────────────────── */
.key-indicator {
    font-size: 12px;
    font-weight: 500;
    padding: 4px 10px;
    border-radius: 12px;
}

.key-loaded {
    color: var(--success);
    background: var(--success-bg);
}

.key-not-loaded {
    color: var(--text-muted);
    background: rgba(102, 102, 102, 0.15);
}

.recovery-indicator {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 12px;
    color: var(--text-secondary);
    background: rgba(102, 102, 102, 0.1);
    display: none;
}

.recovery-indicator.warning {
    color: var(--warning);
    background: rgba(255, 170, 51, 0.1);
}

/* ─── Toolbar ─────────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
    gap: 8px;
}

.toolbar-left,
.toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

/* ─── App Content ─────────────────────────────────────────────── */
.app-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* ─── Notes Sidebar ───────────────────────────────────────────── */
.notes-sidebar {
    width: 280px;
    min-width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    flex-shrink: 0;
}

.notes-list {
    padding: 8px;
}

.note-item {
    padding: 12px 14px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background var(--transition);
    margin-bottom: 2px;
}

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

.note-item.active {
    background: var(--accent-dim);
}

.note-item-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

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

.note-item-encrypted {
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

.empty-state {
    text-align: center;
    color: var(--text-muted);
    padding: 40px 20px;
    font-size: 14px;
}

/* ─── Editor Pane ─────────────────────────────────────────────── */
.editor-pane {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.editor-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
}

.editor-active {
    display: flex;
    flex-direction: column;
    height: 100%;
}

.editor-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.editor-title {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 600;
    padding: 4px 0;
    outline: none;
    font-family: var(--font);
}

.editor-title::placeholder {
    color: var(--text-muted);
}

.editor-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.editor-body {
    flex: 1;
    padding: 20px;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.7;
    resize: none;
    outline: none;
}

.editor-body::placeholder {
    color: var(--text-muted);
}

.editor-footer {
    padding: 8px 20px;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.editor-footer span {
    font-size: 12px;
    color: var(--text-muted);
}

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

.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
}

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

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
}

.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 20px;
}

/* ─── Recovery Codes Display ──────────────────────────────────── */
.recovery-codes-list {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 16px 0;
}

.recovery-code {
    font-family: var(--font-mono);
    font-size: 14px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-align: center;
    color: var(--accent);
    user-select: all;
}

/* ─── Warning Text ────────────────────────────────────────────── */
.warning-text {
    color: var(--warning);
    font-size: 14px;
    line-height: 1.6;
}

/* ─── Progress Bar ────────────────────────────────────────────── */
.progress-bar {
    width: 100%;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    overflow: hidden;
    margin: 16px 0 8px;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    width: 0;
    transition: width 0.3s ease;
}

/* ─── Toast Notifications ─────────────────────────────────────── */
#toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.toast {
    padding: 12px 20px;
    border-radius: var(--radius);
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    box-shadow: var(--shadow);
    animation: toast-in 0.3s ease;
    max-width: 360px;
}

.toast.success {
    border-color: rgba(77, 255, 136, 0.3);
    background: rgba(77, 255, 136, 0.1);
}

.toast.error {
    border-color: rgba(255, 77, 77, 0.3);
    background: rgba(255, 77, 77, 0.1);
}

.toast.warning {
    border-color: rgba(255, 170, 51, 0.3);
    background: rgba(255, 170, 51, 0.1);
}

.toast.fade-out {
    animation: toast-out 0.3s ease forwards;
}

@keyframes toast-in {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

@keyframes toast-out {
    from { opacity: 1; transform: translateX(0); }
    to   { opacity: 0; transform: translateX(40px); }
}

/* ─── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
    .app-header {
        flex-wrap: wrap;
        gap: 8px;
        padding: 10px 12px;
    }

    .header-center {
        order: 3;
        flex-basis: 100%;
    }

    .search-bar {
        max-width: 100%;
    }

    .header-right {
        gap: 6px;
    }

    .toolbar {
        padding: 8px 12px;
    }

    .app-content {
        flex-direction: column;
    }

    .notes-sidebar {
        width: 100%;
        min-width: 100%;
        max-height: 200px;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }

    .notes-list {
        display: flex;
        gap: 4px;
        overflow-x: auto;
        padding: 8px;
    }

    .note-item {
        min-width: 150px;
        margin-bottom: 0;
    }

    .editor-header {
        padding: 10px 12px;
        flex-wrap: wrap;
    }

    .editor-title {
        font-size: 16px;
    }

    .editor-body {
        padding: 12px;
        font-size: 13px;
    }

    .auth-container {
        padding: 24px 16px;
    }

    .recovery-codes-list {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 480px) {
    .toolbar-right {
        gap: 4px;
    }

    .btn-small {
        padding: 5px 8px;
        font-size: 12px;
    }

    .key-indicator,
    .recovery-indicator {
        font-size: 11px;
        padding: 3px 8px;
    }
}

/* ─── Scrollbar ───────────────────────────────────────────────── */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

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

::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--border-light);
}

/* ─── Selection ───────────────────────────────────────────────── */
::selection {
    background: var(--accent);
    color: #000;
}
