/* ============================================
   レシート管理アプリ - スタイルシート
   スマホファースト・白基調+ブルーアクセント
   ============================================ */

/* --- CSS変数（テーマ設定） --- */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --success: #22c55e;
  --warning: #f59e0b;
  --text: #1e293b;
  --text-light: #64748b;
  --bg: #f8fafc;
  --white: #ffffff;
  --border: #e2e8f0;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 12px rgba(0, 0, 0, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --max-width: 480px;
  --header-height: 52px;
  --nav-height: 60px;
}

/* --- hidden 属性の強制適用 --- */
[hidden] {
  display: none !important;
}

/* --- リセット --- */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100dvh;
  padding-top: var(--header-height);
  padding-bottom: var(--nav-height);
  overflow-x: hidden;
}

/* --- ヘッダー --- */
.app-header {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--header-height);
  background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.app-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

/* --- タブナビゲーション（下部固定） --- */
.tab-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--nav-height);
  background: var(--white);
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom, 0);
}

.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 4px;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-light);
  transition: color 0.2s;
  -webkit-tap-highlight-color: transparent;
}

.tab-btn.active {
  color: var(--primary);
}

.tab-icon {
  font-size: 1.4rem;
}

.tab-label {
  font-size: 0.7rem;
  font-weight: 600;
}

/* --- タブコンテンツ --- */
.tab-content {
  display: none;
  animation: fadeIn 0.2s ease;
}

.tab-content.active {
  display: block;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* --- コンテナ --- */
.container {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 16px;
}

/* --- セクションタイトル --- */
.section-title {
  font-size: 1rem;
  font-weight: 700;
  margin-bottom: 12px;
  color: var(--text);
}

/* --- アップロードエリア --- */
.upload-area {
  margin-bottom: 16px;
}

.upload-buttons {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.upload-btn {
  width: 100%;
  padding: 24px 12px;
  background: var(--primary-light);
  border: 2px dashed var(--primary);
  border-radius: var(--radius);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.upload-btn:active {
  transform: scale(0.98);
  background: #dbeafe;
}

.upload-btn-icon {
  font-size: 2rem;
}

.upload-btn-text {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--primary);
}

/* --- 画像プレビュー --- */
.preview-area {
  margin-bottom: 16px;
}

.preview-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.preview-item {
  position: relative;
  aspect-ratio: 1;
  border-radius: var(--radius-sm);
  overflow: hidden;
  border: 1px solid var(--border);
}

.preview-item img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-item .remove-btn {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  border: none;
  font-size: 0.7rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.preview-actions {
  display: flex;
  gap: 8px;
}

/* --- ボタン共通 --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}

.btn:active {
  transform: scale(0.97);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

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

.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
}

.btn-secondary {
  background: var(--white);
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg);
}

.btn-danger {
  background: none;
  color: var(--danger);
  border: 1px solid var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: #fef2f2;
}

.btn-large {
  width: 100%;
  padding: 16px;
  font-size: 1.05rem;
  border-radius: var(--radius);
}

.btn-icon {
  font-size: 1.1em;
}

/* --- ローディング --- */
.loading {
  text-align: center;
  padding: 40px 20px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top: 3px solid var(--primary);
  border-radius: 50%;
  margin: 0 auto 16px;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.loading-sub {
  font-size: 0.85rem;
  color: var(--text-light);
}

/* --- 解析結果エリア --- */
.result-area {
  margin-top: 16px;
}

.result-card {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
  box-shadow: var(--shadow);
}

.result-type {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
  margin-bottom: 12px;
}

.result-field {
  margin-bottom: 12px;
}

.result-field label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-light);
  margin-bottom: 4px;
}

.result-field input,
.result-field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--bg);
  transition: border-color 0.2s;
}

.result-field input:focus,
.result-field textarea:focus {
  outline: none;
  border-color: var(--primary);
  background: var(--white);
}

.result-field textarea {
  resize: vertical;
  min-height: 60px;
}

.result-items-table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 0.85rem;
}

.result-items-table th {
  background: var(--bg);
  padding: 8px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
}

.result-items-table td {
  padding: 8px;
  border-bottom: 1px solid var(--border);
}

.result-items-table input {
  width: 100%;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 0.85rem;
  font-family: inherit;
}

.result-items-table input:focus {
  outline: none;
  border-color: var(--primary);
}

.result-actions {
  display: flex;
  gap: 8px;
}

.result-actions .btn-primary {
  flex: 1;
}

/* --- 履歴 --- */
.history-note {
  font-size: 0.8rem;
  color: var(--text-light);
  margin-bottom: 12px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-item {
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}

.history-item-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.history-item-type {
  font-size: 0.75rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  background: var(--primary-light);
  color: var(--primary);
}

.history-item-date {
  font-size: 0.75rem;
  color: var(--text-light);
}

.history-item-summary {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 4px;
}

.history-item-amount {
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
}

.history-item-status {
  font-size: 0.75rem;
  margin-top: 8px;
  padding: 4px 8px;
  border-radius: 4px;
  display: inline-block;
}

.history-item-status.sent {
  background: #f0fdf4;
  color: #16a34a;
}

.history-item-status.pending {
  background: #fffbeb;
  color: #d97706;
}

.history-item-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.history-item-actions .btn {
  padding: 8px 12px;
  font-size: 0.8rem;
}

/* --- 空状態 --- */
.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--text-light);
}

.empty-icon {
  font-size: 3rem;
  display: block;
  margin-bottom: 8px;
}

/* --- 設定フォーム --- */
.settings-form {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

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

.form-label {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text);
}

.form-hint {
  display: block;
  font-size: 0.75rem;
  font-weight: 400;
  color: var(--text-light);
  margin-top: 2px;
}

.input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.form-input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: var(--white);
  transition: border-color 0.2s;
}

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

.input-wrapper .form-input {
  padding-right: 44px;
}

.toggle-visibility {
  position: absolute;
  right: 4px;
  background: none;
  border: none;
  padding: 8px;
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.6;
  -webkit-tap-highlight-color: transparent;
}

.toggle-visibility:hover {
  opacity: 1;
}

.form-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

.settings-info {
  margin-top: 24px;
  padding: 16px;
  background: var(--primary-light);
  border-radius: var(--radius);
  font-size: 0.85rem;
  color: var(--text-light);
  line-height: 1.7;
}

.settings-info h3 {
  font-size: 0.9rem;
  color: var(--text);
  margin-bottom: 8px;
}

.settings-info p + p {
  margin-top: 6px;
}

/* --- トースト通知 --- */
.toast-container {
  position: fixed;
  top: calc(var(--header-height) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: calc(100% - 32px);
  max-width: var(--max-width);
  pointer-events: none;
}

.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.9rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: slideDown 0.3s ease, fadeOut 0.3s ease 2.7s;
  pointer-events: auto;
}

.toast.success {
  background: #f0fdf4;
  color: #16a34a;
  border: 1px solid #bbf7d0;
}

.toast.error {
  background: #fef2f2;
  color: #dc2626;
  border: 1px solid #fecaca;
}

.toast.info {
  background: var(--primary-light);
  color: var(--primary);
  border: 1px solid #bfdbfe;
}

@keyframes slideDown {
  from { transform: translateY(-20px); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

@keyframes fadeOut {
  from { opacity: 1; }
  to { opacity: 0; }
}

/* --- モーダル --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 300;
  padding: 20px;
}

.modal {
  background: var(--white);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 320px;
  width: 100%;
  box-shadow: var(--shadow-lg);
}

.modal-message {
  font-size: 0.95rem;
  margin-bottom: 20px;
  line-height: 1.6;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

/* --- 撮影のコツガイド（折りたたみ） --- */
.shooting-tips {
  background: #f0f9ff;
  border: 1px solid #bae6fd;
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-top: 14px;
  margin-bottom: 4px;
  font-size: 0.88rem;
  color: #0c4a6e;
}

.shooting-tips__summary {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-weight: 600;
  list-style: none;
  user-select: none;
  outline: none;
}

/* ブラウザ標準の三角マーカーを消す（Chromeなど） */
.shooting-tips__summary::-webkit-details-marker {
  display: none;
}

/* カスタム開閉マーカー（右側に配置） */
.shooting-tips__summary::after {
  content: '▼';
  margin-left: auto;
  font-size: 0.75rem;
  transition: transform 0.2s;
  color: #0284c7;
}

/* 開いた時にマーカーを回転 */
.shooting-tips[open] .shooting-tips__summary::after {
  transform: rotate(180deg);
}

.shooting-tips__icon {
  font-size: 1.15rem;
  flex-shrink: 0;
}

.shooting-tips__title {
  flex: 1;
}

.shooting-tips__list {
  margin-top: 10px;
  margin-left: 0;
  padding-left: 20px;
  line-height: 1.7;
}

.shooting-tips__list li {
  margin-bottom: 4px;
}

.shooting-tips__list strong {
  color: #0369a1;
}

/* --- セットアップ促進バナー --- */
.setup-banner {
  background: #fffbeb;
  border: 1px solid #fde68a;
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.85rem;
  color: #92400e;
}

.setup-banner-icon {
  font-size: 1.3rem;
  flex-shrink: 0;
}

.setup-banner a {
  color: var(--primary);
  font-weight: 600;
  text-decoration: none;
}

/* --- レスポンシブ（PC向け微調整） --- */
@media (min-width: 600px) {
  :root {
    --max-width: 520px;
  }

  .container {
    padding: 24px;
  }

  .upload-btn {
    padding: 40px 24px;
  }

  .preview-grid {
    grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  }
}
