/* ガルーン認証ゲートウェイ 共通スタイル
   色は紺（淀川ヒューテックの社内ツールとして落ち着いた配色）。OS の設定でダークモードに自動切替。 */

:root {
  --bg: #f3f4f7;
  --surface: #ffffff;
  --surface-2: #f7f8fb;
  --ink: #1a2233;
  --muted: #5a6578;
  --faint: #8a93a4;
  --line: #d9dee7;
  --accent: #243b7a;
  --accent-hover: #1b2f64;
  --accent-ink: #ffffff;
  --accent-text: #243b7a;
  --accent-soft: #e8edf9;
  --danger: #b3261e;
  --danger-soft: #fdeceb;
  --ok: #1d7a4d;
  --ok-soft: #e5f4ec;
  --info-soft: #e8edf9;
  --focus: rgba(36, 59, 122, .28);
  --shadow-pop: 0 18px 50px rgba(16, 24, 40, .22);
  --radius: 10px;
  --radius-sm: 8px;
  --font: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "BIZ UDPGothic", "Yu Gothic UI", "Noto Sans JP", system-ui, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #171d2c;
    --surface-2: #1d2436;
    --ink: #e7ebf3;
    --muted: #9aa6bb;
    --faint: #6f7b91;
    --line: #2a3348;
    --accent: #4f74d8;
    --accent-hover: #6585e3;
    --accent-ink: #ffffff;
    --accent-text: #9db8ff;
    --accent-soft: #1f2a4a;
    --danger: #ff8f86;
    --danger-soft: #3a1d1f;
    --ok: #6fd3a0;
    --ok-soft: #173326;
    --info-soft: #1f2a4a;
    --focus: rgba(157, 184, 255, .35);
    --shadow-pop: 0 18px 50px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.75 var(--font);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
h1 { font-size: 1.4rem; line-height: 1.4; margin: 0 0 1.1rem; font-weight: 700; }
h2 { font-size: 1.05rem; line-height: 1.5; margin: 0 0 .75rem; font-weight: 700; }
h3 { font-size: 1rem; margin: 0 0 .5rem; font-weight: 700; }
p { margin: .5rem 0; }
form { margin: 0; }
form.inline { display: inline; }
.muted { color: var(--muted); font-size: .9rem; }
.hint { color: var(--muted); font-size: .85rem; margin: .75rem 0 1rem; }
form ~ .hint, .auth-card > .hint:last-child { margin-bottom: 0; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; }

/* ---- フォーム部品 ---- */
label { display: block; font-size: .85rem; font-weight: 700; color: var(--ink); margin: 0 0 .35rem; }
input[type=text], input[type=email], input[type=password], input[type=search], select {
  width: 100%;
  min-height: 2.75rem;
  padding: .55rem .8rem;
  margin: 0 0 1rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1rem;
}
input[readonly] { background: var(--surface-2); color: var(--muted); }
input:focus, select:focus { border-color: var(--accent); outline: 3px solid var(--focus); outline-offset: 0; }
input::placeholder { color: var(--faint); }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); }

.btn, button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 2.5rem;
  padding: .5rem 1.1rem;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: var(--accent-ink);
  font: inherit;
  font-size: .92rem;
  font-weight: 700;
  line-height: 1.2;
  cursor: pointer;
  text-decoration: none;
  transition: background-color .12s ease;
}
.btn:hover, button:hover { background: var(--accent-hover); text-decoration: none; }
.btn.secondary, button.secondary { background: var(--surface); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover, button.secondary:hover { background: var(--surface-2); }
.btn.ghost, button.ghost { background: transparent; color: var(--accent-text); border-color: var(--line); }
.btn.ghost:hover, button.ghost:hover { background: var(--accent-soft); }
button.danger, .btn.danger { background: var(--danger); color: #fff; }
button.danger:hover, .btn.danger:hover { filter: brightness(.92); background: var(--danger); }

/* ---- メッセージ ---- */
.error, .info {
  padding: .75rem .9rem;
  border-radius: var(--radius-sm);
  margin: 0 0 1rem;
  font-size: .9rem;
  border-left: 4px solid;
}
.error { background: var(--danger-soft); color: var(--danger); border-color: var(--danger); }
.info { background: var(--info-soft); color: var(--accent-text); border-color: var(--accent); }

/* ---- 認証画面（ログイン・登録・認証コードなど） ---- */
.auth-shell { min-height: 100vh; display: flex; flex-direction: column; align-items: center; padding: 2.5rem 1rem 1.5rem; }
.auth-brand { width: 100%; max-width: 420px; margin: 0 0 1.25rem; display: flex; align-items: baseline; gap: .6rem; }
.auth-brand .org { font-weight: 700; font-size: 1rem; letter-spacing: .04em; }
.auth-brand .app { color: var(--muted); font-size: .85rem; }
.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-top: 4px solid var(--accent);
  border-radius: var(--radius);
  padding: 1.75rem 1.75rem 1.5rem;
}
.auth-card h1 { font-size: 1.3rem; margin-bottom: 1.1rem; }
.auth-card button[type=submit] { width: 100%; min-height: 2.9rem; font-size: 1rem; }
.auth-card button.secondary { width: 100%; margin-top: .6rem; }
.auth-card form + form { margin-top: .6rem; }
.auth-card .hint a { font-weight: 700; }

/* ログインの 2 段階（パスワード → メール認証）を示す */
.steps { display: flex; gap: .5rem; list-style: none; padding: 0; margin: 0 0 1.25rem; font-size: .8rem; }
.steps li { flex: 1; display: flex; align-items: center; gap: .45rem; color: var(--faint); padding-bottom: .5rem; border-bottom: 2px solid var(--line); font-weight: 700; }
.steps li .n { display: inline-grid; place-items: center; width: 1.3rem; height: 1.3rem; border-radius: 50%; border: 1.5px solid currentColor; font-size: .72rem; }
.steps li.current { color: var(--accent-text); border-color: var(--accent); }
.steps li.done { color: var(--ok); border-color: var(--ok); }

.helpdesk {
  display: flex; flex-wrap: wrap; gap: .2rem 1rem; align-items: baseline;
  color: var(--muted); font-size: .82rem;
}
.helpdesk strong { color: var(--ink); font-weight: 700; }
.auth-shell .helpdesk { width: 100%; max-width: 420px; margin-top: 1.25rem; }

/* パスワード条件のチェックリスト（入力に合わせて更新） */
.pw-rules { list-style: none; margin: -.25rem 0 1rem; padding: .7rem .9rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); font-size: .85rem; display: grid; gap: .25rem; }
.pw-rules li { color: var(--muted); padding-left: 1.5rem; position: relative; }
.pw-rules li::before { content: "○"; position: absolute; left: 0; color: var(--faint); }
.pw-rules li.ok { color: var(--ok); font-weight: 700; }
.pw-rules li.ok::before { content: "✓"; color: var(--ok); }
.pw-rules li.ng { color: var(--danger); }
.pw-rules li.ng::before { content: "×"; color: var(--danger); }
button:disabled, button:disabled:hover { background: var(--line); color: var(--faint); cursor: not-allowed; border-color: transparent; }

/* ---- アプリ画面（ログイン後・管理） ---- */
header { background: var(--surface); border-bottom: 1px solid var(--line); padding: 0 1.5rem; position: sticky; top: 0; z-index: 20; }
header .inner { max-width: 1180px; margin: 0 auto; display: flex; align-items: center; justify-content: space-between; min-height: 3.5rem; gap: 1rem; }
header a { color: var(--muted); font-size: .9rem; font-weight: 700; text-decoration: none; }
header a:hover { color: var(--ink); }
nav { display: flex; gap: .25rem; align-items: center; white-space: nowrap; min-width: max-content; }
nav a { display: inline-flex; align-items: center; min-height: 3.5rem; padding: 0 .8rem; border-bottom: 3px solid transparent; }
nav a.active { color: var(--accent-text); border-bottom-color: var(--accent); }
.brand { font-weight: 700; color: var(--ink); margin-right: 1.25rem; flex: 0 0 auto; letter-spacing: .02em; }
.user-chip { font-size: .82rem; color: var(--muted); }
.header-left { display: flex; align-items: center; min-width: 0; flex: 1 1 auto; overflow: hidden; }
.nav-scroll { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.nav-scroll::-webkit-scrollbar { display: none; }
.header-right { display: flex; align-items: center; gap: .85rem; flex: 0 0 auto; }
.header-right button.secondary { min-height: 2.2rem; padding: .3rem .85rem; font-size: .85rem; }
.nav-badge { display: inline-flex; align-items: center; justify-content: center; min-width: 1.25rem; height: 1.25rem; padding: 0 .35rem; margin-left: .35rem; border-radius: 999px; background: var(--danger); color: #fff; font-size: .7rem; font-weight: 700; line-height: 1; }

main { max-width: 1180px; margin: 0 auto; padding: 1.75rem 1.5rem; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem 1.5rem; margin-bottom: 1.25rem; }
.actions { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; margin-bottom: 1.25rem; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; }
.stat .num { font-size: 1.9rem; font-weight: 700; line-height: 1.2; color: var(--accent-text); }
.stat .label { font-size: .82rem; color: var(--muted); margin-top: .2rem; }
.stat .value { font-size: 1rem; font-weight: 700; word-break: break-word; }
.stat .label + .value { margin-top: .15rem; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .7rem .75rem; text-align: left; border-bottom: 1px solid var(--line); font-size: .9rem; }
th { background: var(--surface-2); color: var(--muted); font-size: .8rem; font-weight: 700; white-space: nowrap; }
tbody tr:hover td { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: 0; }

.badge { display: inline-block; font-size: .72rem; font-weight: 700; padding: .12rem .5rem; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--line); }
.badge.admin { background: var(--accent-soft); color: var(--accent-text); border-color: transparent; }
.badge.inactive, .status-ng { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.status-ok { background: var(--ok-soft); color: var(--ok); }
.status-text { color: var(--ok); font-weight: 700; font-size: .85rem; }

.app-footer { max-width: 1180px; margin: 0 auto; padding: 0 1.5rem 2rem; }

/* ---- ユーザー管理・承認待ち ---- */
.page-head { display: flex; justify-content: space-between; gap: 1rem; align-items: center; margin-bottom: 1.15rem; }
.page-head h1, .users-page h1 { margin: 0; }
.page-actions { display: flex; gap: .55rem; align-items: center; }
.user-table-card, .logs-table-card { padding: 0; overflow: hidden; }
.user-table-wrap, .logs-table-wrap { overflow-x: auto; }
.user-table { min-width: 860px; }
.user-table td { vertical-align: middle; padding: .85rem .75rem; }
.user-name, .log-user { font-weight: 700; }
.user-meta { color: var(--muted); font-size: .82rem; margin-top: .2rem; word-break: break-word; }
.actions-cell { width: 280px; }
.row-actions { display: flex; gap: .4rem; align-items: center; flex-wrap: nowrap; }
.row-actions .btn, .row-actions button { min-width: 56px; min-height: 2.15rem; padding: .35rem .7rem; font-size: .85rem; white-space: nowrap; }
.empty-cell { color: var(--faint); }
.empty-state, .empty-log { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

.modal-toggle { position: fixed; opacity: 0; pointer-events: none; }
.modal { position: fixed; inset: 0; z-index: 1000; display: none; align-items: center; justify-content: center; padding: 1.5rem; }
.modal-toggle:checked + .modal { display: flex; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(8, 12, 22, .55); cursor: pointer; }
.modal-dialog { position: relative; z-index: 1; width: min(720px, 100%); max-height: min(760px, calc(100vh - 3rem)); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-pop); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-close { display: inline-flex; align-items: center; justify-content: center; width: 2rem; height: 2rem; border-radius: var(--radius-sm); color: var(--muted); cursor: pointer; font-size: 1.4rem; line-height: 1; }
.modal-close:hover { background: var(--surface-2); color: var(--ink); }
.modal-body { padding: 1.25rem; }
.modal-note { margin-top: .85rem; margin-bottom: 0; }
.user-form { display: grid; gap: 1rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .85rem; align-items: start; }
.form-field { min-width: 0; }
.form-field input[type=text], .form-field input[type=email], .form-field input[type=password] { margin: 0; }
.form-checks { display: flex; flex-wrap: wrap; gap: .9rem; align-items: center; padding-top: .15rem; }
.form-checks label { display: inline-flex; align-items: center; gap: .4rem; margin: 0; }
.form-actions { display: flex; justify-content: flex-end; gap: .55rem; align-items: center; padding-top: .25rem; }

/* ---- ログ ---- */
.logs-page h1 { margin-bottom: 1rem; }
.filter-card { padding: 1rem 1.25rem; }
.filter-form { display: grid; grid-template-columns: 1.2fr .8fr 1fr auto; gap: .75rem; align-items: end; }
.filter-field input, .filter-field select { margin: 0; min-height: 2.5rem; font-size: .92rem; }
.filter-field label { font-size: .78rem; color: var(--muted); }
.filter-actions { display: flex; gap: .5rem; align-items: center; }
.logs-table { min-width: 1040px; }
.logs-table td { vertical-align: top; padding: .75rem .75rem; }
.log-time { white-space: nowrap; font-weight: 700; }
.log-detail { color: var(--muted); max-width: 240px; word-break: break-word; }
.log-agent { color: var(--muted); max-width: 320px; word-break: break-word; font-size: .82rem; line-height: 1.5; }

/* ---- システム管理 ---- */
.system-grid { display: grid; gap: 0; }
.setting-row { display: grid; grid-template-columns: 1fr minmax(240px, 380px); gap: 1.25rem; align-items: center; padding: 1.1rem 0; border-bottom: 1px solid var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-title { font-weight: 700; margin-bottom: .2rem; }
.setting-desc { color: var(--muted); font-size: .85rem; line-height: 1.6; }
.setting-input input[type=text] { margin: 0; }
.switch { display: inline-flex; align-items: center; gap: .5rem; white-space: nowrap; font-weight: 700; margin: 0; justify-self: end; }
.system-actions { display: flex; gap: .65rem; margin-top: 1.1rem; }

/* ---- セッション ---- */
.session-summary { display: grid; grid-template-columns: minmax(160px, 220px) 1fr; gap: 1rem; align-items: stretch; margin-bottom: 1rem; }
.session-count, .session-note { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; }
.session-count { text-align: center; }
.session-count .num { color: var(--accent-text); font-size: 2rem; font-weight: 700; line-height: 1; }
.session-count .label { color: var(--muted); font-size: .85rem; margin-top: .45rem; }
.session-note { color: var(--muted); font-size: .9rem; display: flex; align-items: center; }
.session-list { display: grid; gap: .8rem; }
.session-item { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.1rem; display: grid; grid-template-columns: minmax(180px, 1fr) minmax(320px, 2fr) auto; gap: 1rem; align-items: start; }
.session-user { min-width: 0; }
.session-user .name { font-weight: 700; word-break: break-word; }
.session-user .email { color: var(--muted); font-size: .85rem; margin-top: .2rem; word-break: break-word; }
.session-badges { display: flex; flex-wrap: wrap; gap: .35rem; margin-top: .55rem; }
.session-details { display: grid; grid-template-columns: repeat(2, minmax(140px, 1fr)); gap: .75rem 1rem; min-width: 0; }
.session-field .label { color: var(--muted); font-size: .75rem; margin-bottom: .2rem; font-weight: 700; }
.session-field .value { font-size: .88rem; line-height: 1.5; word-break: break-word; }
.session-ua { grid-column: 1 / -1; }
.session-ua .value { max-height: 4.4rem; overflow: auto; padding: .45rem .6rem; background: var(--surface-2); border: 1px solid var(--line); border-radius: var(--radius-sm); font-family: var(--mono); font-size: .76rem; }
.session-action { min-width: 84px; display: flex; justify-content: flex-end; align-items: flex-start; }
.session-action button { min-width: 64px; }
.session-action .locked { color: var(--muted); font-size: .85rem; white-space: nowrap; padding-top: .55rem; }

/* ---- スマホ ---- */
@media (max-width: 900px) {
  header .inner { flex-direction: column; align-items: stretch; gap: 0; padding-top: .5rem; }
  nav a { min-height: 2.75rem; }
  .header-left { width: 100%; }
  .header-right { width: 100%; justify-content: space-between; padding-bottom: .5rem; }
  .user-chip { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}
@media (max-width: 860px) {
  .session-summary, .session-item, .session-details { grid-template-columns: 1fr; }
  .session-action { justify-content: flex-start; }
}
@media (max-width: 760px) {
  .filter-form { grid-template-columns: 1fr; }
  .filter-actions button, .filter-actions .btn { flex: 1 1 auto; }
  .setting-row { grid-template-columns: 1fr; gap: .6rem; }
  .switch { justify-self: start; }
}
@media (max-width: 640px) {
  header { padding: 0 .8rem; }
  main { padding: 1.1rem .9rem; }
  .app-footer { padding: 0 .9rem 1.5rem; }
  .auth-shell { padding-top: 1.5rem; }
  .auth-card { padding: 1.4rem 1.2rem 1.25rem; }
  .page-head { align-items: stretch; flex-direction: column; }
  .page-actions .btn { text-align: center; }
  .modal { align-items: flex-end; padding: .75rem; }
  .modal-dialog { max-height: calc(100vh - 1.5rem); }
  .form-grid { grid-template-columns: 1fr; }
  .form-actions { align-items: stretch; flex-direction: column-reverse; }
  .form-actions button, .form-actions .btn { width: 100%; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
