/* 会議コストメーター */
:root {
  --bg: #f3f5f8;
  --card: #ffffff;
  --text: #1f2933;
  --muted: #66727f;
  --border: #d5dbe3;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #15803d;
  --danger: #c62828;
  --ok-bg: #e8f6ec;
  --ok-text: #166534;
  --warn-bg: #fff6d6;
  --warn-text: #8a5a00;
  --over-bg: #fde4e4;
  --over-text: #b91c1c;
  --none-bg: #eef1f5;
  --radius: 10px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Yu Gothic UI", "Meiryo", system-ui, sans-serif;
  line-height: 1.6;
}

main {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px;
}

/* ヘッダー・タブ */
.app-header {
  background: #1e293b;
  color: #fff;
  padding: 12px 16px 0;
}

.app-title {
  margin: 0 auto 8px;
  max-width: 960px;
  font-size: 1.3rem;
}

.tabs {
  display: flex;
  gap: 4px;
  max-width: 960px;
  margin: 0 auto;
}

.tab {
  flex: 0 1 auto;
  border: none;
  background: transparent;
  color: #cbd5e1;
  padding: 8px 18px;
  font-size: 1rem;
  border-radius: 8px 8px 0 0;
  cursor: pointer;
}

.tab:hover {
  color: #fff;
}

.tab.is-active {
  background: var(--bg);
  color: var(--text);
  font-weight: bold;
}

.tab:focus-visible,
.btn:focus-visible,
input:focus-visible {
  outline: 3px solid #93c5fd;
  outline-offset: 2px;
}

.warning {
  max-width: 960px;
  margin: 12px auto 0;
  padding: 8px 16px;
  background: var(--warn-bg);
  color: var(--warn-text);
  border-radius: var(--radius);
}

/* カード */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}

.card-title {
  margin: 0 0 12px;
  font-size: 1.1rem;
}

.card-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
}

.card-head .card-title {
  margin: 0;
}

.sub-title {
  margin: 16px 0 8px;
  font-size: 1rem;
}

/* フォーム */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 0.9rem;
  color: var(--muted);
}

.field-wide {
  grid-column: 1 / -1;
}

.field input {
  font-size: 1rem;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  background: #fff;
  width: 100%;
  min-width: 0;
}

.field input:disabled {
  background: #eef1f5;
  color: var(--muted);
}

.hint {
  margin: 8px 0 0;
  font-size: 0.85rem;
  color: var(--muted);
}

/* ボタン */
.btn {
  font-size: 1rem;
  padding: 10px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}

.btn:hover:not(:disabled) {
  background: #f1f5f9;
}

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

.btn-small {
  padding: 6px 12px;
  font-size: 0.9rem;
  min-height: 36px;
}

.btn-primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

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

.btn-success {
  background: var(--success);
  border-color: var(--success);
  color: #fff;
}

.btn-success:hover:not(:disabled) {
  background: #166534;
}

.btn-danger {
  background: #fff;
  border-color: var(--danger);
  color: var(--danger);
}

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

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.controls .btn {
  flex: 1 1 140px;
}

/* メーター表示 */
.stage-top {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.status-label {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  background: var(--none-bg);
  font-size: 0.85rem;
  font-weight: bold;
}

.status-running .status-label {
  background: #dbeafe;
  color: var(--primary-dark);
}

.status-paused .status-label {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.meeting-name {
  flex: 1 1 auto;
  min-width: 0;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cost-display {
  margin-top: 12px;
  padding: 16px;
  border-radius: var(--radius);
  text-align: center;
  background: var(--none-bg);
  transition: background-color 0.3s;
}

.cost-value {
  font-size: clamp(2.6rem, 11vw, 5.5rem);
  font-weight: bold;
  line-height: 1.15;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.alert-message {
  margin-top: 4px;
  font-weight: bold;
}

.level-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.level-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
}

.level-over {
  background: var(--over-bg);
  color: var(--over-text);
}

.level-over .cost-value {
  animation: blink 1s ease-in-out infinite;
}

@keyframes blink {
  50% {
    opacity: 0.3;
  }
}

@media (prefers-reduced-motion: reduce) {
  .level-over .cost-value {
    animation: none;
    text-decoration: underline;
  }
}

.progress {
  margin: 10px auto 0;
  max-width: 600px;
  height: 12px;
  background: rgba(0, 0, 0, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0;
  background: currentColor;
  transition: width 0.25s linear;
}

.progress-label {
  margin-top: 4px;
  font-size: 0.85rem;
  min-height: 1.3em;
}

.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
  margin: 12px 0 0;
}

.stat {
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 12px;
  text-align: center;
}

.stat dt {
  font-size: 0.8rem;
  color: var(--muted);
}

.stat dd {
  margin: 0;
  font-size: 1.4rem;
  font-weight: bold;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

.notice {
  margin: 8px 0 0;
  min-height: 1.4em;
  font-size: 0.9rem;
  color: var(--success);
}

.big-hint {
  display: none;
}

/* 人数変更ログ */
.log-list {
  margin: 0;
  padding-left: 1.4em;
  max-height: 240px;
  overflow-y: auto;
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 0;
  color: var(--muted);
}

/* 見積もり */
.est-total {
  font-size: clamp(2.2rem, 9vw, 4rem);
  font-weight: bold;
  text-align: center;
  font-variant-numeric: tabular-nums;
  word-break: break-all;
}

/* テーブル */
.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.95rem;
}

.table th,
.table td {
  border-bottom: 1px solid var(--border);
  padding: 6px 8px;
  text-align: left;
  vertical-align: middle;
}

.table th {
  background: #f8fafc;
  font-size: 0.85rem;
  color: var(--muted);
  white-space: nowrap;
}

.table .num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.history-table td {
  white-space: nowrap;
}

.history-table td.name-cell {
  white-space: normal;
  word-break: break-all;
  min-width: 8em;
}

.badge {
  display: inline-block;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: bold;
}

.badge-over {
  background: var(--over-bg);
  color: var(--over-text);
}

.badge-ok {
  background: var(--ok-bg);
  color: var(--ok-text);
}

.badge-none {
  background: var(--none-bg);
  color: var(--muted);
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* 大きく表示モード */
body.big-mode {
  overflow: hidden;
}

body.big-mode .stage {
  position: fixed;
  inset: 0;
  z-index: 100;
  margin: 0;
  border: none;
  border-radius: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2vh 4vw;
  overflow-y: auto;
}

body.big-mode .meeting-name {
  font-size: 1.6rem;
}

body.big-mode .cost-display {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

body.big-mode .cost-value {
  font-size: clamp(3rem, 16vw, 18vh);
}

body.big-mode .alert-message {
  font-size: clamp(1.1rem, 3vw, 2rem);
}

body.big-mode .progress {
  height: 18px;
  max-width: 80%;
  width: 100%;
}

body.big-mode .stat dd {
  font-size: clamp(1.4rem, 4vw, 3rem);
}

body.big-mode .big-hint {
  display: block;
  margin: 8px 0 0;
  text-align: center;
  font-size: 0.85rem;
  color: var(--muted);
}

/* スマホ幅 */
@media (max-width: 480px) {
  main {
    padding: 10px;
  }

  .app-title {
    font-size: 1.1rem;
  }

  .tab {
    flex: 1 1 0;
    padding: 8px 4px;
  }

  .card {
    padding: 12px;
  }

  .form-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .stat {
    padding: 6px 4px;
  }

  .stat dd {
    font-size: 1.05rem;
  }

  .controls .btn {
    flex: 1 1 100px;
    padding: 10px 8px;
  }

  .history-table {
    font-size: 0.85rem;
  }
}
