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

:root {
  --bg: #12161e;
  --bg-elev: rgba(255, 255, 255, 0.06);
  --bg-input: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.96);
  --muted: rgba(255, 255, 255, 0.55);
  --accent: #4a86c4;
  --accent-hover: #5c98d4;
  --danger: #d46a6a;
  --success: #5aad78;
  --radius: 10px;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  font-family: Inter, "Noto Sans JP", "Hiragino Sans", sans-serif;
  font-size: 13px;
  line-height: 1.45;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(74, 134, 196, 0.18), transparent 50%),
    var(--bg);
  color: var(--text);
}

.screen {
  display: none;
  min-height: 100vh;
}

.screen.active {
  display: flex;
}

.screen-app.active {
  display: grid;
  grid-template-columns: 188px 1fr;
}

.login-card {
  margin: auto;
  width: min(420px, calc(100% - 32px));
  padding: 32px 28px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 22px;
}

.login-mark {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 12px;
  background: var(--accent);
  font-weight: 600;
  margin-bottom: 16px;
}

.login-card h1 {
  font-size: 22px;
  font-weight: 600;
}

.login-card h1 span,
.brand-ktc {
  color: var(--accent);
}

.login-lead,
.hint,
.muted {
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 10px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
}

.field-help {
  font-size: 12px;
  line-height: 1.45;
  color: var(--muted);
}

.field input,
.field select {
  height: 34px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  padding: 0 10px;
  font: inherit;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.btn,
.btn-primary,
.btn-secondary,
.btn-danger,
.btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.08s ease;
}

.btn:active,
.btn-primary:active,
.btn-secondary:active,
.btn-danger:active {
  transform: translateY(1px);
}

.btn-sm {
  height: 28px;
  padding: 0 10px;
  font-size: 12px;
  border-radius: 7px;
}

.btn-primary {
  background: linear-gradient(180deg, #5c98d4 0%, var(--accent) 100%);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.12) inset, 0 8px 20px rgba(74, 134, 196, 0.18);
}

.btn-primary:hover {
  background: linear-gradient(180deg, #6aa6de 0%, var(--accent-hover) 100%);
}

.btn-secondary,
.btn-ghost {
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover,
.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  border-color: rgba(255, 255, 255, 0.18);
}

.btn-danger {
  background: rgba(212, 106, 106, 0.16);
  color: #ffb4b4;
  border-color: rgba(212, 106, 106, 0.35);
}

.btn-danger:hover {
  background: rgba(212, 106, 106, 0.24);
}

.error {
  color: var(--danger);
  font-size: 13px;
}

.flash {
  margin-bottom: 10px;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 12px;
}

.flash.ok {
  background: rgba(90, 173, 120, 0.16);
  color: var(--success);
}

.flash.err {
  background: rgba(212, 106, 106, 0.16);
  color: var(--danger);
}

.sidebar {
  display: flex;
  flex-direction: column;
  padding: 16px 10px;
  border-right: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.18);
}

.brand {
  display: flex;
  gap: 6px;
  align-items: baseline;
  padding: 2px 8px 14px;
  font-weight: 600;
}

.brand-desktop {
  font-size: 11px;
  color: var(--muted);
  font-weight: 500;
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  text-align: left;
  background: transparent;
  border: 0;
  color: var(--muted);
  padding: 7px 10px;
  border-radius: 8px;
  font: inherit;
  cursor: pointer;
}

.nav-btn.active,
.nav-btn:hover {
  background: rgba(74, 134, 196, 0.16);
  color: var(--text);
}

.sidebar-foot {
  margin-top: auto;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-email {
  font-size: 12px;
  color: var(--muted);
  word-break: break-all;
  padding: 0 4px;
}

.main {
  padding: 18px 24px 32px;
  overflow: auto;
}

.page-head {
  margin-bottom: 12px;
}

.page-head h2 {
  font-size: 18px;
  font-weight: 600;
}

.page-head p {
  color: var(--muted);
  margin-top: 2px;
  font-size: 12px;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.dash-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}

.dash-note {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}

.dash-section {
  margin-bottom: 14px;
}

.dash-section-title {
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-bottom: 6px;
  color: var(--muted);
}

.dash-hint {
  margin-top: 4px;
}

.dash-grid-2 {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 18px;
}

.metric-row,
.shortcut-grid,
.panel-grid {
  display: grid;
  gap: 8px;
}

.metric-row {
  grid-template-columns: repeat(auto-fit, minmax(118px, 1fr));
  margin-bottom: 8px;
}

.metric,
.shortcut,
.panel,
.org-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
}

.metric strong {
  display: block;
  font-size: 16px;
  line-height: 1.25;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.metric span {
  color: var(--muted);
  font-size: 11px;
}

.warn-text {
  color: var(--danger);
}

.ok-text {
  color: var(--success);
}

.shortcut-grid {
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

.shortcut,
.card-link {
  text-align: left;
  color: inherit;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elev);
  transition: background 0.15s ease, border-color 0.15s ease;
}

.shortcut:hover,
.card-link:hover {
  background: rgba(74, 134, 196, 0.1);
  border-color: rgba(74, 134, 196, 0.28);
}

.shortcut span {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 13px;
}

.panel-grid {
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel h3 {
  font-size: 13px;
}

.org-card {
  margin-bottom: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.org-card .org-id {
  grid-column: 1 / -1;
  font-weight: 600;
}

.row-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}

.toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 10px;
  flex-wrap: wrap;
}

.toolbar input {
  flex: 1;
  height: 32px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  padding: 0 10px;
  font: inherit;
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(280px, 0.8fr);
  gap: 16px;
  align-items: start;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.table-wrap-full .data-table {
  min-width: 0;
}

.data-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
  font-size: 12px;
}

.data-table th,
.data-table td {
  padding: 6px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table th {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.03);
}

/* Long free text (error details) wraps instead of forcing a horizontal scrollbar. */
#view-errors .data-table td {
  white-space: normal;
  word-break: break-word;
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr[data-select] {
  cursor: pointer;
}

.data-table tbody tr[data-select]:hover,
.data-table tbody tr[data-select].active {
  background: rgba(74, 134, 196, 0.12);
}

.data-table-static tbody tr {
  cursor: default;
}

.detail-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

.detail-head h4 {
  font-size: 16px;
  word-break: break-all;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: flex-end;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  background: var(--bg-input);
}

.badge.ok {
  color: var(--success);
}

.badge.warn {
  color: var(--danger);
}

.row-actions {
  display: flex;
  gap: 6px;
}

.row-actions button {
  height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.detail-panel {
  position: sticky;
  top: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.user-detail-header {
  margin-bottom: 10px;
}

.btn-back {
  margin-bottom: 6px;
  padding-left: 0;
  height: 24px;
  border: 0;
  background: transparent;
  font-size: 12px;
  color: var(--muted);
}

.user-detail-top {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
}

.detail-page-head h2 {
  font-size: 18px;
  font-weight: 600;
  word-break: break-all;
}

.detail-page-head p {
  margin-top: 2px;
  font-size: 12px;
}

.user-detail-loading {
  padding: 24px 0;
}

.detail-grid {
  display: grid;
  grid-template-columns: minmax(0, 3fr) minmax(0, 2fr);
  align-items: start;
  gap: 8px;
  margin-bottom: 8px;
}

/* Even spacing between every block of the detail page (the first block used to touch the next one). */
#user-detail-content {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

#user-detail-content > .detail-grid {
  margin-bottom: 0;
}

/* A single record reads better in a bounded column than stretched across a very wide window. */
#view-user-detail {
  max-width: 1040px;
}

/* On wide windows the session history moves to its own column instead of leaving the right side empty. */
@media (min-width: 1400px) {
  #view-user-detail {
    max-width: 1500px;
  }

  #user-detail-content {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(380px, 460px);
    grid-template-rows: auto auto 1fr;
    gap: 8px;
    align-items: start;
  }

  #user-detail-content > .panel,
  #user-detail-content > .detail-grid {
    grid-column: 1;
    margin-bottom: 0;
  }

  #user-detail-content > .detail-sessions {
    grid-column: 2;
    grid-row: 1 / -1;
  }

  #user-detail-content .table-scroll {
    max-height: calc(100vh - 220px);
  }
}

#view-user-detail .panel h3 {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--muted);
}

/* Compact label/value cells; they keep their natural width and flow left to right instead of stretching across a wide card. */
.kv-strip {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  gap: 6px 28px;
}

.kv {
  display: flex;
  flex-direction: column;
  min-width: 84px;
}

.kv span {
  font-size: 11px;
  color: var(--muted);
}

.kv strong {
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.chip {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--bg-input);
  font-size: 11px;
  font-weight: 500;
  text-transform: none;
  letter-spacing: 0;
  color: var(--text);
}

.inline-forms {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}

.inline-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.inline-form .field {
  flex-direction: row;
  align-items: center;
  gap: 6px;
}

.inline-form .field input,
.inline-form .field select {
  width: 92px;
  height: 28px;
  padding: 0 8px;
}

.table-scroll {
  max-height: 240px;
  overflow: auto;
}

.modal {
  /* The global reset removes the browser's auto margin, which is what centers a modal dialog. */
  margin: auto;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #1a202b;
  color: var(--text);
  padding: 0;
  max-width: 420px;
  width: calc(100% - 32px);
}

.modal::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.modal .panel {
  margin: 0;
  border: 0;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

@media (max-width: 800px) {
  .screen-app.active {
    grid-template-columns: 1fr;
  }

  .detail-grid {
    grid-template-columns: 1fr;
  }

  .inline-form {
    flex-wrap: wrap;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

  .sidebar-nav {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .split,
  .row-head {
    grid-template-columns: 1fr;
    flex-direction: column;
  }
}


.lang-select {
  margin-bottom: 12px;
  padding: 4px 8px;
  border: 1px solid var(--border, #d0d5dd);
  border-radius: 6px;
  background: transparent;
  color: inherit;
  font: inherit;
  font-size: 13px;
}
.login-card .lang-select { display: block; margin-left: auto; }
.sidebar-foot .lang-select { margin-bottom: 0; }

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 120px;
  padding-top: 6px;
}

.bar-col {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  height: 100%;
  font-size: 11px;
}

.bar-col .bar {
  width: 100%;
  max-width: 28px;
  min-height: 2px;
  border-radius: 4px 4px 0 0;
  background: var(--accent, #3b82f6);
}

.bar-col .bar-val {
  margin-bottom: 2px;
  font-variant-numeric: tabular-nums;
}

.bar-col .bar-day {
  margin-top: 4px;
  opacity: 0.7;
  white-space: nowrap;
}

.mfa-key {
  padding: 8px 10px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  letter-spacing: 0.08em;
  word-break: break-all;
  user-select: all;
}

#dialog-mfa .modal-actions {
  justify-content: space-between;
}

.hint a {
  color: var(--accent-hover);
}
