:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff6ff;
  --side: #0f172a;
  --side-text: #cbd5e1;
  --ok: #059669;
  --ok-soft: #ecfdf5;
  --warn: #d97706;
  --warn-soft: #fffbeb;
  --ng: #dc2626;
  --ng-soft: #fef2f2;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, 0.06), 0 1px 3px rgba(15, 23, 42, 0.08);
  font-family: "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.6; }
a { color: var(--brand); }
button { font: inherit; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 2px; }

/* ---- レイアウト(左メニュー) ---- */
.layout { display: grid; grid-template-columns: 244px 1fr; min-height: 100vh; }
.side { background: var(--side); color: var(--side-text); display: flex; flex-direction: column; padding: 18px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 10px 20px; color: #fff; font-weight: 700; font-size: 14px; white-space: nowrap; }
.brand-mark { width: 30px; height: 30px; border-radius: 8px; background: var(--brand); display: grid; place-items: center; font-size: 16px; }
.brand small { display: block; font-weight: 400; font-size: 11px; color: #94a3b8; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: 8px; color: var(--side-text); text-decoration: none; }
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav .ico { width: 18px; text-align: center; }
.nav .count { margin-left: auto; background: var(--ng); color: #fff; border-radius: 999px; font-size: 11px; padding: 0 7px; line-height: 18px; }
.side-foot { margin-top: auto; border-top: 1px solid rgba(255, 255, 255, 0.08); padding: 12px 10px 0; font-size: 12px; }
.side-foot .who { color: #fff; word-break: break-all; }
.side-foot .plan { color: #94a3b8; margin-bottom: 8px; }
.side-foot button { width: 100%; }

.main { padding: 26px 32px 60px; min-width: 0; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
.page-head h1 { font-size: 21px; margin: 0; }
.page-head .sub { color: var(--muted); font-size: 13px; width: 100%; margin-top: -8px; }
.page-head .spacer { flex: 1; }

/* ---- 部品 ---- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--line); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; font-size: 13px; white-space: nowrap; text-decoration: none; }
.btn:hover { background: #f8fafc; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.danger { color: var(--ng); border-color: #fecaca; }
.btn.danger:hover { background: var(--ng-soft); }
.btn.ghost { background: transparent; border-color: rgba(255, 255, 255, 0.15); color: var(--side-text); }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.06); }
.btn.sm { padding: 4px 10px; font-size: 12px; }
.btn.lg { padding: 10px 20px; font-size: 15px; }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 16px; }
.kpis .card + .card { margin-top: 0; }
.card-head { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { font-size: 15px; margin: 0; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px 18px; }
.empty { padding: 36px 18px; text-align: center; color: var(--muted); }
.empty .big { font-size: 30px; margin-bottom: 6px; }

.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 16px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12px; }
.kpi .value { font-size: 28px; font-weight: 700; line-height: 1.3; }
.kpi .hint { font-size: 12px; color: var(--muted); }
.kpi.alert { border-color: #fecaca; background: var(--ng-soft); }
.kpi.alert .value { color: var(--ng); }
.kpi a { font-size: 12px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: #f8fafc; }
tr:last-child td { border-bottom: none; }
td .meta { color: var(--muted); font-size: 12px; word-break: break-all; }
.nowrap { white-space: nowrap; }
td.actions { text-align: right; }
td.actions .btn { margin: 2px 0; }
td.actions .btn + .btn { margin-left: 4px; }
.table-wrap { overflow-x: auto; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 1px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #f1f5f9; color: #475569; white-space: nowrap; }
.badge.ok { background: var(--ok-soft); color: #065f46; }
.badge.warn { background: var(--warn-soft); color: #92400e; }
.badge.ng { background: var(--ng-soft); color: #991b1b; }
.badge.run { background: var(--brand-soft); color: #1e40af; }
.badge.run::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { opacity: 0.3; } }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 12px; }
.tabs button { border: none; background: none; padding: 11px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs button.active { color: var(--brand); border-bottom-color: var(--brand); }

.field { margin-bottom: 16px; }
.field label { display: block; font-weight: 600; margin-bottom: 5px; }
.field .req { color: var(--ng); font-size: 12px; margin-left: 4px; }
.field .opt { color: var(--muted); font-size: 12px; font-weight: 400; margin-left: 4px; }
.field input, .field textarea, .field select { width: 100%; padding: 9px 11px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; background: #fff; }
.field textarea { min-height: 84px; resize: vertical; }
.field input:focus, .field textarea:focus { border-color: var(--brand); outline: none; box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); }
.help { font-size: 12px; color: var(--muted); margin-top: 5px; }
.help.tip { background: var(--brand-soft); color: #1e3a8a; padding: 8px 10px; border-radius: 8px; }
.error-text { color: var(--ng); font-size: 13px; margin-top: 6px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mt { margin-top: 12px; }
.notice { border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.notice.warn { background: var(--warn-soft); color: #92400e; border: 1px solid #fde68a; }
.notice.info { background: var(--brand-soft); color: #1e3a8a; border: 1px solid #bfdbfe; }
.notice.ng { background: var(--ng-soft); color: #991b1b; border: 1px solid #fecaca; }

.attention-item { display: flex; align-items: center; gap: 12px; padding: 12px 18px; border-bottom: 1px solid var(--line); }
.attention-item:last-child { border-bottom: none; }
.attention-item .grow { min-width: 0; }
.attention-item .name { font-weight: 600; }

.steps { margin: 6px 0 0; padding-left: 18px; font-size: 12px; color: #334155; }
.steps li { margin: 2px 0; }
details summary { cursor: pointer; color: var(--brand); font-size: 12px; }

/* ---- モーダル(POP UP) ---- */
.modal-bg { position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); display: grid; place-items: center; z-index: 50; padding: 20px; }
.modal { background: #fff; border-radius: 14px; width: min(560px, 100%); max-height: calc(100vh - 40px); overflow: auto; box-shadow: 0 20px 50px rgba(15, 23, 42, 0.25); }
.modal.wide { width: min(1100px, 100%); }
.modal-head { position: sticky; top: 0; background: #fff; z-index: 1; border-radius: 14px 14px 0 0; display: flex; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 17px; flex: 1; }
.modal-head .x { border: none; background: none; font-size: 22px; cursor: pointer; color: var(--muted); line-height: 1; }
.modal-body { padding: 18px 20px; }
.modal-foot { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding: 14px 20px; border-top: 1px solid var(--line); background: #f8fafc; border-radius: 0 0 14px 14px; position: sticky; bottom: 0; z-index: 1; }
.modal-foot[hidden] { display: none; }

.choice { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.choice button { text-align: left; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 12px; cursor: pointer; }
.choice button strong { display: block; margin-bottom: 2px; }
.choice button span { font-size: 12px; color: var(--muted); }
.choice button.active { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15); background: var(--brand-soft); }
.rec { font-size: 10px; background: var(--brand); color: #fff; border-radius: 4px; padding: 0 5px; margin-left: 4px; vertical-align: 2px; }

.remote { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; background: #0f172a; height: min(56vh, 620px); min-height: 320px; position: relative; }
.remote iframe { width: 100%; height: 100%; border: 0; display: block; }
.remote .loading { position: absolute; inset: 0; display: grid; place-items: center; color: #cbd5e1; text-align: center; padding: 20px; }
.spinner { width: 28px; height: 28px; border: 3px solid rgba(255, 255, 255, 0.2); border-top-color: #fff; border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto 10px; }
.spinner.dark { border-color: #e2e8f0; border-top-color: var(--brand); }
@keyframes spin { to { transform: rotate(360deg); } }
.paste { display: flex; gap: 6px; margin-top: 10px; flex-wrap: wrap; }
.paste input { flex: 1; min-width: 200px; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 8px; font: inherit; }

/* ---- ログイン画面 ---- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero { background: linear-gradient(140deg, #0f172a, #1e3a8a 60%, #2563eb); color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center; }
.auth-hero h1 { font-size: 30px; line-height: 1.35; margin: 0 0 14px; }
.auth-hero p { color: #cbd5e1; margin: 0 0 22px; }
.auth-hero ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 10px; }
.auth-hero li { display: flex; gap: 10px; color: #e2e8f0; }
.auth-hero li b { color: #fff; }
.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: min(380px, 100%); }
.auth-card h2 { font-size: 22px; margin: 0 0 6px; }
.auth-card .btn.primary { width: 100%; padding: 11px; font-size: 15px; }

#toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: #0f172a; color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; transition: 0.25s; pointer-events: none; z-index: 100; max-width: 90vw; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
#toast.error { background: var(--ng); }

.boot { min-height: 100vh; display: grid; place-items: center; color: var(--muted); }
.menu-toggle, .side-close, .side-backdrop { display: none; }

@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .side { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); visibility: hidden; transition: transform 0.2s, visibility 0.2s; }
  .side.open { transform: none; visibility: visible; }
  .side-close { display: inline-flex; position: absolute; top: 14px; right: 12px; font-size: 18px; }
  .side-backdrop.open { display: block; position: fixed; inset: 0; background: rgba(15, 23, 42, 0.45); z-index: 39; }
  .menu-toggle { display: inline-flex; }
  .main { padding: 16px; }
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-hero { padding: 32px 24px; }
  .choice { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
  /* 狭い画面では表をカード表示にし、操作ボタンを各項目の直下に置く */
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--line); padding: 6px 0; }
  table.stack tr:last-child { border-bottom: none; }
  table.stack td { display: block; border: none; padding: 4px 14px; }
  table.stack td.hide-sm { display: none; }
  table.stack td.actions { text-align: left; white-space: normal; display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 10px; }
  table.stack td.actions .btn + .btn { margin-left: 0; }
  .attention-item { flex-wrap: wrap; }
  .attention-item .grow { flex-basis: 100%; }
  td .meta, td b { word-break: break-word; }
}
