/* ==========================================================================
   Notepad App — Windows 11-style online notepad
   BEM-ish "notepad__*" naming. Uses design tokens from main.css only.
   Breakpoints: 768px / 480px (house standard).
   ========================================================================== */

/* ---------- Screen-reader only (mirrors house pattern) ---------- */
.notepad-container .sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ---------- Container ---------- */
.notepad-container {
    max-width: 1000px;
    margin: 0 auto;
}

/* ---------- Window frame ---------- */
.notepad-window {
    --notepad-zoom: 1;
    --notepad-titlebar-height: 48px;
    --notepad-statusbar-height: 32px;
    --notepad-line-height: calc(var(--font-size-base) * var(--notepad-zoom, 1) * var(--line-height-normal));
    position: relative;
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    margin-bottom: var(--space-6);
}

@media (max-width: 768px) {
    .notepad-window {
        --notepad-titlebar-height: 44px;
    }
}

/* ---------- Title bar ---------- */
.notepad__titlebar {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    height: var(--notepad-titlebar-height);
    padding: 0 var(--space-3);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
}

.notepad__titlebar-label {
    flex: 1 1 auto;
    min-width: 0;
    display: block;
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--color-text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notepad__titlebar-doc {
    color: var(--color-text);
}

/* ---------- Icon buttons (title bar + find bar) ---------- */
.notepad__icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    padding: 0;
    background: transparent;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: var(--font-size-base);
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition-fast),
        border-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

.notepad__icon-btn:hover {
    background: var(--color-bg-card);
    border-color: var(--color-border);
    color: var(--color-text);
}

.notepad__icon-btn:active {
    transform: scale(0.98);
}

.notepad__icon-btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.notepad__icon-btn:disabled {
    opacity: 0.45;
    cursor: default;
    transform: none;
}

.notepad__menu-icon svg {
    width: 20px;
    height: 20px;
}

.notepad__help-btn {
    font-weight: 600;
}

@media (max-width: 480px) {
    .notepad__icon-btn {
        width: 44px;
        height: 44px;
    }
}

/* ---------- Menu flyout ---------- */
.notepad__menu {
    position: absolute;
    top: var(--notepad-titlebar-height);
    left: var(--space-3);
    z-index: 60;
    width: 280px;
    max-height: 70vh;
    overflow-y: auto;
    padding: var(--space-2);
    background: var(--color-bg-card);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    opacity: 0;
    visibility: hidden;
    transform: translateY(-4px);
    transition: opacity var(--transition-fast),
        transform var(--transition-fast),
        visibility var(--transition-fast);
}

.notepad__menu--open {
    opacity: 1;
    visibility: visible;
    transform: translateY(0);
}

.notepad__menu[hidden] {
    display: none;
}

.notepad__menu-section {
    padding: var(--space-1) 0;
}

.notepad__menu-section + .notepad__menu-section {
    border-top: 1px solid var(--color-border);
}

.notepad__menu-header {
    padding: var(--space-1) var(--space-2);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--color-text-muted);
}

.notepad__menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-2);
    width: 100%;
    min-height: 36px;
    padding: 0 var(--space-2);
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--font-size-sm);
    text-align: left;
    cursor: pointer;
    transition: background-color var(--transition-fast);
}

.notepad__menu-item:hover {
    background: var(--color-bg-alt);
}

.notepad__menu-item:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.notepad__menu-item:active {
    background: var(--color-bg-alt);
}

.notepad__menu-item[aria-disabled="true"] {
    opacity: 0.45;
    cursor: default;
}

.notepad__menu-check {
    flex: 0 0 auto;
    width: 1.25rem;
    text-align: center;
    font-size: var(--font-size-sm);
    color: var(--color-primary-text);
}

.notepad__menu-label {
    flex: 1 1 auto;
    min-width: 0;
}

.notepad__menu-shortcut {
    flex: 0 0 auto;
    min-width: 5.5rem;
    text-align: right;
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
}

@media (max-width: 768px) {
    .notepad__menu {
        width: 240px;
    }

    .notepad__menu-item {
        min-height: 40px;
    }
}

@media (max-width: 480px) {
    .notepad__menu {
        width: calc(100vw - 2 * var(--space-4));
        left: var(--space-3);
    }

    .notepad__menu-item {
        min-height: 44px;
    }
}

/* ---------- Tab bar ---------- */
.notepad__tabbar {
    display: flex;
    align-items: stretch;
    position: relative;
    height: 40px;
    padding-left: var(--space-1);
    background: var(--color-bg-alt);
    border-bottom: 1px solid var(--color-border);
    overflow: hidden;
}

.notepad__tablist {
    display: flex;
    align-items: stretch;
    flex: 1 1 auto;
    min-width: 0;
    overflow-x: auto;
    overflow-y: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--color-border) transparent;
}

.notepad__tablist::-webkit-scrollbar {
    height: 4px;
}

.notepad__tablist::-webkit-scrollbar-track {
    background: transparent;
}

.notepad__tablist::-webkit-scrollbar-thumb {
    background: var(--color-border);
    border-radius: var(--radius-full);
}

@media (max-width: 768px) {
    .notepad__tabbar {
        height: 44px;
    }
}

.notepad__tab {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    flex: 0 1 auto;
    min-width: 120px;
    max-width: 200px;
    height: calc(100% - var(--space-1));
    margin: var(--space-1) 0 0 var(--space-1);
    padding: 0 var(--space-2);
    background: transparent;
    border-top: 1px solid transparent;
    border-right: 1px solid transparent;
    border-bottom: 2px solid transparent;
    color: var(--color-text-muted);
    font-size: var(--font-size-sm);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
    transition: background-color var(--transition-fast), color var(--transition-fast);
    z-index: 0;
}

.notepad__tab:hover {
    background: var(--color-bg-card);
}

.notepad__tab:focus {
    outline: none;
}

.notepad__tab:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.notepad__tab--active {
    position: relative;
    background: var(--color-bg-card);
    color: var(--color-text);
    border-top: 1px solid var(--color-border);
    border-right: 1px solid var(--color-border);
    border-bottom: 2px solid var(--color-primary);
    margin-bottom: -1px;
    z-index: 1;
}

.notepad__tab-name {
    flex: 1 1 auto;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: center;
}

.notepad__tab-dot {
    flex: 0 0 auto;
    width: 6px;
    height: 6px;
    border-radius: var(--radius-full);
    background: var(--color-primary);
}

.notepad__tab-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    width: 20px;
    height: 20px;
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: var(--font-size-xs);
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.notepad__tab-close:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.notepad__tab-close:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

/* Close button visibility: touch always, pointer devices on hover/focus/active */
.notepad__tab-close {
    visibility: hidden;
}

@media (hover: hover) {
    .notepad__tab:hover .notepad__tab-close,
    .notepad__tab:focus .notepad__tab-close,
    .notepad__tab:focus-within .notepad__tab-close,
    .notepad__tab--active .notepad__tab-close {
        visibility: visible;
    }
}

@media (hover: none) {
    .notepad__tab-close {
        visibility: visible;
    }
}

@media (max-width: 768px) {
    .notepad__tab {
        min-width: 100px;
        max-width: 180px;
    }
}

@media (max-width: 480px) {
    .notepad__tab-close {
        width: 24px;
        height: 24px;
    }
}

/* Inline rename input inside a tab */
.notepad__tab-rename-input {
    flex: 1 1 auto;
    min-width: 40px;
    height: 22px;
    padding: 0 var(--space-1);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-bg);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--font-size-sm);
}

.notepad__tab-rename-input:focus {
    outline: none;
    box-shadow: var(--focus-ring);
}

.notepad__newtab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
    align-self: center;
    width: 32px;
    height: 32px;
    margin-right: var(--space-2);
    padding: 0;
    background: transparent;
    border: 0;
    border-radius: var(--radius-sm);
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: var(--font-size-lg);
    line-height: 1;
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.notepad__newtab:hover {
    background: var(--color-bg-card);
    color: var(--color-text);
}

.notepad__newtab:active {
    transform: scale(0.98);
}

.notepad__newtab:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

@media (max-width: 480px) {
    .notepad__newtab {
        width: 44px;
        height: 44px;
    }
}

/* ---------- Editor area ---------- */
.notepad__editor-area {
    display: flex;
    height: clamp(360px, 55vh, 640px);
    background: var(--color-bg-card);
}

@media (max-width: 768px) {
    .notepad__editor-area {
        height: min(55vh, 420px);
        min-height: 280px;
    }
}

@media (max-width: 480px) {
    .notepad__editor-area {
        height: min(50vh, 400px);
        min-height: 260px;
    }
}

/* Line-number gutter (content rendered by JS, synced on scroll) */
.notepad__gutter {
    position: relative;
    flex: 0 0 auto;
    width: 3rem;
    overflow: hidden;
    background: var(--color-bg-alt);
    border-right: 1px solid var(--color-border);
}

.notepad__gutter--wide {
    width: 3.5rem;
}

.notepad__gutter[hidden] {
    display: none;
}

@media (max-width: 768px) {
    .notepad__gutter {
        width: 2.5rem;
    }
}

.notepad__gutter-inner {
    position: absolute;
    top: var(--space-4);
    left: 0;
    right: 0;
    will-change: transform;
}

@media (max-width: 480px) {
    .notepad__gutter-inner {
        top: var(--space-3);
    }
}

.notepad__gutter-line {
    display: block;
    padding-right: var(--space-2);
    font-family: var(--font-mono);
    font-size: var(--font-size-sm);
    line-height: var(--notepad-line-height);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    text-align: right;
    white-space: pre;
}

.notepad__gutter-line--active {
    color: var(--color-primary-text);
    background: var(--color-bg-card);
}

/* Editor wrapper hosts the highlight overlay + the textarea (same metrics) */
.notepad__editor-wrap {
    position: relative;
    flex: 1 1 auto;
    min-width: 0;
}

.notepad__highlight,
.notepad__editor {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    margin: 0;
    padding: var(--space-4);
    border: 0;
    background: transparent;
    font-family: var(--font-mono);
    font-size: calc(var(--font-size-base) * var(--notepad-zoom, 1));
    line-height: var(--notepad-line-height);
    white-space: pre-wrap;
    overflow-wrap: break-word;
}

@media (max-width: 480px) {
    .notepad__highlight,
    .notepad__editor {
        padding: var(--space-3);
    }
}

/* Overlay: invisible text, colored marks behind the (transparent) textarea */
.notepad__highlight {
    z-index: 1;
    color: transparent;
    overflow: hidden;
    pointer-events: none;
}

.notepad__mark {
    border-radius: 2px;
    background: var(--color-warning);
    color: transparent;
}

.notepad__mark--current {
    background: var(--color-primary);
}

.notepad__editor {
    z-index: 2;
    color: var(--color-text);
    caret-color: var(--color-primary);
    resize: none;
    overflow: auto;
}

.notepad__editor:focus {
    outline: none;
}

.notepad__editor:focus-visible {
    outline: none;
    box-shadow: inset 0 0 0 2px var(--color-primary);
}

.notepad__editor::placeholder {
    color: var(--color-text-muted);
    opacity: 0.8;
}

/* Word wrap disabled: horizontal scrolling instead of wrapping */
.notepad__editor-area--nowrap .notepad__highlight,
.notepad__editor-area--nowrap .notepad__editor {
    white-space: pre;
    overflow-wrap: normal;
}

/* ---------- Find & Replace bar ---------- */
.notepad__findbar {
    position: absolute;
    left: 0;
    right: 0;
    bottom: var(--notepad-statusbar-height);
    z-index: 10;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    padding: var(--space-2) var(--space-3);
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-border);
    transform: translateY(calc(100% + 1px));
    opacity: 0;
    visibility: hidden;
    transition: transform var(--transition-base),
        opacity var(--transition-base),
        visibility var(--transition-base);
}

.notepad__findbar--open {
    transform: translateY(0);
    opacity: 1;
    visibility: visible;
}

.notepad__findbar-row {
    display: flex;
    align-items: center;
    gap: var(--space-2);
}

.notepad__findbar-row:first-child {
    padding-right: calc(32px + var(--space-2));
}

.notepad__find-input {
    flex: 1 1 auto;
    min-width: 0;
    height: 32px;
    padding: 0 var(--space-2);
    border: 1px solid var(--color-border);
    border-radius: var(--radius-sm);
    background: var(--color-bg-card);
    color: var(--color-text);
    font-family: inherit;
    font-size: var(--font-size-sm);
    transition: border-color var(--transition-fast);
}

.notepad__find-input:focus {
    outline: none;
    border-color: var(--color-primary);
    box-shadow: var(--focus-ring);
}

.notepad__match-count {
    flex: 0 0 auto;
    min-width: 4.5rem;
    text-align: center;
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    white-space: nowrap;
}

.notepad__find-prev,
.notepad__find-next,
.notepad__find-close {
    width: 32px;
    height: 32px;
    font-size: var(--font-size-xs);
}

.notepad__find-close {
    position: absolute;
    top: var(--space-2);
    right: var(--space-2);
}

.notepad__btn {
    flex: 0 0 auto;
    height: 32px;
    padding: 0 var(--space-3);
    border: 1px solid var(--color-primary);
    border-radius: var(--radius-sm);
    background: var(--color-bg-card);
    color: var(--color-primary-text);
    font-family: inherit;
    font-size: var(--font-size-sm);
    font-weight: 600;
    cursor: pointer;
    transition: background-color var(--transition-fast),
        color var(--transition-fast),
        transform var(--transition-fast);
}

.notepad__btn:hover {
    background: var(--color-primary);
    color: var(--color-text-inverse);
}

.notepad__btn:active {
    transform: translateY(1px);
}

.notepad__btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.notepad__btn-replace-all {
    border-color: var(--color-border);
    color: var(--color-text);
    font-weight: 400;
}

.notepad__btn-replace-all:hover {
    background: var(--color-border);
    color: var(--color-text);
}

.notepad__matchcase {
    flex: 0 0 auto;
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    font-size: var(--font-size-xs);
    color: var(--color-text);
    cursor: pointer;
    -webkit-user-select: none;
    user-select: none;
}

.notepad__matchcase input {
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--color-primary);
    cursor: pointer;
}

.notepad__matchcase input:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

@media (max-width: 480px) {
    .notepad__findbar {
        padding: var(--space-2);
    }

    .notepad__findbar-row {
        flex-wrap: wrap;
    }

    .notepad__find-input {
        flex: 1 1 140px;
    }
}

/* ---------- Status bar ---------- */
.notepad__statusbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-2);
    height: var(--notepad-statusbar-height);
    padding: 0 var(--space-3);
    background: var(--color-bg-alt);
    border-top: 1px solid var(--color-border);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    color: var(--color-text-muted);
    font-variant-numeric: tabular-nums;
    overflow: hidden;
}

.notepad__status-right {
    display: inline-flex;
    align-items: center;
    gap: var(--space-3);
    min-width: 0;
}

.notepad__status-item {
    display: inline-flex;
    align-items: center;
    gap: var(--space-1);
    white-space: nowrap;
}

.notepad__status-encoding select {
    height: 22px;
    margin: 0;
    padding: 0 var(--space-1);
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--color-text-muted);
    font-family: inherit;
    font-size: var(--font-size-xs);
    cursor: pointer;
    transition: background-color var(--transition-fast), color var(--transition-fast);
}

.notepad__status-encoding select:hover {
    background: var(--color-bg-card);
    color: var(--color-text);
}

.notepad__status-encoding select:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.notepad__status-saved {
    min-width: 5.5rem;
    text-align: right;
    color: var(--color-success-text);
    opacity: 0;
    transition: opacity var(--transition-base);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notepad__status-saved--show {
    opacity: 1;
}

.notepad__status-saved--error {
    color: var(--color-error-text);
}

/* Small screens: the instrument strip must never overflow the window.
   Per the layout contract the word/char counts group hides first, and the
   encoding select caps its width so the row stays on one line. */
@media (max-width: 480px) {
    .notepad__status-counts {
        display: none;
    }

    .notepad__status-encoding select {
        max-width: 96px;
    }

    .notepad__status-saved {
        min-width: 4.5rem;
    }
}

/* ---------- Print ---------- */
.notepad__print-doc {
    display: none;
}

@media print {
    /* Hard-coded black-on-white is intentional: the print stylesheet must be
       legible regardless of the active light/dark theme. */
    body {
        background: #fff !important;
    }

    .skip-link,
    .site-header,
    .site-footer,
    .app-header,
    .notepad-window,
    .use-cases,
    .faq-section,
    .help-panel {
        display: none !important;
    }

    .main-content.app-page {
        padding: 0;
    }

    .notepad-container {
        max-width: none;
        padding: 0;
    }

    .notepad__print-doc {
        display: block;
        padding: var(--space-4);
        color: #000;
        font-family: var(--font-mono);
        font-size: 12pt;
        line-height: 1.5;
        white-space: pre-wrap;
        overflow-wrap: break-word;
    }
}

/* ---------- Help panel details ---------- */
.notepad__help-shortcuts {
    width: 100%;
    border-collapse: collapse;
    font-size: var(--font-size-sm);
}

.notepad__help-shortcuts td {
    padding: var(--space-1) var(--space-2);
    border-bottom: 1px solid var(--color-border);
    vertical-align: top;
}

.notepad__help-shortcuts kbd {
    display: inline-block;
    padding: 0 var(--space-1);
    border: 1px solid var(--color-border);
    border-bottom-width: 2px;
    border-radius: var(--radius-sm);
    background: var(--color-bg-alt);
    color: var(--color-text);
    font-family: var(--font-mono);
    font-size: var(--font-size-xs);
    line-height: 1.6;
}
