/* ============================================================
   admin.css  —  Stripe決済管理システム 共通スタイル
   PHP 8.2 / モダンブラウザ対象
============================================================ */

/* ============================================================
   CSS Variables
============================================================ */
:root {
  --primary:         #635BFF;
  --primary-hover:   #4f46e5;
  --primary-soft:    rgba(99, 91, 255, .12);
  --sidebar-bg:      #1a1f36;
  --sidebar-hover:   #252d4a;
  --sidebar-active:  rgba(99, 91, 255, .18);
  --sidebar-width:   240px;
  --topbar-height:   64px;
  --bg:              #f6f9fc;
  --surface:         #ffffff;
  --border:          #e3e8ef;
  --text:            #1a1f36;
  --text-muted:      #6b7c93;
  --text-sidebar:    #8492a6;
  --success:         #0aca8b;
  --warning:         #f59e0b;
  --danger:          #e02020;
  --info:            #1a90ff;
  --radius:          10px;
  --radius-sm:       6px;
  --shadow-sm:       0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow:          0 2px 8px rgba(0,0,0,.08);
  --shadow-lg:       0 8px 32px rgba(0,0,0,.14);
  --transition:      0.18s ease;
}

/* ============================================================
   Reset & Base
============================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 16px; -webkit-font-smoothing: antialiased; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto,
               'Helvetica Neue', Arial, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
}

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

/* ============================================================
   Layout（サイドバー + メインコンテンツ）
============================================================ */
.admin-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ============================================================
   Sidebar
============================================================ */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 100;
  overflow-y: auto;
}

/* --- ロゴ --- */
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 22px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-logo-icon {
  width: 34px;
  height: 34px;
  background: var(--primary);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(99,91,255,.4);
}

.sidebar-logo-text {
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* --- ナビゲーション --- */
.sidebar-section {
  padding: 20px 12px 6px;
}

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: #4a556a;
  padding: 0 8px;
  margin-bottom: 6px;
}

.sidebar-nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-sidebar);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: background var(--transition), color var(--transition);
  margin-bottom: 2px;
  text-decoration: none;
}

.sidebar-nav-item:hover {
  background: var(--sidebar-hover);
  color: #d0d9e8;
  text-decoration: none;
}

.sidebar-nav-item.active {
  background: var(--sidebar-active);
  color: #8b86ff;
  font-weight: 600;
}

.sidebar-nav-item.active:hover {
  background: var(--sidebar-active);
}

.nav-icon {
  font-size: 14px;
  width: 18px;
  text-align: center;
  flex-shrink: 0;
}

/* --- フッター（ユーザー情報） --- */
.sidebar-footer {
  margin-top: auto;
  padding: 16px;
  border-top: 1px solid rgba(255,255,255,.06);
  flex-shrink: 0;
}

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-user-name {
  color: #cfd8e8;
  font-size: 13px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar-user-role {
  font-size: 11px;
  color: #4a556a;
  margin-top: 1px;
}

/* ============================================================
   Main Content
============================================================ */
.main-content {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-width: 0;
}

/* ============================================================
   Topbar
============================================================ */
.topbar {
  height: var(--topbar-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-shrink: 0;
}

.topbar-title {
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.2px;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.topbar-user {
  font-size: 13px;
  color: var(--text-muted);
}

.topbar-user strong {
  color: var(--text);
  font-weight: 600;
}

/* ============================================================
   Page Content
============================================================ */
.page-content {
  padding: 28px;
  flex: 1;
}

/* ============================================================
   Stat Cards
============================================================ */
.stat-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 24px;
  box-shadow: var(--shadow-sm);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  background: var(--card-accent, var(--primary));
  border-radius: var(--radius) var(--radius) 0 0;
}

.stat-card.accent-primary { --card-accent: var(--primary); }
.stat-card.accent-success  { --card-accent: var(--success); }
.stat-card.accent-warning  { --card-accent: var(--warning); }
.stat-card.accent-info     { --card-accent: var(--info); }
.stat-card.accent-danger   { --card-accent: var(--danger); }

.stat-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.stat-value {
  font-size: 28px;
  font-weight: 800;
  color: var(--text);
  line-height: 1.15;
  margin-bottom: 4px;
  letter-spacing: -.5px;
}

.stat-sub {
  font-size: 12px;
  color: var(--text-muted);
}

/* ============================================================
   Card
============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card + .card {
  margin-top: 20px;
}

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text);
}

.card-body {
  padding: 24px;
}

/* ============================================================
   Table
============================================================ */
.table-responsive { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 11px 16px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  background: #fafbfc;
}

tbody td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }

tbody tr:hover { background: #f8fafc; }

.table-empty {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ============================================================
   Badge
============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge-admin    { background: var(--primary-soft);               color: var(--primary); }
.badge-operator { background: rgba(10,202,139,.12);              color: #0a7a58; }
.badge-viewer   { background: rgba(107,124,147,.1);              color: var(--text-muted); }
.badge-success  { background: rgba(10,202,139,.12);              color: #0a7a58; }
.badge-warning  { background: rgba(245,158,11,.12);              color: #9a6100; }
.badge-danger   { background: rgba(224,32,32,.1);                color: var(--danger); }
.badge-info     { background: rgba(26,144,255,.1);               color: #005ecc; }

/* ============================================================
   Button
============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 18px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background var(--transition), box-shadow var(--transition), color var(--transition);
  text-decoration: none;
  white-space: nowrap;
  font-family: inherit;
  line-height: 1.4;
}

.btn:hover { text-decoration: none; }
.btn:focus-visible { outline: 3px solid rgba(99,91,255,.4); outline-offset: 2px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 3px rgba(99,91,255,.3);
}
.btn-primary:hover {
  background: var(--primary-hover);
  color: #fff;
  box-shadow: 0 2px 6px rgba(99,91,255,.4);
}

.btn-outline {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-outline:hover { background: var(--bg); color: var(--text); }

.btn-danger  { background: var(--danger);  color: #fff; }
.btn-danger:hover { background: #c01818; color: #fff; }

.btn-sm  { padding: 5px 12px; font-size: 12.5px; }
.btn-lg  { padding: 13px 24px; font-size: 15px; }
.btn-block { width: 100%; }

/* ログアウトボタン（topbar用） */
.btn-logout {
  display: inline-flex;
  align-items: center;
  padding: 6px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  cursor: pointer;
  transition: all var(--transition);
  text-decoration: none;
  font-family: inherit;
}
.btn-logout:hover {
  background: #fff0f0;
  border-color: #fca5a5;
  color: var(--danger);
  text-decoration: none;
}

/* ============================================================
   Alert（フラッシュメッセージ等）
============================================================ */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 20px;
  border: 1px solid transparent;
}

.alert-error   { background: rgba(224,32,32,.07);   border-color: rgba(224,32,32,.25);   color: #c41e1e; }
.alert-success { background: rgba(10,202,139,.08);  border-color: rgba(10,202,139,.25);  color: #0a6b4a; }
.alert-warning { background: rgba(245,158,11,.08);  border-color: rgba(245,158,11,.25);  color: #9a6100; }
.alert-info    { background: rgba(26,144,255,.08);  border-color: rgba(26,144,255,.25);  color: #0050aa; }

/* ============================================================
   Form
============================================================ */
.form-group { margin-bottom: 20px; }

.form-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 10px 14px;
  font-size: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
  font-family: inherit;
}

.form-control:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,91,255,.15);
}

.form-control::placeholder { color: #aab7c4; }

.form-hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 5px;
}

/* ============================================================
   Login Page
============================================================ */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #7c75ff 0%, #635BFF 55%, #4338ca 100%);
  padding: 20px;
}

.login-card {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  padding: 46px 42px 42px;
  width: 100%;
  max-width: 420px;
}

.login-logo {
  text-align: center;
  margin-bottom: 30px;
}

.login-logo-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  background: var(--primary);
  border-radius: 14px;
  font-size: 26px;
  margin-bottom: 16px;
  box-shadow: 0 4px 16px rgba(99,91,255,.45);
}

.login-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text);
  margin-bottom: 4px;
  letter-spacing: -.3px;
}

.login-subtitle {
  font-size: 13.5px;
  color: var(--text-muted);
}

.login-form { margin-top: 26px; }

/* ============================================================
   Utility
============================================================ */
.text-muted   { color: var(--text-muted); }
.text-center  { text-align: center; }
.text-right   { text-align: right; }
.fw-600       { font-weight: 600; }
.mt-1 { margin-top:  6px; }
.mt-2 { margin-top: 12px; }
.mt-3 { margin-top: 20px; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom:  6px; }
.mb-2 { margin-bottom: 12px; }
.mb-3 { margin-bottom: 20px; }
.d-flex          { display: flex; }
.align-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2           { gap: 8px; }

/* ============================================================
   Pagination
============================================================ */
.pagination {
  display: flex;
  gap: 5px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
}

.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 34px;
  height: 34px;
  padding: 0 8px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  transition: all var(--transition);
  user-select: none;
}

.page-link:hover {
  background: var(--bg);
  color: var(--text);
  text-decoration: none;
}

.page-link.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  font-weight: 700;
  pointer-events: none;
}

.page-link.disabled {
  opacity: .3;
  pointer-events: none;
}

/* ============================================================
   Modal（ポップアップ）
============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 20, 40, .52);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  visibility: hidden;
  transition: opacity .22s ease, visibility .22s ease;
}

.modal-overlay.open {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.28);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(-18px) scale(.97);
  transition: transform .22s ease;
}

.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 1;
  border-radius: 14px 14px 0 0;
}

.modal-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  font-family: inherit;
  flex-shrink: 0;
}

.modal-close:hover {
  background: var(--bg);
  color: var(--text);
}

.modal-body {
  padding: 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-radius: 0 0 14px 14px;
}

/* ============================================================
   select (form-control 対応)
============================================================ */
select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%236b7c93' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ============================================================
   顧客プランサブパネル（expandable rows）
============================================================ */

/* 展開ボタン */
.expand-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 10px;
  width: 26px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: background var(--transition), color var(--transition);
  padding: 0;
  line-height: 1;
}

.expand-btn:hover {
  background: var(--primary-soft);
  color: var(--primary);
}

.expand-btn.open {
  color: var(--primary);
  background: var(--primary-soft);
}

/* プラン件数バッジ */
.item-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 22px;
  height: 20px;
  padding: 0 6px;
  background: var(--primary-soft);
  color: var(--primary);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
}

/* サブパネルを含む行（余白ゼロ） */
.items-row > td {
  padding: 0 !important;
  border-top: none !important;
}

/* サブパネルラッパー（高さ制御） */
.items-panel {
  display: none;
  padding: 4px 16px 12px 52px;
  background: var(--bg);
}

.items-panel.open {
  display: block;
}

/* サブパネル内カード */
.items-panel-inner {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* サブパネル内テーブル */
.items-panel-inner table {
  width: 100%;
  border-collapse: collapse;
}

.items-panel-inner table th,
.items-panel-inner table td {
  font-size: 12.5px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}

.items-panel-inner table th {
  background: var(--bg);
  font-weight: 600;
  color: var(--text-muted);
  font-size: 11.5px;
  text-transform: none;
}

.items-panel-inner table tbody tr:last-child td {
  border-bottom: none;
}

.items-panel-inner table tbody tr:hover {
  background: rgba(99, 91, 255, .03);
}

/* サブパネルフッター（プラン追加ボタン行） */
.items-panel-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
}

/* ============================================================
   決済系ページ タブナビゲーション（filter-tab と同デザイン）
============================================================ */
.payment-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.payment-tab {
  display: inline-block;
  padding: 6px 16px;
  border-radius: 20px;
  font-size: 12.5px;
  font-weight: 600;
  border: 1.5px solid var(--border);
  color: var(--text-muted);
  background: var(--surface);
  text-decoration: none;
  transition: all var(--transition);
  white-space: nowrap;
}
.payment-tab:hover {
  border-color: var(--primary);
  color: var(--primary);
  text-decoration: none;
}
.payment-tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

/* ============================================================
   登録モーダル内 プランアイテム行（動的追加）
============================================================ */
.plan-item {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 12px;
  background: var(--bg);
}

.plan-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
}

.plan-item-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.plan-item-remove {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--danger);
  font-size: 11.5px;
  padding: 3px 10px;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition);
  line-height: 1.5;
}

.plan-item-remove:hover {
  background: rgba(224, 32, 32, .06);
  border-color: var(--danger);
}
