/* =============================================
   CSPJ Manage — Admin UI Stylesheet
   /public/css/manage.css
   Vanilla CSS。外部フレームワーク・ビルド工程なし。
   ============================================= */

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

:root {
  --bg:          #0b0d12;
  --surface:     #12151c;
  --surface-2:   #171b24;
  --border:      #232733;

  --text:        #e6e8ec;
  --text-dim:    #9095a3;
  --text-muted:  #5b6172;

  --accent:      #7c6cf6;
  --accent-dim:  rgba(124, 108, 246, 0.15);

  --success:     #34d399;
  --success-dim: rgba(52, 211, 153, 0.12);
  --danger:      #f87171;
  --danger-dim:  rgba(248, 113, 113, 0.12);

  --radius: 10px;
  --sidebar-w: 248px;
  --topbar-h: 56px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
}

html, body { margin: 0; padding: 0; }

/* 重要: .gate / .app に display:flex を直接指定しているため、そのままでは
   author stylesheetの規則がUAデフォルトの [hidden]{display:none} を上書きしてしまい、
   hidden属性が効かなくなる。明示的に最優先で無効化する。 */
[hidden] { display: none !important; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

a { color: inherit; text-decoration: none; }
button, input, select { font-family: inherit; }

/* ─── Auth gate ──────────────────────────────── */
.gate {
  min-height: 100svh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.gate__card {
  max-width: 420px;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
}

.gate__card h1 { font-size: 1.05rem; margin: 0 0 0.75rem; }
.gate__card p { color: var(--text-dim); margin: 0 0 1rem; word-break: break-word; }

.gate__card button {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  padding: 0.6rem 1.25rem;
  cursor: pointer;
  font-size: 0.85rem;
}

.gate__logout-link {
  display: inline-block;
  margin-top: 0.5rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.gate__logout-link:hover { color: var(--text); }

/* ─── App shell ──────────────────────────────── */
.app { display: flex; min-height: 100svh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 0.9rem;
  position: sticky;
  top: 0;
  height: 100svh;
  overflow-y: auto;
}

.sidebar__brand {
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  padding: 0 0.5rem 1.5rem;
}
.sidebar__brand span { color: var(--accent); }

.sidebar__nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
}

.nav-link {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-dim);
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-link:hover { background: var(--surface-2); color: var(--text); }
.nav-link.is-active { background: var(--accent-dim); color: var(--text); }

.soon-badge {
  font-size: 0.6rem;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  white-space: nowrap;
}

.sidebar__divider {
  height: 1px;
  background: var(--border);
  margin: 0.75rem 0.5rem;
}

.sidebar__user {
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
  margin-top: 0.9rem;
}
.sidebar__user-email { font-size: 0.78rem; color: var(--text); word-break: break-all; }
.sidebar__user-role {
  display: inline-block;
  margin-top: 0.35rem;
  font-size: 0.62rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 999px;
  padding: 0.1rem 0.5rem;
}
.sidebar__logout {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.sidebar__logout:hover { color: var(--text); }

.app__body {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0 1.5rem;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg);
  z-index: 10;
}
.topbar__title { font-size: 0.95rem; font-weight: 600; margin: 0; }

.topbar__menu {
  display: none;
  flex-direction: column;
  justify-content: center;
  gap: 4px;
  width: 36px;
  height: 36px;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  flex-shrink: 0;
}
.topbar__menu span { display: block; height: 1.5px; background: var(--text); margin: 0 7px; }

.content { padding: 1.5rem; flex: 1; min-width: 0; }

/* ─── Shared components ──────────────────────── */
.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.stat-card__value { font-size: 1.9rem; font-weight: 700; }
.stat-card__label { font-size: 0.78rem; color: var(--text-dim); margin-top: 0.25rem; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
}
.panel h2 { font-size: 0.95rem; margin: 0 0 0.5rem; }
.panel p { color: var(--text-dim); margin: 0; }

.toolbar { display: flex; justify-content: flex-end; margin-bottom: 1rem; }

.btn {
  border-radius: 8px;
  padding: 0.55rem 1.1rem;
  font-size: 0.82rem;
  cursor: pointer;
  border: 1px solid transparent;
}
.btn--primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn--primary:hover { filter: brightness(1.08); }
.btn--primary:disabled { opacity: 0.6; cursor: not-allowed; }
.btn--ghost { background: transparent; color: var(--text-dim); border-color: var(--border); }
.btn--ghost:hover { color: var(--text); border-color: var(--text-dim); }

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-x: auto;
}
.table { width: 100%; border-collapse: collapse; min-width: 560px; }
.table th, .table td {
  text-align: left;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.82rem;
}
.table th {
  color: var(--text-muted);
  font-weight: 500;
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
.table tr:last-child td { border-bottom: none; }
.table code {
  background: var(--surface-2);
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  font-size: 0.78rem;
}
.table__actions { text-align: right; white-space: nowrap; }

.status-badge {
  display: inline-block;
  font-size: 0.68rem;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.status-badge--active { background: var(--success-dim); color: var(--success); }
.status-badge--inactive { background: rgba(255, 255, 255, 0.06); color: var(--text-muted); }

.empty-state, .loading {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem 1.5rem;
  text-align: center;
  color: var(--text-dim);
}

.error-banner {
  background: var(--danger-dim);
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.82rem;
}

/* ─── Modal ───────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 6, 10, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
  z-index: 100;
}
.modal {
  width: 100%;
  max-width: 420px;
  max-height: 90svh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}
.modal h2 { font-size: 1rem; margin: 0 0 1.1rem; }

.form-row { margin-bottom: 1rem; display: flex; flex-direction: column; gap: 0.35rem; }
.form-row label { font-size: 0.75rem; color: var(--text-dim); }
.form-row input, .form-row select {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.7rem;
  color: var(--text);
  font-size: 0.85rem;
  width: 100%;
}
.form-row input:focus, .form-row select:focus {
  outline: none;
  border-color: var(--accent);
}
.form-row input:disabled { color: var(--text-muted); }

.form-error {
  background: var(--danger-dim);
  color: var(--danger);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.78rem;
  margin-bottom: 1rem;
}

.form-success {
  background: var(--success-dim);
  color: var(--success);
  border-radius: 8px;
  padding: 0.6rem 0.8rem;
  font-size: 0.78rem;
  margin: 0 0 1rem;
}

.form-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  margin-top: 1.25rem;
}

/* ─── Responsive ──────────────────────────────── */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    height: 100svh;
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    z-index: 90;
  }
  .sidebar.is-open {
    transform: translateX(0);
    box-shadow: 20px 0 40px rgba(0, 0, 0, 0.4);
  }
  .topbar__menu { display: flex; }
  .content { padding: 1rem; }
}

@media (max-width: 480px) {
  .card-grid { grid-template-columns: 1fr 1fr; }
  .modal { padding: 1.25rem; }
}

:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
