/* B2 Notes — Components */

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius-md);
    font-size: 0.875rem;
    font-weight: 500;
    font-family: var(--font-sans);
    cursor: pointer;
    border: 1px solid transparent;
    transition: all var(--transition-fast);
    text-decoration: none;
    white-space: nowrap;
}

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

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

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

.btn-secondary {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

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

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

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

.btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    padding: 6px 8px;
}

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

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8125rem;
}

.btn-full {
    width: 100%;
}

.btn-icon {
    padding: 6px;
    border-radius: var(--radius-md);
}

.btn-icon svg {
    width: 18px;
    height: 18px;
}

/* ── Form Elements ── */
.form-group {
    margin-bottom: 16px;
}

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

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.875rem;
    font-family: var(--font-sans);
    outline: none;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 3px var(--color-primary-light);
}

.form-error {
    color: var(--color-danger);
    font-size: 0.8125rem;
    margin-top: 4px;
    min-height: 20px;
}

/* ── Modal ── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.modal-overlay.active {
    opacity: 1;
    visibility: visible;
}

.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    border: 1px solid var(--border-color);
    transform: translateY(10px);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal {
    transform: translateY(0);
}

.modal-header {
    padding: 20px 24px 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    padding: 0 24px 20px;
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

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

.toast {
    padding: 12px 20px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-md);
    font-size: 0.875rem;
    color: var(--text-primary);
    display: flex;
    align-items: center;
    gap: 8px;
    animation: toastSlideIn 0.3s ease;
    max-width: 380px;
}

.toast.toast-success {
    border-left: 4px solid var(--color-success);
}

.toast.toast-error {
    border-left: 4px solid var(--color-danger);
}

.toast.toast-warning {
    border-left: 4px solid var(--color-warning);
}

@keyframes toastSlideIn {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

/* ── Dropdown ── */
.dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-menu {
    position: absolute;
    top: 100%;
    right: 0;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px 0;
    z-index: 500;
    display: none;
}

.dropdown-menu.active {
    display: block;
}

.dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-sans);
    transition: background var(--transition-fast);
}

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

.dropdown-item.danger {
    color: var(--color-danger);
}

.dropdown-divider {
    border-top: 1px solid var(--border-color);
    margin: 4px 0;
}

.dropdown-label {
    padding: 6px 16px;
    font-size: 0.6875rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Tags ── */
.tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-hover);
    color: var(--text-secondary);
    cursor: default;
}

.tag-removable {
    cursor: pointer;
}

.tag-removable:hover {
    opacity: 0.8;
}

/* ── Context Menu (right-click) ── */
.context-menu {
    position: fixed;
    min-width: 180px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px 0;
    z-index: 1500;
    display: none;
}

.context-menu.active {
    display: block;
}

.context-menu .dropdown-item.has-submenu {
    justify-content: space-between;
    cursor: default;
}

.context-menu .dropdown-item.has-submenu::after {
    content: '\25B6';
    font-size: 0.625rem;
    color: var(--text-muted);
    margin-left: 12px;
    flex-shrink: 0;
}

.context-menu .dropdown-item.has-submenu:hover::after {
    color: var(--text-primary);
}

.context-menu .context-submenu {
    position: fixed;
}

.context-menu .dropdown-item .ctx-check {
    width: 16px;
    flex-shrink: 0;
    text-align: center;
    font-size: 0.75rem;
    color: var(--color-primary);
    margin-right: 4px;
}

/* ── Loading Spinner ── */
.spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--color-primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

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

::-webkit-scrollbar-track {
    background: transparent;
}

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

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

/* ── Selection ── */
::selection {
    background: var(--color-primary-light);
    color: var(--color-primary);
}

/* ── Theme Editor ── */
.theme-editor-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg-modal-overlay);
    z-index: 1100;
    display: none;
    justify-content: flex-end;
}

.theme-editor-overlay.active {
    display: flex;
}

.theme-editor {
    width: 360px;
    max-width: 90vw;
    height: 100%;
    max-height: 100dvh;
    background: var(--bg-card);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    animation: slideInRight 0.25s ease;
}

@keyframes slideInRight {
    from { transform: translateX(100%); }
    to { transform: translateX(0); }
}

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

.theme-editor-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.theme-editor-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
}

.theme-section {
    margin-bottom: 20px;
}

.theme-section-title {
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color-light);
}

.theme-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 0;
}

.theme-row label {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.theme-row input[type="color"] {
    width: 36px;
    height: 28px;
    padding: 1px;
    border: 2px solid var(--border-color);
    border-radius: var(--radius-sm);
    cursor: pointer;
    background: transparent;
}

.theme-row input[type="color"]:hover {
    border-color: var(--color-primary);
}

.theme-select {
    width: 180px;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 0.8125rem;
    font-family: var(--font-sans);
    cursor: pointer;
}

.theme-editor-footer {
    padding: 16px 20px;
    padding-bottom: calc(16px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

/* ── Settings Controls ── */

.settings-value {
    font-size: 0.75rem;
    color: var(--text-muted);
    min-width: 44px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.theme-row input[type="range"] {
    flex: 1;
    max-width: 120px;
    accent-color: var(--color-primary);
    margin: 0 8px;
}

.settings-toggle {
    position: relative;
    display: inline-block;
    width: 38px;
    height: 22px;
    cursor: pointer;
}

.settings-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}

.settings-toggle-track {
    position: absolute;
    inset: 0;
    background: var(--border-color);
    border-radius: 11px;
    transition: background var(--transition-fast);
}

.settings-toggle-track::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: var(--bg-main);
    border-radius: 50%;
    transition: transform var(--transition-fast);
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}

.settings-toggle input:checked + .settings-toggle-track {
    background: var(--color-primary);
}

.settings-toggle input:checked + .settings-toggle-track::after {
    transform: translateX(16px);
}

.theme-section-divider {
    height: 1px;
    background: var(--border-color);
    margin: 8px 0 20px;
    position: relative;
}

.theme-section-divider::after {
    content: 'THEME COLORS';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-card);
    padding: 0 10px;
    font-size: 0.625rem;
    font-weight: 600;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

/* ── Folder Drag-and-Drop ── */
.folder-dragging {
    opacity: 0.5;
}

.folder-drag-over-before {
    box-shadow: inset 0 2px 0 0 var(--color-primary);
}

.folder-drag-over-inside {
    background: var(--color-primary-light) !important;
}

.folder-drag-over-after {
    box-shadow: inset 0 -2px 0 0 var(--color-primary);
}

/* Note card while it's being dragged into a folder. Source card dims so
   users can see the drag is in flight. The floating clone for touch
   dragging is styled inline by notes.js. */
.note-card-dragging {
    opacity: 0.45;
}

/* ── Detail Popup (click-driven info popup with click-origin animation) ──
   Animates from the point the user clicked toward viewport center, growing
   into a card. Used by Overview / Kanban Progress / Activity heatmap. */
.detail-popup-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(0, 0, 0, 0);
    transition: background 250ms ease;
    /* pointer-events disabled by default so a stale / closing overlay
       can't swallow right-clicks (or any other event) on the dashboard
       underneath. Re-enabled only while the popup is actively open. */
    pointer-events: none;
}
.detail-popup-overlay.open {
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(3px);
    -webkit-backdrop-filter: blur(3px);
    pointer-events: auto;
}
.detail-popup-card {
    position: fixed;
    width: min(520px, calc(100vw - 32px));
    max-height: 80vh;
    overflow-y: auto;
    /* ~60% opaque, theme-aware. `color-mix` blends the theme's --bg-card
       with transparency so the dashboard behind shows through softly.
       The backdrop-filter blur on the card itself frosts whatever is
       behind so text stays legible. */
    background: color-mix(in srgb, var(--bg-card, #ffffff) 60%, transparent);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow:
        0 20px 50px rgba(0, 0, 0, 0.5),
        0 4px 12px rgba(0, 0, 0, 0.28);
    /* Both `top/left` and `transform` are transitioned so the card travels
       from click point → center while scaling up. The cubic-bezier with
       slight overshoot gives the "fluid" feel. */
    transition:
        left 420ms cubic-bezier(0.34, 1.4, 0.64, 1),
        top  420ms cubic-bezier(0.34, 1.4, 0.64, 1),
        transform 420ms cubic-bezier(0.34, 1.4, 0.64, 1),
        opacity 220ms ease;
    will-change: transform, top, left, opacity;
}
.detail-popup-card::before {
    /* Accent stripe at the top of the card, color set per-popup via the
       --detail-accent custom property */
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--detail-accent, var(--color-primary));
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
}
.detail-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px 10px;
    border-bottom: 1px solid var(--border-color);
}
.detail-popup-title {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--text-primary);
}
.detail-popup-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
    padding: 0 6px;
    border-radius: 4px;
}
.detail-popup-close:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}
.detail-popup-body {
    padding: 16px 20px;
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 1.55;
}
.detail-popup-body h4 {
    margin: 16px 0 6px;
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.6px;
}
.detail-popup-body h4:first-child { margin-top: 0; }
.detail-popup-body .dp-stat-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px 16px;
    margin: 8px 0;
}
.detail-popup-body .dp-stat {
    display: flex;
    flex-direction: column;
    background: var(--bg-hover, #f1f5f9);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 10px;
}
.detail-popup-body .dp-stat-num {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}
.detail-popup-body .dp-stat-lbl {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.detail-popup-body .dp-row {
    display: flex;
    justify-content: space-between;
    padding: 4px 0;
    border-bottom: 1px dashed var(--border-color);
}
.detail-popup-body .dp-row:last-child { border-bottom: none; }
.detail-popup-body .dp-row-label { color: var(--text-secondary); }
.detail-popup-body .dp-row-value { color: var(--text-primary); font-weight: 500; }
.detail-popup-body .dp-empty {
    text-align: center;
    color: var(--text-muted);
    font-style: italic;
    padding: 20px 0;
}
.detail-popup-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    padding: 12px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-hover, #f1f5f9);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

/* Make Overview / Kanban progress / heatmap items obviously clickable */
.ov-tool-row,
.ov-extra,
.ov-hero-row,
.ov-donut-wrap,
.kanban-progress-item,
.heatmap-cell:not(.empty):not(.level-0) {
    cursor: pointer;
    transition: background 0.15s ease, transform 0.15s ease;
}
.ov-tool-row:hover,
.ov-extra:hover,
.ov-hero-row:hover,
.kanban-progress-item:hover {
    background: var(--hover-bg);
    border-radius: 6px;
}
.ov-donut-wrap:hover { transform: scale(1.02); }
.heatmap-cell:not(.empty):not(.level-0):hover {
    outline: 1px solid var(--color-primary);
    outline-offset: 1px;
}

/* ── Shared user color palette for folders ─────────────────────────
   Used by both the notes folder modal and the feature-folder edit
   dialog (Charts, Roadmaps). Visual matches kanban-palette-swatch. */
.folder-palette-swatches {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-bottom: 6px;
    min-height: 24px;
    align-items: center;
}
.folder-palette-swatch {
    width: 24px;
    height: 24px;
    border-radius: 4px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: transform 0.1s, border-color 0.15s;
}
.folder-palette-swatch:hover {
    transform: scale(1.15);
    border-color: rgba(255, 255, 255, 0.4);
}
.folder-palette-swatch.active {
    border-color: var(--color-primary, #6366f1);
    box-shadow: 0 0 0 1px var(--color-primary, #6366f1);
}
.folder-palette-empty {
    font-size: 0.7rem;
    color: var(--text-muted);
    opacity: 0.6;
}
