/* mdedit component styles — reset and tokens from shared/base.css */

/* Pane resizer */
.pane-resizer:hover {
    background-color: var(--primary) !important;
}

/* File tree */
.file-tree {
    font-size: 0.9rem;
}

.directory-item,
.file-item {
    transition: background-color 0.15s ease;
}

.dir-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transform: rotate(90deg);
    transition: transform 0.2s ease;
    vertical-align: middle;
}

.dir-icon svg {
    width: 12px;
    height: 12px;
    stroke: currentColor;
    stroke-width: 2;
}

.directory-item.collapsed .dir-icon {
    transform: rotate(0deg);
}

/* Two-line filename styles */
.filename-main {
    font-size: 0.9rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.filename-secondary {
    font-size: 0.75rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Active file highlighting */
.active-file {
    background-color: var(--primary) !important;
    color: var(--text-light) !important;
    font-weight: 500;
}

.active-file * {
    color: var(--text-light) !important;
}

/* ── File Tree Action Buttons ──────────────────────────────────────────────── */
.tree-actions {
    display: flex;
    gap: 0.25rem;
    align-items: center;
    margin-left: auto;
    opacity: 0;
    transition: opacity 0.2s ease;
}

.directory-item:hover .tree-actions,
.file-item:hover .tree-actions,
.active-file .tree-actions {
    opacity: 1;
}

/* Always-visible action buttons (e.g. scratchpad download) */
.tree-actions--always { opacity: 1; }

.tree-btn:disabled,
.tree-btn.is-disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.tree-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.25rem;
    height: 1.25rem;
    padding: 0;
    border: none;
    background-color: transparent;
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 0.25rem;
    transition: background-color 0.15s ease, color 0.15s ease;
}

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

.tree-btn--danger:hover {
    background-color: #fee2e2;
    color: #dc2626;
}

[data-theme="dark"] .tree-btn--danger:hover {
    background-color: rgba(127, 29, 29, 0.5);
    color: #fca5a5;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) .tree-btn--danger:hover {
        background-color: rgba(127, 29, 29, 0.5);
        color: #fca5a5;
    }
}

.tree-btn svg {
    width: 1rem;
    height: 1rem;
    stroke: currentColor;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

/* Directory toggle indicator */
.directory-item {
    position: relative;
}

.directory-item.collapsed .directory-contents {
    display: none;
}

/* File view container */
.file-view-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    width: 100%;
}

/* File header */
.file-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 1rem;
    background-color: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.file-title {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text);
    margin: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* File content area */
.file-content-area {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Content container */
#content-container {
    flex-direction: column;
    height: 100%;
}

/* Image preview */
.image-preview-container {
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: var(--bg-secondary);
}

.image-preview {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

/* HTML preview iframe */
.html-preview-container {
    width: 100%;
    height: 100%;
}

.html-preview-iframe {
    width: 100%;
    height: 100%;
    border: 0;
}

/* Dirty indicator */
.dirty-indicator {
    margin-left: 0.25rem;
    color: var(--warning);
    font-weight: bold;
}

.is-dirty {
    font-style: italic;
}

/* ── Tailwind class overrides: use CSS tokens instead of hardcoded colours ── */
/* bg-white / bg-gray-100 are used on the pane backgrounds in template.html.  */
/* Override them here so they follow the design-token system (light + dark).   */
.bg-white     { background-color: var(--bg) !important; }
.bg-gray-100  { background-color: var(--bg-secondary) !important; }

/* ── Section headers (YAML front matter, TOC, etc.) ───────────────────────── */
/* Shared style for all collapsible/section headers inside the side pane —
   keeps font, padding, weight identical to the file-tree pane header. */
.pane-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: var(--bg-secondary);
    color: var(--text);
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
    font-weight: 500;
    user-select: none;
}

.pane-section-header .toggle-icon {
    font-size: 0.75rem;
    color: var(--text-muted);
    width: 0.75rem;
    text-align: center;
}

/* ── Front matter section ──────────────────────────────────────────────────── */
.front-matter-nav {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
    background-color: var(--bg);
}

.front-matter-header:hover {
    background-color: var(--bg-hover);
}

.front-matter-content {
    flex: 1;
    overflow: auto;
    min-height: 0;
}

/* When collapsed, hide content; height shrinks to header */
.front-matter-nav.collapsed {
    height: auto !important;
    flex-shrink: 0;
}

.front-matter-nav.collapsed .front-matter-content {
    display: none;
}

/* Front matter textarea fills the content area */
.front-matter-textarea {
    color: var(--text);
    background-color: var(--bg);
    border: none;
    resize: none;
    font-family: var(--font-mono);
    font-size: 0.8rem;
    white-space: pre;
    overflow: auto;
    width: 100%;
    height: 100%;
    padding: 0.5rem 1rem;
    box-sizing: border-box;
    display: block;
}

.front-matter-textarea:focus {
    outline: none;
}

/* ── Horizontal pane resizer (height split) ─────────────────────────────── */
.pane-resizer.horizontal {
    height: 4px;
    width: 100%;
    cursor: row-resize;
    background-color: var(--border);
    flex-shrink: 0;
    transition: background-color 0.15s ease;
}

.pane-resizer.horizontal:hover,
.pane-resizer.horizontal.active {
    background-color: var(--primary);
}

/* ── Hidden utility (for disabled buttons) ─────────────────────────────────── */
.hide { display: none; }

/* ── File tree row layout ───────────────────────────────────────────────────── */
.tree-row {
    display: flex;
    align-items: center;
    min-width: 0;
}

.tree-row__label {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* The text wrapper inside a tree-row label. For ZDDC-conforming files and
   folders, this wraps two stacked <div>s (filename-main + filename-secondary)
   so the row reads top-to-bottom as title + metadata — same shape the archive
   tool uses for its transmittal-folder list. For non-ZDDC entries it just
   contains a single line. flex column makes the two-line case work; min-width:0
   lets each line truncate independently. */
.tree-row__name {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    line-height: 1.25;
}

/* ── New-file modal ─────────────────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-overlay.hidden { display: none; }
.modal-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 0.5rem;
    padding: 1.5rem;
    min-width: 20rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    box-shadow: 0 4px 24px rgba(0,0,0,0.18);
}
.modal-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text);
    margin: 0;
}
.modal-input {
    width: 100%;
    padding: 0.4rem 0.6rem;
    border: 1px solid var(--border);
    border-radius: 0.25rem;
    font-size: 0.9rem;
    color: var(--text);
    background: var(--bg);
    box-sizing: border-box;
}
.modal-input:focus {
    outline: 2px solid var(--primary);
    outline-offset: 1px;
}
.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
}

/* File-nav pane: initial width + minimum size. Runtime resizer (resizer.js)
   overrides via inline style.width when the user drags; the min-width here
   is a defensive backstop. */
#file-nav {
    width: 450px;
    min-width: 200px;
}
