/* ============================================================
   Mobile shell — clean, full-bleed, native mobile patterns.
   Activates when [data-shell="mobile"] on <html>.
   Tablet (768–1099): tweaks the desktop layout for touch.
   ============================================================ */

/* ── Tablet (touch-first desktop) ─────────────────────────── */
:root[data-shell="tablet"] .workspace-body { grid-template-columns: 240px 1fr; }
:root[data-shell="tablet"] .omnibar { min-width: 280px; }
:root[data-shell="tablet"] .file-row { padding: 8px 14px 8px 28px; font-size: 13px; }
:root[data-shell="tablet"] .tab { height: 40px; }
:root[data-shell="tablet"] .terminal { max-height: 200px; min-height: 160px; }
:root[data-shell="tablet"] .title-bar-center { display: flex; justify-content: center; }

/* ── Mobile shell ─────────────────────────────────────────── */
:root[data-shell="mobile"] body { overflow: hidden; }

/* Hide the original responsive sidebar on mobile (we use mworkspace) */
:root[data-shell="mobile"] .workspace,
:root[data-shell="mobile"] .twk-panel-toggle { /* keep panel toggle if present */ }

.mworkspace {
  display: grid;
  grid-template-rows: 56px auto 1fr 64px;
  height: 100vh;
  height: 100dvh;
  background: var(--bg);
  overflow: hidden;
}

/* ── Top bar ────────────────────────────────────────────── */
.mtopbar {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elev);
  height: 56px;
  padding-top: env(safe-area-inset-top);
}
.mtopbar-menu {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--fg);
  transition: background 0.15s ease;
}
.mtopbar-menu:active { background: var(--bg-elev-2); transform: scale(0.95); }
.mtopbar-title {
  display: flex; align-items: center; gap: 10px;
  min-width: 0;
}
.mtopbar-glyph { width: 12px; height: 12px; flex: none; }
.mtopbar-path {
  font-size: 14px;
  color: var(--fg-strong);
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mtopbar-actions { display: flex; gap: 4px; }
.mtopbar-icon {
  width: 40px; height: 40px;
  display: grid; place-items: center;
  border-radius: 8px;
  color: var(--fg-dim);
  font-size: 17px;
  transition: background 0.15s ease, color 0.15s ease;
}
.mtopbar-icon:active { background: var(--bg-elev-2); color: var(--fg); transform: scale(0.95); }

/* ── Tab strip ──────────────────────────────────────────── */
.mtab-strip {
  display: flex;
  gap: 6px;
  padding: 8px 14px;
  background: var(--bg-elev);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  scroll-behavior: smooth;
}
.mtab-strip::-webkit-scrollbar { display: none; }
.mtab {
  display: inline-flex; align-items: center; gap: 8px;
  flex: none;
  padding: 7px 12px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--fg-dim);
  font-size: 12px;
  white-space: nowrap;
  transition: all 0.18s ease;
  cursor: pointer;
  user-select: none;
}
.mtab:active { transform: scale(0.96); }
.mtab-active {
  background: var(--accent-soft);
  border-color: transparent;
  color: var(--accent);
  font-weight: 500;
  box-shadow: inset 0 0 0 1px color-mix(in oklch, var(--accent) 50%, transparent);
}
.mtab-icon {
  display: inline-grid; place-items: center;
  width: 14px; height: 14px;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: -0.04em;
}
.mtab-active .mtab-icon { color: var(--accent); }
.mfile-icon-md   { color: var(--icon-md); }
.mfile-icon-json { color: var(--icon-json); }
.mfile-icon-ts   { color: var(--icon-ts); }
.mtab-name { font-size: 12px; }
.mtab-close {
  width: 16px; height: 16px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: inherit;
  opacity: 0.7;
  margin-right: -4px;
}
.mtab-close:active { background: rgba(255,255,255,0.1); }

/* ── Editor pane ────────────────────────────────────────── */
.meditor {
  overflow: hidden;
  position: relative;
  animation: meditor-fade 0.32s cubic-bezier(0.2, 0.8, 0.2, 1);
}
@keyframes meditor-fade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.meditor-pane {
  height: 100%;
  overflow: auto;
  padding-bottom: 24px;
  -webkit-overflow-scrolling: touch;
}
.meditor-pane::-webkit-scrollbar { width: 4px; }
.meditor-pane::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 2px; }

.meditor-filehead {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 5;
}
.meditor-filehead .file-icon {
  width: 18px; height: 18px;
  font-size: 10px;
}
.meditor-filename {
  flex: 1;
  font-size: 13px;
  color: var(--fg-strong);
  font-weight: 500;
  font-family: "JetBrains Mono", monospace;
}
.meditor-lang {
  font-size: 10.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--fg-dim);
  padding: 3px 8px;
  border-radius: 10px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}

/* Mobile-tuned content: bigger type, tighter gutter */
:root[data-shell="mobile"] .code-view {
  font-size: 13px;
  line-height: 1.7;
  padding: 14px 0 80px;
}
:root[data-shell="mobile"] .line-gutter {
  padding: 0 10px 0 10px;
}
:root[data-shell="mobile"] .code-pre {
  padding-right: 16px;
  font-size: 12.5px;
  white-space: pre-wrap;
  word-break: break-word;
}
:root[data-shell="mobile"] .md-view {
  padding: 16px 0 80px;
  display: block;
}
:root[data-shell="mobile"] .line-gutter { display: none; }
:root[data-shell="mobile"] .md-body {
  padding: 0 20px;
  font-size: 16px;
  line-height: 1.7;
  max-width: 100%;
}
:root[data-shell="mobile"] .md-h1 { font-size: 26px; }
:root[data-shell="mobile"] .md-h2 { font-size: 18px; }
:root[data-shell="mobile"] .md-pre {
  margin: 1em -8px;
  border-radius: 8px;
  font-size: 12px;
}
:root[data-shell="mobile"] .md-table {
  display: block;
  overflow-x: auto;
  font-size: 11.5px;
  white-space: nowrap;
}
:root[data-shell="mobile"] .commits-view {
  padding: 18px 18px 80px;
}
:root[data-shell="mobile"] .commit-title { font-size: 15px; }
:root[data-shell="mobile"] .commit-msg { font-size: 12.5px; }
:root[data-shell="mobile"] .commit-meta { gap: 8px; font-size: 11px; }

/* JSON skill bars wrap nicely */
:root[data-shell="mobile"] .skill-line { flex-wrap: wrap; gap: 6px; }
:root[data-shell="mobile"] .skill-bar { width: 100%; margin-left: 0; margin-top: 4px; }

/* ── Bottom nav ─────────────────────────────────────────── */
.mbottom {
  display: grid;
  grid-template-columns: 56px 1fr auto 1fr 56px;
  align-items: center;
  border-top: 1px solid var(--border);
  background: var(--bg-elev);
  padding: 0 14px env(safe-area-inset-bottom) 14px;
  padding-top: 10px;
  gap: 8px;
}
.mbottom-btn {
  height: 44px;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 0 14px;
  border-radius: 10px;
  color: var(--fg-dim);
  font-size: 12px;
  letter-spacing: 0.04em;
  transition: all 0.15s ease;
}
.mbottom-btn:active { background: var(--bg-elev-2); color: var(--fg); transform: scale(0.96); }
.mbottom-btn:first-child, .mbottom-btn:last-child {
  width: 44px; padding: 0; justify-self: center;
}
.mbottom-term {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 500;
  font-family: "JetBrains Mono", monospace;
}
.mbottom-progress {
  display: flex; align-items: center; gap: 4px;
  font-family: "JetBrains Mono", monospace;
  font-size: 12px;
  color: var(--fg-dim);
  font-variant-numeric: tabular-nums;
  justify-self: end;
  padding-right: 8px;
}
.mbottom-progress-sep { color: var(--fg-faint); }
.mbottom-progress-total { color: var(--fg-faint); }

/* ── Bottom sheet (file picker / terminal) ──────────────── */
.sheet-backdrop {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0);
  z-index: 60;
  pointer-events: none;
  transition: background 0.28s ease;
  backdrop-filter: blur(0);
}
.sheet-backdrop-open {
  background: rgba(0, 0, 0, 0.5);
  pointer-events: auto;
  backdrop-filter: blur(6px);
}
.sheet {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 61;
  background: var(--bg-elev);
  border-top-left-radius: 20px;
  border-top-right-radius: 20px;
  border-top: 1px solid var(--border);
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.36s cubic-bezier(0.32, 0.72, 0.18, 1);
  padding-bottom: env(safe-area-inset-bottom);
  overflow: hidden;
  touch-action: none;
}
.sheet-open {
  transform: translateY(0);
}
.sheet-grip-zone {
  display: flex;
  justify-content: center;
  padding: 10px 0 6px;
  cursor: grab;
  touch-action: none;
}
.sheet-grip {
  width: 40px;
  height: 4px;
  border-radius: 2px;
  background: var(--border-strong);
}
.sheet-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 18px 12px;
  border-bottom: 1px solid var(--border);
}
.sheet-title {
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--fg-dim);
  font-weight: 600;
}
.sheet-close {
  width: 30px; height: 30px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--bg-elev-2);
  color: var(--fg-dim);
}
.sheet-close:active { background: var(--bg); transform: scale(0.92); }
.sheet-body {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

/* ── Mobile file list (in sheet) ────────────────────────── */
.mfile-list { padding: 4px 0 12px; }
.mfile-folder {
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px 8px;
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--fg-dim);
  font-weight: 600;
}
.mfile-folder-chev { color: var(--fg-faint); font-size: 9px; }
.mfile-count {
  margin-left: auto;
  font-size: 10.5px;
  padding: 2px 8px;
  border-radius: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  letter-spacing: 0;
  color: var(--fg-dim);
}
.mfile {
  display: flex;
  align-items: center;
  gap: 14px;
  width: 100%;
  padding: 14px 20px;
  text-align: left;
  color: var(--fg);
  border: 0;
  background: transparent;
  position: relative;
  transition: background 0.15s ease;
  font-family: inherit;
}
.mfile:active { background: var(--bg-elev-2); }
.mfile-active {
  background: linear-gradient(90deg, var(--accent-soft) 0%, transparent 100%);
}
.mfile-active::before {
  content: "";
  position: absolute;
  left: 0; top: 8px; bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.mfile-icon {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: -0.04em;
  flex: none;
}
.mfile-active .mfile-icon {
  background: var(--bg-elev-2);
  border-color: transparent;
}
.mfile-text {
  flex: 1;
  min-width: 0;
}
.mfile-name {
  font-family: "JetBrains Mono", monospace;
  font-size: 14px;
  color: var(--fg-strong);
  font-weight: 500;
  margin-bottom: 2px;
}
.mfile-active .mfile-name { color: var(--accent); }
.mfile-desc {
  font-family: "Inter", system-ui, sans-serif;
  font-size: 12.5px;
  color: var(--fg-dim);
  line-height: 1.4;
}
.mfile-active-mark {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--accent);
  flex: none;
  box-shadow: 0 0 0 4px var(--accent-soft);
}

/* ── Mobile terminal (in sheet) ─────────────────────────── */
.mterm-wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
}
.mterm-wrap .terminal {
  border-top: 0;
  max-height: none;
  min-height: 0;
  flex: 1;
  height: 100%;
}
.mterm-wrap .terminal-header { padding: 8px 18px; }
.mterm-wrap .terminal-body {
  font-size: 13px;
  padding: 14px 18px env(safe-area-inset-bottom);
}
.mterm-wrap .term-input {
  font-size: 16px; /* prevents iOS zoom on focus */
}

/* ── Palette adjustments for mobile ─────────────────────── */
:root[data-shell="mobile"] .palette-overlay { padding-top: 60px; align-items: flex-start; }
:root[data-shell="mobile"] .palette { width: 92vw; }
:root[data-shell="mobile"] .palette-input { font-size: 16px; padding: 16px 18px; }
:root[data-shell="mobile"] .palette-item { padding: 12px 14px; }

/* Tweaks panel — pin to top-right on mobile, but allow scroll */
:root[data-shell="mobile"] .twk-panel {
  max-width: calc(100vw - 24px);
  max-height: calc(100dvh - 80px);
}

/* Hide desktop-only chrome cleanly */
:root[data-shell="mobile"] .desktop-only { display: none !important; }
