:root {
  --bg: #f5f6f8;
  --fg: #1f2933;
  --muted: #62707d;
  --accent: #2563eb;
  --card: #fff;
  --border: #d9dee3;
  --error: #b42318;
  --ok: #067647;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
  line-height: 1.6;
}

.site-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1rem;
  background: var(--card);
  border-bottom: 1px solid var(--border);
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: bold;
  color: var(--fg);
  text-decoration: none;
}

.user-nav { display: flex; align-items: center; gap: 1rem; }
.user-name { color: var(--muted); }
.inline-form { display: inline; margin: 0; }

main { max-width: 1800px; margin: 1rem auto; padding: 0 1rem; }

a { color: var(--accent); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1.5rem;
}

.narrow { max-width: 420px; margin: 2rem auto; }

label { display: block; margin-bottom: 1rem; font-size: 0.9rem; }

input[type="text"], input[type="password"] {
  display: block;
  width: 100%;
  margin-top: 0.25rem;
  padding: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 1rem;
}

button {
  padding: 0.5rem 1.25rem;
  border: 0;
  border-radius: 4px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

button.link-button {
  padding: 0;
  background: none;
  color: var(--accent);
  font-size: inherit;
  text-decoration: underline;
}

.error { color: var(--error); }
.notice { color: var(--ok); }

.fetch-status {
  margin-bottom: 0.5rem;
  color: var(--muted);
  font-size: 0.85rem;
}

.fetch-status.alert {
  padding: 0.5rem 1rem;
  border: 1px solid #f0c36d;
  border-radius: 4px;
  background: #fff8e6;
  color: var(--fg);
  font-size: inherit;
  font-weight: normal;
}

.fetch-status p { margin: 0.1rem 0; }

.card-groups { display: grid; grid-template-columns: 1fr; gap: 0.75rem 1.5rem; margin-bottom: 1rem; }
@media (min-width: 1100px) {
  .card-groups { grid-template-columns: 2fr 1.2fr; }
}
.group-title { margin: 0 0 0.25rem; padding: 0; border: 0; font-size: 0.9rem; color: var(--muted); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 0.75rem; }
.card { padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 4px; background: var(--card); }
.card-link { display: block; color: inherit; text-decoration: none; }
.card-link:hover { border-color: var(--accent); }
.card-active { border: 2px solid var(--accent); }
.card-label { color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.card-value { font-size: 1.25rem; font-weight: bold; white-space: nowrap; }
.card-sub { color: var(--muted); font-size: 0.85rem; }
.card-rows { display: grid; gap: 0.15rem; margin: 0.25rem 0 0; }
.card-rows > div { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0 0.6rem; }
.card-rows dt { flex: 0 0 3.5rem; color: var(--muted); font-size: 0.85rem; white-space: nowrap; }
.cards-2 { grid-template-columns: repeat(auto-fill, minmax(15rem, 1fr)); }
.card-rows dd { margin: 0; }
.card-rows .card-value { font-size: 1.15rem; }

.filters { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; margin-bottom: 0.5rem; }
.count { color: var(--muted); margin: 0.25rem 0; }
.table-wrap { overflow-x: auto; }
table.devices { width: 100%; border-collapse: collapse; background: var(--card); }
table.devices th, table.devices td { padding: 0.4rem 0.6rem; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
table.devices td.num { text-align: right; }
table.devices th.num { text-align: right; }
table.devices .col-name { width: 14rem; max-width: 14rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
table.devices td a, table.devices th a { text-decoration: none; }
table.devices td a:hover, table.devices th a:hover { text-decoration: underline; }
table.devices th a { color: var(--fg); }
.alert { color: var(--error); font-weight: bold; }
.muted { color: var(--muted); }
.sort-note { margin-left: 0.5rem; }

.badge { display: inline-block; white-space: nowrap; padding: 0.05rem 0.5rem; border-radius: 999px; background: #e5e7eb; font-size: 0.85rem; }
.badge-needs_check { background: #fde2e0; color: var(--error); }
.badge-offline, .badge-offline_est { background: #e5e7eb; color: var(--muted); }
.badge-producing { background: #d1fadf; color: var(--ok); }
.badge-running { background: #e8f5ee; color: #2f6b4a; }
.badge-apk-old { background: #fef3c7; color: #92400e; }
.badge-sleep, .badge-burner_off { background: #fef3c7; color: #92400e; }

h2 { margin-top: 1.5rem; padding-bottom: 0.25rem; border-bottom: 1px solid var(--border); }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(18rem, 1fr)); gap: 1rem 1.5rem; }
.pager { text-align: center; }
.raw-json { overflow-x: auto; margin: 0.75rem 0 0; padding: 0.75rem; background: var(--bg); border: 1px solid var(--border); border-radius: 4px; font-size: 0.8rem; white-space: pre-wrap; word-break: break-all; }

/* 端末詳細 */
.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
.mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.85em; }
.api-name { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 0.75rem; font-weight: normal; }
.back-link { margin: 0 0 0.25rem; font-size: 0.9rem; }
.device-head { margin-bottom: 1rem; }
.device-title { display: flex; flex-wrap: wrap; align-items: center; gap: 0.75rem; }
.device-title h1 { margin: 0; font-size: 1.75rem; line-height: 1.3; }
.badge-lg { padding: 0.15rem 0.75rem; font-size: 1rem; }
.device-meta dl { display: flex; flex-wrap: wrap; gap: 0.25rem 1.75rem; margin: 0.5rem 0 0; font-size: 0.9rem; }
.device-meta dl > div { display: flex; gap: 0.5rem; }
.device-meta dt { color: var(--muted); }
.device-meta dd { margin: 0; }

.panel { margin-bottom: 1rem; padding: 1rem 1.25rem 1.25rem; background: var(--card); border: 1px solid var(--border); border-radius: 8px; }
.panel h2 { margin: 0; padding: 0; border: 0; font-size: 1.1rem; }
.panel h3 { margin: 1.25rem 0 0.5rem; font-size: 0.95rem; }
.panel-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 0.75rem; }
.panel .cards { margin-bottom: 0.5rem; }
.panel table.devices th { color: var(--muted); font-size: 0.85rem; font-weight: normal; }
.panel table.devices td.empty { color: var(--muted); text-align: center; }

.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; font-size: 0.85rem; }
.segment { padding: 0.2rem 0.9rem; color: var(--fg); text-decoration: none; }
.segment + .segment { border-left: 1px solid var(--border); }
.segment:hover { background: var(--bg); }
.segment.active { background: var(--accent); color: #fff; font-weight: bold; }

.chart { margin: 0 0 1rem; min-width: 0; }
.chart figcaption { margin-bottom: 0.25rem; font-size: 0.85rem; font-weight: bold; }
.chart-box { position: relative; height: 220px; }
.chart-box-bands { height: 150px; }
.chart-empty { display: flex; align-items: center; justify-content: center; height: 100%; margin: 0; border: 1px dashed var(--border); border-radius: 4px; color: var(--muted); font-size: 0.9rem; }
.chart-grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 1.5rem; }
@media (min-width: 900px) {
  .chart-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .chart-grid-sales { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
}

@media (min-width: 1100px) {
  .cards-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .cards-2 { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); }
}
.table-scroll { max-height: 30rem; overflow-y: auto; border-bottom: 1px solid var(--border); }
.table-scroll thead th { position: sticky; top: 0; z-index: 1; background: var(--card); box-shadow: inset 0 -1px 0 var(--border); }
table.devices td.wrap { min-width: 10rem; white-space: normal; }

.split { display: grid; grid-template-columns: minmax(0, 1fr); gap: 0 1.5rem; }
@media (min-width: 1100px) {
  .split { grid-template-columns: minmax(0, 2fr) minmax(0, 5fr); }
}
.more summary { margin: 0.5rem 0; color: var(--accent); cursor: pointer; font-size: 0.9rem; }
.refund { margin: 0.5rem 0 0; font-size: 0.9rem; }
.summary-title { display: inline; margin: 0; }
.panel details > summary { cursor: pointer; }
