/* ============================================================
   ミリーちゃん管理ダッシュボード CSS
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #070710;
  --bg2:      #0d0d1a;
  --bg3:      #13131f;
  --surface:  #1a1a2e;
  --border:   rgba(102,0,204,0.18);
  --border2:  rgba(102,0,204,0.35);
  --purple:   #6600cc;
  --purple2:  #4a0080;
  --purple3:  #8800ff;
  --red:      #cc0044;
  --red2:     #ff0055;
  --green:    #06c755;
  --yellow:   #ffcc00;
  --white:    #f0eeff;
  --gray:     #8888aa;
  --gray2:    #555570;

  --font:     'Noto Sans JP', sans-serif;
  --font-r:   'M PLUS Rounded 1c', sans-serif;
  --mono:     'JetBrains Mono', monospace;

  --sidebar-w: 240px;
  --topbar-h:  64px;
  --radius:    12px;
}

html, body { height: 100%; font-size: 14px; }
body {
  background: var(--bg);
  color: var(--white);
  font-family: var(--font);
  display: flex;
  overflow: hidden;
}

/* ============================================================
   SIDEBAR
   ============================================================ */
#sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: fixed;
  left: 0; top: 0;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 24px 20px;
  border-bottom: 1px solid var(--border);
}
.logo-icon { font-size: 1.5rem; }
.logo-title { font-family: var(--font-r); font-weight: 700; font-size: 1rem; letter-spacing: 0.1em; }
.logo-sub   { font-size: 0.68rem; color: var(--gray); letter-spacing: 0.05em; margin-top: 2px; }

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  overflow-y: auto;
}

.snav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--gray);
  font-size: 0.85rem;
  font-family: var(--font-r);
  transition: background 0.2s, color 0.2s;
  text-decoration: none;
  cursor: pointer;
}
.snav-item:hover   { background: rgba(102,0,204,0.08); color: var(--white); }
.snav-item.active  { background: rgba(102,0,204,0.18); color: var(--white); border: 1px solid var(--border2); }
.snav-icon { font-size: 1rem; width: 20px; text-align: center; }

.snav-divider { height: 1px; background: var(--border); margin: 8px 4px; }

.sidebar-status {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.72rem;
  color: var(--gray);
  font-family: var(--font-r);
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gray2);
}
.status-dot.active {
  background: var(--green);
  box-shadow: 0 0 8px var(--green);
  animation: statusPulse 2s ease-in-out infinite;
}
@keyframes statusPulse { 0%,100%{opacity:1} 50%{opacity:0.4} }

/* ============================================================
   MAIN
   ============================================================ */
#main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

/* Top Bar */
.topbar {
  height: var(--topbar-h);
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  flex-shrink: 0;
}
.topbar-title {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: 0.05em;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}
.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 14px;
}
.search-box input {
  background: none;
  border: none;
  outline: none;
  color: var(--white);
  font-family: var(--font);
  font-size: 0.82rem;
  width: 180px;
}
.search-box input::placeholder { color: var(--gray2); }

.tb-btn {
  background: rgba(102,0,204,0.15);
  border: 1px solid var(--border2);
  color: var(--white);
  font-family: var(--font-r);
  font-size: 0.8rem;
  padding: 7px 16px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}
.tb-btn:hover { background: rgba(102,0,204,0.3); }

.topbar-avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: radial-gradient(var(--purple3), var(--purple2));
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem;
}

/* ============================================================
   PAGE SYSTEM
   ============================================================ */
.page {
  display: none;
  flex: 1;
  overflow-y: auto;
  padding: 28px;
  flex-direction: column;
  gap: 20px;
}
.page.active { display: flex; }

/* ============================================================
   OVERVIEW — Stats
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}
.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  transition: border-color 0.2s, transform 0.2s;
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, var(--purple), var(--purple3));
  opacity: 0;
  transition: opacity 0.3s;
}
.stat-card:hover { border-color: var(--border2); transform: translateY(-2px); }
.stat-card:hover::before { opacity: 1; }
.stat-icon { font-size: 1.8rem; }
.stat-body { flex: 1; }
.stat-num  { font-size: 2rem; font-weight: 700; line-height: 1; letter-spacing: -0.02em; }
.stat-label { font-size: 0.72rem; color: var(--gray); margin-top: 4px; font-family: var(--font-r); }
.stat-trend { font-size: 0.68rem; font-family: var(--font-r); padding: 3px 8px; border-radius: 100px; }
.stat-trend.up      { color: var(--green); background: rgba(6,199,85,0.1); }
.stat-trend.neutral { color: var(--gray);  background: rgba(255,255,255,0.05); }

/* Overview Grid */
.overview-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}
.full-width { grid-column: 1 / -1; }

/* Card */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.card-header h3 { font-size: 0.95rem; font-weight: 700; letter-spacing: 0.05em; }
.card-badge {
  font-size: 0.65rem;
  font-family: var(--font-r);
  padding: 3px 10px;
  border-radius: 100px;
  background: rgba(102,0,204,0.15);
  color: var(--purple3);
  border: 1px solid rgba(102,0,204,0.3);
}

/* Phase Distribution */
.phase-dist { display: flex; flex-direction: column; gap: 12px; }
.pd-row { display: flex; align-items: center; gap: 12px; }
.pd-label { font-family: var(--font-r); font-size: 0.75rem; color: var(--gray); width: 80px; flex-shrink: 0; }
.pd-bar-wrap { flex: 1; background: rgba(255,255,255,0.05); border-radius: 100px; height: 8px; overflow: hidden; }
.pd-bar { height: 100%; border-radius: 100px; transition: width 1s cubic-bezier(0.4,0,0.2,1); width: 0; }
.pd-bar.p1 { background: var(--green); }
.pd-bar.p2 { background: var(--yellow); }
.pd-bar.p3 { background: var(--red2); }
.pd-bar.p4 { background: var(--purple3); }
.pd-num { font-family: var(--mono); font-size: 0.75rem; color: var(--gray); width: 32px; text-align: right; }

/* Ending Chart */
.ending-chart { display: flex; flex-direction: column; gap: 14px; }
.ec-item { display: flex; align-items: center; gap: 14px; }
.ec-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.ec-label { font-family: var(--font-r); font-size: 0.8rem; flex: 1; }
.ec-bar-wrap { width: 120px; background: rgba(255,255,255,0.05); border-radius: 100px; height: 6px; overflow: hidden; }
.ec-bar { height: 100%; border-radius: 100px; transition: width 1s cubic-bezier(0.4,0,0.2,1); width: 0; }
.ec-pct { font-family: var(--mono); font-size: 0.72rem; color: var(--gray); width: 34px; text-align: right; }

/* Activity Log */
.activity-log { display: flex; flex-direction: column; gap: 0; }
.al-row {
  display: grid;
  grid-template-columns: 140px 100px 1fr 100px;
  align-items: center;
  padding: 12px 0;
  border-bottom: 1px solid rgba(102,0,204,0.08);
  font-size: 0.8rem;
  gap: 12px;
}
.al-row.header { color: var(--gray); font-size: 0.7rem; letter-spacing: 0.08em; font-family: var(--font-r); }
.al-row:last-child { border-bottom: none; }
.al-id { font-family: var(--mono); font-size: 0.72rem; color: var(--purple3); }
.al-time { color: var(--gray); font-size: 0.72rem; }
.al-msg { color: var(--white); }
.al-phase { }

/* ============================================================
   SCENARIOS PAGE
   ============================================================ */
.page-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}

.btn-primary {
  background: var(--purple);
  color: var(--white);
  border: none;
  font-family: var(--font-r);
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s;
}
.btn-primary:hover { background: var(--purple3); transform: scale(1.02); }

.btn-ghost {
  background: transparent;
  color: var(--gray);
  border: 1px solid var(--border);
  font-family: var(--font-r);
  font-size: 0.85rem;
  padding: 10px 20px;
  border-radius: 8px;
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s;
}
.btn-ghost:hover { border-color: var(--border2); color: var(--white); }

.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
  color: var(--gray);
}
.btn-icon:hover { background: rgba(255,255,255,0.08); color: var(--white); }
.btn-icon.danger:hover { background: rgba(204,0,68,0.15); color: var(--red2); }

.filter-tabs { display: flex; gap: 6px; }
.ftab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--gray);
  font-family: var(--font-r);
  font-size: 0.75rem;
  padding: 6px 14px;
  border-radius: 100px;
  cursor: pointer;
  transition: all 0.2s;
}
.ftab.active, .ftab:hover { background: rgba(102,0,204,0.18); border-color: var(--border2); color: var(--white); }

/* Scenario List */
.scenario-list { display: flex; flex-direction: column; gap: 10px; }
.scenario-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: grid;
  grid-template-columns: 80px 90px 130px 1fr 110px 80px 80px;
  align-items: center;
  gap: 12px;
  transition: border-color 0.2s, background 0.2s;
}
.scenario-card:hover { border-color: var(--border2); background: rgba(102,0,204,0.04); }
.scenario-card.header {
  background: var(--bg3);
  border-color: var(--border);
  font-size: 0.7rem;
  color: var(--gray);
  letter-spacing: 0.08em;
  font-family: var(--font-r);
  padding: 10px 20px;
}

.sc-id      { font-family: var(--mono); font-size: 0.78rem; color: var(--purple3); }
.sc-phase   { }
.sc-trigger { font-family: var(--mono); font-size: 0.72rem; color: var(--gray); }
.sc-msg     { font-size: 0.82rem; color: var(--white); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.sc-time    { font-size: 0.72rem; font-family: var(--font-r); }
.sc-active  { }
.sc-actions { display: flex; gap: 4px; justify-content: flex-end; }

/* Phase Badge */
.phase-badge {
  display: inline-block;
  font-family: var(--font-r);
  font-size: 0.68rem;
  padding: 3px 10px;
  border-radius: 100px;
  font-weight: 700;
}
.phase-badge.p1 { background: rgba(6,199,85,0.12);   color: var(--green);   border: 1px solid rgba(6,199,85,0.3); }
.phase-badge.p2 { background: rgba(255,204,0,0.12);  color: var(--yellow);  border: 1px solid rgba(255,204,0,0.3); }
.phase-badge.p3 { background: rgba(255,0,85,0.12);   color: var(--red2);    border: 1px solid rgba(255,0,85,0.3); }
.phase-badge.p4 { background: rgba(136,0,255,0.12);  color: var(--purple3); border: 1px solid rgba(136,0,255,0.3); }

/* Toggle */
.toggle { position: relative; display: inline-block; width: 40px; height: 22px; }
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 100px;
  cursor: pointer;
  transition: 0.2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 2px; top: 2px;
  background: var(--gray);
  border-radius: 50%;
  transition: 0.2s;
}
.toggle input:checked + .toggle-slider { background: rgba(102,0,204,0.3); border-color: var(--purple); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); background: var(--purple3); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(6px);
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 16px;
  width: 560px;
  max-width: 95vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 40px rgba(102,0,204,0.15);
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 700; }
.modal-close {
  background: none; border: none; color: var(--gray); cursor: pointer; font-size: 1rem;
  width: 30px; height: 30px; border-radius: 6px; transition: background 0.2s;
}
.modal-close:hover { background: rgba(255,255,255,0.08); color: var(--white); }

.modal-body {
  padding: 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group label { font-size: 0.75rem; color: var(--gray); font-family: var(--font-r); letter-spacing: 0.05em; }
.hint { color: var(--purple3); font-size: 0.68rem; margin-left: 8px; }
.form-group input, .form-group select, .form-group textarea {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--white);
  font-family: var(--font);
  font-size: 0.85rem;
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.2s;
  resize: vertical;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--purple); }
.form-group select option { background: var(--bg2); }

.toggle-row { flex-direction: row; align-items: center; justify-content: space-between; }

/* ============================================================
   USERS PAGE
   ============================================================ */
.user-summary {
  display: flex; gap: 12px;
  font-family: var(--font-r); font-size: 0.78rem; color: var(--gray);
}
.us-chip {
  padding: 5px 12px;
  border-radius: 100px;
  border: 1px solid var(--border);
  background: var(--bg2);
}

.table-wrap { overflow-x: auto; }
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.data-table th {
  text-align: left;
  padding: 10px 14px;
  font-size: 0.7rem;
  color: var(--gray);
  letter-spacing: 0.08em;
  font-family: var(--font-r);
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
  white-space: nowrap;
}
.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid rgba(102,0,204,0.07);
  vertical-align: middle;
}
.data-table tr:hover td { background: rgba(102,0,204,0.04); }

.ending-badge {
  display: inline-block;
  font-family: var(--font-r);
  font-size: 0.65rem;
  padding: 3px 9px;
  border-radius: 100px;
}
.eb-none   { background: rgba(255,255,255,0.05); color: var(--gray); }
.eb-spread { background: rgba(6,199,85,0.12);  color: var(--green);   border: 1px solid rgba(6,199,85,0.2); }
.eb-ignore { background: rgba(255,0,85,0.12);  color: var(--red2);    border: 1px solid rgba(255,0,85,0.2); }
.eb-silent { background: rgba(102,0,204,0.12); color: var(--purple3); border: 1px solid rgba(102,0,204,0.2); }

.active-chip {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 6px var(--green);
}
.inactive-chip {
  display: inline-block;
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--gray2);
}

/* ============================================================
   FLOW PAGE
   ============================================================ */
.flow-canvas {
  position: relative;
  min-height: 600px;
  overflow-x: auto;
}
.fc-wrapper {
  display: flex;
  gap: 40px;
  padding: 20px;
  min-width: 900px;
}
.fc-col {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 180px;
}
.fc-col-label {
  font-family: var(--font-r);
  font-size: 0.68rem;
  letter-spacing: 0.15em;
  color: var(--gray);
  text-align: center;
  margin-bottom: 4px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
}
.fc-node {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 14px;
  font-family: var(--font-r);
  font-size: 0.78rem;
  cursor: default;
  transition: border-color 0.2s, transform 0.2s;
  position: relative;
}
.fc-node:hover { border-color: var(--border2); transform: scale(1.02); }
.fc-node.p1 { border-color: rgba(6,199,85,0.3);   box-shadow: 0 0 12px rgba(6,199,85,0.08); }
.fc-node.p2 { border-color: rgba(255,204,0,0.3);  box-shadow: 0 0 12px rgba(255,204,0,0.08); }
.fc-node.p3 { border-color: rgba(255,0,85,0.3);   box-shadow: 0 0 12px rgba(255,0,85,0.08); }
.fc-node.p4 { border-color: rgba(136,0,255,0.3);  box-shadow: 0 0 12px rgba(136,0,255,0.1); }
.fc-node-id { font-family: var(--mono); font-size: 0.65rem; color: var(--purple3); margin-bottom: 4px; }
.fc-node-trigger { font-size: 0.65rem; color: var(--gray); margin-top: 4px; }

.fc-arrow-col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  color: var(--gray2);
  font-size: 1.2rem;
  padding-top: 36px;
}

/* ============================================================
   TOAST
   ============================================================ */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 12px 18px;
  font-family: var(--font-r);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  animation: toastIn 0.3s ease;
  min-width: 240px;
}
@keyframes toastIn { from{opacity:0;transform:translateY(10px)} to{opacity:1;transform:translateY(0)} }
.toast.success { border-color: rgba(6,199,85,0.4); }
.toast.error   { border-color: rgba(255,0,85,0.4); }

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(102,0,204,0.3); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: rgba(102,0,204,0.5); }
