/* =============================================================================
 * app.css — 電気工事 追加工事管理ツール 共通デザインシステム（T-07）
 *
 * モバイルファースト / 現場の職人がスマホで迷わず使えることを最優先。
 * 手袋でも押せる 44px 以上のタップ領域・大きめボタン・明快なラベル。
 * 他チケットのHTML(site.php, admin/sites.php, report.php, work_form.js)が
 * このクラスを流用できるよう命名を統一（詳細は docs/FRONTEND_CONTRACT.md 末尾）。
 * ========================================================================== */

/* ---------------------------------------------------------------------------
 * 1. デザイントークン（CSS変数）
 * ------------------------------------------------------------------------- */
:root {
  /* 色: プライマリ=cunimi オレンジ / 警告=赤 / 完了=緑（R5 デザイン適用） */
  --color-primary: #f5820a;
  --color-primary-dark: #d96e00;
  --color-primary-light: #fff4e6;
  --color-danger: #ff3b30;
  --color-danger-dark: #d92c22;
  --color-success: #34c759;
  --color-success-dark: #28a648;
  --color-warning: #f5820a;

  /* ピン色（API_CONTRACT: in_progress=赤 / completed=緑） */
  --pin-in-progress: #ff3b30;
  --pin-completed: #34c759;

  /* 中立色（クリーム背景＋白カード） */
  --color-bg: #fffdf5;
  --color-surface: #ffffff;
  --color-border: #d2d2d7;
  --color-text: #1d1d1f;
  --color-text-muted: #6e6e73;
  --color-text-inverse: #ffffff;

  /* 余白（8pxグリッド） */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-8: 48px;

  /* フォント（R5: 見出し=Nunito / 本文=Noto Sans JP、system-ui フォールバック） */
  --font-family: "Noto Sans JP", "Nunito", system-ui, -apple-system, "Segoe UI",
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  --font-heading: "Nunito", "Noto Sans JP", system-ui, -apple-system, sans-serif;
  --font-size-sm: 0.875rem;   /* 14px */
  --font-size-base: 1rem;     /* 16px（iOS拡大防止のため入力は16px以上） */
  --font-size-lg: 1.125rem;   /* 18px */
  --font-size-xl: 1.375rem;   /* 22px */
  --font-size-2xl: 1.75rem;   /* 28px */

  /* 角丸・影 */
  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.08);
  --shadow: 0 2px 8px rgba(15, 23, 42, 0.12);
  --shadow-lg: 0 8px 24px rgba(15, 23, 42, 0.18);

  /* タップ領域最小 */
  --tap-min: 44px;

  /* レイアウト */
  --header-height: 56px;
  --container-max: 960px;
}

/* ---------------------------------------------------------------------------
 * 2. リセット / ベース
 * ------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  font-family: var(--font-family);
  font-size: var(--font-size-base);
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 {
  margin: 0 0 var(--space-3);
  line-height: 1.3;
  font-family: var(--font-heading);
  font-weight: 800;
  letter-spacing: -0.2px;
}

h1 { font-size: var(--font-size-2xl); }
h2 { font-size: var(--font-size-xl); }
h3 { font-size: var(--font-size-lg); }

a {
  color: var(--color-primary);
  text-decoration: none;
}
a:hover { text-decoration: underline; }

img { max-width: 100%; height: auto; }

/* ---------------------------------------------------------------------------
 * 3. レイアウト（共通ヘッダ / コンテナ）
 * ------------------------------------------------------------------------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  gap: var(--space-3);
  height: var(--header-height);
  padding: 0 var(--space-4);
  /* R5: 白系ヘッダ＋下ボーダーの清潔な見た目（ダークバー廃止） */
  background: var(--color-surface);
  color: var(--color-text);
  border-bottom: 1px solid var(--border-light, #e8e8ed);
  box-shadow: var(--shadow-sm);
}

.app-header__title {
  font-family: var(--font-heading);
  font-size: var(--font-size-lg);
  font-weight: 800;
  letter-spacing: -0.2px;
  margin: 0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.app-header__spacer { flex: 1; }

.app-header__user {
  font-size: var(--font-size-sm);
  color: var(--color-text-muted);
  max-width: 40vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-main {
  max-width: var(--container-max);
  margin: 0 auto;
  padding: var(--space-4);
}

.stack > * + * { margin-top: var(--space-4); }

.grid-cards {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

/* ---------------------------------------------------------------------------
 * 4. ボタン（大きめ・手袋でも押せる）
 * ------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: var(--space-3) var(--space-5);
  font-size: var(--font-size-base);
  font-weight: 800;
  font-family: var(--font-heading);
  line-height: 1.2;
  color: var(--color-text-inverse);
  background: var(--color-primary);
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background-color 0.15s, opacity 0.15s;
  text-align: center;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: var(--color-primary-dark); text-decoration: none; }
.btn:active { opacity: 0.85; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn--block { width: 100%; }
.btn--lg { min-height: 56px; font-size: var(--font-size-lg); }

.btn--secondary {
  color: var(--color-primary);
  background: var(--color-surface);
  border: 2px solid var(--color-primary);
}
.btn--secondary:hover { background: var(--color-primary-light); }

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

.btn--success { background: var(--color-success); }
.btn--success:hover { background: var(--color-success-dark); }

.btn--ghost {
  /* R5: 白系ヘッダ上に置くため、暗色テキスト＋控えめな境界線に */
  color: var(--color-text);
  background: transparent;
  border: 1px solid var(--color-border);
  min-height: var(--tap-min);
  padding: var(--space-2) var(--space-4);
}
.btn--ghost:hover { background: var(--bg-alt, #f5f5f7); }

/* ---------------------------------------------------------------------------
 * 5. フォーム（縦積み）
 * ------------------------------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: var(--space-4); }

.field { display: flex; flex-direction: column; gap: var(--space-2); }

.field__label {
  font-size: var(--font-size-sm);
  font-weight: 600;
  color: var(--color-text);
}

.field__hint { font-size: var(--font-size-sm); color: var(--color-text-muted); }

.input,
.textarea,
.select {
  width: 100%;
  min-height: var(--tap-min);
  padding: var(--space-3);
  font-size: var(--font-size-base); /* 16px: iOSズーム防止 */
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
}
.textarea { min-height: 96px; resize: vertical; }
.input:focus,
.textarea:focus,
.select:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px var(--color-primary-light);
}
.input--error { border-color: var(--color-danger); }

.field__error {
  font-size: var(--font-size-sm);
  color: var(--color-danger);
  font-weight: 600;
}

/* ---------------------------------------------------------------------------
 * 6. カード
 * ------------------------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  padding: var(--space-4);
}

.card--link { display: block; color: inherit; transition: box-shadow 0.15s, transform 0.1s; }
.card--link:hover { box-shadow: var(--shadow); text-decoration: none; transform: translateY(-1px); }
.card--link:active { transform: translateY(0); }

.card__title { font-size: var(--font-size-lg); margin-bottom: var(--space-2); }
.card__body { color: var(--color-text-muted); }

/* ---------------------------------------------------------------------------
 * 7. バッジ / ステータス / ピン凡例
 * ------------------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 2px var(--space-2);
  font-size: var(--font-size-sm);
  font-weight: 700;
  border-radius: 999px;
  line-height: 1.4;
}
.badge--in-progress { color: #fff; background: var(--pin-in-progress); }
.badge--completed { color: #fff; background: var(--pin-completed); }
.badge--neutral { color: var(--color-text); background: var(--color-bg); }

/* ピン凡例（マップ画面・報告書で共通利用） */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-4);
  align-items: center;
  padding: var(--space-3) var(--space-4);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
}
.legend__item { display: inline-flex; align-items: center; gap: var(--space-2); font-size: var(--font-size-sm); font-weight: 600; }
.legend__dot { width: 16px; height: 16px; border-radius: 50%; border: 2px solid rgba(0, 0, 0, 0.15); flex: none; }
.legend__dot--in-progress { background: var(--pin-in-progress); }
.legend__dot--completed { background: var(--pin-completed); }

/* マップピン共通スタイル（map.js が .map-pin / 状態クラスを流用） */
.map-pin {
  width: 28px;
  height: 28px;
  border-radius: 50% 50% 50% 0;
  transform: rotate(-45deg);
  border: 3px solid #fff;
  box-shadow: var(--shadow);
  cursor: pointer;
}
.map-pin--in-progress { background: var(--pin-in-progress); }
.map-pin--completed { background: var(--pin-completed); }

/* ---------------------------------------------------------------------------
 * 8. モーダル（work_form.js が流用）
 * ------------------------------------------------------------------------- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 0;
  background: rgba(15, 23, 42, 0.55);
}
.modal-backdrop[hidden] { display: none; }

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 92vh;
  overflow-y: auto;
  background: var(--color-surface);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  padding: var(--space-5) var(--space-4) calc(var(--space-5) + env(safe-area-inset-bottom));
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}
.modal__title { margin: 0; font-size: var(--font-size-xl); }
.modal__close {
  min-width: var(--tap-min);
  min-height: var(--tap-min);
  font-size: var(--font-size-xl);
  line-height: 1;
  color: var(--color-text-muted);
  background: transparent;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.modal__close:hover { background: var(--color-bg); }
.modal__footer { display: flex; gap: var(--space-3); margin-top: var(--space-5); }
.modal__footer .btn { flex: 1; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: var(--space-4); }
  .modal { border-radius: var(--radius-lg); }
}

/* ---------------------------------------------------------------------------
 * 9. トースト通知（app.js の window.Toast が生成）
 * ------------------------------------------------------------------------- */
.toast-container {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  width: calc(100% - var(--space-8));
  max-width: 420px;
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  color: #fff;
  font-weight: 600;
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.2s ease-out;
  pointer-events: auto;
}
.toast--info { background: var(--color-primary); }
.toast--success { background: var(--color-success); }
.toast--error { background: var(--color-danger); }
.toast--warning { background: var(--color-warning); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ---------------------------------------------------------------------------
 * 10. ローディング（app.js の window.Loading が制御）
 * ------------------------------------------------------------------------- */
.loading-overlay {
  position: fixed;
  inset: 0;
  z-index: 1500;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.6);
}
.loading-overlay[hidden] { display: none; }
.spinner {
  width: 40px;
  height: 40px;
  border: 4px solid var(--color-primary-light);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------------------------------------------------------------------
 * 11. 認証画面（ログイン）
 * ------------------------------------------------------------------------- */
.auth-screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-5);
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: var(--space-6) var(--space-5);
}
.auth-card__brand {
  text-align: center;
  margin-bottom: var(--space-5);
}
.auth-card__logo {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-3);
  font-family: var(--font-heading);
  font-size: 30px;
  font-weight: 900;
  color: #fff;
  background: var(--color-primary);
  border-radius: 18px;
  box-shadow: 0 6px 16px rgba(245, 130, 10, 0.35);
}
.auth-card__title {
  font-family: var(--font-heading);
  font-weight: 800;
  font-size: var(--font-size-xl);
  letter-spacing: -0.3px;
  margin: 0;
}
.auth-card__sub { font-size: var(--font-size-sm); color: var(--color-text-muted); margin: var(--space-1) 0 0; }

/* ---------------------------------------------------------------------------
 * 12. ユーティリティ
 * ------------------------------------------------------------------------- */
.text-muted { color: var(--color-text-muted); }
.text-center { text-align: center; }
.mt-0 { margin-top: 0; }
.mt-4 { margin-top: var(--space-4); }
.hidden { display: none !important; }
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}
.empty-state {
  text-align: center;
  color: var(--color-text-muted);
  padding: var(--space-6) var(--space-4);
}

/* ===========================================================================
 * R11: 削除依頼（管理者ダッシュボード）
 * ========================================================================= */
.btn--sm { min-height: 40px; padding: var(--space-2) var(--space-4); font-size: var(--font-size-sm); }

.delreq-badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 22px; height: 22px; padding: 0 7px; margin-left: 6px;
  font-size: 12px; font-weight: 800; color: #fff; background: #8e44ad; border-radius: 999px;
  vertical-align: middle;
}
.delreq-card { border-left: 4px solid #8e44ad; display: flex; flex-direction: column; gap: 6px; }
.delreq-card__top { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.delreq-card__no { font-weight: 800; font-size: var(--font-size-base); color: #7b2fa5; }
.delreq-card__site { font-size: var(--font-size-sm); color: var(--color-text-muted); }
.delreq-card__meta { margin: 0; font-size: var(--font-size-sm); color: var(--color-text-muted); }
.delreq-card__reason { margin: 0; font-size: var(--font-size-base); color: var(--color-text); white-space: pre-wrap; word-break: break-word; }
.delreq-card .btn--sm { align-self: flex-start; }
