/* ── Visibility: Desktop vs Mobile ── */
.desktop-only { display: block; }
.mobile-only { display: none; }

@media (max-width: 767px) {
  .desktop-only { display: none !important; }
  .mobile-only { display: block; }

  /* ── Safe Area ── */
  #app { padding-bottom: env(safe-area-inset-bottom); }

  /* ── Layout Overrides ── */
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 270px;
    max-width: 80vw;
    height: 100%;
    height: 100dvh;
    z-index: 1100;
    display: none;
    background: var(--bg-card);
    border-right: 1px solid var(--border-default);
    padding: 12px 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    box-shadow: 4px 0 24px rgba(0,0,0,0.3);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  }
  .sidebar.open {
    display: block;
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1099;
    display: none;
    opacity: 0;
    transition: opacity 0.25s ease;
  }
  .sidebar-backdrop.open {
    display: block;
    opacity: 1;
  }
  .topbar { padding: 8px 12px; }
  .topbar-right { gap: 4px; }
  .user-name, .role-badge { display: none !important; }
  .user-menu { gap: 4px; padding: 2px 4px 2px 2px; }
  .logout-btn { min-width: 100px; padding: 4px 8px; font-size: 10px; }
  .app-layout { flex-direction: column; overflow: visible; }
  .main-content {
    flex: 1;
    min-height: 0;
    padding: 12px 12px 80px 12px;
    max-width: 100%;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
  }
  .metrics-grid { grid-template-columns: repeat(4, 1fr); gap: 6px; padding: 0; }
  .metric-card { padding: 6px 8px; }
  .metric-card .metric-value { font-size: 16px; }
  .metric-card .metric-label { font-size: 9px; margin-bottom: 2px; letter-spacing: 0.3px; }
  .metric-sub { display: none; }

  /* ── Project Cover (mobile compact) ── */
  .project-cover { height: 120px; padding: 20px 16px; }
  .project-cover .project-cover-title { font-size: 16px; }
  .project-cover .project-cover-subtitle { font-size: 11px; }
  .cover-edit-btn { display: none; }
  .back-link { padding: 0; margin-bottom: 8px; }
  .project-cover.cover-collapsed { height: 44px; padding: 4px 10px; }
  .project-cover.cover-collapsed .project-cover-title { font-size: 13px; }
  .project-cover.cover-collapsed .project-cover-subtitle { font-size: 10px; }
  .project-detail .main-content { padding: 4px 12px 80px 12px; }
  .project-detail .back-link { margin-bottom: 6px; }

  /* ── Attention Load Widget (mobile compact) ── */
  .project-cover .attention-load-widget { display: none; }
  #mobile-kanban-container .attention-load-widget {
    position: static;
    margin-bottom: 12px;
    padding: 12px 14px;
    border-radius: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-default);
  }
  .attention-load-label { font-size: 11px; }
  .attention-load-value { font-size: 13px; }

  .spec-convert-btn {
    width: 100%;
    display: flex;
    justify-content: center;
    font-size: 14px;
    padding: 10px 20px;
  }

  /* ── Stacked Sections ── */
  .stacked-sections { display: flex; flex-direction: column; gap: 12px; }

  .stacked-section {
    background: var(--bg-card);
    border: 1px solid var(--border-default);
    border-radius: 12px;
    overflow: hidden;
    transition: box-shadow 0.2s ease;
  }
  .stacked-section-expanded {
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
  }

  .stacked-section-header {
    display: flex;
    align-items: center;
    padding: 14px 14px;
    gap: 10px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    user-select: none;
    min-height: 44px;
  }
  .stacked-section-header:active {
    background: var(--bg-card-hover);
  }

  .stacked-section-status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
  }
  .stacked-section-status-dot.status-backlog { background: var(--text-muted); }
  .stacked-section-status-dot.status-spec_ready { background: var(--accent); }
  .stacked-section-status-dot.status-in_progress { background: var(--accent-amber); }
  .stacked-section-status-dot.status-review { background: var(--accent-purple); }
  .stacked-section-status-dot.status-done { background: var(--accent-green); }
  .stacked-section-name {
    flex: 1;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .stacked-section-count {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
    min-width: 22px;
    text-align: center;
  }
  .stacked-section-chevron {
    color: var(--text-muted);
    font-size: 14px;
    transition: transform 0.2s ease;
    width: 40px;
    height: 40px;
    text-align: center;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .stacked-section-expanded .stacked-section-chevron i {
    transform: rotate(180deg);
  }

  .stacked-section-cards {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.25s ease;
  }
  .stacked-section-expanded .stacked-section-cards {
    max-height: 60vh;
    overflow-y: auto;
    padding: 0 12px 10px;
    -webkit-overflow-scrolling: touch;
  }
  .stacked-section-loading,
  .stacked-section-empty {
    padding: 24px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
  }

  /* ── Mobile Kanban Cards ── */
  .mobile-kanban-card {
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 88px;
    padding: 16px;
    margin-bottom: 6px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: 16px;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: transform 0.12s ease, box-shadow 0.12s ease;
  }
  .mobile-kanban-card:active {
    transform: scale(0.985);
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  }
  .mobile-kanban-card.kanban-card-locked {
    border-left: 3px solid var(--accent-amber);
  }
  .mobile-kanban-card.swiping {
    transition: none !important;
    touch-action: none;
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
  }

  .mobile-card-top {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
  }
  .mobile-card-title {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .mobile-card-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted);
  }
  .mobile-avatar-initials {
    font-size: 10px;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    padding: 3px 6px;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .mobile-kanban-card .spec-type-badge {
    font-family: var(--font-sans);
  }
  .mobile-kanban-card .card-slot-size {
    font-family: var(--font-sans);
  }
  .mobile-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: 2px solid var(--bg-card);
  }

  /* ── Bottom Sheet ── */
  .bottom-sheet-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 1000;
    display: none;
    animation: bs-fade-in 0.2s ease;
  }
  @keyframes bs-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
  }

  .bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 75%;
    background: var(--bg-card);
    border-radius: 20px 20px 0 0;
    z-index: 1001;
    display: flex;
    flex-direction: column;
    box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.25);
    transition: height 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    overflow: hidden;
  }
  .bottom-sheet.expanded {
    height: 90%;
  }

  .bottom-sheet-handle {
    width: 100%;
    padding: 8px 0 4px;
    display: flex;
    justify-content: center;
    cursor: grab;
    touch-action: none;
    flex-shrink: 0;
  }
  .bottom-sheet-handle::before {
    content: '';
    width: 36px;
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
  }
  .bottom-sheet-handle:active {
    cursor: grabbing;
  }

  .bottom-sheet-body {
    flex: 1;
    overflow-y: auto;
    padding: 0 16px 24px;
    -webkit-overflow-scrolling: touch;
  }
  .bottom-sheet-body .spec-meta-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 8px;
  }
  .bottom-sheet-body .modal-meta-item {
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 4px;
    min-height: auto;
  }
  .bottom-sheet-body .meta-label {
    width: 52px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 2px;
  }
  .bottom-sheet-body .meta-label i {
    width: 12px;
    text-align: center;
    flex-shrink: 0;
    font-size: 11px;
  }
  .bottom-sheet-body .meta-label strong {
    white-space: nowrap;
    font-size: 10px;
  }
  .bottom-sheet-body .modal-meta-item .inline-select,
  .bottom-sheet-body .modal-meta-item .meta-label + :not(.meta-label) {
    flex: 1;
    min-width: 0;
  }
  .bottom-sheet-body .inline-select {
    width: auto;
    flex: 1;
    min-width: 0;
    box-sizing: border-box;
    font-size: 12px;
    padding: 4px 6px;
    min-height: 38px;
  }
  .bottom-sheet-body .spec-description {
    font-size: 14px;
    line-height: 1.5;
    max-height: 35vh;
    overflow-y: auto;
    margin-bottom: 12px;
  }
  .bottom-sheet-body h3 {
    font-size: 18px;
  }
  .bottom-sheet-body .card-priority {
    font-size: 11px;
    padding: 2px 6px;
  }
  .bottom-sheet-body .ac-list-title {
    font-size: 13px;
  }
  .bottom-sheet-body .ac-list-item {
    font-size: 14px;
    min-height: 44px;
    padding: 10px 6px;
  }
  .bottom-sheet-body .ac-check {
    font-size: 17px;
    min-width: 24px;
  }
  .bottom-sheet-body .btn {
    font-size: 12px;
    padding: 6px 12px;
    min-height: 38px;
  }
  .bottom-sheet-body .ac-list-scroll {
    max-height: 25vh !important;
  }

  .bottom-sheet-body .ac-list {
    margin-top: 16px;
  }

  /* ── Bottom Navigation ── */
  .bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    justify-content: center;
    gap: 48px;
    align-items: center;
    background: var(--bg-card);
    border-top: 1px solid var(--border-default);
    z-index: 900;
    padding-bottom: env(safe-area-inset-bottom);
    box-shadow: 0 -1px 6px rgba(0, 0, 0, 0.08);
  }
  .bottom-nav-tab {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    flex: 1;
    height: 100%;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 12px;
    font-family: var(--font-body);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    transition: color 0.15s ease;
    min-width: 44px;
    padding: 0 16px;
  }
  .bottom-nav-tab i {
    font-size: 18px;
    margin-bottom: 1px;
  }
  .bottom-nav-tab.active {
    color: var(--accent);
  }
  .bottom-nav-tab:active {
    opacity: 0.7;
  }

  /* ── FAB ── */
  .fab {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex !important;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(37, 99, 235, 0.35);
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
  }
  .fab i {
    font-size: 24px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1em;
    height: 1em;
  }
  .fab:active {
    transform: scale(0.9);
  }

  /* ── Fab Speed Dial ── */
  .fab-container {
    position: fixed;
    bottom: calc(68px + env(safe-area-inset-bottom));
    left: 16px;
    z-index: 950;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
  }
  /* ── Niko widget mobile reposition ── */
  .niko-widget {
    bottom: 68px;
    right: 16px;
  }
  .fab-actions {
    display: none;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 8px;
  }
  .fab-actions.open {
    display: flex;
  }
  .fab-action {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-default);
    border-radius: 8px;
    padding: 8px 12px;
    cursor: pointer;
    text-decoration: none;
    color: var(--text-primary);
    font-size: 13px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    transition: transform 0.15s ease;
    -webkit-tap-highlight-color: transparent;
  }
  .fab-action:active {
    transform: scale(0.95);
  }
  .fab-action-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
  }
  #fab-full-spec .fab-action-icon {
    background: var(--accent);
    color: #fff;
  }
  .fab-action .fab-action-icon {
    background: var(--accent-green);
    color: #fff;
  }
  .fab-action-label {
    white-space: nowrap;
  }

  /* ── My Work ── */
  .mobile-my-work .stacked-section {
    margin-bottom: 6px;
  }

  /* ── Hide desktop modals on mobile ── */
  .modal-card { max-width: 90vw; }

  /* ── Login (mobile) ── */
  .login-container { max-width: 340px; }
  .login-brand { margin-bottom: 16px; }
  .login-brand .logo-icon { width: 44px; height: 44px; font-size: 26px; margin-bottom: 8px; }
  .login-brand h1 { font-size: 18px; }
  .login-brand .tagline { font-size: 9px; margin-top: 2px; }
  .login-card { padding: 14px; max-height: calc(100vh - 90px); overflow-y: auto; }
  .login-card h2 { font-size: 14px; margin-bottom: 2px; }
  .login-card .subtitle { font-size: 11px; }
  .form-group select { font-size: 13px; padding: 8px 10px; }
  #role-filter, #person-select { min-height: 44px; }

  /* ── Reports: scrollable tab strip ── */
  .tab-nav { overflow-x: auto; flex-wrap: nowrap; -webkit-overflow-scrolling: touch; scrollbar-width: none; padding-bottom: 4px; }
  .tab-nav::-webkit-scrollbar { display: none; }
  .tab-btn { padding: 6px 12px; font-size: 12px; white-space: nowrap; flex-shrink: 0; }

  /* ── Mobile Kanban: move arrows ── */
  .card-move-arrows {
    display: flex;
    flex-direction: column;
    gap: 4px;
    flex-shrink: 0;
    margin-left: auto;
  }
  .card-move-btn {
    width: 48px; height: 48px;
    display: flex; align-items: center; justify-content: center;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-default);
    border-radius: 50%;
    color: var(--text-muted);
    font-size: 20px;
    cursor: pointer;
    flex-shrink: 0;
    touch-action: manipulation;
    transition: transform 0.1s, background 0.1s, color 0.1s;
    -webkit-tap-highlight-color: transparent;
  }
  .card-move-btn:active {
    background: var(--accent);
    color: #fff;
    transform: scale(0.85);
  }
  .card-move-btn.hidden-btn {
    visibility: hidden;
    pointer-events: none;
  }

  /* ── Prevent text selection on mobile kanban ── */
  #mobile-kanban-container {
    user-select: none;
    -webkit-user-select: none;
  }
}

/* Desktop: mobile-only is hidden */
@media (min-width: 768px) {
  .mobile-only { display: none !important; }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .main-content { padding: 16px; }
  .project-detail .main-content { padding: 6px 16px; }
  .cards-grid { grid-template-columns: 1fr; }
  .kanban-column { min-width: 230px; flex: 1; }
  .spec-editor .form-row { grid-template-columns: 1fr; }
  .reports-grid { grid-template-columns: 1fr; }
  .login-brand .logo-icon { width: 48px; height: 48px; font-size: 36px; }
}
