:root {
  --bg: #f1f4f8;
  --surface: #ffffff;
  --text: #1c2733;
  --muted: #64748b;
  --border: #e2e8f0;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eff4ff;
  --danger: #dc2626;
  --success-bg: #ecfdf3;
  --success-text: #15803d;
  --warn-bg: #fef9e7;
  --warn-text: #92650a;
  --error-bg: #fef2f2;
  --error-text: #b91c1c;
  --sidebar-bg: #0f1b2d;
  --sidebar-text: #94a3b8;
  --sidebar-active: #1e2f47;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.65;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===== レイアウト ===== */
.layout { display: flex; min-height: 100vh; }
.layout-plain {
  display: block;
  min-height: 100vh;
  background: linear-gradient(160deg, #0f1b2d 0%, #1e3a5f 100%);
}

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  color: #fff;
  font-weight: 700;
  font-size: 15px;
  padding: 4px 8px 18px;
}
.brand:hover { text-decoration: none; }
.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 15px;
  flex-shrink: 0;
}

.side-nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.side-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
}
.side-link:hover { background: var(--sidebar-active); color: #e2e8f0; text-decoration: none; }
.side-link.active { background: var(--sidebar-active); color: #fff; }
.side-link.active svg { color: #60a5fa; }

.sidebar-foot { border-top: 1px solid #223650; padding-top: 14px; display: flex; flex-direction: column; gap: 8px; }
.admin-chip { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #334e6e;
  color: #dbeafe;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}
.admin-name { color: #cbd5e1; font-size: 13px; overflow: hidden; text-overflow: ellipsis; }
.sidebar-foot .btn-ghost { color: var(--sidebar-text); text-align: left; padding: 6px 8px; }
.sidebar-foot .btn-ghost:hover { background: var(--sidebar-active); color: #e2e8f0; }

.content { flex: 1; min-width: 0; padding: 28px 32px 64px; max-width: 1200px; }
.content-plain { max-width: none; padding: 0; }

/* ===== 見出し・ページヘッダ ===== */
h1 { font-size: 21px; margin: 0 0 20px; letter-spacing: 0.01em; }
h2 { font-size: 15px; margin: 28px 0 12px; color: #334155; }
section.card h2, .card h2 { margin-top: 0; }

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.page-head h1, .page-head h2 { margin: 0; }

.breadcrumb { margin: -8px 0 16px; font-size: 13px; color: var(--muted); }

/* ===== フラッシュ ===== */
.flash {
  padding: 11px 16px;
  border-radius: 8px;
  margin-bottom: 18px;
  font-weight: 500;
  border: 1px solid transparent;
}
.flash-success { background: var(--success-bg); color: var(--success-text); border-color: #bbe7c9; }
.flash-error { background: var(--error-bg); color: var(--error-text); border-color: #fecaca; }

/* ===== テーブル ===== */
.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}
table { width: 100%; border-collapse: collapse; }
th, td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}
th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.03em;
}
tbody tr:hover { background: #f8fafc; }
tr:last-child td { border-bottom: none; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; }
td.wrap { white-space: normal; }

/* ===== バッジ ===== */
.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: #eef1f5;
  color: #475569;
}
.badge-active, .badge-paid { background: var(--success-bg); color: var(--success-text); }
.badge-suspended, .badge-sent { background: var(--warn-bg); color: var(--warn-text); }
.badge-terminated, .badge-canceled { background: #eef1f5; color: #64748b; }
.badge-overdue { background: var(--error-bg); color: var(--error-text); }
.badge-draft { background: var(--primary-soft); color: var(--primary-dark); }

/* ===== ボタン ===== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 15px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.12s;
}
.btn:hover { background: #f1f5f9; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--surface); border-color: #fca5a5; color: var(--danger); }
.btn-danger:hover { background: var(--error-bg); }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; box-shadow: none; }
.btn-small { padding: 4px 11px; font-size: 12px; border-radius: 6px; }
.btn-block { width: 100%; }

.inline-form { display: inline-block; margin: 0; }

/* ===== フォーム・カード ===== */
.form-card, .card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px 24px;
}
.form-card { max-width: 780px; }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px 22px;
}
.form-grid .span2 { grid-column: span 2; }
label { display: block; font-size: 13px; font-weight: 600; color: #334155; }
input, select, textarea {
  width: 100%;
  margin-top: 5px;
  padding: 8px 11px;
  border: 1px solid #cbd5e1;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  border-color: var(--primary);
}
.req { color: var(--danger); font-size: 11px; font-weight: 500; }
.form-actions { margin-top: 20px; display: flex; gap: 10px; }

.search-form { display: flex; gap: 8px; margin-bottom: 16px; max-width: 440px; }
.search-form input { margin-top: 0; }

/* ===== 統計カード ===== */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 12px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.stat-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.stat-icon svg { width: 22px; height: 22px; }
.stat-icon-blue { background: var(--primary-soft); color: var(--primary); }
.stat-icon-green { background: var(--success-bg); color: var(--success-text); }
.stat-icon-amber { background: var(--warn-bg); color: var(--warn-text); }
.stat-icon-red { background: var(--error-bg); color: var(--error-text); }
.stat-label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.stat-value { font-size: 26px; font-weight: 700; line-height: 1.2; font-variant-numeric: tabular-nums; }
.stat-value .unit { font-size: 13px; font-weight: 500; color: var(--muted); margin-left: 2px; }

/* ===== 詳細 ===== */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

.dl { display: grid; grid-template-columns: 130px 1fr; gap: 8px 14px; margin: 0; }
.dl dt { color: var(--muted); font-size: 13px; }
.dl dd { margin: 0; min-width: 0; overflow-wrap: break-word; }
.dl dd.pre { white-space: pre-wrap; }

.muted { color: var(--muted); }
.small { font-size: 12px; font-weight: 400; }
.secret-value { margin-left: 8px; word-break: break-all; }
.empty-note {
  background: var(--surface);
  border: 1px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 22px;
  text-align: center;
  color: var(--muted);
}

/* ===== ログイン ===== */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-box {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 14px;
  padding: 36px 32px;
  box-shadow: 0 20px 50px rgba(2, 8, 20, 0.4);
}
.login-brand { display: flex; align-items: center; justify-content: center; gap: 10px; margin-bottom: 22px; font-weight: 700; font-size: 16px; }
.login-brand .brand-mark { width: 34px; height: 34px; border-radius: 9px; background: linear-gradient(135deg, #3b82f6, #1d4ed8); color: #fff; display: grid; place-items: center; }
.login-box h1 { font-size: 15px; text-align: center; color: var(--muted); font-weight: 500; margin-bottom: 20px; }
.login-box label { margin-bottom: 14px; }
.login-box .btn { margin-top: 10px; padding: 10px; }

/* ===== レスポンシブ ===== */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    flex-direction: row;
    align-items: center;
    padding: 10px 14px;
    gap: 8px;
  }
  .brand { padding: 0 8px; }
  .brand-text { display: none; }
  .side-nav { flex-direction: row; flex: 1; }
  .side-link span { display: none; }
  .sidebar-foot { border-top: none; padding-top: 0; flex-direction: row; align-items: center; }
  .admin-chip .admin-name { display: none; }
  .content { padding: 20px 16px 48px; }
  .form-grid, .detail-grid { grid-template-columns: 1fr; }
  .form-grid .span2 { grid-column: span 1; }
}
