/* ==========================================================================
   Flashnotes v3 — styling
   All colors live in CSS custom properties; the derived ones (--surface,
   --border, --muted) are recomputed by app.js whenever bg/text change.
   ========================================================================== */

:root {
    --bg: #1a1a1a;
    --text: #c8a96e;
    --accent: #c8a96e;
    --surface: #262523;
    --border: #3a3835;
    --muted: #8d867a;
    --font: 'JetBrains Mono', monospace;
    --font-size: 15px;
    --line-height: 1.8;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }

::selection { background: var(--accent); color: var(--bg); }

html, body {
    height: 100%;                   /* bounds #app to the viewport so only the
                                       editor scrolls internally, keeping the
                                       header/tab bar/status bar always visible */
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    transition: background-color 0.35s ease, color 0.35s ease;
}

/* Centered container, switchable to full width */
#app {
    width: 100%;
    max-width: 860px;
    height: 100vh;                  /* bounded (not just a floor): header/tab
                                       bar/status bar stay pinned, the editor
                                       is the only part that scrolls */
    margin: 0 auto;
    padding: 0 24px 5px;
    display: flex;
    flex-direction: column;
    transition: max-width 0.4s ease;
}

#app.full-width {
    max-width: 100%;
}

/* --------------------------------------------------------------------------
   Header
   -------------------------------------------------------------------------- */

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 22px 0 16px;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.35s ease, opacity 0.3s ease;
}

.logo {
    color: var(--accent);
    font-size: 20px;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.logo .version {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
    margin-left: 4px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.btn {
    background: transparent;
    color: var(--muted);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 14px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    transition: color 0.2s ease, border-color 0.2s ease, background-color 0.2s ease;
}

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

.btn-icon {
    padding: 6px 10px;
    font-size: 14px;
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
    color: var(--muted);
    border-color: var(--border);
}

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

.btn-danger:hover {
    color: #d16a6a;
    border-color: #d16a6a;
}

/* --------------------------------------------------------------------------
   Settings panel (collapsible)
   -------------------------------------------------------------------------- */

.settings-panel {
    max-height: 0;
    opacity: 0;
    overflow: hidden;
    transition: max-height 0.4s ease, opacity 0.3s ease;
}

.settings-panel.open {
    max-height: 640px;
    opacity: 1;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
    gap: 18px 28px;
    padding: 22px 4px;
    border-bottom: 1px solid var(--border);
    transition: border-color 0.35s ease;
}

.setting label {
    display: block;
    color: var(--muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.setting .live-value {
    color: var(--accent);
    text-transform: none;
    letter-spacing: 0;
}

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

/* Color pickers */
input[type="color"] {
    width: 34px;
    height: 26px;
    padding: 0;
    border: 1px solid var(--border);
    border-radius: 5px;
    background: transparent;
    cursor: pointer;
}

/* Preset color dots */
.presets {
    display: flex;
    gap: 6px;
}

.preset-dot {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 1px solid var(--border);
    cursor: pointer;
    padding: 0;
    transition: transform 0.15s ease, border-color 0.2s ease;
}

.preset-dot:hover {
    transform: scale(1.2);
    border-color: var(--accent);
}

/* Select */
select {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 6px 10px;
    font-family: inherit;
    font-size: 12px;
    cursor: pointer;
    width: 100%;
    max-width: 200px;
}

/* Range sliders */
input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    max-width: 200px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    outline: none;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
}

/* Custom toggle switch */
.switch {
    position: relative;
    display: inline-block;
    width: 42px;
    height: 22px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.switch .slider {
    position: absolute;
    inset: 0;
    background: var(--border);
    border-radius: 22px;
    transition: background-color 0.25s ease;
}

.switch .slider::before {
    content: "";
    position: absolute;
    width: 16px;
    height: 16px;
    left: 3px;
    top: 3px;
    background: var(--text);
    border-radius: 50%;
    transition: transform 0.25s ease, background-color 0.25s ease;
}

.switch input:checked + .slider {
    background: var(--accent);
}

.switch input:checked + .slider::before {
    transform: translateX(20px);
    background: var(--bg);
}

/* --------------------------------------------------------------------------
   Tab bar
   -------------------------------------------------------------------------- */

main.content {
    flex: 1;                       /* grow to fill remaining height so the
                                       status bar below it stays pinned to
                                       the bottom on short content */
    min-height: 0;                  /* override the flex default
                                       min-height:auto, which would otherwise
                                       let the editor's content inflate this
                                       container instead of scrolling inside
                                       it */
    display: flex;
    flex-direction: column;        /* lets the editor (not empty space) absorb
                                       that grown height, see #editor flex */
}

.tab-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 16px 0 12px;
    overflow-x: auto;
    scrollbar-width: none;         /* horizontally scrollable, no visible bar */
    transition: opacity 0.3s ease;
}

.tab-bar::-webkit-scrollbar { display: none; }

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--muted);
    font-size: 12px;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    flex-shrink: 0;
    transition: color 0.2s ease, border-color 0.2s ease,
                background-color 0.2s ease, opacity 0.2s ease;
}

.tab:hover { color: var(--text); border-color: var(--accent); }

.tab.active {
    color: var(--text);
    border-color: var(--accent);
    background: var(--surface);
}

/* Content indicator dot */
.tab .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--accent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.tab.has-content .dot { opacity: 1; }

/* Close button, visible on hover */
.tab .close {
    font-size: 13px;
    opacity: 0;
    padding: 0 1px;
    transition: opacity 0.2s ease, color 0.2s ease;
}

.tab:hover .close { opacity: 0.7; }
.tab .close:hover { opacity: 1; color: var(--accent); }

/* Drag & drop states */
.tab.dragging {
    opacity: 0.4;
    border-style: dashed;
}

.tab.drag-over {
    border-color: var(--accent);
    background: var(--surface);
}

/* New-note button */
.tab-add {
    border: 1px dashed var(--border);
    border-radius: 6px;
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 14px;
    line-height: 1;
    padding: 5px 12px;
    cursor: pointer;
    flex-shrink: 0;
    transition: color 0.2s ease, border-color 0.2s ease;
}

.tab-add:hover {
    color: var(--accent);
    border-color: var(--accent);
}

/* --------------------------------------------------------------------------
   Editor
   -------------------------------------------------------------------------- */

.editor-wrap {
    display: flex;
    min-height: 0;                  /* no fixed floor: with #app bounded to
                                       100vh, a floor here can demand more
                                       room than is available (e.g. at higher
                                       browser zoom) and push the tab bar
                                       partly out of view; flex:1 alone
                                       always fits exactly */
    flex: 1;                       /* fills the tab bar's leftover space
                                       instead of leaving a gap above the
                                       status bar */
    margin-bottom: 8px;             /* small breathing room above the status bar */
}

/* Wrap-aware line-number gutter: one row per *visible* (wrapped) line, kept
   in sync with the textarea via app.js (content, width, scroll, settings). */
.line-numbers {
    flex-shrink: 0;
    min-height: 0;                  /* same flex auto-min-height guard as #editor */
    box-sizing: border-box;
    padding: 8px 10px 8px 0;
    margin-right: 8px;
    border-right: 1px solid var(--border);
    text-align: right;
    color: var(--muted);
    opacity: 0.45;                   /* dimmer than regular muted text so
                                        numbers don't compete with the note */
    font-family: var(--font);
    font-size: var(--font-size);
    line-height: var(--line-height);
    font-variant-ligatures: none;
    font-feature-settings: "calt" 0, "liga" 0;
    white-space: pre;
    overflow: hidden;
    user-select: none;
    transition: color 0.35s ease, border-color 0.35s ease;
}

.line-numbers.hidden {
    display: none;
}

#editor {
    width: 100%;
    min-width: 0;                  /* allow shrinking inside the flex row */
    min-height: 0;                  /* without this, a flex item's default
                                       min-height:auto lets a <textarea>
                                       grow to fit all its content instead
                                       of stretching to .editor-wrap and
                                       scrolling internally */
    flex: 1;
    background: transparent;
    color: var(--text);
    border: none;
    outline: none;
    resize: none;
    font-family: var(--font);
    font-size: var(--font-size);
    line-height: var(--line-height);
    font-variant-ligatures: none;
    font-feature-settings: "calt" 0, "liga" 0;
    caret-color: var(--accent);
    padding: 8px 0;
    transition: color 0.35s ease;
}

/* Ligatures toggle (Settings): default off (see #editor/.line-numbers above)
   to avoid a Chromium ligature-reshaping rendering bug with JetBrains Mono
   (e.g. "-->" + space visually loses the leading characters). */
#app.ligatures-on #editor,
#app.ligatures-on .line-numbers {
    font-variant-ligatures: normal;
    font-feature-settings: normal;
}

#editor::placeholder {
    color: var(--muted);
    opacity: 0.7;
}

/* --------------------------------------------------------------------------
   Status bar
   -------------------------------------------------------------------------- */

.status-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 0;
    border-top: 1px solid var(--border);
    color: var(--muted);
    font-size: 11px;
    transition: border-color 0.35s ease, opacity 0.3s ease;
}

.status-bar .sep { opacity: 0.5; }

.save-indicator {
    margin-left: auto;
    color: var(--accent);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.save-indicator.flash { opacity: 1; }

/* --------------------------------------------------------------------------
   Focus mode: only the editor remains
   -------------------------------------------------------------------------- */

body.focus-mode .app-header,
body.focus-mode .settings-panel,
body.focus-mode .tab-bar,
body.focus-mode .status-bar {
    opacity: 0;
    max-height: 0;
    padding-top: 0;
    padding-bottom: 0;
    border-width: 0;
    overflow: hidden;
    pointer-events: none;
    transition: opacity 0.3s ease, max-height 0.35s ease, padding 0.35s ease;
}

.app-header,
.tab-bar,
.status-bar {
    max-height: 90px;              /* transition anchor for focus mode */
}

/* --------------------------------------------------------------------------
   Toasts
   -------------------------------------------------------------------------- */

.toast-container {
    position: fixed;
    right: 20px;
    bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.toast {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-left: 3px solid var(--accent);
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 12px;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity 0.3s ease, transform 0.3s ease;
}

.toast.show {
    opacity: 1;
    transform: translateY(0);
}

/* --------------------------------------------------------------------------
   Narrow screens
   -------------------------------------------------------------------------- */

@media (max-width: 560px) {
    #app { padding: 0 14px 24px; }

    .app-header {
        flex-wrap: wrap;
        gap: 10px;
        max-height: 140px;
    }

    .settings-grid { grid-template-columns: 1fr; }
}
