/* =========================================================
   Pipeline OS — Mobile Styles
   Target: screens ≤ 640px
   ========================================================= */

/* ── BASE RESET FOR MOBILE ── */
#mobile-app {
  display: none;
  position: fixed;
  inset: 0;
  flex-direction: column;
  background: #1c1816;
  font-family: 'IBM Plex Mono', monospace;
  color: #ddd8cc;
  z-index: 1000;
  overflow: hidden;
}

/* ── HEADER ── */
#m-header {
  height: 50px;
  min-height: 50px;
  background: rgba(20, 17, 15, 0.98);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 6px;
  flex-shrink: 0;
  position: relative;
  z-index: 10;
}

#m-menu-btn {
  width: 36px;
  height: 36px;
  background: transparent;
  border: none;
  color: #9a9088;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
  transition: background 0.12s, color 0.12s;
}

#m-menu-btn:active {
  background: rgba(255, 255, 255, 0.07);
  color: #ddd8cc;
}

#m-menu-btn svg {
  width: 16px;
  height: 16px;
}

#m-title-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
}

#m-title {
  font-size: 11px;
  font-weight: 500;
  color: #ddd8cc;
  letter-spacing: 0.04em;
  font-family: 'IBM Plex Sans', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#m-subtitle {
  font-size: 9px;
  color: #3a3630;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 1px;
}

#m-timer {
  font-size: 12px;
  color: #9a9088;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.05em;
  min-width: 38px;
  text-align: center;
  flex-shrink: 0;
}

#m-timer.live {
  color: #8fb8ff;
}

#m-header-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}

.m-hbtn {
  width: 30px;
  height: 30px;
  background: transparent;
  border: none;
  color: #706860;
  font-size: 13px;
  cursor: pointer;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.12s, color 0.12s;
}

.m-hbtn:active {
  background: rgba(255, 255, 255, 0.06);
  color: #c8a040;
}

/* ── SCREEN SWITCHING ── */
.m-screen {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.m-screen.hidden {
  display: none !important;
}

/* ── HOME SCREEN ── */
#m-home {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  -webkit-overflow-scrolling: touch;
}

#m-home::-webkit-scrollbar { width: 0; }

/* Input area */
#m-input-area {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.09);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  min-height: 80px;
}

#m-main-input {
  flex: 1;
  background: transparent;
  border: none;
  color: #ddd8cc;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  line-height: 1.5;
  resize: none;
  outline: none;
  min-height: 44px;
  max-height: 120px;
  -webkit-overflow-scrolling: touch;
}

#m-main-input::placeholder {
  color: #3a3630;
}

#m-send-btn {
  width: 38px;
  height: 38px;
  background: #c8a040;
  border: none;
  border-radius: 50%;
  color: #1a1200;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.12s, transform 0.1s;
  line-height: 1;
}

#m-send-btn:active {
  background: #dab848;
  transform: scale(0.94);
}

/* Tour button */
#m-tour-btn {
  background: rgba(74, 138, 191, 0.06);
  border: 1px solid rgba(74, 138, 191, 0.25);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 10px;
  color: #6a9abf;
  font-size: 12px;
  transition: background 0.12s;
  animation: tour-pulse 2.4s ease-in-out infinite;
}

#m-tour-btn:active {
  background: rgba(74, 138, 191, 0.12);
  animation: none;
}

@keyframes tour-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(74, 138, 191, 0.0); }
  50% { box-shadow: 0 0 0 4px rgba(74, 138, 191, 0.18); }
}

#m-tour-btn .m-tour-icon {
  font-size: 18px;
  flex-shrink: 0;
}

#m-tour-btn .m-tour-text {
  flex: 1;
  min-width: 0;
}

#m-tour-btn .m-tour-title {
  font-size: 12px;
  color: #7ab0d8;
  font-weight: 500;
}

#m-tour-btn .m-tour-sub {
  font-size: 10px;
  color: #4a6a8a;
  margin-top: 2px;
}

/* Suggestions */
#m-suggestions {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.m-sugg-label {
  font-size: 9px;
  color: #3a3630;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 4px;
}

.m-sugg-item {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 8px;
  padding: 11px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background 0.12s, border-color 0.12s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.m-sugg-item:active {
  background: rgba(200, 160, 64, 0.07);
  border-color: rgba(200, 160, 64, 0.2);
  transform: scale(0.98);
}

.m-sugg-icon {
  font-size: 15px;
  flex-shrink: 0;
  color: #706860;
  width: 20px;
  text-align: center;
}

.m-sugg-body {
  flex: 1;
  min-width: 0;
}

.m-sugg-text {
  font-size: 12px;
  color: #ddd8cc;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-sugg-desc {
  font-size: 10px;
  color: #706860;
  margin-top: 2px;
}

.m-sugg-arrow {
  font-size: 12px;
  color: #3a3630;
  flex-shrink: 0;
}

/* ── PIPELINE SCREEN ── */
#m-pipeline {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Terminal panel */
#m-terminal {
  min-height: 90px;
  max-height: 160px;
  background: rgba(10, 12, 8, 0.8);
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  gap: 3px;
  overflow: hidden;
  flex-shrink: 0;
  position: relative;
}

#m-terminal::before {
  content: 'TERMINAL';
  position: absolute;
  top: 8px;
  right: 10px;
  font-size: 8px;
  color: #3a3630;
  letter-spacing: 0.1em;
}

.m-term-msg {
  font-size: 11px;
  line-height: 1.45;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.3s ease, transform 0.3s ease;
  white-space: pre-wrap;
  word-break: break-word;
}

.m-term-msg.show {
  opacity: 1;
  transform: translateY(0);
}

.m-term-msg.fading {
  opacity: 0;
  transition: opacity 0.4s ease;
}

.m-term-msg.type-think {
  color: #8a7860;
  font-style: italic;
}

.m-term-msg.type-action {
  color: #6a8a6a;
}

.m-term-msg.type-done {
  color: #3a8a3a;
}

.m-term-msg.type-warn {
  color: #c8a040;
}

.m-term-msg.type-system {
  color: #4a6a8a;
}

.m-term-cursor {
  display: inline-block;
  width: 6px;
  height: 12px;
  background: #4a8abf;
  border-radius: 1px;
  vertical-align: middle;
  margin-left: 3px;
  animation: blink-cursor 1.1s step-end infinite;
}

@keyframes blink-cursor {
  0%, 100% { opacity: 1; }
  50% { opacity: 0; }
}

/* Agents area */
#m-agents-area {
  flex: 1;
  overflow-y: auto;
  padding: 10px 12px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  -webkit-overflow-scrolling: touch;
}

#m-agents-area::-webkit-scrollbar { width: 0; }

/* Agent cards */
.m-agent-card {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 10px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.m-agent-card.running {
  border-color: rgba(200, 160, 64, 0.3);
}

.m-agent-card.done {
  border-color: rgba(58, 138, 58, 0.25);
}

.m-agent-card.error {
  border-color: rgba(138, 42, 42, 0.35);
}

.m-card-header {
  display: flex;
  align-items: center;
  padding: 9px 12px;
  gap: 9px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.05);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.m-card-color-bar {
  width: 3px;
  height: 30px;
  border-radius: 2px;
  flex-shrink: 0;
  opacity: 0.7;
}

.m-card-info {
  flex: 1;
  min-width: 0;
}

.m-card-name {
  font-size: 11px;
  color: #ddd8cc;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-card-meta {
  font-size: 10px;
  color: #706860;
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-card-status {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #1e1c1a;
  flex-shrink: 0;
  transition: background 0.3s;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.m-card-status.idle {
  background: #1e1c1a;
}

.m-card-status.running {
  background: #c8a040;
  animation: status-pulse 1s ease-in-out infinite;
  border-color: rgba(200, 160, 64, 0.4);
}

.m-card-status.done {
  background: #3a8a3a;
  border-color: rgba(58, 138, 58, 0.4);
  animation: none;
}

.m-card-status.error {
  background: #8a2a2a;
  border-color: rgba(138, 42, 42, 0.4);
  animation: none;
}

@keyframes status-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(200, 160, 64, 0.0); }
  50% { box-shadow: 0 0 0 3px rgba(200, 160, 64, 0.2); }
}

.m-card-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.m-card-btn {
  background: rgba(255, 255, 255, 0.05);
  border: none;
  border-radius: 4px;
  color: #706860;
  font-size: 9px;
  padding: 4px 7px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  transition: background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.m-card-btn:active {
  background: rgba(255, 255, 255, 0.1);
  color: #c8a040;
}

.m-card-output {
  padding: 10px 12px;
  border-top: 1px solid rgba(255, 255, 255, 0.05);
  display: none;
}

.m-card-output.visible {
  display: block;
}

.m-card-output-text {
  font-size: 11px;
  color: #9a9088;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

/* ── AGENT EDIT SCREEN ── */
#m-agent-edit {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: #1c1816;
}

#m-edit-header {
  height: 50px;
  min-height: 50px;
  background: rgba(20, 17, 15, 0.98);
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 8px;
  flex-shrink: 0;
}

#m-edit-back {
  background: transparent;
  border: none;
  color: #9a9088;
  font-size: 18px;
  cursor: pointer;
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 6px;
  flex-shrink: 0;
  transition: background 0.12s;
}

#m-edit-back:active {
  background: rgba(255, 255, 255, 0.07);
}

#m-edit-title {
  flex: 1;
  font-size: 12px;
  color: #ddd8cc;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#m-edit-save {
  background: #c8a040;
  border: none;
  border-radius: 6px;
  color: #1a1200;
  font-size: 11px;
  font-weight: 600;
  padding: 7px 14px;
  cursor: pointer;
  font-family: 'IBM Plex Mono', monospace;
  transition: background 0.12s;
  flex-shrink: 0;
}

#m-edit-save:active {
  background: #dab848;
}
#m-edit-save.tour-highlight {
  background: #dab848;
  box-shadow: 0 0 0 3px rgba(200,160,64,.5), 0 0 18px rgba(200,160,64,.35);
  transform: scale(1.04);
  transition: all 0.15s;
}

#m-edit-tabs {
  display: flex;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: rgba(20, 17, 15, 0.5);
  flex-shrink: 0;
}

.m-edit-tab {
  flex: 1;
  padding: 10px 4px;
  text-align: center;
  font-size: 10px;
  color: #706860;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color 0.12s, border-color 0.12s;
  -webkit-tap-highlight-color: transparent;
  letter-spacing: 0.03em;
}

.m-edit-tab.active {
  color: #c8a040;
  border-bottom-color: #c8a040;
}

#m-edit-body {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

#m-edit-body::-webkit-scrollbar { width: 0; }

.m-tab-panel {
  display: none;
  flex-direction: column;
  gap: 12px;
}

.m-tab-panel.active {
  display: flex;
}

.m-field-group {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.m-field-label {
  font-size: 9px;
  color: #706860;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.m-field-input {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 8px;
  color: #ddd8cc;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 13px;
  padding: 11px 12px;
  outline: none;
  width: 100%;
  transition: border-color 0.15s;
  min-height: 44px;
  -webkit-appearance: none;
}

.m-field-input:focus {
  border-color: rgba(200, 160, 64, 0.4);
  background: rgba(255, 255, 255, 0.05);
}

.m-field-textarea {
  min-height: 100px;
  resize: none;
  line-height: 1.5;
}

.m-context-box {
  background: rgba(200, 160, 64, 0.04);
  border: 1px solid rgba(200, 160, 64, 0.15);
  border-radius: 8px;
  padding: 10px 12px;
}

.m-context-label {
  font-size: 9px;
  color: #706860;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.m-context-input {
  background: transparent;
  border: none;
  color: #9a9088;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  line-height: 1.55;
  width: 100%;
  min-height: 60px;
  resize: none;
  outline: none;
}

#m-edit-actions {
  height: 56px;
  min-height: 56px;
  background: rgba(14, 12, 10, 0.97);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  display: flex;
  align-items: center;
  padding: 0 10px;
  gap: 6px;
  flex-shrink: 0;
}

.m-action-btn {
  flex: 1;
  height: 36px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 7px;
  color: #9a9088;
  font-size: 10px;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  transition: background 0.12s, color 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.m-action-btn:active {
  background: rgba(255, 255, 255, 0.08);
  color: #ddd8cc;
}

/* ── MENU OVERLAY + BOTTOM SHEET ── */
#m-menu-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 1100;
  opacity: 0;
  transition: opacity 0.25s ease;
}

#m-menu-overlay.open {
  opacity: 1;
}

#m-menu-sheet {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: 75vh;
  background: rgba(16, 14, 12, 0.99);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 16px 16px 0 0;
  z-index: 1200;
  transform: translateY(100%);
  transition: transform 0.32s cubic-bezier(0.32, 0.72, 0, 1);
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 -4px 40px rgba(0, 0, 0, 0.6);
  /* hidden by default via transform; shown via .open */
  display: none;
}
@media (max-width: 640px) {
  #m-menu-sheet { display: flex; }
}

#m-menu-sheet.open {
  transform: translateY(0);
}

#m-sheet-handle {
  width: 36px;
  height: 4px;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 2px;
  margin: 10px auto 6px;
  flex-shrink: 0;
}

#m-sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 16px 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  flex-shrink: 0;
}

#m-sheet-title {
  font-size: 12px;
  font-family: 'IBM Plex Sans', sans-serif;
  font-weight: 600;
  color: #9a9088;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#m-sheet-new {
  background: rgba(200, 160, 64, 0.1);
  border: 1px solid rgba(200, 160, 64, 0.25);
  border-radius: 6px;
  color: #c8a040;
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
  padding: 6px 12px;
  cursor: pointer;
  transition: background 0.12s;
}

#m-sheet-new:active {
  background: rgba(200, 160, 64, 0.18);
}

#m-sheet-body {
  flex: 1;
  overflow-y: auto;
  padding: 6px 0 30px;
  -webkit-overflow-scrolling: touch;
}

#m-sheet-body::-webkit-scrollbar { width: 0; }

.m-sheet-sec {
  padding: 8px 16px 4px;
}

.m-sheet-sec-label {
  font-size: 8px;
  color: #3a3630;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  margin-bottom: 6px;
}

.m-sheet-divider {
  height: 1px;
  background: rgba(255, 255, 255, 0.05);
  margin: 4px 0;
}

.m-sheet-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 16px;
  cursor: pointer;
  transition: background 0.12s;
  -webkit-tap-highlight-color: transparent;
}

.m-sheet-item:active {
  background: rgba(255, 255, 255, 0.04);
}

.m-sheet-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
}

.m-sheet-item-name {
  flex: 1;
  font-size: 12px;
  color: #9a9088;
  font-family: 'IBM Plex Sans', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m-sheet-item.active .m-sheet-item-name {
  color: #c8a040;
}

.m-sheet-item-sub {
  font-size: 9px;
  color: #3a3630;
}

.m-sheet-empty {
  font-size: 10px;
  color: #3a3630;
  padding: 10px 16px;
  font-style: italic;
}

/* ── PIPELINE STOP BUTTON ── */
#m-stop-bar {
  background: rgba(14, 12, 10, 0.97);
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  padding: 10px 14px;
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

#m-stop-btn {
  flex: 1;
  height: 42px;
  background: rgba(138, 42, 42, 0.12);
  border: 1px solid rgba(138, 42, 42, 0.3);
  border-radius: 8px;
  color: #c87070;
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: background 0.12s;
}

#m-stop-btn:active {
  background: rgba(138, 42, 42, 0.22);
}

#m-live-btn {
  flex: 1;
  height: 42px;
  background: rgba(200, 160, 64, 0.1);
  border: 1px solid rgba(200, 160, 64, 0.35);
  border-radius: 8px;
  color: #c8a040;
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: background 0.18s, border-color 0.18s, color 0.18s, box-shadow 0.18s;
}

#m-live-btn:active {
  background: rgba(200, 160, 64, 0.2);
}

#m-live-btn.live {
  background: rgba(45, 108, 223, 0.18);
  border-color: rgba(45, 108, 223, 0.55);
  color: #7bb3ff;
  box-shadow: 0 0 10px rgba(45, 108, 223, 0.25);
  animation: live-pulse 1.8s ease-in-out infinite;
}

@keyframes live-pulse {
  0%, 100% { box-shadow: 0 0 8px rgba(45, 108, 223, 0.25); }
  50%       { box-shadow: 0 0 18px rgba(45, 108, 223, 0.55); }
}

#m-back-home-btn {
  flex: 1;
  height: 42px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 8px;
  color: #9a9088;
  font-size: 12px;
  font-family: 'IBM Plex Mono', monospace;
  cursor: pointer;
  transition: background 0.12s;
}

#m-back-home-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

/* ── MEDIA QUERY: ACTIVATE MOBILE ── */
@media (max-width: 640px) {
  /* Hide all desktop elements */
  #toolbar,
  #wrap,
  #zc,
  #mm,
  #logwin,
  #mtwin,
  #agentwin,
  #skillwin,
  #expandwin,
  #moverlay,
  #pside,
  #pback,
  #ctx,
  #noise {
    display: none !important;
  }

  /* Show mobile app */
  #mobile-app {
    display: flex !important;
  }

  /* Safe area support for notched devices */
  #mobile-app {
    padding-bottom: env(safe-area-inset-bottom, 0);
  }

  #m-edit-actions {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0));
    height: calc(56px + env(safe-area-inset-bottom, 0));
  }

  #m-stop-bar {
    padding-bottom: max(10px, env(safe-area-inset-bottom, 0));
  }
}
