:root {
  --bg: #eef1f0;
  --panel: #ffffff;
  --ink: #1a2420;
  --muted: #5c6b63;
  --line: #d5ddd8;
  --accent: #1b5e45;
  --accent-2: #0f3d2d;
  --warn: #b45309;
  --danger: #b91c1c;
  --radius: 12px;
  --shadow: 0 10px 28px rgba(20, 40, 30, 0.08);
  font-family: "Zen Kaku Gothic New", "Hiragino Sans", "Yu Gothic", sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #d9ebe2 0%, transparent 55%),
    linear-gradient(180deg, #f5f7f6 0%, var(--bg) 100%);
  min-height: 100vh;
}

.app { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: linear-gradient(180deg, var(--accent-2), #143528);
  color: #f3faf6;
  padding: 22px 16px;
}
.brand-kicker { font-size: 11px; letter-spacing: .12em; opacity: .75; }
.brand h1 { font-size: 18px; margin: 6px 0 4px; font-weight: 700; }
.brand p { margin: 0; font-size: 12px; opacity: .8; line-height: 1.5; }
.nav { margin-top: 28px; display: grid; gap: 6px; }
.nav button {
  border: 0;
  background: transparent;
  color: #dceee5;
  text-align: left;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  font: inherit;
}
.nav button.active, .nav button:hover { background: rgba(255,255,255,.12); color: #fff; }

.main { padding: 22px 26px 40px; max-width: 1200px; margin: 0 auto; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding: 14px 22px;
  background: linear-gradient(90deg, var(--accent-2), #1a4a36);
  color: #f3faf6;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar .brand { font-size: 16px; font-weight: 700; letter-spacing: .02em; white-space: nowrap; }
.topbar .nav {
  display: flex;
  gap: 4px;
  margin: 0;
  flex: 1;
  justify-content: center;
}
.topbar .nav button {
  color: #dceee5;
  padding: 8px 12px;
  border-radius: 8px;
  white-space: nowrap;
}
.topbar .nav button.active, .topbar .nav button:hover { background: rgba(255,255,255,.14); color: #fff; }
.topbar .muted { color: #c5ddd1; }
.login-card .brand { font-size: 22px; font-weight: 700; margin-bottom: 6px; color: var(--accent-2); }
.login-card .sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
}
.stack { display: grid; gap: 14px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 10px;
}
.toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}
.toolbar-actions .btn {
  white-space: nowrap;
  height: 40px;
  display: inline-flex;
  align-items: center;
}
.grow { flex: 1; }

.btn {
  appearance: none;
  border: 0;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  padding: 9px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #174f3a; }
.btn.secondary { background: #e8eeeb; color: var(--ink); }
.btn.secondary:hover { background: #dce5e0; }
.btn.danger { background: var(--danger); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

input, select, textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 10px;
  font: inherit;
  background: #fff;
}
label { display: grid; gap: 5px; font-size: 12px; color: var(--muted); font-weight: 600; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.grid-2 .full { grid-column: 1 / -1; }
.seal-preview-wrap {
  width: 96px;
  height: 96px;
  flex: 0 0 96px;
  border: 1px dashed var(--line);
  border-radius: 50%;
  background: #fff;
  display: grid;
  place-items: center;
  overflow: hidden;
}
.seal-preview { width: 88px; height: 88px; object-fit: contain; }

table.data { width: 100%; border-collapse: collapse; font-size: 13px; }
table.data th, table.data td { border-bottom: 1px solid var(--line); padding: 9px 8px; text-align: left; vertical-align: middle; }
table.data th { font-size: 11px; color: var(--muted); font-weight: 700; }
table.data tr:hover td { background: #f5faf7; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  background: #e7f2ec;
  color: var(--accent-2);
}
.badge.warn { background: #fff7ed; color: var(--warn); }
.badge.off { background: #f3f4f6; color: #6b7280; }

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(420px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 28px 24px;
}
.login-card h1 { margin: 0 0 8px; font-size: 22px; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-size: 13px; }
.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  background: #123528;
  color: #fff;
  padding: 10px 14px;
  border-radius: 10px;
  opacity: 0;
  transform: translateY(8px);
  transition: .2s;
  z-index: 50;
}
.toast.show { opacity: 1; transform: none; }
.hidden { display: none !important; }
.modal-overlay {
  position: fixed; inset: 0; background: rgba(16,28,22,.45);
  display: grid; place-items: center; padding: 20px; z-index: 40;
}
.modal {
  width: min(1100px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
  padding: 18px 18px 14px;
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin: 0 0 12px;
}
.modal-header h3 { margin: 0; flex: 1; min-width: 0; }
.modal-close {
  flex-shrink: 0;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.modal-close:hover {
  background: #eef2f0;
  color: var(--text);
}
.hint { font-size: 12px; color: var(--muted); line-height: 1.6; }
.row-inactive td { color: var(--muted); }

/* Dashboard */
.dash { display: grid; gap: 12px; }
.dash-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; }
.dash-title { margin: 0 0 4px; font-size: 18px; font-weight: 700; color: var(--accent-2); }
.dash-kpis {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}
.kpi {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 14px 12px;
  box-shadow: var(--shadow);
}
.kpi-accent {
  background: linear-gradient(160deg, #1b5e45 0%, #143528 100%);
  color: #f3faf6;
  border-color: transparent;
}
.kpi-accent .k, .kpi-accent .s { color: #c5ddd1; }
.kpi-accent .v { color: #fff; }
.kpi .k { font-size: 11px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.kpi .v { font-size: 22px; font-weight: 700; margin-top: 6px; line-height: 1.2; }
.kpi .v .unit { font-size: 13px; font-weight: 600; margin-left: 4px; color: var(--muted); }
.kpi-accent .v .unit { color: #c5ddd1; }
.kpi .s { font-size: 11px; color: var(--muted); margin-top: 6px; line-height: 1.4; }
.kpi .delta.up { color: #15803d; font-weight: 600; }
.kpi .delta.down { color: #b91c1c; font-weight: 600; }
.kpi-accent .delta.up, .kpi-accent .delta.down, .kpi-accent .delta.flat { color: #bbf7d0; }
.dash-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr;
  gap: 10px;
}
.dash-card { min-height: 220px; }
.dash-chart { width: 100%; height: auto; display: block; }
.chart-base { stroke: var(--line); stroke-width: 1; }
.bar-est { fill: #1b5e45; }
.bar-inv { fill: #94b8a8; }
.bar-label { fill: var(--muted); font-size: 11px; }
.chart-legend {
  display: flex;
  gap: 14px;
  margin-top: 8px;
  font-size: 11px;
  color: var(--muted);
}
.chart-legend i {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 2px;
  margin-right: 5px;
  vertical-align: -1px;
}
.chart-legend .lg-est { background: #1b5e45; }
.chart-legend .lg-inv { background: #94b8a8; }
table.data.compact th, table.data.compact td { padding: 8px 10px; font-size: 12px; }

@media (max-width: 960px) {
  .dash-kpis { grid-template-columns: repeat(2, 1fr); }
  .dash-grid { grid-template-columns: 1fr; }
}
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; }
.stat {
  background: #f4f8f6;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 20px; font-weight: 700; margin-top: 4px; }

/* License 選択マトリクス（Excel準拠） */
.license-matrix-wrap { padding: 14px; }
.license-scroll { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
.license-matrix {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  min-width: 720px;
}
.license-matrix th,
.license-matrix td {
  border: 1px solid #c5cdd4;
  padding: 8px 10px;
  text-align: center;
  vertical-align: middle;
}
.license-matrix thead th {
  background: #eef2f5;
  font-weight: 700;
  color: #243038;
  line-height: 1.35;
}
.license-matrix thead .sub {
  display: block;
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  margin-top: 2px;
}
.license-matrix .col-no { width: 48px; }
.license-matrix .col-sys { min-width: 140px; }
.license-matrix td.sys-name {
  text-align: left;
  font-weight: 700;
  background: #fafbfc;
}
.license-matrix .sys-access-link {
  color: var(--accent-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.license-matrix .sys-access-link:hover { color: var(--accent); }
.license-matrix .sys-access-row {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  font-weight: 500;
}
.license-matrix .sys-access-url {
  font-size: 11px;
  color: var(--muted);
  background: #eef2f0;
  padding: 2px 6px;
  border-radius: 4px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.license-matrix .sys-copy-btn {
  padding: 2px 8px !important;
  font-size: 11px !important;
  font-weight: 600;
}
.license-matrix td.num { color: var(--muted); font-variant-numeric: tabular-nums; }
.license-matrix td.plan-price {
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  min-width: 96px;
}
.license-matrix td.plan-select { width: 64px; }
.license-matrix .special-unit {
  width: 110px;
  margin: 0 auto;
  text-align: right;
  padding: 6px 8px;
}
.license-matrix .plan-check {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  cursor: pointer;
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { padding-bottom: 10px; }
  .nav { grid-auto-flow: column; overflow: auto; }
  .grid-2, .grid-3, .stat-grid { grid-template-columns: 1fr 1fr; }
}
