/* Maritime Transcriber 遠隔モニタ — dashboard styles
   モバイル優先 (iPhone/iPad/Android Chrome)、Pixel 10 Pro XL 対応を
   明示スコープに含む。safe-area-inset を考慮。 */

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Helvetica Neue",
               "Noto Sans JP", "Hiragino Sans", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  color: #222;
  background: #f4f5f7;
  -webkit-text-size-adjust: 100%;
}

body {
  padding:
    env(safe-area-inset-top, 0)
    env(safe-area-inset-right, 0)
    env(safe-area-inset-bottom, 0)
    env(safe-area-inset-left, 0);
}

/* ==== ヘッダ ================================================================ */

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: #ffffff;
  border-bottom: 1px solid #e0e2e6;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 600;
}

.header-right {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  align-items: center;
}

.conn-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #c33;
  box-shadow: 0 0 6px rgba(204,51,51,0.45);
  display: inline-block;
  transition: background 0.2s;
}
.conn-dot.connected { background: #1a8; box-shadow: 0 0 6px rgba(26,136,136,0.5); }
.conn-dot.connecting { background: #c90; box-shadow: 0 0 6px rgba(204,153,0,0.5); }
/* 2026-04-24 Pillar 5: 接続失敗の状態細分化 (ユーザー側で切り分け可能に) */
.conn-dot.refused { background: #d93025; box-shadow: 0 0 6px rgba(217,48,37,0.6); }
.conn-dot.unauthorized { background: #f9a825; box-shadow: 0 0 6px rgba(249,168,37,0.6); }
.conn-dot.timeout { background: #9c27b0; box-shadow: 0 0 6px rgba(156,39,176,0.5); }

.badge {
  display: inline-block;
  padding: 3px 10px;
  font-size: 13px;
  font-weight: 600;
  border-radius: 999px;
  background: #eee;
  color: #333;
  min-height: 24px;
  line-height: 18px;
}

.lang-badge { background: #d6e8f8; color: #0b5ea8; }
.engine-badge { background: #e6e1f8; color: #4b2ba6; }
.mode-badge { background: #f8eed6; color: #86540b; }
.paused-badge { background: #f8d6d6; color: #a60b0b; }

/* ==== メイン ================================================================ */

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card {
  background: #ffffff;
  border: 1px solid #e0e2e6;
  border-radius: 10px;
  padding: 12px 14px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.03);
}

.card h2 {
  margin: 0 0 10px 0;
  font-size: 15px;
  color: #555;
  font-weight: 600;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
}

.muted {
  color: #888;
  font-size: 13px;
  font-weight: 400;
}

.kv-grid {
  display: grid;
  grid-template-columns: minmax(110px, auto) 1fr;
  gap: 6px 12px;
  font-size: 14px;
}

.kv-label {
  color: #666;
}

.kv-value {
  font-weight: 500;
  word-break: break-word;
}

/* ==== レベルバッジ ========================================================== */

.level-badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
  background: #ddd;
  color: #333;
}
.level-badge.level-silent    { background: #dfe1e5; color: #666; }
.level-badge.level-low       { background: #fff3d6; color: #8a6b12; }
.level-badge.level-ok        { background: #d6f1e3; color: #0d6b3f; }
.level-badge.level-high      { background: #ffe1c7; color: #a8520b; }
.level-badge.level-clip      { background: #ffd6d6; color: #a60b0b; }
.level-badge.level-speaking  { background: #d6f1e3; color: #0d6b3f; }
.level-badge.level-silence   { background: #e5e6e8; color: #666; }
.level-badge.level-connected { background: #d6f1e3; color: #0d6b3f; }
.level-badge.level-reconnecting { background: #fff3d6; color: #8a6b12; }
.level-badge.level-idle      { background: #e5e6e8; color: #666; }
.level-badge.level-error     { background: #ffd6d6; color: #a60b0b; }

/* ==== transcript ============================================================ */

.transcript-list {
  max-height: 320px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse; /* 新しい entry を上に */
  gap: 6px;
  padding: 4px 2px;
}

.transcript-entry {
  display: flex;
  gap: 8px;
  padding: 6px 8px;
  border-radius: 6px;
  background: #fafbfc;
  border: 1px solid #eee;
  font-size: 14px;
}
.transcript-entry.disagreement {
  background: #fff8e1;
  border-color: #f0d070;
}
.transcript-entry.corrected {
  background: #edf7ed;
  border-color: #b0d0b0;
}

.transcript-speaker {
  flex-shrink: 0;
  font-weight: 600;
  color: #4b2ba6;
  min-width: 60px;
}

.transcript-text {
  flex-grow: 1;
  word-break: break-word;
}

.transcript-corrected-mark {
  color: #080;
  font-size: 11px;
  margin-left: 4px;
}

/* ==== events ================================================================ */

.event-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 200px;
  overflow-y: auto;
  display: flex;
  flex-direction: column-reverse;
  gap: 4px;
}

.event-item {
  padding: 5px 8px;
  border-radius: 5px;
  font-size: 13px;
  background: #fafbfc;
  border-left: 3px solid #bbb;
}
.event-item.severity-info { border-left-color: #5a8fd6; }
.event-item.severity-warning { border-left-color: #d69d5a; background: #fff8e1; }
.event-item.severity-error { border-left-color: #c33; background: #fff0f0; }

.event-time {
  color: #888;
  font-size: 11px;
  margin-right: 6px;
}

/* ==== control buttons ======================================================= */

.control-card {
  background: #fffbea;
  border-color: #f0d070;
}

.control-buttons {
  display: flex;
  gap: 10px;
  margin-top: 4px;
}

.btn {
  min-height: 44px;
  padding: 10px 18px;
  font-size: 15px;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary { background: #1a8; color: #fff; }
.btn-primary:active { background: #0a6a6a; }

.btn-warning { background: #d69d5a; color: #fff; }
.btn-warning:active { background: #a6783b; }

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

.note {
  margin: 8px 0 0 0;
  font-size: 12px;
  color: #888;
}

/* ==== フッタ ================================================================ */

.app-footer {
  text-align: center;
  padding: 10px;
  font-size: 12px;
  color: #888;
}

/* ==== ユーティリティ ======================================================== */

.hidden { display: none !important; }

/* 小画面 (Pixel 10 Pro XL = 412-448 dp, iPhone = 390-428 dp) 調整 */
@media (max-width: 480px) {
  .app-header { padding: 8px 10px; }
  main { padding: 8px; gap: 8px; }
  .card { padding: 10px 12px; border-radius: 8px; }
  .card h2 { font-size: 14px; }
  .kv-grid { grid-template-columns: 96px 1fr; font-size: 13px; }
  .transcript-entry { font-size: 13px; }
  .badge { font-size: 11px; padding: 2px 8px; }
}

/* ==================================================================
 * UX-3 施策 4 (2026-04-23): Toast / Modal
 * severity=warning → toast 5s 自動消滅
 * severity=error   → modal 要手動 dismiss
 * ================================================================== */
.ux3-toast-container {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.ux3-toast {
  min-width: 280px;
  max-width: 86vw;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  pointer-events: auto;
  cursor: pointer;
  transition: opacity 400ms, transform 400ms;
}

.ux3-toast-info { background: #1565c0; color: white; }
.ux3-toast-warning { background: #ef6c00; color: white; border-left: 4px solid #e65100; }
.ux3-toast-error { background: #c62828; color: white; border-left: 4px solid #b71c1c; }

.ux3-toast-fading {
  opacity: 0;
  transform: translateY(-20px);
}

.ux3-modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 9500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.ux3-modal {
  background: white;
  color: #222;
  border-radius: 10px;
  padding: 24px;
  max-width: 480px;
  width: 100%;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.ux3-modal-error { border-top: 6px solid #c62828; }
.ux3-modal-warning { border-top: 6px solid #ef6c00; }

.ux3-modal-title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 12px;
}

.ux3-modal-message {
  font-size: 15px;
  line-height: 1.5;
  margin-bottom: 20px;
  white-space: pre-wrap;
}

.ux3-modal-dismiss {
  padding: 10px 24px;
  background: #1976d2;
  color: white;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  float: right;
}

.ux3-modal-dismiss:hover { background: #1565c0; }
