/* ==============================================
   SEED Billing System - Responsive
   スマホ・タブレット最適化
   ============================================== */

/* ---------- Tablet (〜1100px) ---------- */
@media screen and (max-width: 1100px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .form-row {
    grid-template-columns: repeat(2, 1fr);
  }

  .template-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* ==============================================
   Mobile (〜768px)
   サイドバーをオーバーレイ式に、メインを全幅へ
   ============================================== */
@media screen and (max-width: 768px) {
  :root {
    --topbar-h: 56px;
  }

  /* レイアウトをスマホ用に解除 */
  .app {
    display: block;
  }

  /* サイドバーを画面外に隠す(オーバーレイ式) */
  .sidebar {
    transform: translateX(-100%);
    width: 280px;
    box-shadow: var(--shadow-lg);
    z-index: 50;
    transition: transform 0.25s ease;
  }

  .sidebar.is-open {
    transform: translateX(0);
  }

  .sidebar-close {
    display: block;
  }

  /* メインを全幅にし、サイドバーが開いても圧縮しない */
  .main {
    margin-left: 0 !important;
    width: 100% !important;
    min-width: 0 !important;
    display: block !important;
  }

  .menu-btn {
    display: flex;
  }

  .topbar {
    padding: 0 12px;
    gap: 8px;
  }

  .page-title {
    font-size: 15px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .topbar-actions {
    gap: 6px;
  }

  .view-container {
    padding: 14px 12px;
  }

  .view-header h2 {
    font-size: 18px;
  }

  /* ダッシュボード:統計カード */
  .stats-grid {
    grid-template-columns: 1fr 1fr !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 14px;
    min-width: 0;
  }

  .stat-value {
    font-size: 20px;
    word-break: break-all;
  }

  .stat-label {
    font-size: 11px;
  }

  /* フォーム類は縦1列に */
  .form-grid,
  .form-row {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .template-grid {
    grid-template-columns: 1fr;
  }

  /* モーダル */
  .modal-overlay {
    padding: 8px;
    align-items: flex-start;
    padding-top: 16px;
  }

  .modal-dialog {
    max-height: calc(100vh - 32px);
    width: 100%;
    max-width: 100%;
  }

  .modal-head, .modal-foot {
    padding: 12px 14px;
  }

  .modal-head h3 {
    font-size: 15px;
  }

  .modal-body {
    padding: 14px;
  }

  /* プレビュー画面のアクションボタン */
  .preview-actions {
    flex-wrap: wrap;
    gap: 6px;
  }

  .preview-actions .btn { 
    padding: 6px 10px; 
    font-size: 12px; 
  }

  /* ツールバーは縦並びに */
  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .toolbar .btn-primary {
    margin-left: 0;
    width: 100%;
  }

  .search-input { 
    max-width: none; 
    width: 100%;
  }

  .filter-group {
    width: 100%;
    flex-wrap: wrap;
  }

  .filter-group select {
    flex: 1;
    min-width: 0;
  }

  .totals-box { 
    width: 100%; 
  }

  /* テーブルを横スクロール可能に */
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 0 -12px;
    padding: 0 12px;
  }

  .data-table {
    min-width: 600px;
  }

  .data-table thead th,
  .data-table tbody td {
    padding: 10px 12px;
    font-size: 12.5px;
    white-space: nowrap;
  }

  /* 税率行 */
  .tax-row {
    grid-template-columns: 1fr 1fr 1fr 36px;
    gap: 6px;
  }

  /* サイドバー開いた時の暗転オーバーレイ */
  body.sidebar-open::after {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(31, 28, 24, 0.5);
    z-index: 45;
    cursor: pointer;
  }

  /* 帳票エディタの明細編集セクション */
  .doc-editor-grid {
    grid-template-columns: 1fr;
    gap: 16px;
  }

  .doc-editor-side {
    position: static;
  }

  /* 商品/顧客カード */
  .card-grid {
    grid-template-columns: 1fr;
    gap: 10px;
  }

  /* ダッシュボードの最近の請求書テーブル */
  .recent-docs {
    margin: 0 -12px;
    border-radius: 0;
  }

  .recent-docs table {
    min-width: 500px;
  }

  /* フォーム要素のタッチ最適化 */
  input, select, textarea {
    font-size: 16px !important; /* iOS自動ズーム防止 */
  }

  .btn {
    min-height: 40px;
    padding: 8px 14px;
  }

  /* モーダル下部ボタン */
  .modal-foot {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* アクションメニュー */
  .row-actions {
    gap: 4px;
  }

  .row-actions .btn {
    padding: 4px 8px;
    font-size: 11.5px;
    min-height: 32px;
  }
}

/* ==============================================
   Small Mobile (〜480px)
   小型スマホ向け追加調整
   ============================================== */
@media screen and (max-width: 480px) {
  .view-container {
    padding: 12px 10px;
  }

  .view-header h2 {
    font-size: 17px;
  }

  /* 統計カードを1列に */
  .stats-grid {
    grid-template-columns: 1fr !important;
    gap: 10px !important;
  }

  .stat-card {
    padding: 16px;
  }

  .stat-value {
    font-size: 22px;
  }

  /* モーダルフッター縦並び */
  .modal-foot {
    flex-direction: column-reverse;
    gap: 8px;
  }

  .modal-foot .btn,
  .modal-foot .foot-right {
    width: 100%;
  }

  .modal-foot .foot-right {
    margin-left: 0;
    flex-direction: column;
    gap: 8px;
  }

  /* ボタングループ縦並び */
  .preview-actions .btn {
    flex: 1 1 calc(50% - 3px);
  }

  /* 税率設定行をコンパクトに */
  .tax-row {
    grid-template-columns: 1fr 1fr 80px 36px;
    gap: 4px;
  }

  .tax-row input {
    font-size: 14px !important;
    padding: 6px 8px;
  }
}

/* ==============================================
   Extra Small (〜360px)
   ============================================== */
@media screen and (max-width: 360px) {
  .topbar {
    padding: 0 10px;
  }

  .page-title {
    font-size: 14px;
  }

  .view-container {
    padding: 10px 8px;
  }

  .stat-value {
    font-size: 18px;
  }

  .data-table thead th,
  .data-table tbody td {
    padding: 8px 10px;
    font-size: 12px;
  }
}

/* ==============================================
   横向き (landscape) 対応
   ============================================== */
@media screen and (max-width: 900px) and (orientation: landscape) {
  .modal-dialog {
    max-height: calc(100vh - 16px);
  }

  .modal-overlay {
    padding-top: 8px;
  }
}

/* ==============================================
   タッチデバイス向けホバー無効化
   ============================================== */
@media (hover: none) {
  .btn:hover,
  .nav-item:hover,
  .stat-card:hover {
    transform: none;
  }
}
