/* ==========================================================================
   1. UTILITIES & GLOBALS
   ========================================================================== */
.mobile-only {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.desktop-only {
  display: none !important;
}

.collapsible-group {
  display: none;
}

.collapsible-group.show-mobile {
  display: flex;
}

.no-pre,
.raw_html {
  white-space: normal;
  display: inline-block;
  margin: 0;
}

.app-name,
.menu-item {
  display: block;
}

input[type="text"] {
  font-size: var(--text-base);
}

.focus-title {
  text-align: center;
}

.help-grid {
  flex-direction: column;
}

.help-grid > div {
  flex: 1 1 100%;
}

/* ==========================================================================
   2. WINDOW LAYOUT & CONTAINERS (Mobile Base)
   ========================================================================== */
.terminal-window {
  max-width: 950px;
  margin: 0 auto;
  opacity: 0;
}

.terminal-window.show {
  opacity: 1;
  padding: 5px;
}

/* App & Terminal Windows */
.app-window,
.new-terminal-window,
.new-terminal-window.maximized,
.app-window.maximized {
  position: fixed;
  top: 40px;
  bottom: calc(55px + env(safe-area-inset-bottom));
  left: 0;
  width: 100%;
  height: auto;
  margin-bottom: 0;
  transform: none;
  background: var(--bg-theme-app, rgba(30, 30, 30, 0.3));
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: var(--window-border-radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 1;
}

/* Specific Base Styles for New Terminal */
.new-terminal-window {
  background: var(--terminal-bg) !important;
  font-family: var(--terminal-font) !important;
  color: var(--color-text);
  border: 1px solid var(--window-border);
  box-shadow: var(--new-terminal-shadow);
}

.window-content-area,
.app-window-content {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
  position: relative;
}

.window-body {
  display: none;
  flex-direction: column;
  flex-grow: 1;
  height: 100%;
  min-height: 0;
}

.window-body.active {
  display: flex;
}

/* Headers */
.terminal-header,
.app-window-header {
  padding: 8px 12px;
  cursor: grab;
  user-select: none;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: var(--window-header-font-size);
  background: var(--bg-theme-app, rgba(30, 30, 30, 0.3));
  border-bottom: 0px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.terminal-header {
  padding: 0;
  align-items: flex-end;
}

.app-window-header:active {
  cursor: grabbing;
}

.app-window-title {
  color: #eee;
  font-family: var(--font-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.app-window-header i.ph,
.app-window-header i.ph-fill {
  font-size: var(--window-header-icons);
  line-height: 1;
}

/* Window Controls */
.app-window-controls {
  display: flex;
  gap: 1px;
  background-color: transparent;
  border-radius: 16px;
  padding: 1px;
  align-items: center;
  height: 100%;
}

.app-window-controls button {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.8rem;
}

.app-window-controls button i {
  background-color: transparent;
  position: relative;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  width: 1em;
  height: 1em;
  font-style: normal;
}

.app-window-controls button:hover i::after {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-family: var(--font-primary);
  font-weight: bold;
  line-height: 1;
  color: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}

.app-maximize-btn {
  display: none; /* Desktop only by default */
  color: #28c840;
}

.app-minimize-btn {
  color: #febc2e;
}

.app-close-btn {
  color: #ff5f56;
  padding: 0 5px;
}

.app-maximize-btn:hover { color: #1e9e30; }
.app-minimize-btn:hover { color: #e0a628; }
.app-close-btn:hover { color: #ff3b30; }

.app-minimize-btn:hover i::after { content: "🗕"; font-size: 0.6em; margin-top: -2px; }
.app-maximize-btn:hover i::after { content: "🗖"; font-size: 0.6em; margin-top: -1px; }
.app-close-btn:hover i::after { content: "✖"; font-size: 0.6em; margin-top: 0px; margin-left: -0.2px; }

/* Resizers */
.resizer {
  display: none;
}

.resizer.bottom-right {
  width: 15px;
  height: 15px;
  right: 0;
  bottom: 0;
  cursor: se-resize;
}

.resizer.bottom {
  height: 5px;
  bottom: 0;
  left: 0;
  right: 0;
  cursor: s-resize;
}

.resizer.right {
  width: 5px;
  right: 0;
  top: 0;
  bottom: 0;
  cursor: e-resize;
}

/* ==========================================================================
   3. TABS
   ========================================================================== */
.terminal-tabs {
  display: flex;
  align-items: flex-end;
  flex-grow: 1;
  overflow: hidden;
  margin-right: 15px;
}

.tab-list {
  display: flex;
  gap: 0;
  height: 35px;
}

.tab-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 14px;
  background: rgba(255, 255, 255, 0.05);
  color: rgba(255, 255, 255, 0.5);
  border-radius: 0;
  cursor: pointer;
  user-select: none;
  font-size: 0.9em;
  border-right: 1px solid rgba(255, 255, 255, 0.1);
  transition: background 0.2s, color 0.2s;
}

.tab-item:hover,
.tab-item.active {
  background: rgba(255, 255, 255, 0.1);
}

.tab-item:hover {
  color: rgba(255, 255, 255, 0.8);
}

.tab-item.active {
  color: #ffffff;
  border-color: rgba(255, 255, 255, 0.1);
}

.tab-title {
  white-space: nowrap;
}

.tab-close-btn {
  font-size: 1.2em;
  line-height: 1;
  opacity: 0.6;
}

.tab-close-btn:hover {
  opacity: 1;
  color: #ff5f56;
}

.add-tab-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.5);
  cursor: pointer;
  padding: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
  height: 35px;
}

.add-tab-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

/* ==========================================================================
   4. ANIMATIONS
   ========================================================================== */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%, 75% { transform: translateX(-5px); }
  50% { transform: translateX(5px); }
}

.shake-window {
  animation: shake 0.3s ease-in-out;
}

/* ==========================================================================
   5. DESKTOP OVERRIDES
   ========================================================================== */
@media (min-width: 940px) {
  .desktop-only {
    display: flex !important;
  }

  .welcome-divider {
    width: 50%;
  }

  .window-form {
    border-radius: 0;
    margin: 0;
    padding: 0;
    background-color: transparent;
    border: none;
    box-shadow: none;
  }

  .window-form:focus-within {
    border: none;
    background-color: transparent;
  }

  .window-input {
    color: var(--color-text);
    padding: 8px;
    font-family: var(--terminal-font);
    border: none;
  }

  .window-send-btn,
  #mobileSendBtn {
    display: none !important;
  }

  /* Desktop Windows Base */
  .app-window,
  .new-terminal-window,
  .new-terminal-window.maximized,
  .app-window.maximized {
    position: absolute;
    min-width: 200px;
    min-height: 150px;
    top: auto;
    bottom: auto;
    left: auto;
    right: auto;
    width: auto;
    height: auto;
    transform: none;
  }

  /* Specific Sizing for New Terminal Window Desktop */
  .new-terminal-window {
    border-radius: var(--terminal-border-radius);
    width: 950px;
    height: 555px;
    resize: both;
  }
  
  /* Desktop Maximized Styles */
  .app-window.maximized {
    top: var(--window-top-margin-max);
    height: calc(100dvh - 70px);
    transition: width 0.2s ease, height 0.2s ease, top 0.2s ease, left 0.2s ease, border-radius 0.2s ease;
  }

  .resizer {
    display: block;
    position: absolute;
    z-index: var(--z-window, 100);
  }

  /* Maximized Button Tooltips */
  .app-maximize-btn {
    display: inline-flex;
  }

  .app-window.maximized .app-maximize-btn:hover i::after,
  .new-terminal-window.maximized .app-maximize-btn:hover i::after {
    content: "🗗";
    font-size: 0.6em;
    margin-top: -1px;
  } 

}