/* ───────────── Mobile layout for code2uml (max-width: 768px) ─────────────
   All styles that adapt the workspace to phone screens live here; the
   desktop stylesheet (styles.css) stays untouched. index.html loads this
   file AFTER styles.css, so equal-specificity rules below win the cascade.
   The Code/Diagram toggle bar itself is injected by mobile/mobile.js. */

/* Desktop default: hide the JS-injected Diagram tab outside the stacked
   phone layout below. */
.mobile-diagram-tab {
  display: none;
}

@media (max-width: 768px) {
  /* Topbar: compact 56px bar. */
  .topbar {
    position: relative; /* Mobile: containing block for the pinned wordmark. */
    height: 56px;
    padding: 0 10px;
  }

  /* Mobile: the long h1 title is replaced by the code2uml logo wordmark,
     which is already a link to about.html, pinned to the left edge. */
  .website-title {
    display: none;
  }

  .account-wordmark {
    position: absolute;
    left: 12px;
    top: 50%;
    height: 44px; /* Mobile: 44px touch target for the logo link. */
    display: flex;
    align-items: center;
    transform: translateY(-50%);
  }

  .account-actions {
    gap: 8px;
  }

  .account {
    height: 44px; /* Mobile: 44px touch target. */
    padding: 0 10px;
  }

  /* Mobile: whole workspace becomes one vertical column. */
  .workspace {
    height: calc(100vh - 56px);
    height: calc(100dvh - 56px); /* dvh: keeps layout stable when the URL bar hides */
    flex-direction: column;
  }

  /* Mobile: sidebar becomes a horizontal language strip above the panes. */
  .sidebar {
    width: 100%;
    flex: 0 0 auto;
    flex-direction: row;
    align-items: center;
    justify-content: flex-start;
    gap: 10px;
    border-right: 0;
    padding: 0 10px;
  }

  .auto-button {
    height: 44px;
    margin: 0;
  }

  .language-selection {
    flex: 1;
    flex-direction: row;
    justify-content: flex-start;
    gap: 6px;
    padding: 5px 0;
  }

  /* Mobile: 34px icon + 8px padding + 2px border = 44px touch target. */
  .lang-icon {
    width: 34px;
    height: 34px;
    margin: 0;
  }

  /* Mobile: collapsing the strip makes no sense; hide the collapse handle. */
  .nav-icon {
    display: none;
  }

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

  /* Mobile: header bar was absolutely positioned over the two desktop
     panes; it now sits in normal flow at full width as a two-row grid —
     row 1: Run, Theme, Download, Style, Settings; row 2: Diagram, main.
     It also anchors the download dropdown (see .save-menu below). */
  .header-bar {
    width: 100%;
    height: auto;
    position: relative;
    flex: 0 0 auto; /* Mobile: never squeezed by overflowing pane content. */
    display: grid;
    grid-template-columns: repeat(10, 1fr);
    grid-template-rows: 48px 48px;
  }

  /* Mobile: thin rule between the two toolbar rows. */
  .header-bar::after {
    content: '';
    position: absolute;
    top: 48px;
    left: 0;
    right: 0;
    height: 1px;
    background: var(--line);
  }

  /* Mobile: flatten the tab and button wrapper groups so their items become
     direct grid items of the header bar and can be placed per row. */
  .tab-bar,
  .button-row,
  .save-wrap {
    display: contents;
  }

  /* Mobile: row 1 reads Run | Theme | Download | Style | Settings, each
     taking one fifth of the width. */
  #generateUMLButton {
    grid-area: 1 / 1 / 2 / 3;
  }

  #themeToggle {
    grid-area: 1 / 3 / 2 / 5;
  }

  #saveIconButton {
    grid-area: 1 / 5 / 2 / 7;
  }

  .tab-bar .tab[data-target='styleView'] {
    grid-area: 1 / 7 / 2 / 9;
    /* Mobile: separator between Style and Settings, matching the button
       borders (Run|Theme, Theme|Download, Download|Style). The .tab-bar
       prefix keeps this above the light-theme `border-color` override in
       styles.css, so the line keeps the same color as its neighbors. */
    border-right: 1px solid #39434e;
  }

  .tab[data-target='settingsView'] {
    grid-area: 1 / 9 / 2 / 11;
  }

  /* Mobile: row 2 reads main | Diagram — the two workspace views, split
     half/half, with the Diagram tab on main's right. */
  #fileTabBtn {
    grid-area: 2 / 1 / 3 / 6;
  }

  .mobile-diagram-tab {
    grid-area: 2 / 6 / 3 / 11;
    display: flex; /* Mobile: un-hide the injected tab inside the phone layout. */
  }

  /* Mobile: tabs share the space left by the icon-only action buttons. */
  .tab-bar .tab {
    width: auto;
    min-width: 0;
    flex: 1 1 auto;
    gap: 4px;
    padding: 0 4px;
    overflow: hidden;
    font-size: 14px; /* Mobile: fits main + Style + Settings beside 3 buttons at 320px. */
    text-overflow: ellipsis; /* Mobile: graceful label shortening on very narrow phones. */
    white-space: nowrap;
  }

  /* Mobile: smaller language icon so the main tab needs less width. */
  .main-language-icon {
    width: 20px;
    height: 22px;
    flex: 0 0 20px;
  }

  /* Mobile: Style/Settings show the blue underline on hover; :active is the
     touch-screen equivalent of hover feedback. */
  .tab-bar .tab:hover:not(#fileTabBtn),
  .tab-bar .tab:active:not(#fileTabBtn),
  .tab-bar .tab.active:not(#fileTabBtn) {
    border-bottom-color: var(--blue);
  }

  /* Mobile: grid cells size the buttons; the desktop fixed widths would
     overflow the cells. Icons center inside each one-fifth-wide cell. */
  #saveIconButton,
  #themeToggle,
  #generateUMLButton {
    width: auto !important;
    min-width: 0;
    justify-content: center;
  }

  #saveIconButton {
    padding: 0;
    /* Mobile: the adjacent Style tab carries no border (on desktop the
       Theme button provides one), so the Download button needs its own
       right edge to match its left border. */
    border-right: 1px solid #39434e;
  }

  /* Mobile: must beat the desktop `display: inline-block !important` rule. */
  #themeToggle .button-label {
    display: none !important;
  }

  /* Mobile: diagram-type tabs become a normal scrollable row, visible only
     in the Diagram view (JS toggles the `show-diagram-view` body class). */
  #typeView {
    display: none;
    width: 100%;
    height: 44px;
    position: static;
    flex: 0 0 auto; /* Mobile: never squeezed by overflowing pane content. */
    justify-content: flex-start;
    overflow-x: auto;
    box-shadow: none;
  }

  body.show-diagram-view #typeView {
    display: flex;
  }

  .diagram-tabs .tab-item {
    padding: 0 14px;
    border-bottom-width: 4px;
  }

  /* Mobile: exactly one pane visible at a time; default is the editor. */
  .uml-column,
  .divider {
    display: none;
  }

  body.show-diagram-view .uml-column {
    display: flex;
  }

  body.show-diagram-view .editor-pane {
    display: none;
  }

  /* Mobile: while the diagram shows, the row-1 editor tabs read as
     inactive — only the Diagram tab carries the active look. */
  body.show-diagram-view .tab-bar .tab.active:not(#fileTabBtn):not(.mobile-diagram-tab) {
    border-bottom-color: transparent;
    background: #151b22;
    color: #d8e0e8;
  }

  body:not(.dark-theme).show-diagram-view .tab-bar .tab.active:not(#fileTabBtn):not(.mobile-diagram-tab) {
    background: #f4f6f8;
    color: #3d4650;
  }

  /* Mobile: likewise the main tab reads as inactive while the diagram is
     the visible view (its .active look belongs to the editor pane). */
  body.show-diagram-view #fileTabBtn.active {
    height: 100%;
    margin-bottom: 0;
    border-right: 0;
    background: #151b22;
    color: #d8e0e8;
  }

  body:not(.dark-theme).show-diagram-view #fileTabBtn.active {
    background: #f4f6f8;
    color: #3d4650;
  }

  /* Mobile: toolbars are in normal flow now, panes need no top padding. */
  .editor-pane,
  .uml-column {
    padding-top: 0;
  }

  /* Mobile: !important beats the inline flex-basis left by desktop divider drags. */
  .editor-pane {
    flex: 1 1 0 !important;
    min-width: 0;
    /* Mobile: override the flex `min-height: auto` default, else the tall
       style/settings lists force .panes to overflow and squeeze the toolbars. */
    min-height: 0;
  }

  .uml-column {
    min-width: 0;
    min-height: 0;
  }

  /* Mobile: .save-wrap no longer generates a box (display: contents), so
     anchor the download dropdown to the header bar instead, right-aligned
     and just below it. */
  .save-menu {
    top: calc(100% + 4px);
    right: 0;
  }

  /* Mobile: taller form controls in the Settings panel for touch. */
  .toggle-button,
  .dropdown {
    height: 44px;
  }

  /* Mobile: bump the canvas overlay buttons to 44px touch targets. */
  .zoom-controls button,
  .edit-toggle {
    width: 44px;
    height: 44px;
  }

  /* Mobile: light-theme variants of the stacked chrome. */
  body:not(.dark-theme) .sidebar {
    border-right: 0;
    border-bottom-color: #aab3bc;
  }

  body:not(.dark-theme) #typeView {
    border-bottom-color: #aab3bc;
    background: #f4f6f8;
  }
}
