/* ── Mobile sidebar overlay ──────────────────────────────────────────────── */

.sidebar-toggle {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: 8px;
  box-shadow: var(--shadow-sm);
  color: var(--text);
  cursor: pointer;
  display: none;
  font-size: 20px;
  height: 40px;
  justify-content: center;
  left: 12px;
  line-height: 1;
  position: fixed;
  top: 12px;
  transition: background .15s, border-color .15s;
  width: 40px;
  z-index: 300;
}

.sidebar-toggle:hover {
  background: var(--surface2);
  border-color: var(--accent);
}

.sidebar-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.sidebar-backdrop {
  background: rgba(0, 0, 0, .55);
  display: none;
  inset: 0;
  position: fixed;
  z-index: 199;
}

.admin-actions-group-danger .btn-danger {
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}

@media (max-width: 640px) {
  .main-help-bar {
    padding: 8px 12px 0 60px;
  }

  #usage-summary-widget {
    margin: 12px 12px 16px;
    padding: 12px;
    overflow-x: visible;
  }

  #usage-summary-widget .usw-head {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  #usage-summary-widget .usw-periods {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
  }

  #usage-summary-widget button {
    min-height: 40px;
    padding: 9px 12px;
    text-align: center;
  }

  #usage-summary-widget button.active {
    box-shadow: inset 0 0 0 1px rgba(56, 189, 248, .52);
  }

  #usage-summary-widget table,
  #usage-summary-widget thead,
  #usage-summary-widget tbody,
  #usage-summary-widget tr,
  #usage-summary-widget td {
    display: block;
  }

  #usage-summary-widget table {
    font-size: 13px;
  }

  #usage-summary-widget thead {
    display: none;
  }

  #usage-summary-widget tbody {
    display: grid;
    gap: 10px;
  }

  #usage-summary-widget tr {
    background: var(--control-bg);
    border: 1px solid var(--border-soft);
    border-radius: 8px;
    padding: 10px;
  }

  #usage-summary-widget td {
    border-top: 0;
    padding: 0;
  }

  #usage-summary-widget .period {
    display: flex;
  }

  #usage-summary-widget .project-name {
    font-weight: 650;
    line-height: 1.3;
    margin-bottom: 9px;
    max-width: 100%;
    overflow: hidden;
    overflow-wrap: anywhere;
    text-overflow: ellipsis;
  }

  #usage-summary-widget .bar-cell {
    display: flex;
    flex-direction: column;
    gap: 5px;
    margin-bottom: 9px;
    min-width: 0;
    width: 100%;
  }

  #usage-summary-widget .bar {
    width: 100%;
  }

  #usage-summary-widget .num {
    align-items: baseline;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    text-align: left;
    white-space: normal;
  }

  #usage-summary-widget .num + .num {
    margin-top: 5px;
  }

  #usage-summary-widget .mobile-label {
    color: var(--text-dim);
    display: inline;
    font-size: 12px;
    font-weight: 650;
  }

  #usage-summary-widget .metric-value {
    font-variant-numeric: tabular-nums;
    font-weight: 650;
    overflow-wrap: anywhere;
    text-align: right;
  }

  #usage-summary-widget .empty,
  #usage-summary-widget .error,
  .cost-budget-note,
  .cost-data-note,
  .cost-load-error,
  #costEmpty {
    max-width: 100%;
    overflow-wrap: anywhere;
  }

  #btnToggleCosts,
  #btnExportCostsPdf {
    min-height: 44px;
    min-width: 0;
    overflow-wrap: anywhere;
    white-space: normal;
  }

  #budget-alert-banner {
    font-size: 12px;
    padding: 9px 12px;
  }

  .admin-actions-dropdown {
    gap: 10px;
  }

  .admin-actions-group {
    gap: 8px;
    padding-top: 10px;
  }

  .admin-actions-group-title {
    padding: 0 2px 1px;
  }

  .admin-actions-group-danger {
    margin-top: 2px;
  }

  /* Undo the stacking layout in favour of an overlay sidebar */
  .layout {
    flex-direction: row;
  }

  body.sidebar-open {
    overflow: hidden;
  }

  body.sidebar-open .main {
    overflow: hidden;
    overscroll-behavior: contain;
    touch-action: none;
  }

  .sidebar-toggle {
    display: flex;
    top: max(12px, env(safe-area-inset-top));
  }

  .main {
    padding-top: calc(48px + env(safe-area-inset-top));
  }

  body.project-user-mode .main,
  body.project-admin-mode .main {
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
  }

  .project-view {
    padding-top: 8px;
  }

  .project-view {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }

  .project-view .project-tab-panels {
    order: 1;
  }

  .project-view.idea-mode #ideaPanel {
    margin-top: 0;
    order: 1;
  }

  .project-view #userStatusDetails {
    order: 2;
  }

  .project-view #projectTabs {
    order: 3;
  }

  .project-view #warningBar,
  .project-view #budgetWarningBar,
  .project-view #setupChecklist {
    order: 4;
  }

  .project-view .config-panel.admin-view-only,
  .project-view #mergeQueueBar {
    order: 5;
  }

  .project-view .app-page-header {
    order: 6;
  }

  .project-view #mobileProjectContext {
    order: 7;
  }

  .project-view #mobileRoleBar {
    order: 8;
  }

  .app-page-header {
    margin-bottom: 8px;
    padding: 10px 12px;
  }

  .app-page-header::before {
    left: 12px;
    right: 12px;
  }

  .project-view.idea-mode.user-mode .app-page-header {
    display: none;
  }

  .project-view.idea-mode.user-mode #mobileProjectContext {
    order: 0;
  }

  .mobile-role-bar {
    background: rgba(15, 23, 42, .92);
    border: 1px solid rgba(148, 163, 184, .28);
    border-radius: 14px;
    bottom: max(10px, env(safe-area-inset-bottom));
    box-shadow: 0 12px 36px rgba(0, 0, 0, .42);
    display: none;
    gap: 4px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    left: 12px;
    padding: 4px;
    position: fixed;
    right: 12px;
    z-index: 190;
  }

  body.light .mobile-role-bar {
    background: rgba(255, 255, 255, .94);
    box-shadow: 0 12px 32px rgba(15, 23, 42, .18);
  }

  body.project-user-mode .mobile-role-bar,
  body.project-admin-mode .mobile-role-bar {
    display: grid;
  }

  .mobile-role-bar[hidden] {
    display: none !important;
  }

  .mobile-role-btn {
    background: transparent;
    border: 0;
    border-radius: 10px;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 13px;
    font-weight: 750;
    min-height: 44px;
    min-width: 0;
    padding: 0 10px;
    touch-action: manipulation;
  }

  .mobile-role-btn.active {
    background: var(--accent);
    color: #fff;
  }

  .mobile-role-btn:focus-visible {
    outline: 2px solid var(--accent-h);
    outline-offset: 2px;
  }

  .mobile-project-context {
    margin-bottom: 8px;
  }

  .sidebar {
    bottom: 0;
    height: 100vh !important;
    height: 100dvh !important;
    max-height: none !important;
    min-width: var(--sidebar-w) !important;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
    position: fixed;
    top: 0;
    transform: translateX(-100%);
    transition: transform .26s ease, box-shadow .26s ease;
    width: var(--sidebar-w) !important;
    z-index: 200;
  }

  .layout.sidebar-open .sidebar {
    box-shadow: 16px 0 48px rgba(0, 0, 0, .45);
    transform: translateX(0);
  }

  .layout.sidebar-open .sidebar-backdrop {
    display: block;
    height: 100vh;
    height: 100dvh;
    padding-bottom: env(safe-area-inset-bottom);
    padding-top: env(safe-area-inset-top);
  }

  /* Sticky segmented project tabs stay below mobile navigation and context. */
  .project-tabs {
    background: var(--surface);
    box-shadow: 0 2px 8px rgba(0, 0, 0, .28);
    position: sticky;
    top: calc(64px + env(safe-area-inset-top));
    z-index: 150;
  }

  body.light .project-tabs {
    box-shadow: 0 2px 8px rgba(15, 23, 42, .1);
  }

  .project-tabs {
    -webkit-overflow-scrolling: touch;
    border: 1px solid var(--border);
    border-radius: 8px;
    display: flex;
    gap: 4px;
    margin-bottom: 14px;
    overflow-x: auto;
    overflow-y: hidden;
    overscroll-behavior-x: contain;
    padding: 4px;
    scroll-padding-inline: 4px;
    scrollbar-width: none;
  }

  .project-tabs::-webkit-scrollbar {
    display: none;
  }

  .project-tab {
    border-bottom: 0;
    border-radius: 6px;
    flex: 0 0 auto;
    font-size: 12px;
    line-height: 1.15;
    min-height: 44px;
    min-width: 78px;
    overflow: hidden;
    padding: 0 12px;
    scroll-margin-inline: 4px;
    text-align: center;
    text-overflow: ellipsis;
    touch-action: manipulation;
  }

  .project-tab.active {
    background: var(--accent);
    color: #fff;
  }

  .project-view.user-mode .project-tabs.admin-view-only {
    display: none !important;
  }

  .project-view.idea-mode .idea-form-grid {
    display: flex;
    flex-direction: column;
    gap: 0;
  }

  .project-view.idea-mode .idea-panel {
    border-left: 0;
    border-radius: 10px;
    padding: 14px;
  }

  .project-view.idea-mode .idea-section {
    max-width: none;
    padding: 0;
  }

  .project-view.idea-mode .idea-section::before,
  .project-view.idea-mode .idea-section-create::after {
    display: none;
  }

  .project-view.idea-mode .idea-section + .idea-section {
    padding-top: 16px;
  }

  .project-view.idea-mode .idea-panel-title {
    font-size: 17px;
  }

  .project-view.idea-mode .flow-idea-sub {
    font-size: 13px;
  }

  .project-view.idea-mode .idea-compose {
    align-items: stretch;
    gap: 10px;
  }

  .project-view.idea-mode .idea-textarea-wrap,
  .project-view.idea-mode .idea-input-tools,
  .project-view.idea-mode .idea-recent-panel {
    width: 100%;
  }

  .project-view.idea-mode .idea-panel #ideaTextarea {
    font-size: 16px;
    min-height: 138px;
    padding: 12px 42px 12px 12px;
  }

  .project-view.idea-mode.user-mode .idea-panel {
    padding: 18px 14px;
  }

  .project-view.idea-mode.user-mode .idea-panel #ideaTextarea {
    box-shadow: none;
    font-size: 16px;
    min-height: 220px;
    padding: 14px 42px 14px 14px;
  }

  .project-view.idea-mode.user-mode .idea-actions {
    grid-template-columns: 1fr;
  }

  .project-view.idea-mode .idea-actions {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .project-view.idea-mode .idea-panel .btn-compact {
    min-height: 46px;
    min-width: 0;
  }

  .project-view.idea-mode.user-mode .user-collapsible-section {
    border-top: 1px solid var(--border-soft);
    margin-top: 14px;
    padding-top: 12px;
  }

  .project-view.idea-mode.user-mode #userActiveIdeasDetails {
    margin-top: 10px;
  }

  .project-view.idea-mode .user-status-panel {
    grid-template-columns: 1fr;
    margin-bottom: 0;
    padding: 12px;
  }

  .project-view.idea-mode .user-status-title {
    font-size: 16px;
  }

  .project-view.idea-mode .user-status-text,
  .project-view.idea-mode .user-steps {
    display: none;
  }

  .project-view.idea-mode .user-status-stats {
    display: grid;
    gap: 6px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .project-view.idea-mode .user-status-stats span {
    min-width: 0;
    padding: 8px;
  }

  .flow-running-banner {
    align-items: flex-start;
    flex-wrap: wrap;
    line-height: 1.35;
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .flow-running-banner span,
  .flow-running-link {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .flow-card-top {
    gap: 10px;
  }

  .flow-card-num,
  .flow-card-status,
  .flow-card-status a {
    min-width: 0;
    overflow-wrap: anywhere;
  }

  .analyze-issue-row {
    grid-template-columns: 1fr;
  }

  .analyze-issue-actions {
    align-items: stretch;
    width: 100%;
  }

  .analyze-issue-actions .btn,
  .analyze-issue-actions a {
    justify-content: center;
    width: 100%;
  }

  .issue-card,
  .mr-entry {
    min-width: 0;
  }

  .mr-entry {
    flex-direction: column;
  }

  .mr-title-link,
  .issue-title,
  .issue-desc,
  .cost-card-title {
    white-space: normal;
    overflow-wrap: anywhere;
  }

  .config-actions,
  .global-settings-actionbar,
  .input-row,
  .cost-card-head,
  .usage-stats-head {
    align-items: stretch;
    flex-direction: column;
  }

  .config-actions .btn,
  .global-settings-actionbar .btn,
  .input-row .btn,
  .input-row input {
    width: 100%;
  }

  #configPanel .config-actions {
    background: var(--surface);
    border-top: 1px solid var(--border);
    bottom: 0;
    box-shadow: 0 -10px 28px rgba(0, 0, 0, .28);
    display: grid;
    gap: 8px;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    margin: 2px -16px 0;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
    position: sticky;
    z-index: 35;
  }

  #configPanel .config-actions .btn {
    min-height: 44px;
    width: 100%;
  }

  .time-slots {
    flex-direction: column;
  }

  .time-slot,
  .time-slot input[type="time"] {
    width: 100%;
  }

  .auto-toggle-label {
    align-items: flex-start;
    line-height: 1.35;
  }

  .toast-container {
    bottom: max(12px, env(safe-area-inset-bottom));
    left: 12px;
    right: 12px;
    top: auto;
    width: auto;
  }

  .toast {
    max-width: none;
    width: 100%;
  }

}

@media (max-width: 420px) {
  :root {
    --sidebar-w: min(300px, calc(100vw - 44px));
  }

  .project-view,
  .global-settings-view {
    padding-left: 10px;
    padding-right: 10px;
  }

  .app-page-header,
  .config-panel,
  .settings-group,
  .process-flow,
  .user-status-panel {
    padding-left: 12px;
    padding-right: 12px;
  }

  #configPanel .config-actions {
    margin-left: -12px;
    margin-right: -12px;
    padding-left: 12px;
    padding-right: 12px;
  }

  .project-name,
  .overview-intro-title,
  .wizard-title {
    font-size: 18px;
  }

  .view-switch,
  .wizard-provider-row,
  .cost-card-values,
  .user-status-stats,
  .overview-stats {
    grid-template-columns: 1fr;
  }

  .view-switch {
    display: grid;
  }

  .wizard-provider-row {
    display: grid;
    gap: 8px;
  }

  .mobile-project-context {
    align-items: stretch;
    flex-direction: column;
  }

  .mobile-project-context-actions {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    width: 100%;
  }

  .mobile-project-context-link,
  .mobile-project-admin-btn,
  .mobile-project-actions-btn,
  .mobile-project-config-btn {
    min-width: 0;
    width: 100%;
  }

  .flow-card-action-group.secondary {
    flex-direction: column;
  }

  .flow-card-link,
  .flow-card-discard,
  .flow-card-primary-action {
    width: 100%;
  }
}

/* ── Preflight clarification ─────────────────────────────────────────────── */

.flow-card-clarification {
  background: rgba(245, 158, 11, .1);
  border: 1px solid rgba(245, 158, 11, .36);
  border-radius: 6px;
  display: flex;
  flex-direction: column;
  font-size: 12px;
  gap: 7px;
  margin-top: 6px;
  padding: 8px;
}

.flow-card-clarification .fcc-title {
  color: var(--yellow);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}

.flow-card-clarification .fcc-question {
  color: var(--text);
  font-weight: 600;
  line-height: 1.45;
}

.flow-card-clarification .fcc-answer {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 5px 7px;
  resize: vertical;
  width: 100%;
  box-sizing: border-box;
}

.flow-card-clarification .fcc-answer:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(14, 165, 233, .18);
  outline: none;
}

.flow-card-clarification .fcc-answer[aria-invalid="true"] {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(239, 68, 68, .14);
}

.flow-card-clarification .fcc-error {
  color: var(--red);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.35;
  min-height: 15px;
}

.flow-card-clarification .fcc-status {
  color: var(--yellow);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.35;
}

.flow-card-clarification .fcc-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.flow-card-clarification .fcc-submit {
  background: var(--accent);
  border: none;
  border-radius: 5px;
  color: #fff;
  cursor: pointer;
  flex: 1 1 auto;
  font-size: 11px;
  padding: 5px 8px;
  transition: opacity .13s;
}

.flow-card-clarification .fcc-submit:hover { opacity: .86; }

.flow-card-clarification .fcc-cancel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-dim);
  cursor: pointer;
  font-size: 11px;
  padding: 5px 8px;
  transition: opacity .13s;
}

.flow-card-clarification .fcc-cancel:hover { opacity: .72; }

.flow-card-clarification .fcc-answer:disabled,
.flow-card-clarification .fcc-submit:disabled,
.flow-card-clarification .fcc-cancel:disabled {
  cursor: wait;
  opacity: .68;
}

.flow-card-clarification.sending {
  border-color: rgba(14, 165, 233, .48);
}

.flow-card-clarification.sending .fcc-status {
  color: var(--accent-h);
}

/* ── Issue Workflow Stepper ───────────────────────────────────────────────── */

.issue-workflow {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 16px;
  background: var(--panel-bg-soft);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-top: 8px;
}

.workflow-steps {
  display: flex;
  align-items: flex-start;
  gap: 0;
}

.workflow-step {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  flex: 1;
  position: relative;
  text-align: center;
}

.wf-connector {
  position: absolute;
  top: 10px;
  left: 50%;
  width: 100%;
  height: 2px;
  background: var(--border);
  z-index: 0;
}

.workflow-step--done   .wf-connector,
.workflow-step--active .wf-connector { background: var(--green); }
.workflow-step--error  .wf-connector { background: var(--red); }

.wf-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--border);
  background: var(--surface2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  position: relative;
  z-index: 1;
  flex-shrink: 0;
  transition: border-color .2s, background .2s;
}

.workflow-step--done  .wf-icon { background: rgba(34,197,94,.15); border-color: var(--green); color: var(--green); }
.workflow-step--error .wf-icon { background: rgba(239,68,68,.12);  border-color: var(--red);   color: var(--red); }
.workflow-step--active .wf-icon { border-color: var(--green); animation: wf-pulse 1.4s ease-in-out infinite; }

@keyframes wf-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(34,197,94,.4); }
  50%       { box-shadow: 0 0 0 5px rgba(34,197,94,0); }
}

.wf-label {
  font-size: 11px;
  color: var(--text-dim);
  line-height: 1.3;
  max-width: 76px;
  word-break: break-word;
}

.workflow-step--done   .wf-label { color: var(--green); }
.workflow-step--active .wf-label { color: var(--text); font-weight: 600; }
.workflow-step--error  .wf-label { color: var(--red); }

.workflow-celebration {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding-top: 8px;
  border-top: 1px solid var(--border-soft);
}

.workflow-celebration.celebrate {
  animation: wf-celebrate .45s cubic-bezier(.22,1,.36,1) both;
}

@keyframes wf-celebrate {
  0%   { opacity: 0; transform: scale(.88); }
  100% { opacity: 1; transform: scale(1); }
}

.workflow-celebration-icon {
  font-size: 26px;
  color: var(--green);
  line-height: 1;
}

.workflow-celebration-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.workflow-celebration-link {
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
}
.workflow-celebration-link:hover { color: var(--accent-h); text-decoration: underline; }

@media (max-width: 600px) {
  .workflow-steps { flex-direction: column; gap: 8px; }
  .workflow-step  { flex-direction: row; align-items: center; text-align: left; gap: 10px; }
  .wf-connector   { position: static; width: 2px; height: 14px; top: auto; left: 10px; margin-left: 10px; flex-shrink: 0; }
  .wf-label       { max-width: none; }
}
