/* =========================================================
   あかり サンプル「みはらし」 アプリ画面（ダッシュボード）
   style.css（トークン・部品）の上に重ねる。骨格は DESIGN.md 8.1〜8.3・9.14。
   サイドバー 240px（md で 64px、sm でドロワー）、ヘッダー 56px は密度で変えない。
   余白・行の高さ・文字は密度のトークンだけを参照する。
   ========================================================= */

.app { min-height: 100vh; }
.shell { display: grid; grid-template-columns: 240px minmax(0, 1fr); min-height: 100vh; }

/* ---------- サイドバー（9.14） ---------- */
.sidebar {
  position: sticky; top: 0; height: 100vh; z-index: 30;
  display: flex; flex-direction: column; overflow-y: auto;
  background: var(--surface); border-right: 1px solid var(--line);
  padding: 0 12px 16px;
}
.sidebar__logo { display: flex; align-items: center; gap: 10px; height: 56px; flex: none; padding: 0 12px; margin: 0 -12px 8px; border-bottom: 1px solid var(--line); }
.sidebar__logo .logo { font-size: 16px; }
.sidebar__group { display: flex; flex-direction: column; gap: 2px; }
.sidebar__group + .sidebar__group { margin-top: 16px; }
.sidebar__heading { padding: 0 12px; margin-bottom: 4px; font-size: var(--fs-small); font-weight: 500; color: var(--text-3); line-height: 1.5; }
.sidebar__bottom { margin-top: auto; padding-top: 16px; }
.nav-item {
  position: relative; display: flex; align-items: center; gap: 10px; width: 100%;
  height: var(--control-h); padding: 0 12px; border: 0; border-radius: var(--radius-md);
  background: none; color: var(--text-2); font-size: var(--fs-body); text-align: left; text-decoration: none !important; cursor: pointer; white-space: nowrap;
  transition: background-color var(--t-hover), color var(--t-hover);
}
.nav-item .ui-icon { width: var(--icon); height: var(--icon); color: var(--text-2); }
.nav-item:hover { background: var(--hover); color: var(--text); }
.nav-item:hover .ui-icon { color: var(--text); }
.nav-item[aria-current="page"] { background: var(--selected); color: var(--text); }
.nav-item[aria-current="page"] .ui-icon { color: var(--accent); }
.nav-item .tag--count { margin-left: auto; }
.nav-item__label { overflow: hidden; text-overflow: ellipsis; }
.sidebar__account { display: flex; align-items: center; gap: 10px; padding: 12px; margin-top: 8px; border-top: 1px solid var(--line); }
.sidebar__account .who { min-width: 0; font-size: var(--fs-small); line-height: 1.4; }
.sidebar__account .who span { display: block; color: var(--text-2); font-family: var(--font-mono); letter-spacing: 0; overflow: hidden; text-overflow: ellipsis; }

/* ---------- ヘッダー（56px 固定） ---------- */
.main { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20; height: 56px; flex: none;
  display: flex; align-items: center; gap: 12px; padding: 0 var(--page-pad);
  background: var(--surface); border-bottom: 1px solid var(--line);
}
.crumbs { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: var(--fs-body); color: var(--text-2); white-space: nowrap; }
.crumbs .sep { color: var(--text-3); }
.crumbs [aria-current] { color: var(--text); font-weight: 500; }
.topbar__right { margin-left: auto; display: flex; align-items: center; gap: 8px; }
.search { position: relative; width: 240px; }
.search .ui-icon { position: absolute; left: var(--pad); top: 50%; transform: translateY(-50%); color: var(--text-3); pointer-events: none; }
.search .input { padding-left: calc(var(--pad) + var(--icon) + 8px); }
.search kbd { position: absolute; right: 8px; top: 50%; transform: translateY(-50%); padding: 0 6px; border: 1px solid var(--line); border-radius: var(--radius-sm); font-family: var(--font-mono); font-size: 12px; color: var(--text-3); line-height: 18px; }
.bell { position: relative; }
.bell__count {
  position: absolute; right: 2px; top: 2px; min-width: 16px; height: 16px; padding: 0 4px;
  border-radius: var(--radius-sm); background: var(--accent); color: var(--on-accent);
  font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-size: 12px; font-weight: 500; line-height: 16px; text-align: center; letter-spacing: 0;
}
.bell-panel { right: 0; top: calc(100% + 4px); width: 360px; min-width: 0; max-width: 360px; max-height: 480px; padding: 0; }
.bell-panel__head { display: flex; align-items: center; justify-content: space-between; padding: var(--pad-y) var(--pad); border-bottom: 1px solid var(--line); font-size: var(--fs-small); color: var(--text-2); }
.bell-panel .alert { grid-template-columns: 64px minmax(0, 1fr) auto; }
.bell-panel .alert__dur { display: none; }
.menu-btn { display: none; }

/* ---------- コンテンツ ---------- */
.content { width: 100%; max-width: 1440px; padding: var(--page-pad); display: flex; flex-direction: column; gap: var(--section-gap); }
.page-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px var(--gap); }
.page-head h1 { font-size: var(--fs-h1); line-height: 1.4; }
.page-head__sum { color: var(--text-2); font-size: var(--fs-small); }
.page-head__actions { margin-left: auto; display: flex; gap: var(--gap); }
.toolbar { display: flex; align-items: center; flex-wrap: wrap; gap: var(--gap) var(--section-gap); margin-top: calc(var(--section-gap) * -1 + var(--gap)); }
.toolbar__item { display: flex; align-items: center; gap: 8px; }
.toolbar__label { font-size: var(--fs-small); font-weight: 500; color: var(--text-2); }
.toolbar__updated { margin-left: auto; display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-small); color: var(--text-2); }

.dash-grid { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: var(--section-gap); }
.span-3 { grid-column: span 3; }
.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-8 { grid-column: span 8; }
.span-12 { grid-column: span 12; }

/* KPI：最低幅 200px を保って折り返す（8.2） */
.kpis { grid-column: span 12; display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: var(--section-gap); }

/* 応答時間のグラフ */
.chart-card .chart { height: 240px; }
.chart-card .chart > svg { height: 240px; }
.chart:focus-visible { outline-offset: 4px; border-radius: var(--radius-sm); }
.chart-card .legend { margin-bottom: var(--gap); }

/* 状態の内訳 */
.stack { display: flex; gap: 2px; height: 12px; margin: 4px 0 var(--gap); }
.stack > span { height: 100%; background: var(--st); min-width: 2px; }
.breakdown li { display: flex; align-items: center; min-height: var(--row-h); border-bottom: 1px solid var(--line); }
.breakdown li:last-child { border-bottom: 0; }
.breakdown .st-inline { font-size: var(--fs-body); }
.breakdown .num { margin-left: auto; font-size: var(--fs-body); }
.breakdown .unit { margin-left: 4px; font-size: var(--fs-small); }
.breakdown__note { margin-top: var(--gap); font-size: var(--fs-small); color: var(--text-2); }

/* 監視対象の表 */
.table-card .tabs { padding: 0 var(--card-pad); }
.table-card .table-wrap { overflow-x: auto; }
.table-card .table th:first-child, .table-card .table td:first-child { padding-left: var(--card-pad); }
.table-card .table th:last-child, .table-card .table td:last-child { padding-right: calc(var(--card-pad) - var(--pad) / 2); }
.table .mon-name .col-sub { margin-left: 8px; font-family: var(--font-mono); letter-spacing: 0; }
.table-card .table tbody td:first-child, .table-card .table thead th:first-child { position: sticky; left: 0; z-index: 2; background: var(--surface); }
.table-card .table tbody tr:hover td:first-child { background-image: linear-gradient(var(--hover), var(--hover)); }
.table-card .table tbody tr.is-flash td:first-child { background-image: linear-gradient(var(--selected), var(--selected)); }
.table .row-act { width: calc(var(--control-h) + var(--pad)); text-align: right; }
.table .row-act .btn--icon { width: calc(var(--row-h) - 8px); height: calc(var(--row-h) - 8px); }
.table td.st-cell .st-note { margin-left: 8px; }
.table .no-match td { height: auto; padding: var(--section-gap) var(--card-pad); text-align: center; color: var(--text-2); white-space: normal; }

/* アラート履歴 */
.alerts-card .alerts { margin: 0 calc(var(--card-pad) * -1) calc(var(--card-pad) * -1); }
.alerts-card .alert, .alerts-card .alert-day { padding-left: var(--card-pad); padding-right: var(--card-pad); }
.alerts-card .alert-day { border-top: 1px solid var(--line); }
.alerts-card .alerts > .alert-day:first-child { border-top: 1px solid var(--line); }

/* 稼働の帯 */
.uptime li + li { margin-top: var(--section-gap); }
.uptime__head { display: flex; align-items: baseline; flex-wrap: wrap; gap: 4px 8px; margin-bottom: 8px; }
.uptime__name { font-weight: 500; }
.uptime__sum { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.uptime__axis { display: flex; justify-content: space-between; margin-top: 4px; font-size: var(--fs-small); color: var(--text-2); }
.uptime__track { width: max-content; max-width: 100%; overflow-x: auto; padding: 4px; margin: -4px; }
.uptime .band > span { --band-w: 8px; }
@media (max-width: 1279px) { .uptime .band > span { --band-w: 8px; } }
@media (max-width: 767px) { .uptime .band > span { --band-w: 6px; } }
.uptime-legend { margin-top: var(--section-gap); padding-top: var(--gap); border-top: 1px solid var(--line); }

/* 行の操作メニュー */
.row-menu { position: absolute; }

/* 状態が変わった直後の強調（9.3：行に --selected を 2秒） */
.table tbody tr.is-flash { background: var(--selected); transition: background-color .4s ease-out; }

/* ---------- ブレークポイント（8.2） ---------- */
@media (max-width: 1279px) {
  .span-8, .span-4, .span-7, .span-5 { grid-column: span 12; }
  .chart-card.span-8 { grid-column: span 12; }
}
@media (min-width: 1024px) and (max-width: 1279px) {
  .breakdown-card.span-4 { grid-column: span 12; }
}
@media (max-width: 1023px) {
  .shell { grid-template-columns: 64px minmax(0, 1fr); }
  .sidebar { padding: 0 8px 12px; overflow: visible; }
  .sidebar__logo { justify-content: center; padding: 0; margin: 0 -8px 8px; }
  .sidebar__logo .logo span, .sidebar__heading, .nav-item .tag--count, .sidebar__account .who { display: none; }
  .sidebar__heading { display: block; height: 1px; margin: 0 8px 8px; padding: 0; overflow: hidden; color: transparent; background: var(--line); }
  .nav-item { justify-content: center; padding: 0; }
  /* 畳んだサイドバーのラベルはツールチップ（9.11）で出す */
  .nav-item__label {
    position: absolute; left: calc(100% + 8px); top: 50%; transform: translateY(-50%); z-index: 40;
    padding: 6px 8px; background: var(--surface-overlay); border: 1px solid var(--line); border-radius: var(--radius-sm); box-shadow: var(--shadow-overlay);
    font-size: var(--fs-small); color: var(--text); opacity: 0; visibility: hidden; transition: opacity var(--t-hover); pointer-events: none;
  }
  .nav-item:hover .nav-item__label, .nav-item:focus-visible .nav-item__label { opacity: 1; visibility: visible; transition-delay: 300ms; }
  .sidebar__account { justify-content: center; padding: 12px 0 0; }
  .search { width: 200px; }
}
@media (max-width: 767px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0; width: 240px; height: auto; z-index: 65; padding: 0 12px 16px;
    transform: translateX(-100%); transition: transform var(--t-overlay); box-shadow: none; overflow-y: auto;
  }
  .sidebar.is-open { transform: none; box-shadow: var(--shadow-modal); }
  .sidebar__logo { justify-content: flex-start; padding: 0 12px; margin: 0 -12px 8px; }
  .sidebar__logo .logo span, .nav-item .tag--count, .sidebar__account .who { display: initial; }
  .sidebar__heading { display: block; height: auto; margin: 0 0 4px; padding: 0 12px; color: var(--text-3); background: none; }
  .nav-item { justify-content: flex-start; padding: 0 12px; }
  .nav-item__label { position: static; transform: none; padding: 0; background: none; border: 0; box-shadow: none; opacity: 1; visibility: visible; font-size: var(--fs-body); color: inherit; }
  .sidebar__account { justify-content: flex-start; padding: 12px; }
  .drawer-backdrop { position: fixed; inset: 0; z-index: 64; background: var(--backdrop); }
  .drawer-backdrop[hidden] { display: none; }
  .menu-btn { display: inline-flex; margin-left: calc(var(--pad) * -.5); }
  .search { display: none; }
  .crumbs .crumbs__team, .crumbs .sep { display: none; }
  .page-head__actions { margin-left: 0; width: 100%; }
  .toolbar__updated { margin-left: 0; }
  .bell-panel { position: fixed; left: 8px; right: 8px; top: 60px; width: auto; max-width: none; }
  .alert { grid-template-columns: 64px minmax(0, 1fr) auto; }
  .alert__dur { grid-column: 2; grid-row: 2; }
  .alert__time { grid-row: 1; grid-column: 3; }
}
@media (prefers-reduced-motion: reduce) { .sidebar { transition: none; } }
