/* ============================================
   WriteBox - Minimalist Writing App Styles
   ============================================ */

/* ---------- CSS Variables (Theming) ---------- */
:root {
    /* Light theme (default) */
    --bg: #ffffff;
    --bg-soft: #fafafa;
    --bg-elevated: #ffffff;
    --text: #1a1a1a;
    --text-soft: #555555;
    --text-muted: #999999;
    --border: #ececec;
    --accent: #2563eb;
    --accent-soft: #eff4ff;
    --danger: #dc2626;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
    --font-serif: 'Iowan Old Style', 'Apple Garamond', 'Baskerville', 'Times New Roman', serif;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    --transition: 0.25s ease;
}

html.dark,
[data-theme="dark"] {
    --bg: #1a1a1a;
    --bg-soft: #242424;
    --bg-elevated: #2a2a2a;
    --text: #e8e8e8;
    --text-soft: #b0b0b0;
    --text-muted: #707070;
    --border: #333333;
    --accent: #60a5fa;
    --accent-soft: #1e3a5f;
    --danger: #f87171;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

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

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

button {
    font-family: inherit;
    cursor: pointer;
    background: none;
    border: none;
    color: inherit;
}

/* ---------- Toolbar ---------- */
.toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background-color: var(--bg);
    border-bottom: 1px solid transparent;
    z-index: 50;
    transition: opacity 0.4s ease, border-color var(--transition), background-color var(--transition);
}

.toolbar.hidden {
    opacity: 0.05;
}

.toolbar.hidden:hover {
    opacity: 1;
}

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

.toolbar-center {
    flex: 1;
    display: flex;
    justify-content: center;
    padding: 0 16px;
}

.app-title {
    font-weight: 600;
    font-size: 16px;
    color: var(--text);
    margin-left: 4px;
    letter-spacing: -0.01em;
}

.doc-title-input {
    width: 100%;
    max-width: 400px;
    padding: 8px 12px;
    text-align: center;
    background: transparent;
    border: 1px solid transparent;
    border-radius: 6px;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition), background-color var(--transition);
}

.doc-title-input:hover {
    border-color: var(--border);
}

.doc-title-input:focus {
    outline: none;
    border-color: var(--accent);
    background-color: var(--bg-soft);
}

.icon-btn {
    width: 36px;
    height: 36px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    color: var(--text-soft);
    transition: background-color var(--transition), color var(--transition);
}

.icon-btn:hover {
    background-color: var(--bg-soft);
    color: var(--text);
}

.icon-btn:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.save-status {
    font-size: 12px;
    color: var(--text-muted);
    margin-right: 8px;
    transition: color var(--transition);
    user-select: none;
}

.save-status.saving {
    color: var(--accent);
}

/* ---------- Sidebar ---------- */
.sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 300px;
    background-color: var(--bg-elevated);
    border-right: 1px solid var(--border);
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    z-index: 100;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow);
}

.sidebar.open {
    transform: translateX(0);
}

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

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-soft);
}

.new-doc-btn {
    margin: 12px 16px;
    padding: 10px 16px;
    background-color: var(--accent);
    color: white;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    transition: opacity var(--transition), transform var(--transition);
}

.new-doc-btn:hover {
    opacity: 0.9;
    transform: translateY(-1px);
}

.new-doc-btn:active {
    transform: translateY(0);
}

.doc-list {
    list-style: none;
    flex: 1;
    overflow-y: auto;
    padding: 4px 8px 16px;
}

.doc-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 2px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color var(--transition);
    animation: fadeIn 0.3s ease;
}

.doc-item:hover {
    background-color: var(--bg-soft);
}

.doc-item.active {
    background-color: var(--accent-soft);
}

.doc-item.active .doc-item-title {
    color: var(--accent);
    font-weight: 500;
}

.doc-item-info {
    flex: 1;
    min-width: 0;
}

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

.doc-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.doc-item-delete {
    opacity: 0;
    width: 28px;
    height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: var(--text-muted);
    transition: opacity var(--transition), color var(--transition), background-color var(--transition);
    flex-shrink: 0;
    margin-left: 8px;
}

.doc-item:hover .doc-item-delete {
    opacity: 1;
}

.doc-item-delete:hover {
    color: var(--danger);
    background-color: var(--bg);
}

/* ---------- Backdrop ---------- */
.backdrop {
    position: fixed;
    inset: 0;
    background-color: rgba(0, 0, 0, 0.4);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
    z-index: 90;
}

.backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* ---------- Writing Area ---------- */
.writing-area {
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 32px;
    display: flex;
    justify-content: center;
    overflow-y: auto;
    overflow-x: hidden;
    animation: fadeIn 0.5s ease;
}

.editor {
    width: 100%;
    max-width: 720px;
    min-height: 100%;
    padding: 48px 32px 120px;
    background: transparent;
    border: none;
    outline: none;
    resize: none;
    color: var(--text);
    font-family: var(--font-serif);
    font-size: 19px;
    line-height: 1.7;
    letter-spacing: 0.01em;
    transition: color var(--transition);
    /* Disable browser scroll inside textarea — parent handles scrolling */
    overflow: hidden;
}

.editor::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

.editor::selection {
    background-color: var(--accent);
    color: white;
}

/* ---------- Status bar ---------- */
.status-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 0 16px;
    background-color: var(--bg);
    border-top: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
    z-index: 40;
    transition: opacity 0.4s ease, background-color var(--transition), border-color var(--transition);
    user-select: none;
}

.status-bar.hidden {
    opacity: 0.05;
}

.status-bar.hidden:hover {
    opacity: 1;
}

.stat-sep {
    opacity: 0.4;
}

/* ---------- Toast ---------- */
.toast {
    position: fixed;
    bottom: 56px;
    left: 50%;
    transform: translate(-50%, 20px);
    padding: 10px 18px;
    background-color: var(--text);
    color: var(--bg);
    border-radius: 8px;
    font-size: 13px;
    font-weight: 500;
    box-shadow: var(--shadow);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease, transform 0.3s ease;
    z-index: 200;
}

.toast.visible {
    opacity: 1;
    transform: translate(-50%, 0);
}

/* ---------- Animations ---------- */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(4px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ---------- Scrollbar ---------- */
.writing-area::-webkit-scrollbar,
.doc-list::-webkit-scrollbar {
    width: 8px;
}

.writing-area::-webkit-scrollbar-track,
.doc-list::-webkit-scrollbar-track {
    background: transparent;
}

.writing-area::-webkit-scrollbar-thumb,
.doc-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 4px;
}

.writing-area::-webkit-scrollbar-thumb:hover,
.doc-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ---------- Responsive ---------- */
@media (max-width: 768px) {
    .toolbar {
        height: 52px;
        padding: 0 8px;
    }

    .app-title {
        display: none;
    }

    .doc-title-input {
        font-size: 13px;
        padding: 6px 8px;
    }

    .editor {
        padding: 32px 20px 80px;
        font-size: 17px;
        line-height: 1.65;
    }

    .writing-area {
        top: 52px;
    }

    .save-status {
        display: none;
    }

    .sidebar {
        width: 85%;
        max-width: 320px;
    }

    .status-bar {
        font-size: 11px;
        gap: 8px;
    }
}

@media (max-width: 480px) {
    .editor {
        padding: 24px 16px 80px;
        font-size: 16px;
    }

    .toolbar-right .icon-btn:nth-child(3) {
        display: none; /* Hide import on very small screens */
    }
}

/* ---------- Print styles ---------- */
@media print {
    .toolbar,
    .sidebar,
    .status-bar,
    .backdrop,
    .toast {
        display: none !important;
    }

    .writing-area {
        position: static;
        overflow: visible;
    }

    .editor {
        color: #000;
        font-size: 12pt;
        max-width: 100%;
    }
}

/* ---------- Font Size Controls ---------- */
.font-size-group {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    margin: 0 4px;
    padding: 2px 4px;
    border-radius: 8px;
    background-color: var(--bg-soft);
    border: 1px solid var(--border);
    transition: background-color var(--transition), border-color var(--transition);
}

.font-size-group .icon-btn {
    width: 28px;
    height: 28px;
    border-radius: 6px;
}

.font-size-display {
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    color: var(--text-soft);
    min-width: 38px;
    text-align: center;
    user-select: none;
    font-family: var(--font-sans);
    transition: color var(--transition);
}

.font-size-btn:disabled,
.font-size-btn[aria-disabled="true"] {
    opacity: 0.35;
    cursor: not-allowed;
}

/* Override editor font-size via CSS variable so JS can update it cleanly */
.editor {
    font-size: var(--editor-font-size, 19px);
}

/* Responsive — hide the size label on small screens, keep buttons */
@media (max-width: 768px) {
    .font-size-display {
        display: none;
    }
    .font-size-group {
        margin: 0 2px;
        padding: 1px 2px;
    }
    .editor {
        /* keep JS-set size on mobile too, but allow a slightly smaller default */
        font-size: var(--editor-font-size, 17px);
    }
}

@media (max-width: 480px) {
    .font-size-group {
        display: none; /* hide on very small screens to save space; shortcuts still work */
    }
    .editor {
        font-size: var(--editor-font-size, 16px);
    }
}

@media print {
    .editor {
        font-size: 12pt;
    }
}
