/* ===================================================================
   iThoughtsX File I/O PoC — Stylesheet
   =================================================================== */

:root {
    --menu-bg: #fafafa;
    --menu-fg: #333;
    --menu-hover: #e8e8e8;
    --menu-active: #ddd;
    --menu-border: #ccc;
    --menu-dropdown-bg: #fff;
    --menu-shortcut: #999;
    --accent: rgb(178, 178, 253);
    --accent-hover: rgb(158, 158, 243);
    --bg: #ffffff;
    --surface: #f5f5f5;
    --surface-hover: #e8e8e8;
    --text: #333;
    --text-muted: #666;
    --text-subtle: #999;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --border: #ddd;
    --radius: 6px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --font-mono: "SF Mono", "Fira Code", "Fira Mono", "Roboto Mono", monospace;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===================================================================
   Menu Bar
   =================================================================== */

.menu-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 40px;
    background: var(--menu-bg);
    border-bottom: 1px solid var(--border);
    padding: 0 12px;
    user-select: none;
    flex-shrink: 0;
    z-index: 1000;
}

.menu-bar-left {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 120px;
}

.app-name {
    font-weight: 600;
    font-size: 13px;
    color: var(--accent);
    letter-spacing: 0.5px;
    text-decoration: none;
}

.menu-bar-center {
    display: flex;
    align-items: center;
    gap: 0;
}

.menu-bar-right {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 120px;
    justify-content: flex-end;
}

.file-name {
    font-size: 12px;
    color: var(--text-muted);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.save-status {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 500;
}

.save-status.saved { color: var(--success); }
.save-status.saving { color: var(--warning); }
.save-status.unsaved { color: var(--text-subtle); }
.save-status.error { color: var(--error); }

/* Menu Items */

.menu-item {
    position: relative;
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
    border-radius: var(--radius);
    color: var(--menu-fg);
}

.menu-item:hover,
.menu-item:focus,
.menu-item:focus-visible,
.menu-item.open,
.menu-dropdown:focus {
    background: var(--menu-hover);
    outline: none;
}

.menu-dropdown {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    min-width: 220px;
    background: var(--menu-dropdown-bg);
    border: 1px solid var(--menu-border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    padding: 4px;
    z-index: 1001;
}

.menu-item.open .menu-dropdown {
    display: block;
}

.menu-entry {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
}

.menu-entry:focus {
    outline: none;
}

.menu-entry:hover,
.menu-entry:focus-visible {
    background: var(--accent);
    color: var(--text);
    outline: none;
}

.menu-entry:hover .menu-shortcut,
.menu-entry:focus-visible .menu-shortcut {
    color: var(--text);
    opacity: 0.7;
}

.menu-label {
    flex: 1;
}

.menu-shortcut {
    font-size: 11px;
    color: var(--menu-shortcut);
    font-family: var(--font-mono);
    margin-left: 24px;
}

.menu-separator {
    height: 1px;
    background: var(--border);
    margin: 4px 8px;
}

/* ===================================================================
   Main Content
   =================================================================== */

.main-content {
    flex: 1;
    overflow: auto;
    display: flex;
    flex-direction: column;
}

.hidden { display: none !important; }

/* Welcome Screen */

.welcome {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    flex: 1;
    padding: 40px 20px;
    text-align: center;
}

.welcome h1 {
    font-size: 32px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 8px;
}

.welcome p {
    font-size: 15px;
    color: var(--text-muted);
    margin-bottom: 32px;
}

.welcome-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

.btn {
    padding: 10px 24px;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border: none;
    font-family: var(--font);
    transition: all 0.15s ease;
}

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

.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--surface-hover); }

/* Drop Zone */

.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 40px 60px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--text-muted);
    font-size: 14px;
    transition: all 0.2s ease;
}

.drop-zone.drag-over {
    border-color: var(--accent);
    background: rgba(137, 180, 250, 0.05);
    color: var(--accent);
}

.drop-icon {
    font-size: 36px;
}

/* Browser Info */

.browser-info {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-subtle);
    line-height: 1.8;
}

.browser-info .cap-yes { color: var(--success); }
.browser-info .cap-no { color: var(--error); }
.browser-info .cap-partial { color: var(--warning); }

/* ===================================================================
   File View (loaded tree)
   =================================================================== */

.file-view {
    flex: 1;
    overflow: auto;
    padding: 24px;
}

.file-header {
    margin-bottom: 24px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.file-header h2 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
    word-break: break-all;
}

.file-stats {
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.6;
}

.file-stats span {
    display: inline-block;
    margin-right: 16px;
}

.file-stats .stat-label {
    color: var(--text-subtle);
}

.file-stats .stat-value {
    color: var(--accent);
    font-weight: 500;
    font-family: var(--font-mono);
    font-size: 12px;
}

/* Topic Tree */

/* Mind map tree — matches existing app DOM structure */
*:focus {
    outline-style: dashed;
    outline-color: black;
    outline-width: 2px;
    outline-offset: 2px;
}

#tree-container.flex-container {
    margin-left: 0;
    overflow: visible;
}

.flex-container {
    display: flex;
    flex-direction: column;
    margin-left: 20px;
    overflow: hidden;
    font-family: var(--font);
    font-size: 14px;
    align-items: flex-start;
}

.flex-item {
    display: flex;
    flex-direction: column;
    padding: 10px 8px 0 0;
    border-left: 2px solid rgb(178, 178, 253);
    transition: transform 0.2s ease, max-height 0.2s ease;
    overflow: hidden;
    position: relative;
    flex-shrink: 0;
}

.flex-item:last-child {
    border-left: none;
}

.flex-item-content {
    position: relative;
    min-height: 20px;
    display: flex;
    align-items: center;
    width: fit-content;
    border: 2px solid rgb(178, 178, 253);
    border-radius: 8px;
    padding: 5px 15px 5px 10px;
    margin-left: 10px;
    background-color: rgb(178, 178, 253);
    font-family: inherit;
    font-size: inherit;
    cursor: default;
    user-select: none;
}

/* L-shaped connectors */
.flex-item-content::before {
    content: '';
    position: absolute;
    left: -12px;
    width: 10px;
    top: 0%;
    transform: translateY(-50%);
    height: 100%;
    border-bottom: 2px solid rgb(178, 178, 253);
    border-left: none;
}

.flex-item:last-child > .flex-item-content::before {
    border-left: 2px solid rgb(178, 178, 253);
    width: 12px;
    margin-left: -2px;
}

.flex-item:last-child > .flex-item-content {
    margin-left: 12px;
}

/* No connector line for root element */
#tree-container > .flex-item > .flex-item-content::before {
    border: none;
}

/* Fold/expand indicator (+ / -) */
.flex-item-content::after {
    content: '+';
    position: absolute;
    right: 5px;
    top: 50%;
    transform: translate(80%, -50%);
    font-size: 16px;
    color: #666;
    border-radius: 50%;
    background-color: #f0f0f0;
    width: 15px;
    height: 15px;
    align-items: center;
    justify-content: center;
    border: 1px solid rgb(178, 178, 253);
    display: none;
}

/* Show toggle if node has children */
.flex-item-content:not(:last-child)::after,
.flex-item-content.folded::after {
    display: flex;
}

.toggle-indicator-transition {
    transition: all 0.2s ease;
}

/* Closed state */
.flex-item-content:not(.folded)::after {
    content: '-';
}

/* Open state */
.flex-item-content.folded::after {
    content: '+';
}

/* Animate container open/close */
.flex-item-content + .flex-container {
    transition: max-height 0.2s ease;
}

/* XML Raw View */

.xml-raw {
    margin-top: 24px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}

.xml-raw h3 {
    font-size: 14px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.xml-raw pre {
    font-family: var(--font-mono);
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface);
    padding: 16px;
    border-radius: var(--radius);
    overflow-x: auto;
    max-height: 400px;
    overflow-y: auto;
    line-height: 1.5;
}

/* ===================================================================
   Responsive
   =================================================================== */

@media (max-width: 600px) {
    .menu-bar-left .app-name { display: none; }
    .menu-bar-right .file-name { max-width: 100px; }
    .welcome-actions { flex-direction: column; }
    .drop-zone { padding: 24px 32px; }
}