:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1c1f24;
  --muted: #6b7280;
  --border: #e3e5e9;
  --primary: #2563eb;
  --primary-text: #ffffff;
  --online: #16a34a;
  --offline: #9ca3af;
  --unknown: #d1d5db;
  --danger: #b91c1c;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
  --panel: #e9edf3;
  --panel-border: #d7dde7;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #111317;
    --surface: #1b1e24;
    --text: #e6e8eb;
    --muted: #9aa1ac;
    --border: #2b2f37;
    --primary: #3b82f6;
    --online: #22c55e;
    --offline: #6b7280;
    --unknown: #3f444d;
    --danger: #f87171;
    --shadow: none;
    --panel: #171a20;
    --panel-border: #2a2f38;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

.muted { color: var(--muted); }
.small { font-size: 0.8125rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.4rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit;
  font-size: 0.875rem;
  text-decoration: none;
  cursor: pointer;
}
.btn:hover { filter: brightness(0.97); }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); }

/* ヘッダー */
.topbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { margin: 0; font-size: 1.25rem; }
.topbar-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; }
.topbar-actions form { margin: 0; }
#checked-at { font-size: 0.8125rem; }

/* レイアウト：左にアプリ、右にサイドバー（時計・サーバー状況） */
.layout {
  max-width: 1480px;
  margin: 0 auto;
  padding: 1rem 16px 3rem;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 20px;
  align-items: start;
}
.apps { min-width: 0; }
.sidebar {
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
  padding: 1rem;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
}
.sidebar .clock-row + .clock-row,
.sidebar .breakdown,
.sidebar .breakdown-table td { border-color: var(--panel-border); }
.sidebar .meter-bar { background: var(--panel-border); }

/* スマホ・狭い画面：1列にし、サイドバーはアプリの上に */
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; gap: 12px; }
  .sidebar { position: static; order: -1; }
}
.group-title { font-size: 0.875rem; color: var(--muted); font-weight: 600; margin: 1.25rem 0 0.5rem; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); gap: 12px; }

.card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.card-head { display: flex; gap: 0.75rem; align-items: flex-start; }
.card-icon { font-size: 1.75rem; line-height: 1; }
.card-title { flex: 1; min-width: 0; }
.card-title h3 { margin: 0; font-size: 1.05rem; overflow-wrap: anywhere; }
.chip {
  display: inline-block;
  margin-top: 0.15rem;
  padding: 0 0.5rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 0.75rem;
  color: var(--muted);
}
.card-desc { margin: 0; font-size: 0.75rem; color: var(--muted); flex: 1; }
.card-foot { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }

.status { display: flex; align-items: center; padding-top: 0.35rem; }
/* 状態はランプだけで示す。文字は画面の読み上げ用に残し、見た目からは隠す */
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--unknown); }
.lamp-online { background: var(--online); box-shadow: 0 0 0 3px color-mix(in srgb, var(--online) 25%, transparent); }
.lamp-offline { background: var(--offline); }

@media (max-width: 600px) {
  .grid { grid-template-columns: 1fr; }
}

/* ログイン */
.login-body { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: 100%;
  max-width: 360px;
  padding: 1.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
}
.login-card .brand { margin-bottom: 1rem; text-align: center; }
.login-card form { display: flex; flex-direction: column; gap: 0.75rem; }
.login-card label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.875rem; }
.login-card input {
  padding: 0.5rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.login-error { color: var(--danger); font-size: 0.875rem; margin: 0 0 0.75rem; }

/* ウィジェット（世界時計） */
.widget-title {
  margin: 0 0 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.clock-list { list-style: none; margin: 0; padding: 0; }
.clock-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.75rem 0;
}
.clock-row + .clock-row { border-top: 1px solid var(--border); }
.clock-place { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.clock-code { width: 1.75rem; font-size: 1.05rem; font-weight: 500; }
.clock-city { font-weight: 600; font-size: 0.95rem; }
.clock-zone, .clock-date { font-size: 0.75rem; color: var(--muted); }
.clock-when { text-align: right; }
.clock-time { display: block; font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ウィジェット（サーバー状況） */
.meters { display: flex; flex-direction: column; gap: 1rem; padding-top: 0.75rem; }
.meter-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-bottom: 0.35rem; }
.meter-label { font-weight: 600; font-size: 0.95rem; }
.meter-value { font-size: 0.8125rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.meter-value strong { color: var(--text); font-size: 1.05rem; margin-right: 0.25rem; }
.meter-bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.meter-fill { height: 100%; border-radius: 999px; transition: width 0.4s ease; }
.meter-ok { background: var(--primary); }
.meter-warn { background: #d97706; }
.meter-danger { background: #dc2626; }

/* アプリごとの内訳 */
.breakdown { border-top: 1px solid var(--border); padding-top: 0.75rem; }
.breakdown-title { margin: 0 0 0.4rem; font-size: 0.8125rem; font-weight: 600; color: var(--muted); cursor: pointer; list-style: none; }
.breakdown-title::-webkit-details-marker { display: none; }
.breakdown-title::after { content: ' ▾'; font-size: 0.7rem; }
.breakdown:not([open]) .breakdown-title { margin-bottom: 0; }
.breakdown:not([open]) .breakdown-title::after { content: ' ▸'; }
.breakdown-table { width: 100%; border-collapse: collapse; font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.breakdown-table th { font-weight: 500; color: var(--muted); font-size: 0.75rem; padding: 0 0 0.25rem; text-align: left; }
.breakdown-table td { padding: 0.3rem 0; border-top: 1px solid var(--border); }
.breakdown-table .num { text-align: right; padding-left: 0.75rem; white-space: nowrap; }
.breakdown-table tr.is-other td:first-child { color: var(--muted); }
.breakdown-note { margin: 0.5rem 0 0; }

/* アプリカード内の処理の進捗 */
.card-progress { display: flex; flex-direction: column; gap: 0.6rem; padding: 0.6rem 0 0.1rem; border-top: 1px solid var(--border); }
.card-progress[hidden] { display: none; }
.job-head { display: flex; justify-content: space-between; align-items: baseline; gap: 0.5rem; margin-bottom: 0.3rem; }
.job-label { font-weight: 600; font-size: 0.875rem; }
.job-state { font-size: 0.8125rem; font-variant-numeric: tabular-nums; }
.job-error { color: #dc2626; }
.job-sub { margin-top: 0.25rem; }

/* フッター */
.site-footer { padding: 1.5rem 16px 2rem; text-align: center; font-size: 0.75rem; color: var(--muted); }
.login-body .site-footer { position: fixed; bottom: 0; left: 0; right: 0; padding-bottom: 1rem; }

/* アプリカード内の一覧（例：自社宛の未納） */
.card-list { padding: 0.6rem 0 0.1rem; border-top: 1px solid var(--border); }
.card-list[hidden] { display: none; }
.list-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 0.3rem; }
.list-rows { list-style: none; margin: 0; padding: 0; }
.list-row { display: flex; gap: 0.5rem; align-items: baseline; padding: 0.2rem 0; font-size: 0.8125rem; border-top: 1px solid var(--border); }
.list-row:first-child { border-top: 0; }
.list-main { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.list-site { color: var(--muted); font-size: 0.75rem; white-space: nowrap; }
.list-date { color: var(--muted); font-size: 0.75rem; white-space: nowrap; font-variant-numeric: tabular-nums; min-width: 2.6rem; text-align: right; }
.list-more summary { cursor: pointer; margin-top: 0.25rem; }
.list-more .list-rows { margin-top: 0.2rem; }

/* アプリカード内の数値のまとめ（例：外注作業管理） */
.card-stats { padding: 0.5rem 0 0.1rem; border-top: 1px solid var(--border); }
.card-stats[hidden] { display: none; }
.stat-row { display: flex; justify-content: space-between; align-items: baseline; gap: 0.75rem; padding: 0.3rem 0; border-top: 1px solid var(--border); }
.stat-row:first-child { border-top: 0; }
.stat-left { display: flex; flex-direction: column; min-width: 0; }
.stat-label { font-size: 0.8125rem; }
.stat-sub { font-size: 0.7rem; color: var(--muted); }
.stat-value { font-size: 0.9rem; font-weight: 700; white-space: nowrap; font-variant-numeric: tabular-nums; }
.stat-ok .stat-value { color: var(--muted); font-weight: 600; }
.stat-info .stat-value { color: var(--text); }
.stat-warn .stat-value { color: #b45309; }
.stat-danger .stat-value, .stat-danger .stat-label { color: #dc2626; }
@media (prefers-color-scheme: dark) {
  .stat-warn .stat-value { color: #f59e0b; }
  .stat-danger .stat-value, .stat-danger .stat-label { color: #f87171; }
}
