/* Hestini Writer — Responsive (Quiet Canvas breakpoints) */

/* Wide desktop: >= 1440px */
@media (min-width: 1440px) {
  :root {
    --left-panel-width: 300px;
    --right-panel-width: 360px;
  }
}

/* Standard desktop: 1024-1439px */
@media (max-width: 1439px) and (min-width: 1024px) {
  .right-panel { width: 300px; }
}

/* Tablet: < 1024px — overlay left panel */
@media (max-width: 1023px) {
  .workspace { position: relative; }
  .left-panel {
    position: fixed;
    left: 0; top: var(--topbar-height); bottom: 0;
    z-index: 70;
    box-shadow: var(--shadow-lg);
    width: 280px;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex !important;
  }
  .left-panel.mobile-open {
    transform: translateX(0);
  }
  .left-panel.collapsed { transform: translateX(-100%); }

  /* Landscape tablet: side-by-side editor + chat */
  .right-panel {
    display: flex !important;
    width: 40% !important;
    max-width: 360px;
    min-width: 260px;
    position: relative;
    border-left: 1px solid var(--border-light);
  }
  /* The hide toggle must still beat the 40% !important above — narrow
     windows / high display scaling land in this range on real desktops
     (Thầy 2026-07-12: "AI panel vẫn chưa hide được"). */
  .right-panel.collapsed {
    width: 0 !important;
    min-width: 0 !important;
    border-left: none;
  }

  /* Backdrop overlay for left panel */
  .mobile-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar-height);
    background: rgba(0, 0, 0, 0.3);
    z-index: 65;
  }
  .mobile-backdrop.visible { display: block; }
}

/* ── Portrait mobile: < 768px ── */
@media (max-width: 767px) {
  /* Welcome screen */
  .welcome-header { padding: 20px 16px 12px; }
  .welcome-title { font-size: 16px; }
  .project-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }
  .project-card { padding: 14px 16px !important; }

  /* Home toolbar compact */
  .home-toolbar { padding: 14px 16px 12px; gap: 8px; flex-wrap: wrap; }
  .home-title { font-size: 22px; }
  .home-search-wrap { width: 100%; order: -1; }
  .home-search { width: 100%; }
  .home-filter { font-size: 11px; flex: 1; min-width: 0; }
  .home-list-head, .home-list-row {
    grid-template-columns: minmax(0, 1fr) 90px 36px; /* drop Owner + Type columns */
    column-gap: 10px;
  }
  .home-list-head span:nth-child(2), .home-list-row .home-list-type,
  .home-list-head span:nth-child(3), .home-list-row .home-list-owner { display: none; }
  .project-container { padding: 0 16px 20px; }

  /* New project form */
  .new-project-content {
    padding: 16px 16px calc(32px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: 100% !important;
  }
  .new-project-heading { font-size: 18px !important; }
  .type-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }
  .type-card { padding: 14px 10px !important; }
  .form-group { margin-bottom: 12px !important; }
  .form-input, .form-textarea {
    font-size: 16px !important; /* 16px = iOS không auto-zoom */
    padding: 10px 12px !important;
  }
  .form-footer {
    flex-direction: column-reverse !important; /* primary button ở trên, secondary ở dưới — ngón cái dễ tap */
    gap: 10px !important;
    margin-top: 20px !important;
    padding-bottom: 8px;
  }
  .form-footer .btn { width: 100%; justify-content: center; min-height: 44px; }

  /* Topbar compact */
  .topbar { padding: 0 8px; }
  .topbar-brand { font-size: 13px; }
  .topbar-action-btn span { display: none; } /* hide text, show only icon */

  /* Left panel: overlay drawer */
  .left-panel {
    position: fixed !important;
    left: 0; top: var(--topbar-height); bottom: 0;
    z-index: 70;
    width: 85vw !important;
    max-width: 320px;
    box-shadow: var(--shadow-lg);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    display: flex !important;
  }
  .left-panel.mobile-open {
    transform: translateX(0);
  }

  /* Right panel: BOTTOM SHEET */
  .right-panel {
    display: flex !important;
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    height: 45dvh;
    min-height: 200px;
    max-height: 85dvh;
    border-radius: 16px 16px 0 0;
    box-shadow: 0 -4px 24px rgba(0, 0, 0, 0.12);
    z-index: 60;
    padding-bottom: env(safe-area-inset-bottom, 0px);
    transform: translateY(100%);
    transition: transform 0.3s ease;
  }
  .right-panel.mobile-chat-open {
    transform: translateY(0);
  }

  /* Bottom sheet drag handle */
  .bottom-sheet-handle {
    display: flex !important;
  }

  /* Mobile chat FAB */
  .mobile-chat-fab {
    display: flex !important;
  }

  /* Adjust editor when chat is open */
  .workspace.chat-open .editor-content {
    padding-bottom: 60px;
  }

  /* Statusbar adjustments — respect Android gesture bar / iOS home indicator */
  .statusbar { bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  .statusbar-pill { padding: 6px 14px; }
  .statusbar-group { padding: 0 8px; }
  .workspace.chat-open .statusbar { bottom: calc(45dvh + 8px + env(safe-area-inset-bottom, 0px)); transition: bottom 0.3s ease; }

  /* FAB moves when chat open — and sits above system nav bar */
  .mobile-chat-fab { bottom: calc(24px + env(safe-area-inset-bottom, 0px)); }
  .workspace.chat-open .mobile-chat-fab { bottom: calc(45dvh + 12px + env(safe-area-inset-bottom, 0px)); transition: bottom 0.3s ease; }

  /* Editor content — less padding, + safe-area bottom so last chunk isn't hidden */
  .editor-content {
    padding: 16px 16px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    max-width: 100% !important;
  }

  /* Hide action button text on mobile */
  .topbar-actions .topbar-action-btn { padding: 6px !important; gap: 0 !important; }

  /* Welcome screen: safe-area bottom so project cards aren't clipped by nav bar */
  .project-container { padding-bottom: calc(20px + env(safe-area-inset-bottom, 0px)) !important; }

  /* Modal: use dvh so footer button isn't hidden by URL bar */
  .modal { max-height: 85dvh !important; }

  /* Modal footer on mobile: stack buttons, full width, primary on top (within reach) */
  .modal-footer {
    flex-direction: column-reverse !important;
    gap: 8px !important;
    padding: 12px 16px calc(16px + env(safe-area-inset-bottom, 0px)) !important;
  }
  .modal-footer .btn { width: 100%; justify-content: center; min-height: 44px; }

  /* Login card: scrollable if keyboard / URL bar squeeze it */
  .login-card { max-height: calc(100dvh - 32px); overflow-y: auto; }
}

/* ── Mobile toggle buttons ── */
.mobile-toggle { display: none; }
@media (max-width: 1023px) {
  .mobile-toggle { display: inline-flex !important; font-size: 18px; }
}

/* ── Bottom sheet handle (hidden on desktop) ── */
.bottom-sheet-handle {
  display: none;
  justify-content: center;
  padding: 8px 0 4px;
  cursor: grab;
  flex-shrink: 0;
  touch-action: none;
}
.handle-bar {
  width: 36px;
  height: 4px;
  background: var(--text-hint);
  border-radius: 2px;
  opacity: 0.5;
}

/* ── Mobile chat FAB (hidden on desktop) ── */
.mobile-chat-fab {
  display: none;
  position: fixed;
  bottom: 24px;
  right: 20px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent-blue);
  color: #fff;
  border: none;
  box-shadow: 0 4px 12px rgba(4, 151, 175, 0.35);
  cursor: pointer;
  z-index: 55;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, bottom 0.3s ease;
}
.mobile-chat-fab:active { transform: scale(0.9); }
.mobile-chat-fab .fab-badge {
  position: absolute;
  top: -2px; right: -2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--accent-red);
  border: 2px solid var(--bg-base);
}

/* ── Mobile backdrop ── */
.mobile-backdrop {
  display: none;
}

/* ── Small phone: < 425px ── */
@media (max-width: 424px) {
  .type-grid { grid-template-columns: 1fr !important; }
  .welcome-title { font-size: 14px; }
  .topbar { font-size: 12px; }
  .statusbar-label { display: none; }
  .right-panel { height: 50dvh; }
}

/* ── Remove old minimum width warning ── */
.screen-warning { display: none !important; }
