/*
 * 利用状況モニター（Issue #895）
 * 色の正本は mobile/recipitz/lib/core/theme（docs/design/design-system/tokens/colors.css）。
 * 状態色（ok / warn / crit）は Claude Design の Ops Dashboard 案の値。
 * 正常時は静かに、異常時だけ枠線・ピル・理由行・バー・グラフの色を変える。
 */
:root {
  --bg: #FFFDF5;
  --surface: #FFFFFF;
  --surface-muted: #FAF7F0;
  --text: #333333;
  --text-sub: #555048;
  --muted: #888888;
  --line: #EAE5DA;
  --track: #F1ECE2;
  --primary: #C5815A;
  --primary-press: #A9663F;
  --neutral-bar: #9C9184;
  --neutral-line: #A89E92;

  --ok-dot: #7C9A6E;  --ok-pill-bg: #F3F1EA;  --ok-pill-fg: #5E6B55;
  --warn-dot: #C9962F; --warn-pill-bg: #FBF3DF; --warn-pill-fg: #7D5A12;
  --warn-line: #D9BE7F; --warn-alert-bg: #FBF5E6; --warn-alert-fg: #6E5010;
  --crit-dot: #B04A3A; --crit-pill-bg: #F8E6E1; --crit-pill-fg: #963A2C;
  --crit-line: #C7705F; --crit-alert-bg: #FBEDEA; --crit-alert-fg: #8A3326;

  --num: "Outfit", system-ui, sans-serif;
  --body: "Noto Sans JP", system-ui, sans-serif;
  --pad: 16px;
  --gap: 12px;
}

* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); }
body {
  font-family: var(--body);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
[hidden] { display: none !important; }
.num { font-family: var(--num); }
.muted { color: var(--muted); font-size: 12.5px; line-height: 1.6; margin: 0; }

.page {
  max-width: 1600px;
  margin: 0 auto;
  padding: var(--pad);
  padding-bottom: calc(var(--pad) + env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--gap);
  min-height: 100vh;
}

/* --- topbar --- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.topbar__title { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.eyebrow { font-family: var(--num); font-size: 11px; font-weight: 500; letter-spacing: .12em; color: var(--muted); }
h1 { margin: 0; font-size: 19px; font-weight: 700; letter-spacing: .02em; }
.topbar__meta { display: flex; align-items: center; gap: 10px; }
.topbar__times { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; font-size: 11px; color: var(--muted); }
.topbar__times b { font-size: 13px; font-weight: 500; color: var(--text); }

.icon-button {
  width: 44px; height: 44px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text);
  display: flex; align-items: center; justify-content: center; cursor: pointer;
}
.icon-button:hover { background: #F7F3EB; }
.icon-button svg, .icon svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.icon-button.is-loading svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* --- summary（① 全体の状態 → ② 要対応リスト） --- */
.summary {
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  padding: 16px; display: flex; flex-direction: column; gap: 16px;
}
.summary[data-status="warn"] { background: #FCF7EA; border-color: #EEDDB2; }
.summary[data-status="crit"] { background: #FBF1EE; border-color: #EBCBC3; }
.summary__status { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.summary__title { display: flex; align-items: center; gap: 10px; }
.summary__dot { width: 12px; height: 12px; border-radius: 50%; flex: none; background: var(--ok-dot); box-shadow: 0 0 0 4px #E3EADD; }
.summary[data-status="warn"] .summary__dot { background: var(--warn-dot); box-shadow: 0 0 0 4px #F3E4BF; }
.summary[data-status="crit"] .summary__dot { background: var(--crit-dot); box-shadow: 0 0 0 4px #F2D6CF; }
.summary__title span { font-size: 22px; font-weight: 700; letter-spacing: .01em; }
.summary[data-status="warn"] .summary__title span { color: var(--warn-alert-fg); }
.summary[data-status="crit"] .summary__title span { color: var(--crit-alert-fg); }
.summary__sub { font-size: 13px; color: #6B655C; padding-left: 22px; }
.issues { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.issue {
  background: var(--surface); border: 1px solid var(--line); border-radius: 12px;
  padding: 10px 12px; display: flex; align-items: flex-start; gap: 10px;
}
.issue[data-status="warn"] { border-color: var(--warn-line); }
.issue[data-status="crit"] { border-color: var(--crit-line); }
.issue__body { min-width: 0; display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.issue__body b { font-weight: 700; }
.issue__body span { color: var(--text-sub); line-height: 1.5; }
.summary__meta { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.tile { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; display: flex; flex-direction: column; gap: 4px; }
.tile__label { font-size: 11px; color: var(--muted); }
.tile__value { font-family: var(--num); font-size: 24px; font-weight: 600; letter-spacing: -.01em; }
.tile__note { font-size: 10.5px; color: var(--muted); line-height: 1.5; }
.dots { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px; display: flex; flex-wrap: wrap; gap: 8px 16px; }
.dots span { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-sub); }
.dots i { width: 8px; height: 8px; border-radius: 50%; background: var(--ok-dot); }
.dots i[data-status="warn"] { background: var(--warn-dot); }
.dots i[data-status="crit"] { background: var(--crit-dot); }

/* --- grid（③ サービスカード） --- */
.grid { display: grid; gap: var(--gap); align-items: start; grid-template-columns: minmax(0, 1fr); }

.card {
  --card-line: var(--line);
  background: var(--surface); border: 1px solid var(--card-line); border-radius: 16px;
  padding: 18px; display: flex; flex-direction: column; gap: 14px; min-width: 0;
}
.card[data-status="warn"] { --card-line: var(--warn-line); }
.card[data-status="crit"] { --card-line: var(--crit-line); border-width: 1.5px; }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card__name { font-size: 14px; font-weight: 700; }
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 11px; font-weight: 700; padding: 4px 9px; border-radius: 999px; background: var(--ok-pill-bg); color: var(--ok-pill-fg); flex: none; }
.pill i { width: 6px; height: 6px; border-radius: 50%; background: var(--ok-dot); }
[data-status="warn"] > .pill, .issue[data-status="warn"] .pill { background: var(--warn-pill-bg); color: var(--warn-pill-fg); }
[data-status="warn"] > .pill i, .issue[data-status="warn"] .pill i { background: var(--warn-dot); }
[data-status="crit"] > .pill, .issue[data-status="crit"] .pill { background: var(--crit-pill-bg); color: var(--crit-pill-fg); }
[data-status="crit"] > .pill i, .issue[data-status="crit"] .pill i { background: var(--crit-dot); }

.hero { display: flex; flex-direction: column; gap: 8px; }
.hero__label { font-size: 12px; color: var(--muted); }
.hero__row { display: flex; align-items: baseline; gap: 6px 8px; flex-wrap: wrap; }
.hero__value { font-family: var(--num); font-size: 34px; font-weight: 600; line-height: 1; letter-spacing: -.02em; }
.hero__total { font-family: var(--num); font-size: 14px; color: var(--muted); }
.delta { font-family: var(--num); font-size: 12px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--ok-pill-bg); color: var(--text-sub); }

.meter { position: relative; height: 6px; border-radius: 999px; background: var(--track); }
.meter__fill { height: 100%; border-radius: 999px; background: var(--neutral-bar); }
.card[data-status="warn"] .meter__fill { background: var(--warn-dot); }
.card[data-status="crit"] .meter__fill { background: var(--crit-dot); }
.meter__marker { position: absolute; top: -3px; width: 2px; height: 12px; background: var(--text); border-radius: 1px; }
.meter__labels { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); }

.expiries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.expiries .expiry { margin-top: 0; background: var(--surface); border: 1px solid var(--warn-line); border-radius: 12px; padding: 9px 12px; flex-wrap: wrap; }
.expiries .expiry[data-tone="crit"] { border-color: var(--crit-line); }
.expiries .expiry b { font-weight: 700; color: var(--text); }
.expiry { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; margin-top: -6px; }
.expiry svg { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; color: var(--muted); }
.expiry[data-tone="warn"] { color: var(--warn-pill-fg); }
.expiry[data-tone="warn"] svg { color: var(--warn-dot); }
.expiry[data-tone="crit"] { color: var(--crit-pill-fg); font-weight: 700; }
.expiry[data-tone="crit"] svg { color: var(--crit-dot); }

.alert { border-radius: 10px; padding: 9px 11px; font-size: 12.5px; line-height: 1.5; display: flex; gap: 8px; align-items: flex-start; }
.card[data-status="warn"] .alert { background: var(--warn-alert-bg); color: var(--warn-alert-fg); }
.card[data-status="crit"] .alert { background: var(--crit-alert-bg); color: var(--crit-alert-fg); }
.alert svg { width: 16px; height: 16px; flex: none; margin-top: 1px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.reasons { margin: 0; padding-left: 18px; font-size: 12px; color: var(--text-sub); line-height: 1.6; }

.kv { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 16px; margin: 0; }
.kv div { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kv dt { font-size: 11px; color: var(--muted); }
.kv dd { margin: 0; font-family: var(--num); font-size: 15px; font-weight: 500; overflow-wrap: anywhere; }
.kv dd small { font-size: 12px; color: var(--muted); font-weight: 400; margin-left: 4px; }
.kv dd[data-tone="crit"] { color: var(--crit-pill-fg); font-weight: 600; }
.ref { display: inline-block; font-family: var(--body); font-size: 10px; font-weight: 500; color: var(--warn-pill-fg); background: var(--warn-pill-bg); border-radius: 4px; padding: 0 4px; margin-left: 4px; vertical-align: 2px; }

.split { border-top: 1px solid var(--track); padding-top: 12px; display: flex; flex-direction: column; gap: 8px; }
.split__head { display: flex; justify-content: space-between; align-items: baseline; font-size: 11px; color: var(--muted); }
.split__head b { font-family: var(--num); font-size: 15px; font-weight: 600; color: var(--text); }
.split__bar { display: flex; height: 6px; border-radius: 999px; overflow: hidden; gap: 2px; background: var(--surface); }
.split__bar i:first-child { background: var(--neutral-bar); }
.split__bar i:last-child { flex: 1; background: #E2DBCD; }
.split__labels { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); }
.split__note { font-size: 11px; color: var(--muted); line-height: 1.5; }

.chart { display: flex; flex-direction: column; gap: 4px; }
.chart__head { display: flex; justify-content: space-between; gap: 8px; font-size: 11px; color: var(--muted); }
.chart svg { width: 100%; height: 44px; display: block; overflow: visible; }
.chart--tall svg { height: 56px; }
.spark-area { fill: var(--neutral-bar); fill-opacity: .08; }
.spark-line { fill: none; stroke: var(--neutral-line); stroke-width: 1.5; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.card[data-status="warn"] .spark-line { stroke: #B8862A; }
.card[data-status="crit"] .spark-line { stroke: var(--crit-dot); }
.cum-prev { fill: none; stroke: #D5CDBF; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.cum-cur { fill: none; stroke: var(--text); stroke-width: 1.75; vector-effect: non-scaling-stroke; stroke-linejoin: round; }
.cum-fc { fill: none; stroke: var(--text); stroke-width: 1.5; stroke-dasharray: 3 3; vector-effect: non-scaling-stroke; }
.legend { display: flex; gap: 10px; }
.legend span { display: flex; align-items: center; gap: 4px; }
.legend i { width: 10px; height: 2px; background: var(--text); }
.legend i.prev { background: #D5CDBF; }

.aws-body { display: flex; flex-wrap: wrap; gap: 16px 28px; align-items: flex-start; }
.aws-body > div { flex: 1 1 220px; min-width: 0; display: flex; flex-direction: column; gap: 14px; }
.breakdown { display: flex; flex-direction: column; gap: 8px; }
.breakdown__bar { display: flex; height: 6px; border-radius: 999px; overflow: hidden; gap: 2px; }
.breakdown ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.breakdown li { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.breakdown li i { width: 8px; height: 8px; border-radius: 2px; flex: none; }
.breakdown li span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.breakdown li b { font-family: var(--num); font-weight: 500; }

.card__foot { font-size: 11px; color: var(--muted); display: flex; align-items: center; gap: 5px; flex-wrap: wrap; }
.card__foot[data-late="true"] { color: #8A6414; }
.card__foot svg { width: 13px; height: 13px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }
.quality { font-size: 11px; color: var(--warn-pill-fg); background: var(--warn-pill-bg); border-radius: 8px; padding: 6px 9px; line-height: 1.5; }
.empty { font-size: 13px; color: var(--muted); line-height: 1.6; }

/* --- forms --- */
.login { display: flex; justify-content: center; padding-top: 10vh; }
.login__card, .dialog__body { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 14px; }
h2 { margin: 0; font-size: 17px; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); }
.field input, .field select { font: inherit; font-size: 16px; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 10px; min-height: 44px; padding: 8px 12px; width: 100%; }
.field input:focus, .field select:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.form-error { margin: 0; min-height: 1em; font-size: 12.5px; color: var(--crit-pill-fg); }
.button { font: inherit; font-size: 14px; font-weight: 500; min-height: 44px; padding: 0 16px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; }
.button:hover { background: #F7F3EB; }
.button--primary { background: var(--primary); border-color: var(--primary); color: #FFFFFF; font-weight: 700; }
.button--primary:hover { background: var(--primary-press); }
.button--quiet { border-color: transparent; background: transparent; color: var(--muted); }
.button:disabled { opacity: .6; cursor: default; }
.segmented { display: grid; grid-template-columns: 1fr 1fr; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented label { display: flex; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { flex: 1; text-align: center; padding: 10px; font-size: 13px; cursor: pointer; }
.segmented input:checked + span { background: var(--surface-muted); font-weight: 700; }
.segmented input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: -2px; }
.dialog { border: 0; padding: 0; background: transparent; width: min(420px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); }
.dialog::backdrop { background: rgba(51, 51, 51, .35); }
.dialog__body { max-width: none; overflow-y: auto; }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; }
.page-footer { display: flex; justify-content: space-between; gap: 8px; flex-wrap: wrap; padding-top: 4px; }
.load-error { color: var(--crit-pill-fg); font-size: 13px; }

/* --- レイアウト（Dashboard Spec §4） --- */
@media (min-width: 600px) {
  :root { --pad: 24px; --gap: 16px; }
  .summary { padding: 20px; flex-direction: row; flex-wrap: wrap; gap: 20px 32px; }
  .summary__status { flex: 1 1 340px; }
  .summary__meta { flex: 1 1 300px; }
  /* 等幅 2 列なので列間がヒンジ上に来る。5 枚目（AWS）は全幅 */
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card--aws { grid-column: 1 / -1; }
}
@media (min-width: 1024px) {
  .grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .card--aws { grid-column: span 2; }
}
@media (min-width: 1100px) {
  :root { --pad: 32px; }
}
@media (min-width: 1280px) {
  .grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .card--aws { grid-column: 1 / -1; }
}
