/* ========================================
   消防設備点検管理システム - 共通スタイル
   ======================================== */

/* CSS Variables - ダークモード（デフォルト） */
:root {
  /* プライマリカラー（ダークモード用 - 落ち着いた青灰色） */
  --primary-color: #546e7a;
  --primary-dark: #37474f;
  --primary-light: #78909c;
  --secondary-color: #757575;

  /* ダークモードカラー */
  --background-color: #121212;
  --surface-color: #1e1e1e;
  --surface-elevated: #2d2d2d;
  --text-primary: #f0f0f0;
  --text-secondary: #c0c0c0;
  --border-color: #333333;

  /* ステータスカラー */
  --success-color: #66bb6a;
  --warning-color: #ffb74d;
  --error-color: #ef5350;

  /* シャドウ */
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.4);

  /* 入力フィールド */
  --input-background: #2d2d2d;
  --input-border: #404040;
  --input-focus-shadow: rgba(84, 110, 122, 0.3);
}

/* ライトモード */
[data-theme="light"] {
  /* プライマリカラー */
  --primary-color: #d32f2f;
  --primary-dark: #b71c1c;
  --primary-light: #ff6659;
  --secondary-color: #424242;

  /* ライトモードカラー */
  --background-color: #f5f5f5;
  --surface-color: #ffffff;
  --surface-elevated: #ffffff;
  --text-primary: #212121;
  --text-secondary: #757575;
  --border-color: #e0e0e0;

  /* ステータスカラー */
  --success-color: #4caf50;
  --warning-color: #ff9800;
  --error-color: #f44336;

  /* シャドウ */
  --shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  --shadow-lg: 0 4px 8px rgba(0, 0, 0, 0.15);

  /* 入力フィールド */
  --input-background: #ffffff;
  --input-border: #e0e0e0;
  --input-focus-shadow: rgba(211, 47, 47, 0.1);
}

/* Reset */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

/* Base */
html {
  font-size: 16px;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  /* ダブルタップ拡大を無効化（ピンチ/入力時拡大はviewportで抑止） */
  touch-action: manipulation;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans',
               'Hiragino Kaku Gothic ProN', 'Meiryo', sans-serif;
  background-color: var(--background-color);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  padding-bottom: 60px;
}

/* Header */
.header {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  background-color: var(--primary-color);
  color: #fff;
  box-shadow: var(--shadow);
}

.header-title {
  font-size: 1.125rem;
  font-weight: 600;
}

/* Sync Status */
.sync-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
}

.status-icon {
  font-size: 0.625rem;
}

.status-icon.synced { color: var(--success-color); }
.status-icon.syncing { color: #64b5f6; }
.status-icon.offline { color: var(--text-secondary); }
.status-icon.conflict { color: var(--error-color); }

/* Main Content */
.main-content {
  padding: 16px;
  max-width: 600px;
  margin: 0 auto;
}

/* Section */
section {
  margin-bottom: 24px;
}

section h2 {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border-color);
}

/* Buildings List */
.buildings-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.building-card {
  display: block;
  background-color: var(--surface-color);
  border-radius: 8px;
  padding: 16px;
  box-shadow: var(--shadow);
  text-decoration: none;
  color: inherit;
  transition: box-shadow 0.2s, transform 0.2s;
}

.building-card:hover,
.building-card:focus {
  box-shadow: var(--shadow-lg);
  transform: translateY(-2px);
}

.building-card:active {
  transform: translateY(0);
}

.building-name {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 4px;
}

.building-address {
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: 8px;
}

.building-meta {
  display: flex;
  gap: 16px;
  font-size: 0.75rem;
  color: var(--text-secondary);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 24px;
  font-size: 1rem;
  font-weight: 500;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background-color 0.2s, transform 0.1s;
}

.btn:active {
  transform: scale(0.98);
}

.btn-primary {
  background-color: var(--primary-color);
  color: #fff;
}

.btn-primary:hover {
  background-color: var(--primary-dark);
}

.btn-secondary {
  background-color: var(--surface-color);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background-color: var(--background-color);
}

.btn-block {
  width: 100%;
}

/* Form Elements */
.form-group {
  margin-bottom: 16px;
}

.form-label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--input-border);
  border-radius: 8px;
  background-color: var(--input-background);
  color: var(--text-primary);
  transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--input-focus-shadow);
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-secondary);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

/* 変更されたフィールドのハイライト */
.field-changed {
  background-color: rgba(255, 193, 7, 0.15) !important;
  border-color: #ffc107 !important;
}

.field-changed:focus {
  box-shadow: 0 0 0 3px rgba(255, 193, 7, 0.3) !important;
}

/* 一覧のフィールド変更ハイライト（span要素用） */
span.field-changed {
  background-color: rgba(255, 193, 7, 0.25);
  padding: 2px 4px;
  border-radius: 3px;
  border: 1px solid rgba(255, 193, 7, 0.5);
}

/* 変更履歴ポップアップ */
.field-history-popup {
  position: fixed;
  z-index: 10000;
  background: var(--surface-color);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  box-shadow: var(--shadow-lg);
  padding: 12px;
  max-width: 320px;
  max-height: 300px;
  overflow-y: auto;
}

.field-history-popup h4 {
  margin: 0 0 8px 0;
  font-size: 14px;
  color: var(--text-primary);
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 8px;
}

.field-history-popup .history-entry {
  padding: 8px 0;
  border-bottom: 1px solid var(--border-color);
  font-size: 12px;
}

.field-history-popup .history-entry:last-child {
  border-bottom: none;
}

.field-history-popup .history-entry .entry-time {
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.field-history-popup .history-entry .entry-user {
  color: var(--primary-color);
  font-weight: 500;
}

.field-history-popup .history-entry .entry-change {
  margin-top: 4px;
}

.field-history-popup .history-entry .old-value {
  color: #ef5350;
  text-decoration: line-through;
}

.field-history-popup .history-entry .new-value {
  color: #66bb6a;
}

.field-history-popup .no-history {
  color: var(--text-secondary);
  font-style: italic;
  text-align: center;
  padding: 16px;
}

.field-history-popup .close-btn {
  position: absolute;
  top: 8px;
  right: 8px;
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 4px 8px;
}

.field-history-popup .close-btn:hover {
  color: var(--text-primary);
}

/* Bottom Navigation */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  justify-content: space-around;
  background-color: var(--surface-color);
  border-top: 1px solid var(--border-color);
  padding: 8px 0;
  z-index: 100;
}

.nav-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 16px;
  text-decoration: none;
  color: var(--text-secondary);
  font-size: 0.75rem;
  transition: color 0.2s;
}

.nav-item.active {
  color: var(--primary-color);
}

.nav-icon {
  font-size: 1.25rem;
}

.nav-label {
  font-weight: 500;
}

/* Loading */
.loading {
  text-align: center;
  padding: 24px;
  color: var(--text-secondary);
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-secondary);
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 16px;
}

.empty-state-text {
  font-size: 0.875rem;
}

/* Toast / Alert */
.toast {
  position: fixed;
  bottom: 80px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  background-color: var(--secondary-color);
  color: #fff;
  border-radius: 8px;
  font-size: 0.875rem;
  box-shadow: var(--shadow-lg);
  z-index: 200;
  opacity: 0;
  transition: opacity 0.3s;
}

.toast.show {
  opacity: 1;
}

.toast.success { background-color: var(--success-color); }
.toast.warning { background-color: var(--warning-color); }
.toast.error { background-color: var(--error-color); }

/* Utilities */
.text-center { text-align: center; }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.hidden { display: none !important; }

/* ========================================
   Save Status Indicator
   ======================================== */

/* Container */
.save-status-container {
  position: fixed;
  top: 12px;
  right: 16px;
  z-index: 200;
}

/* Indicator */
.save-status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 16px;
  background-color: rgba(255, 255, 255, 0.15);
  font-size: 0.75rem;
  transition: opacity 0.3s ease, background-color 0.2s ease;
}

.save-status-icon {
  font-size: 0.875rem;
  font-weight: bold;
  transition: color 0.2s ease;
}

.save-status-text {
  display: none;
}

.save-status-count {
  font-size: 0.7rem;
  opacity: 0.8;
}

/* Status states */
.save-status-indicator.status-pending {
  background-color: rgba(255, 152, 0, 0.2);
}

.save-status-indicator.status-saving {
  background-color: rgba(33, 150, 243, 0.2);
}

.save-status-indicator.status-saved {
  background-color: rgba(76, 175, 80, 0.2);
}

.save-status-indicator.status-offline {
  background-color: rgba(117, 117, 117, 0.2);
}

.save-status-indicator.status-error {
  background-color: rgba(244, 67, 54, 0.2);
}

/* Animation for saving/retrying */
.save-status-indicator.animating .save-status-icon {
  animation: spin 1s linear infinite;
}

@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Light mode adjustments */
[data-theme="light"] .save-status-indicator {
  background-color: rgba(0, 0, 0, 0.08);
}

[data-theme="light"] .save-status-indicator.status-pending {
  background-color: rgba(255, 152, 0, 0.15);
}

[data-theme="light"] .save-status-indicator.status-saving {
  background-color: rgba(33, 150, 243, 0.15);
}

[data-theme="light"] .save-status-indicator.status-saved {
  background-color: rgba(76, 175, 80, 0.15);
}

[data-theme="light"] .save-status-indicator.status-offline {
  background-color: rgba(117, 117, 117, 0.15);
}

[data-theme="light"] .save-status-indicator.status-error {
  background-color: rgba(244, 67, 54, 0.15);
}

/* Responsive */
@media (min-width: 768px) {
  .main-content {
    padding: 24px;
  }

  .buildings-list {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
  }
}
