/* ========== リセット・基本設定 ========== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --success: #16a34a;
  --warning: #f59e0b;
  --gray-50: #f9fafb;
  --gray-100: #f3f4f6;
  --gray-200: #e5e7eb;
  --gray-300: #d1d5db;
  --gray-400: #9ca3af;
  --gray-500: #6b7280;
  --gray-600: #4b5563;
  --gray-700: #374151;
  --gray-800: #1f2937;
  --gray-900: #111827;
  --sidebar-width: 220px;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.1), 0 1px 2px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 6px rgba(0,0,0,0.1), 0 2px 4px rgba(0,0,0,0.06);
}

body {
  font-family: 'Segoe UI', 'Meiryo', 'Hiragino Kaku Gothic ProN', sans-serif;
  background: var(--gray-50);
  color: var(--gray-800);
  display: flex;
  min-height: 100vh;
}

/* ========== サイドバー ========== */
.sidebar {
  width: var(--sidebar-width);
  background: var(--gray-900);
  color: white;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  padding: 20px;
  border-bottom: 1px solid var(--gray-700);
}

.sidebar-header h1 {
  font-size: 16px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.nav-menu {
  list-style: none;
  padding: 8px 0;
}

.nav-link {
  display: flex;
  align-items: center;
  padding: 12px 20px;
  color: var(--gray-300);
  text-decoration: none;
  font-size: 14px;
  transition: all 0.15s;
  gap: 10px;
}

.nav-link:hover {
  background: var(--gray-700);
  color: white;
}

.nav-link.active {
  background: var(--primary);
  color: white;
}

.nav-icon {
  font-size: 16px;
  width: 20px;
  text-align: center;
}

/* ========== サイドバーフッター（ユーザー情報） ========== */
.sidebar-footer {
  margin-top: auto;
  padding: 12px 16px;
  border-top: 1px solid var(--gray-700);
}

.user-info {
  margin-bottom: 8px;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: white;
}

.user-dept {
  font-size: 11px;
  color: var(--gray-400);
}

.user-actions {
  display: flex;
  gap: 12px;
}

.user-link {
  font-size: 11px;
  color: var(--gray-400);
  text-decoration: none;
}

.user-link:hover {
  color: white;
}

/* ========== ログイン画面 ========== */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--gray-100);
}

.login-card {
  background: white;
  padding: 40px;
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  width: 100%;
  max-width: 400px;
}

.login-card h2 {
  text-align: center;
  font-size: 20px;
  margin-bottom: 4px;
}

/* ========== テストモード切替 ========== */
.test-mode-bar {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 6px 14px;
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: var(--radius);
}

.test-mode-label {
  font-size: 12px;
  font-weight: 700;
  color: #92400e;
}

/* ========== メインコンテンツ ========== */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  padding: 24px 32px;
  min-height: 100vh;
}

/* ========== ページヘッダー ========== */
.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.page-header h2 {
  font-size: 22px;
  font-weight: 700;
  color: var(--gray-900);
}

.page-header-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

/* ========== ボタン ========== */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
}
.btn-primary:hover {
  background: var(--primary-hover);
}

.btn-secondary {
  background: white;
  color: var(--gray-700);
  border: 1px solid var(--gray-300);
}
.btn-secondary:hover {
  background: var(--gray-50);
}

.btn-danger {
  background: var(--danger);
  color: white;
}
.btn-danger:hover {
  background: var(--danger-hover);
}

.btn-success {
  background: var(--success);
  color: white;
}
.btn-success:hover {
  background: #15803d;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
}

.btn-icon {
  padding: 6px 10px;
  background: transparent;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  cursor: pointer;
  color: var(--gray-500);
  transition: all 0.15s;
}

.btn-icon:hover {
  background: var(--gray-100);
  color: var(--gray-700);
}

/* ========== 検索・フィルター ========== */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.search-input {
  flex: 1;
  max-width: 350px;
  padding: 8px 14px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}

.search-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.filter-select {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: var(--radius);
  font-size: 13px;
  background: white;
  outline: none;
  cursor: pointer;
}

/* ========== テーブル ========== */
.table-container {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--gray-50);
}

th {
  padding: 10px 14px;
  text-align: left;
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--gray-200);
  white-space: nowrap;
}

td {
  padding: 10px 14px;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
  vertical-align: middle;
}

tr:hover {
  background: var(--gray-50);
}

tr.clickable {
  cursor: pointer;
}

/* ========== ステータスバッジ ========== */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 600;
}

.badge-draft {
  background: var(--gray-100);
  color: var(--gray-600);
}

.badge-confirmed {
  background: #dbeafe;
  color: #1e40af;
}

.badge-sent {
  background: #dcfce7;
  color: #166534;
}

.badge-accepted {
  background: #fef3c7;
  color: #92400e;
}

.badge-rejected {
  background: #fee2e2;
  color: #991b1b;
}

/* ========== カード ========== */
.card {
  background: white;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--gray-200);
}

.card-header h3 {
  font-size: 15px;
  font-weight: 600;
  color: var(--gray-800);
}

/* ========== フォーム ========== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

.form-grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.form-group.full-width {
  grid-column: 1 / -1;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--gray-600);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: 8px 12px;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.form-group textarea {
  min-height: 80px;
  resize: vertical;
}

.form-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--gray-200);
}

/* ========== 見積書詳細 ========== */
.estimate-header-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

/* ロック付きフィールド */
.readonly-field {
  background: var(--gray-100) !important;
  color: var(--gray-600);
  cursor: default;
}

.inline-edit-btn {
  font-size: 11px;
  color: var(--primary);
  cursor: pointer;
  margin-left: 6px;
  font-weight: 400;
  padding: 1px 6px;
  border: 1px solid var(--primary);
  border-radius: 4px;
  user-select: none;
}

.inline-edit-btn:hover {
  background: var(--primary);
  color: white;
}

.inline-edit-btn.editing {
  background: var(--success);
  border-color: var(--success);
  color: white;
}

.inline-edit-btn.editing:hover {
  background: #15803d;
  border-color: #15803d;
}

/* 定型文テンプレート */
.note-template-list {
  max-height: 400px;
  overflow-y: auto;
}

.note-template-group {
  margin-bottom: 16px;
}

.note-template-category {
  font-size: 12px;
  font-weight: 700;
  color: var(--gray-500);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  padding-bottom: 4px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--gray-200);
}

.note-template-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13px;
  transition: background 0.1s;
}

.note-template-item:hover {
  background: var(--gray-50);
}

.note-template-item input[type="checkbox"] {
  margin-top: 2px;
  flex-shrink: 0;
}

.estimate-header-bar .left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.estimate-header-bar .right {
  display: flex;
  gap: 8px;
}

.estimate-number {
  font-size: 14px;
  color: var(--gray-500);
  font-weight: 500;
}

/* 明細テーブル */
.items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 10px;
}

.items-table th {
  background: var(--gray-100);
  padding: 8px 10px;
  font-size: 12px;
  border: 1px solid var(--gray-200);
}

.items-table td {
  padding: 4px 6px;
  border: 1px solid var(--gray-200);
}

.items-table input,
.items-table select {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 13px;
  background: transparent;
  outline: none;
}

.items-table input:focus,
.items-table select:focus {
  border-color: var(--primary);
  background: white;
}

.items-table .col-no { width: 40px; text-align: center; }
.items-table .col-name { }
.items-table .col-qty { width: 70px; }
.items-table .col-unit { width: 60px; }
.items-table .col-price { width: 110px; }
.items-table .col-amount { width: 110px; }
.items-table .col-actions { width: 40px; }

.items-total {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

.items-total table {
  width: 280px;
}

.items-total td {
  padding: 6px 12px;
  font-size: 13px;
  border: none;
}

.items-total .label {
  text-align: right;
  font-weight: 600;
  color: var(--gray-600);
}

.items-total .value {
  text-align: right;
  font-weight: 600;
}

.items-total .total-row td {
  font-size: 16px;
  color: var(--primary);
  border-top: 2px solid var(--gray-300);
  padding-top: 10px;
}

/* 商品検索ドロップダウン */
.product-search-dropdown {
  position: fixed;
  background: white;
  border: 1px solid var(--gray-300);
  border-radius: 6px;
  box-shadow: var(--shadow-md);
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  min-width: 300px;
}

.product-search-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--gray-100);
}

.product-search-item:hover {
  background: var(--primary-light);
}

.product-search-item .sku {
  color: var(--gray-400);
  font-size: 11px;
  margin-right: 8px;
}

/* ========== モーダル ========== */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}

.hidden {
  display: none !important;
}

.modal-overlay.hidden {
  display: none;
}

.modal {
  background: white;
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  width: 90%;
  max-width: 900px;
  max-height: 85vh;
  overflow-y: auto;
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 24px;
  border-bottom: 1px solid var(--gray-200);
}

.modal-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  color: var(--gray-400);
  padding: 0 4px;
}

.modal-close:hover {
  color: var(--gray-700);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 16px 24px;
  border-top: 1px solid var(--gray-200);
}

.confirm-modal {
  max-width: 400px;
}

.confirm-modal p {
  font-size: 14px;
  text-align: center;
  margin: 10px 0;
}

/* ========== メール送信モーダル（ワイド） ========== */
.modal-wide {
  max-width: 1400px;
  width: 95%;
}

.email-send-layout {
  display: flex;
  gap: 24px;
  height: 70vh;
}

.email-send-form {
  flex: 2;
  min-width: 0;
  overflow-y: auto;
}

.email-send-preview {
  flex: 3;
  min-width: 0;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--gray-200);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-header {
  padding: 8px 12px;
  background: var(--gray-50);
  border-bottom: 1px solid var(--gray-200);
}

.preview-header h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--gray-600);
  margin: 0;
}

.pdf-preview-wrapper {
  flex: 1;
  overflow: hidden;
}

.pdf-preview-frame {
  width: 100%;
  height: 100%;
  border: none;
}

@media (max-width: 900px) {
  .email-send-layout {
    flex-direction: column;
  }
  .pdf-preview-frame {
    min-height: 300px;
  }
}

/* ========== トースト通知 ========== */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius);
  color: white;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: slideIn 0.3s ease;
  min-width: 200px;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: var(--primary); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ========== 会社メモプレビュー ========== */
.company-memo-preview {
  margin-top: 4px;
  padding: 4px 8px;
  background: #fffbeb;
  border-left: 3px solid var(--warning);
  border-radius: 0 4px 4px 0;
  font-size: 11px;
  color: var(--gray-600);
  line-height: 1.5;
  white-space: pre-wrap;
  max-height: 60px;
  overflow: hidden;
}

/* ========== 最小数量ハイライト ========== */
.min-qty-highlight {
  display: inline-block;
  background: #fef3c7;
  color: #92400e;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
}

/* ========== 商品詳細モーダル ========== */
.detail-table {
  width: 100%;
  border-collapse: collapse;
}

.detail-table td {
  padding: 6px 0;
  font-size: 13px;
  border: none;
}

.detail-label {
  width: 120px;
  color: var(--gray-500);
  font-weight: 600;
  font-size: 12px;
}

.detail-value {
  color: var(--gray-800);
}

.detail-divider td {
  padding: 4px 0;
  border-bottom: 1px solid var(--gray-200);
}

.detail-description {
  padding: 10px 14px;
  background: var(--gray-50);
  border-radius: 6px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--gray-700);
}

/* ========== 商品画像 ========== */
.image-upload-area {
  padding: 24px;
  background: var(--gray-50);
  border: 2px dashed var(--gray-300);
  border-radius: 8px;
  text-align: center;
  cursor: pointer;
  color: var(--gray-400);
  font-size: 13px;
  transition: border-color 0.15s;
}

.image-upload-area:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.image-preview {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.image-preview img {
  max-width: 200px;
  max-height: 150px;
  border-radius: 6px;
  border: 1px solid var(--gray-200);
  object-fit: contain;
}

.detail-product-image {
  max-width: 300px;
  max-height: 200px;
  border-radius: 8px;
  border: 1px solid var(--gray-200);
  object-fit: contain;
}

/* ========== セット商品プレビュー ========== */
.set-contents-preview {
  margin-top: 3px;
  font-size: 11px;
  color: var(--gray-500);
  padding-left: 8px;
  border-left: 2px solid var(--primary);
}

/* ========== 空状態 ========== */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: var(--gray-400);
}

.empty-state .icon {
  font-size: 48px;
  margin-bottom: 12px;
}

.empty-state p {
  font-size: 14px;
}

/* ========== テキスト補助 ========== */
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-muted { color: var(--gray-400); }
.text-sm { font-size: 12px; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.gap-2 { gap: 8px; }
.flex { display: flex; }
.items-center { align-items: center; }

/* ========== 金額表示 ========== */
.amount-display {
  font-size: 20px;
  font-weight: 700;
  color: var(--gray-900);
}

/* ========== レスポンシブ ========== */
@media (max-width: 768px) {
  .sidebar {
    width: 60px;
  }
  .sidebar-header h1,
  .nav-link span:not(.nav-icon) {
    display: none;
  }
  .nav-link {
    justify-content: center;
    padding: 14px;
  }
  .main-content {
    margin-left: 60px;
    padding: 16px;
  }
  .form-grid {
    grid-template-columns: 1fr;
  }
}
