/* SS PWA — Mobile-first styles */

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

:root {
    --bg: #1e1e1e;
    --bg-surface: #252526;
    --bg-hover: #2a2d2e;
    --bg-active: #37373d;
    --fg: #d4d4d4;
    --fg-dim: #808080;
    --fg-bright: #ffffff;
    --accent: #569cd6;
    --accent-dim: #264f78;
    --green: #4ec9b0;
    --red: #f44747;
    --yellow: #dcdcaa;
    --orange: #ce9178;
    --font-ui: system-ui, -apple-system, sans-serif;
    --font-mono: 'SF Mono', 'Menlo', 'Consolas', 'Liberation Mono', monospace;
    --header-h: 48px;
    --toolbar-h: 44px;
}

html, body {
    height: 100%;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-ui);
    font-size: 15px;
    -webkit-text-size-adjust: 100%;
    overflow: hidden;
}

body {
    display: flex;
    flex-direction: column;
}

/* ---- App shell ---- */

#tab-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    position: relative;
}


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

.tab-bar {
    display: flex;
    align-items: center;
    height: 36px;
    min-height: 36px;
    background: #1e1e1e;
    border-bottom: 1px solid #333;
    overflow-x: auto;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    height: 100%;
    border: none;
    border-right: 1px solid #333;
    background: transparent;
    color: var(--fg-dim);
    font-family: var(--font-mono);
    font-size: 12px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}
.tab:hover { background: var(--bg-hover); color: var(--fg); }
.tab.active { background: var(--bg-surface); color: var(--fg-bright); }

.tab-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--fg-dim);
    font-size: 14px;
    cursor: pointer;
    line-height: 1;
    padding: 0;
}
.tab-close:hover { background: var(--bg-active); color: var(--fg-bright); }

.tab-panel {
    display: flex;
    flex-direction: column;
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
}

.app-iframe {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    border: none;
}

/* ---- Views ---- */

.view {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

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

.header {
    display: flex;
    align-items: center;
    height: var(--header-h);
    min-height: var(--header-h);
    padding: 0 12px;
    background: var(--bg-surface);
    border-bottom: 1px solid #333;
    gap: 8px;
    overflow: hidden;
}

.header-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: var(--fg);
    font-size: 18px;
    cursor: pointer;
    flex-shrink: 0;
}

.header-btn:hover { background: var(--bg-hover); }
.header-btn:active { background: var(--bg-active); }

.breadcrumb {
    display: flex;
    align-items: center;
    overflow-x: auto;
    white-space: nowrap;
    flex: 1;
    gap: 2px;
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.breadcrumb::-webkit-scrollbar { display: none; }

.breadcrumb-seg {
    padding: 4px 6px;
    border-radius: 4px;
    color: var(--accent);
    font-size: 14px;
    font-family: var(--font-mono);
    cursor: pointer;
    flex-shrink: 0;
}
.breadcrumb-seg:hover { background: var(--bg-hover); }
.breadcrumb-seg:last-child { color: var(--fg-bright); }

.breadcrumb-sep {
    color: var(--fg-dim);
    font-size: 12px;
    flex-shrink: 0;
}

.header-title {
    flex: 1;
    font-size: 14px;
    font-family: var(--font-mono);
    color: var(--fg-bright);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Content area ---- */

.content {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---- Loading view ---- */

#loading-view {
    padding: 24px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.6;
}

#loading-view .status { color: var(--accent); }
#loading-view .ok { color: var(--green); }
#loading-view .err { color: var(--red); }

/* ---- Home screen ---- */

.home-header {
    text-align: center;
    padding: 32px 16px 16px;
    font-size: 22px;
    font-weight: 600;
    color: var(--fg-bright);
    letter-spacing: 0.5px;
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, 96px);
    justify-content: center;
    gap: 20px;
    padding: 24px 16px;
}

.app-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    padding: 8px;
    border-radius: 12px;
}
.app-icon:hover { background: var(--bg-hover); }
.app-icon:active { background: var(--bg-active); }

.app-icon-img {
    width: 56px;
    height: 56px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
}

.app-icon-label {
    font-size: 12px;
    color: var(--fg);
    text-align: center;
    max-width: 80px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ---- Navigator view (iOS Files grid) ---- */

.file-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 4px;
    padding: 12px;
    list-style: none;
}

.file-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 12px 4px 10px;
    border-radius: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
    user-select: none;
    gap: 6px;
    position: relative;
}
.file-item:hover { background: var(--bg-hover); }
.file-item:active { background: var(--bg-active); }
.file-item.selected {
    background: var(--accent-dim);
    outline: 2px solid var(--accent);
    outline-offset: -2px;
}

.file-icon {
    font-size: 36px;
    line-height: 1;
    height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.file-info {
    text-align: center;
    min-width: 0;
    max-width: 100%;
}

.file-name {
    font-size: 12px;
    color: var(--fg-bright);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.3;
}

.file-name.dir { color: var(--accent); }

.file-meta {
    font-size: 10px;
    color: var(--fg-dim);
    margin-top: 1px;
}

.empty-dir {
    padding: 32px 16px;
    text-align: center;
    color: var(--fg-dim);
    font-style: italic;
    grid-column: 1 / -1;
}

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

.editor-wrap {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

.editor-textarea {
    flex: 1;
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    color: var(--fg);
    font-family: var(--font-mono);
    font-size: 14px;
    line-height: 1.5;
    border: none;
    outline: none;
    resize: none;
    tab-size: 4;
    -moz-tab-size: 4;
}

.editor-toolbar {
    display: flex;
    align-items: center;
    height: var(--toolbar-h);
    min-height: var(--toolbar-h);
    padding: 0 8px;
    background: var(--bg-surface);
    border-top: 1px solid #333;
    gap: 8px;
}

.toolbar-btn {
    padding: 6px 16px;
    border: 1px solid #555;
    border-radius: 6px;
    background: var(--bg-hover);
    color: var(--fg);
    font-size: 14px;
    cursor: pointer;
}
.toolbar-btn:hover { background: var(--bg-active); border-color: #777; }
.toolbar-btn:active { background: var(--accent-dim); }

.toolbar-btn.primary {
    background: var(--accent-dim);
    border-color: var(--accent);
    color: var(--fg-bright);
}
.toolbar-btn.primary:hover { background: var(--accent); }

.toolbar-status {
    flex: 1;
    text-align: right;
    font-size: 12px;
    color: var(--fg-dim);
}

/* ---- Output view ---- */

.output-log {
    padding: 12px 16px;
    font-family: var(--font-mono);
    font-size: 13px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
}

.output-log .out { color: var(--fg); }
.output-log .err { color: var(--red); }
.output-log .info { color: var(--accent); }
.output-log .ok { color: var(--green); }

/* ---- Settings view ---- */

.settings-content {
    padding: 16px;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-heading {
    font-size: 14px;
    color: var(--fg-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}

.settings-info {
    font-size: 13px;
    color: var(--fg-dim);
    margin-bottom: 12px;
    line-height: 1.5;
}

.settings-info code {
    color: var(--accent);
    font-family: var(--font-mono);
}

/* Env var list */

.env-var-list {
    margin-bottom: 8px;
}

.env-var-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}

.env-var-key {
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--yellow);
    min-width: 80px;
}

.env-var-value {
    flex: 1;
    font-family: var(--font-mono);
    font-size: 13px;
    color: var(--fg);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.env-var-del {
    background: transparent;
    border: none;
    color: var(--red);
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    border-radius: 4px;
}
.env-var-del:hover { background: var(--bg-hover); }

/* Launcher app rows in settings */

.launcher-app-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
    flex-wrap: wrap;
}

.launcher-app-info {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    min-width: 0;
}

.launcher-app-args {
    display: flex;
    align-items: center;
    gap: 6px;
    flex: 1;
    min-width: 120px;
}

.launcher-app-args-label {
    font-size: 12px;
    color: var(--fg-dim);
    flex-shrink: 0;
}

.env-var-add {
    display: flex;
    gap: 8px;
    align-items: center;
}

.env-input {
    padding: 6px 10px;
    background: var(--bg);
    color: var(--fg);
    border: 1px solid #555;
    border-radius: 6px;
    font-family: var(--font-mono);
    font-size: 13px;
    outline: none;
    width: 100px;
}
.env-input:focus { border-color: var(--accent); }
.env-input-val { flex: 1; }

/* ---- Panel toolbar (for Tests, etc.) ---- */

.panel-toolbar {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 8px;
    background: var(--bg-surface);
    border-bottom: 1px solid #333;
    flex-shrink: 0;
}

/* ---- Context menu ---- */

.context-menu {
    position: fixed;
    z-index: 1000;
    min-width: 180px;
    background: var(--bg-surface);
    border: 1px solid #444;
    border-radius: 8px;
    padding: 4px 0;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.5);
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 14px;
    font-size: 14px;
    color: var(--fg);
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: var(--font-ui);
}
.context-menu-item:hover { background: var(--bg-hover); }
.context-menu-item:active { background: var(--bg-active); }

.context-menu-item .ctx-icon {
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.context-menu-item.danger { color: var(--red); }

.context-menu-sep {
    height: 1px;
    background: #444;
    margin: 4px 0;
}

/* ---- Media viewer ---- */

.viewer-content {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
    padding: 16px;
    background: var(--bg);
}

.viewer-content img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.viewer-content video,
.viewer-content audio {
    max-width: 100%;
    max-height: 100%;
    outline: none;
}

/* ---- Utility ---- */

.hidden { display: none !important; }
