/* work internal operations portal · design tokens and global styles
 *
 * Constraints (to match CSP style-src 'self'): no style="…" in the HTML; JS only uses CSSOM (el.style.x) or toggles classes.
 * Theming: component rules always reference the variables below; dark mode only overrides variables on :root and never touches the HTML.
 * Breakpoints: <768px phones (single-column cards, sticky table header); <1024px the top bar collapses into the menu button (the admin navigation items are numerous and do not fit in tablet width).
 */

:root {
  color-scheme: light;

  /* Neutrals: cool grey-blue */
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --surface-3: #eef2f7;
  --border: #e3e8ef;
  --border-strong: #cfd8e3;
  --input-border: #7d8ba0; /* Inputs share the card background, so the border is the only outline: it needs ≥3:1 (WCAG 1.4.11) */
  --text: #0f1b2d;
  --text-2: #334155;
  --muted: #5a6a80;
  --zebra: #f8fafc;
  --row-hover: #f1f5fb;

  /* Brand colors: deep sea blue + restrained teal accents */
  --primary: #1557c0;
  --primary-hover: #0f4699;
  --primary-soft: #e8f0fc;
  --primary-text: #1450b3;
  --on-primary: #ffffff;
  --accent: #0e7c7b;
  --wave-back: #dff1f0;
  --wave-front: #e8f0fc;

  /* Semantic colors (text / background / border) */
  --success: #157a3e;
  --success-bg: #edf8f1;
  --success-border: #bfe5cc;
  --warning: #9a5b06;
  --warning-bg: #fdf6e7;
  --warning-border: #f3dca8;
  --danger: #b42318;
  --danger-bg: #fdf1f0;
  --danger-border: #f6cdc9;
  --info: #1557c0;
  --info-bg: #edf3fd;
  --info-border: #c6d9f7;

  /* 6 soft tones: shared by avatar initial backgrounds (user.id % 6), entry icon backgrounds and role badges */
  --tone-0-bg: #e6effc; --tone-0-fg: #1550b0;
  --tone-1-bg: #ddf2f0; --tone-1-fg: #0b6563;
  --tone-2-bg: #eeeafc; --tone-2-fg: #5a3ec0;
  --tone-3-bg: #fcf0dc; --tone-3-fg: #8a4f08;
  --tone-4-bg: #fce8ed; --tone-4-fg: #a8264a;
  --tone-5-bg: #e9edf3; --tone-5-fg: #3b4a5f;

  /* Three shadow levels: flush / hovering / overlay */
  --shadow-1: 0 1px 2px rgba(16, 24, 40, .05);
  --shadow-2: 0 1px 2px rgba(16, 24, 40, .05), 0 6px 16px -6px rgba(16, 24, 40, .12);
  --shadow-3: 0 24px 48px -12px rgba(16, 24, 40, .22), 0 4px 12px -4px rgba(16, 24, 40, .08);

  /* 8pt spacing, font sizes, radii and motion */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;
  --sp-7: 48px;
  --sp-8: 64px;
  --fs-12: 12px;
  --fs-13: 13px;
  --fs-14: 14px;
  --fs-15: 15px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-20: 20px;
  --fs-24: 24px;
  --fs-28: 28px;
  --radius-sm: 6px;
  --radius: 10px;
  --dur: 160ms;
  --ease: cubic-bezier(.2, 0, 0, 1);
  --control-h: 36px;
  --topbar-h: 60px;
  --content-w: 1160px;

  /* Latin-first UI font stack; Japanese names switch to --font-ja through lang="ja" so they keep proper Japanese glyph shapes */
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB",
          "Microsoft YaHei", "Noto Sans SC", sans-serif;
  --font-ja: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Hiragino Kaku Gothic ProN",
             "Yu Gothic", "Meiryo", "Noto Sans JP", sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Consolas, monospace;

  --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%235a6a80' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;

    --bg: #0b1220;
    --surface: #111a2e;
    --surface-2: #16223a;
    --surface-3: #1c2a45;
    --border: #22314d;
    --border-strong: #31446a;
    --input-border: #5f7398;
    --text: #e6ebf4;
    --text-2: #c3cde0;
    --muted: #94a3bb;
    --zebra: #142036;
    --row-hover: #1a2742;

    --primary: #3a6fc9;
    --primary-hover: #2f62b8;
    --primary-soft: #17294a;
    --primary-text: #8fb5f7;
    --accent: #3cc3bd;
    --wave-back: #162e3f;
    --wave-front: #172644;

    --success: #5fd08a;
    --success-bg: #0f2a1c;
    --success-border: #1d4a31;
    --warning: #f0b45a;
    --warning-bg: #2e2210;
    --warning-border: #57401a;
    --danger: #f2847b;
    --danger-bg: #33161a;
    --danger-border: #5c2a2e;
    --info: #8fb5f7;
    --info-bg: #14233f;
    --info-border: #27406b;

    --tone-0-bg: #172a4b; --tone-0-fg: #9cc0ff;
    --tone-1-bg: #10332f; --tone-1-fg: #7fd6cf;
    --tone-2-bg: #262049; --tone-2-fg: #c4b5ff;
    --tone-3-bg: #36270f; --tone-3-fg: #f2c37c;
    --tone-4-bg: #3b1824; --tone-4-fg: #f6a7ba;
    --tone-5-bg: #1e293b; --tone-5-fg: #c0cadb;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-2: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 20px -8px rgba(0, 0, 0, .55);
    --shadow-3: 0 24px 56px -12px rgba(0, 0, 0, .7), 0 4px 12px -4px rgba(0, 0, 0, .4);

    --chevron: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Cpath d='M4 6l4 4 4-4' fill='none' stroke='%2394a3bb' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  }
}

/* ------------------------------------------------------------------ Base */
*, *::before, *::after { box-sizing: border-box; }
/* Sticky top bar: leave room for its height when focus scrolls or a skip link jumps, so the focused element does not hide underneath it */
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--topbar-h) + var(--sp-2)); }
body {
  margin: 0; min-height: 100vh; background: var(--bg); color: var(--text);
  font-family: var(--font); font-size: var(--fs-14); line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }

h1, h2, h3 { margin: 0; color: var(--text); }
h1 { font-size: var(--fs-24); line-height: 32px; font-weight: 650; letter-spacing: -.01em; }
h2 { font-size: var(--fs-16); line-height: 24px; font-weight: 600; }
h3 { font-size: var(--fs-14); line-height: 22px; font-weight: 600; }
.subtitle { margin: var(--sp-1) 0 0; font-size: var(--fs-14); line-height: 22px; font-weight: 400; color: var(--muted); }
p { margin: 0; max-width: 68ch; }
a { color: var(--primary-text); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }
strong { font-weight: 600; }
code, .mono { font-family: var(--font-mono); font-size: .92em; }
code { padding: 1px 6px; border-radius: 4px; background: var(--surface-3); color: var(--text-2); }
.num { font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.icon { width: 18px; height: 18px; flex: none; }

/* --primary-text reaches ≥3:1 on every background of both themes (--primary in dark mode falls short on light blue) */
:focus-visible { outline: 2px solid var(--primary-text); outline-offset: 2px; }
#main:focus { outline: none; }

.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: var(--sp-4); top: -60px; z-index: 100;
  padding: var(--sp-2) var(--sp-4); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--primary-text); border: 1px solid var(--border);
  box-shadow: var(--shadow-2); font-weight: 600;
}
.skip-link:focus { top: var(--sp-2); }

/* ------------------------------------------------------------------ Top bar */
.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface); border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: var(--content-w); height: var(--topbar-h); margin: 0 auto; padding: 0 var(--sp-5);
  display: flex; align-items: center; gap: var(--sp-5);
}
.brand { display: inline-flex; align-items: center; gap: var(--sp-2); flex: none; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 28px; height: 28px; flex: none; color: var(--primary); }
.brand-name { font-size: var(--fs-16); font-weight: 700; letter-spacing: -.01em; }
.brand-org {
  padding-left: var(--sp-2); border-left: 1px solid var(--border);
  color: var(--muted); font-size: var(--fs-12); font-weight: 600; line-height: 16px;
}
.topbar-menu { flex: 1; min-width: 0; display: flex; align-items: center; gap: var(--sp-4); }
/* The navigation never shrinks; when width runs out the user name / email get ellipsized instead of the links crushing the avatar */
.topbar nav { flex: 1 0 auto; display: flex; gap: 2px; }
.topbar nav a {
  display: inline-flex; align-items: center; height: 34px; padding: 0 10px; border-radius: var(--radius-sm);
  color: var(--text-2); font-weight: 500; white-space: nowrap;
  transition: background-color var(--dur) var(--ease), color var(--dur) var(--ease);
}
.topbar nav a:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.topbar nav a[aria-current="page"] { background: var(--primary-soft); color: var(--primary-text); font-weight: 600; }

.user-chip { flex: 0 1 auto; display: flex; align-items: center; gap: var(--sp-2); min-width: 0; }
.user-meta { display: flex; flex-direction: column; min-width: 0; max-width: 200px; line-height: 18px; }
.user-name { font-size: var(--fs-13); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-email { font-size: var(--fs-12); color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.nav-toggle {
  display: none; width: 40px; height: 40px; margin-left: auto; align-items: center; justify-content: center;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface);
  color: var(--text-2); cursor: pointer;
  transition: background-color var(--dur) var(--ease);
}
.nav-toggle:hover { background: var(--surface-3); }
.nav-toggle .icon-close, .topbar.is-open .nav-toggle .icon-menu { display: none; }
.topbar.is-open .nav-toggle .icon-close { display: block; }

@media (max-width: 1279.98px) {
  .user-meta { display: none; }
}
@media (max-width: 1023.98px) {
  .topbar-inner { gap: var(--sp-3); }
  .nav-toggle { display: inline-flex; }
  .topbar-menu {
    display: none; position: absolute; top: 100%; left: 0; right: 0;
    flex-direction: column; align-items: stretch; gap: var(--sp-2);
    max-height: calc(100vh - var(--topbar-h)); overflow-y: auto;
    padding: var(--sp-2) var(--sp-4) var(--sp-4);
    background: var(--surface); border-bottom: 1px solid var(--border); box-shadow: var(--shadow-3);
  }
  .topbar.is-open .topbar-menu { display: flex; }
  .topbar nav { flex-direction: column; }
  .topbar nav a { height: 44px; padding: 0 var(--sp-3); }
  .user-chip { padding-top: var(--sp-3); border-top: 1px solid var(--border); }
  .user-meta { display: flex; flex: 1; max-width: none; }
}

/* ------------------------------------------------------------------ Layout */
main {
  display: block; max-width: var(--content-w); margin: 0 auto;
  padding: var(--sp-6) var(--sp-5) var(--sp-8);
}
.page-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4);
  flex-wrap: wrap; margin-bottom: var(--sp-5);
}
.page-head > :first-child { min-width: 0; }
.page-actions { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.section-head {
  display: flex; align-items: flex-end; justify-content: space-between; gap: var(--sp-4);
  flex-wrap: wrap; margin: var(--sp-6) 0 var(--sp-4);
}
.stack { display: grid; gap: var(--sp-4); align-content: start; min-width: 0; }
.grid { display: grid; gap: var(--sp-4); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.btn-row { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.center { justify-content: center; text-align: center; margin-inline: auto; }

.card {
  min-width: 0; padding: var(--sp-5); background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-1);
}
main > .card + .card { margin-top: var(--sp-4); }
.card-flush { padding: 0; overflow: clip; }
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  margin-bottom: var(--sp-4); min-height: 24px;
}
.card-head > :first-child { min-width: 0; }

@media (max-width: 1023.98px) {
  .grid-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 767.98px) {
  main { padding: var(--sp-5) var(--sp-4) var(--sp-7); }
  h1 { font-size: var(--fs-20); line-height: 28px; }
  .card { padding: var(--sp-4); }
  .card-flush { padding: 0; }
  .grid-3 { grid-template-columns: minmax(0, 1fr); }
  .section-head { margin-top: var(--sp-5); }
}

/* ------------------------------------------------------------------ Buttons */
.btn {
  --spin-track: var(--border-strong);
  --spin-head: var(--primary);
  position: relative; display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: var(--control-h); padding: 0 var(--sp-4); border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm); background: var(--surface); color: var(--text); box-shadow: var(--shadow-1);
  font: inherit; font-size: var(--fs-14); font-weight: 600; line-height: 1; white-space: nowrap;
  cursor: pointer; user-select: none;
  transition: background-color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.btn:hover { text-decoration: none; }
.btn:hover:not(:disabled) { background: var(--surface-2); }
.btn:active:not(:disabled) { transform: translateY(1px); background: var(--surface-3); }
.btn:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }
.btn .icon { width: 16px; height: 16px; }
.btn-primary {
  --spin-track: color-mix(in srgb, var(--on-primary) 35%, transparent);
  --spin-head: var(--on-primary);
  background: var(--primary); border-color: var(--primary); color: var(--on-primary);
}
.btn-primary:hover:not(:disabled), .btn-primary:active:not(:disabled) {
  background: var(--primary-hover); border-color: var(--primary-hover);
}
.btn-danger { color: var(--danger); border-color: var(--danger-border); }
.btn-danger:hover:not(:disabled) { background: var(--danger-bg); border-color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); color: var(--text); }
.btn-ghost.btn-danger { color: var(--danger); }
.btn-ghost.btn-danger:hover:not(:disabled) { background: var(--danger-bg); color: var(--danger); }
.btn-sm { height: 30px; padding: 0 var(--sp-3); font-size: var(--fs-13); }
.btn-lg { height: 44px; padding: 0 var(--sp-5); font-size: var(--fs-15); }
.btn-block { width: 100%; }
.btn-icon { width: var(--control-h); padding: 0; }
.btn-sm.btn-icon { width: 30px; }
/* Loading state: transparent text keeps the button width, a pure-CSS spinner is layered on top; pairs with aria-busy="true" */
.btn.is-loading { color: transparent; opacity: 1; cursor: progress; pointer-events: none; }
.btn.is-loading > * { visibility: hidden; }
.btn.is-loading::before {
  content: ""; position: absolute; inset: 0; margin: auto; width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--spin-track); border-top-color: var(--spin-head);
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------------------------------------------ Badges / status */
.badge {
  display: inline-flex; align-items: center; gap: var(--sp-1); height: 22px; padding: 0 var(--sp-2);
  border: 1px solid var(--border); border-radius: 999px; background: var(--surface-2); color: var(--text-2);
  font-size: var(--fs-12); font-weight: 600; line-height: 1; white-space: nowrap; vertical-align: middle;
}
.badge-tone { background: var(--tone-bg); border-color: transparent; color: var(--tone-fg); }
.badge-info { background: var(--info-bg); border-color: var(--info-border); color: var(--info); }
.badge-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success); }
.badge-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning); }
.badge-danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.badge.mono { font-weight: 500; }
.badge-more { cursor: default; }
.badge-group { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin: 0; padding: 0; list-style: none; }
.badge-group-nowrap { flex-wrap: nowrap; }

.tone-0 { --tone-bg: var(--tone-0-bg); --tone-fg: var(--tone-0-fg); }
.tone-1 { --tone-bg: var(--tone-1-bg); --tone-fg: var(--tone-1-fg); }
.tone-2 { --tone-bg: var(--tone-2-bg); --tone-fg: var(--tone-2-fg); }
.tone-3 { --tone-bg: var(--tone-3-bg); --tone-fg: var(--tone-3-fg); }
.tone-4 { --tone-bg: var(--tone-4-bg); --tone-fg: var(--tone-4-fg); }
.tone-5 { --tone-bg: var(--tone-5-bg); --tone-fg: var(--tone-5-fg); }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: var(--fs-13); white-space: nowrap; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--success); }
.status.is-off { color: var(--muted); }
.status.is-off::before { background: var(--danger); }

/* ------------------------------------------------------------------ Banners / toast / tooltip */
.alert {
  --alert-color: var(--info);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='10' cy='10' r='8'/%3E%3Cpath d='M10 9v5M10 6.2v.1'/%3E%3C/svg%3E");
  position: relative; margin-bottom: var(--sp-4); padding: 10px var(--sp-4) 10px 42px;
  border: 1px solid var(--info-border); border-radius: var(--radius-sm); background: var(--info-bg);
  color: var(--text); font-size: var(--fs-14); line-height: 22px;
}
.alert::before {
  content: ""; position: absolute; left: 14px; top: 12px; width: 18px; height: 18px;
  background: var(--alert-color);
  -webkit-mask: var(--alert-icon) center / contain no-repeat;
  mask: var(--alert-icon) center / contain no-repeat;
}
.alert-success {
  --alert-color: var(--success);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='10' cy='10' r='8'/%3E%3Cpath d='M6.6 10.2l2.3 2.3 4.6-4.8'/%3E%3C/svg%3E");
  background: var(--success-bg); border-color: var(--success-border);
}
.alert-warning {
  --alert-color: var(--warning);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10 2.8l7.6 13.4H2.4z'/%3E%3Cpath d='M10 8v3.6M10 14v.1'/%3E%3C/svg%3E");
  background: var(--warning-bg); border-color: var(--warning-border);
}
.alert-error {
  --alert-color: var(--danger);
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='black' stroke-width='1.7' stroke-linecap='round'%3E%3Ccircle cx='10' cy='10' r='8'/%3E%3Cpath d='M10 5.8v5M10 13.9v.1'/%3E%3C/svg%3E");
  background: var(--danger-bg); border-color: var(--danger-border);
}

#toast-layer {
  position: fixed; right: var(--sp-5); bottom: var(--sp-5); z-index: 60;
  display: grid; gap: var(--sp-2); justify-items: end; pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px; max-width: 380px; padding: 10px var(--sp-4);
  border-radius: var(--radius-sm); background: var(--text); color: var(--surface); box-shadow: var(--shadow-3);
  font-size: var(--fs-14); line-height: 20px;
}
.toast::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--primary-text); }
.toast-success::before { background: var(--success); }
.toast-error::before { background: var(--danger); }
@media (max-width: 767.98px) {
  #toast-layer { left: var(--sp-4); right: var(--sp-4); bottom: var(--sp-4); }
}

/* Pure-CSS tooltip: shows data-tip on hover or keyboard focus (only generated while shown, so it takes no layout space) */
[data-tip] { position: relative; }
[data-tip]:hover::after, [data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; left: 50%; bottom: calc(100% + 6px); z-index: 30;
  transform: translateX(-50%); padding: 4px var(--sp-2); border-radius: var(--radius-sm);
  background: var(--text); color: var(--surface); box-shadow: var(--shadow-2);
  font-size: var(--fs-12); font-weight: 500; line-height: 18px; white-space: nowrap; pointer-events: none;
  animation: tip-in var(--dur) var(--ease);
}
[data-tip][data-tip-pos="end"]:hover::after, [data-tip][data-tip-pos="end"]:focus-visible::after {
  left: auto; right: 0; transform: none;
}
@keyframes tip-in { from { opacity: 0; } }

/* ------------------------------------------------------------------ Forms */
label, .label {
  display: block; margin-bottom: 6px; color: var(--text-2);
  font-size: var(--fs-13); font-weight: 600; line-height: 20px;
}
label.is-required::after { content: " *"; color: var(--danger); }
.field { min-width: 0; }
.field-hint { margin-top: 6px; color: var(--muted); font-size: var(--fs-12); line-height: 18px; }
.field-error { margin-top: 6px; color: var(--danger); font-size: var(--fs-12); line-height: 18px; }
input[type=text], input[type=tel], input[type=search], select {
  width: 100%; height: var(--control-h); padding: 0 var(--sp-3);
  border: 1px solid var(--input-border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text); font: inherit; font-size: var(--fs-14);
  transition: border-color var(--dur) var(--ease);
}
/* Phones: iOS Safari zooms into focused inputs under 16px and never zooms back out */
@media (max-width: 767.98px) {
  input[type=text], input[type=tel], input[type=search], select { font-size: var(--fs-16); }
}
/* The `font: inherit` above has higher precedence, so Japanese inputs must be listed separately */
:lang(ja), input[type=text]:lang(ja) { font-family: var(--font-ja); }
input::placeholder { color: var(--muted); opacity: 1; }
input:focus, select:focus { border-color: var(--primary); }
input[aria-invalid="true"] { border-color: var(--danger); }
input[type=search]::-webkit-search-cancel-button { cursor: pointer; }
select {
  appearance: none; padding-right: 32px; cursor: pointer;
  background: var(--surface) var(--chevron) no-repeat right 10px center / 16px;
}
input[type=checkbox] { width: 16px; height: 16px; margin: 0; accent-color: var(--primary); }
fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
legend { padding: 0; }
.form-grid {
  display: grid; gap: var(--sp-4) var(--sp-5);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.form-section { margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--border); }
.form-section legend { float: left; width: 100%; margin-bottom: var(--sp-4); color: var(--text); font-weight: 600; }
.form-section legend + * { clear: both; }
.form-actions {
  display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap;
  margin-top: var(--sp-5); padding-top: var(--sp-5); border-top: 1px solid var(--border);
}

.input-icon { position: relative; }
.input-icon .icon {
  position: absolute; left: 10px; top: 50%; width: 16px; height: 16px;
  transform: translateY(-50%); color: var(--muted); pointer-events: none;
}
.input-icon input { padding-left: 34px; }

/* Filter bar: laid out on one line, wraps automatically on narrow screens */
.toolbar { display: flex; align-items: center; gap: var(--sp-2); flex-wrap: wrap; }
.toolbar > * { flex: 0 1 auto; }
.toolbar .grow { flex: 1 1 260px; }
.toolbar select { width: auto; min-width: 136px; }
.toolbar .user-id { width: 180px; }
@media (max-width: 1023.98px) {
  .toolbar .grow { flex-basis: 100%; }
}
@media (max-width: 767.98px) {
  .toolbar select, .toolbar .user-id { flex: 1 1 140px; width: auto; }
}

/* ------------------------------------------------------------------ Tables */
.table-wrap { position: relative; }
/* Edge fades on horizontal scroll (the class names are toggled by app.js watchTableEdges based on scroll position) */
.table-wrap::before, .table-wrap::after {
  content: ""; position: absolute; top: 0; bottom: 0; z-index: 3; width: 32px;
  pointer-events: none; opacity: 0; transition: opacity var(--dur) var(--ease);
}
.table-wrap::before { left: 0; background: linear-gradient(to right, var(--surface), transparent); }
.table-wrap::after { right: 0; background: linear-gradient(to left, var(--surface), transparent); }
.table-wrap.fade-left::before, .table-wrap.fade-right::after { opacity: 1; }
.table-scroll { overflow-x: auto; overscroll-behavior-x: contain; }

table { width: 100%; border-collapse: separate; border-spacing: 0; table-layout: fixed; font-size: var(--fs-14); }
.data-table { min-width: 1080px; }
/* Fixed column widths (table-layout: fixed): columns without a width split the remaining space, long text is ellipsized */
.col-contact { width: 176px; }
.col-roles { width: 200px; }
.col-profile { width: 92px; }
.col-status { width: 92px; }
.col-login { width: 148px; }
.col-actions { width: 104px; }
.audit-table { min-width: 1080px; }
.audit-table td:first-child { font-size: var(--fs-13); white-space: nowrap; }
.col-time { width: 176px; }
.col-action { width: 208px; }
.col-result { width: 148px; }
.col-ip { width: 128px; }
th, td {
  padding: var(--sp-3) var(--sp-4); text-align: left; vertical-align: middle; border-bottom: 1px solid var(--border);
  background: var(--surface); /* Opaque: the pinned action column covers the other columns */
}
th {
  position: sticky; top: 0; z-index: 2; height: 40px; padding-block: 0;
  background: var(--surface-2); color: var(--muted);
  font-size: var(--fs-12); font-weight: 600; letter-spacing: .02em; white-space: nowrap;
}
tbody tr:nth-child(even) > td { background: var(--zebra); }
tbody tr:hover > td { background: var(--row-hover); }
tbody tr:last-child > td { border-bottom: 0; }
tbody tr.is-empty > td, tbody tr.skeleton-row > td { background: transparent; }
td.actions, th.actions { text-align: right; }
/* The action column pins to the right edge: "edit roles / disable" stay reachable while scrolling sideways on tablets/phones; a divider appears on its left when content scrolls under it.
 * z-index: above the right edge fade (3); the header action cell one level higher; hovered/focused rows go to the very top so the first row tooltip is not covered by the header */
.data-table .actions { position: sticky; right: 0; z-index: 4; }
.data-table th.actions { z-index: 5; }
.data-table td.actions:hover, .data-table td.actions:focus-within { z-index: 6; }
.table-wrap.fade-right .data-table .actions { box-shadow: inset 1px 0 0 var(--border-strong); }
/* The empty state stays pinned inside the visible area of the scroll container (--view-w written by watchTableEdges), so on narrow screens it does not land in the middle of a 1080px wide table */
tbody tr.is-empty > td { padding: 0; }
tr.is-empty .empty-state { position: sticky; left: 0; width: var(--view-w, 100%); }
.cell-main, .cell-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cell-main { color: var(--text); font-weight: 600; }
.cell-sub { color: var(--muted); font-size: var(--fs-12); line-height: 18px; }
.cell-user { display: flex; align-items: center; gap: var(--sp-3); min-width: 0; }
.cell-user > div { min-width: 0; }
.cell-title { display: flex; align-items: center; gap: 6px; min-width: 0; }
.row-actions { display: inline-flex; gap: var(--sp-1); }
tr.is-disabled .cell-main { color: var(--muted); }

.pager {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap;
  padding: var(--sp-3) var(--sp-4); border-top: 1px solid var(--border); background: var(--surface);
}
.pager-info { color: var(--muted); font-size: var(--fs-13); }

@media (max-width: 767.98px) {
  /* Phones: the table scrolls in both directions inside the card, header stays sticky */
  .table-scroll { max-height: 70vh; overflow: auto; }
}

/* ------------------------------------------------------------------ Skeleton / empty state */
.skeleton {
  display: block; height: 12px; border-radius: 4px;
  background: linear-gradient(90deg, var(--surface-3) 25%, var(--surface-2) 50%, var(--surface-3) 75%);
  background-size: 200% 100%; animation: shimmer 1.4s ease-in-out infinite;
}
.skeleton-row td:nth-child(odd) .skeleton { width: 72%; }
.skeleton-row td:nth-child(even) .skeleton { width: 48%; }
.skeleton-card { height: 132px; border-radius: var(--radius); }
.skeleton-chip { width: 120px; height: 28px; border-radius: 999px; }
@keyframes shimmer { from { background-position: 100% 0; } to { background-position: -100% 0; } }

.empty-state {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-1);
  padding: var(--sp-7) var(--sp-5); text-align: center; white-space: normal;
}
.empty-icon {
  display: grid; place-items: center; width: 48px; height: 48px; margin-bottom: var(--sp-2);
  border-radius: 50%; background: var(--surface-3); color: var(--muted);
}
.empty-icon .icon { width: 22px; height: 22px; }
.empty-state.is-error .empty-icon { background: var(--danger-bg); color: var(--danger); }
.empty-title { color: var(--text); font-size: var(--fs-15); font-weight: 600; line-height: 22px; }
.empty-text { max-width: 44ch; color: var(--muted); font-size: var(--fs-13); line-height: 20px; }
.empty-state .btn { margin-top: var(--sp-3); }

/* ------------------------------------------------------------------ Avatar */
.avatar {
  --size: 32px;
  display: inline-grid; place-items: center; flex: none; width: var(--size); height: var(--size);
  overflow: hidden; border-radius: 50%;
  background: var(--tone-bg, var(--tone-0-bg)); color: var(--tone-fg, var(--tone-0-fg));
  font-size: calc(var(--size) * .38); font-weight: 650; line-height: 1; user-select: none;
}
.avatar img { display: block; width: 100%; height: 100%; object-fit: cover; }
.avatar-sm { --size: 28px; }
.avatar-lg { --size: 64px; }
.avatar-xl { --size: 96px; }

/* ------------------------------------------------------------------ Progress bar / checklist / key-value */
.progress { height: 6px; overflow: hidden; border-radius: 999px; background: var(--surface-3); }
.progress-bar {
  width: 0; height: 100%; border-radius: inherit; background: var(--primary);
  transition: width var(--dur) var(--ease);
}
.progress-bar.is-complete { background: var(--success); }
.percent { color: var(--text); font-size: var(--fs-20); font-weight: 650; line-height: 28px; font-variant-numeric: tabular-nums; }

.checklist { display: grid; gap: var(--sp-2); margin: var(--sp-4) 0 0; padding: 0; list-style: none; font-size: var(--fs-13); }
.checklist li { display: flex; align-items: center; gap: var(--sp-2); color: var(--text-2); }
.checklist .icon { width: 16px; height: 16px; color: var(--success); }
.checklist li.is-missing { color: var(--text); font-weight: 600; }
.checklist li.is-missing .icon { color: var(--warning); }
.checklist .optional { margin-left: auto; color: var(--muted); font-size: var(--fs-12); font-weight: 400; }

.kv { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: var(--sp-2) var(--sp-5); margin: 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
/* Two key-value groups side by side on wide screens */
.kv-cols { grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr); }
@media (max-width: 1023.98px) {
  .kv-cols { grid-template-columns: max-content minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ Dialogs (native <dialog>: Esc closing and focus management belong to the browser) */
dialog.modal {
  width: min(560px, calc(100vw - 2 * var(--sp-4))); max-height: min(88vh, 760px); padding: 0;
  border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-3);
}
dialog.modal[open] { display: flex; flex-direction: column; }
dialog.modal::backdrop { background: rgba(8, 15, 30, .52); }
.modal-head {
  display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3);
  padding: var(--sp-5) var(--sp-5) var(--sp-4); border-bottom: 1px solid var(--border);
}
.modal-head > :first-child { min-width: 0; }
.modal-head .subtitle { overflow-wrap: anywhere; }
.modal-body { flex: 1; overflow-y: auto; padding: var(--sp-4) var(--sp-5) var(--sp-5); }
.modal-foot {
  display: flex; justify-content: flex-end; gap: var(--sp-2);
  padding: var(--sp-3) var(--sp-5); border-top: 1px solid var(--border); background: var(--surface-2);
}

.role-options { display: grid; gap: var(--sp-2); }
.role-option {
  display: flex; align-items: flex-start; gap: var(--sp-3); margin: 0; padding: var(--sp-3);
  border: 1px solid var(--border); border-radius: var(--radius-sm); cursor: pointer;
  font-size: var(--fs-14); font-weight: 400; color: var(--text);
  transition: border-color var(--dur) var(--ease), background-color var(--dur) var(--ease);
}
.role-option:hover { border-color: var(--border-strong); background: var(--surface-2); }
.role-option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.role-option input { margin-top: 3px; }
.role-option-name { display: flex; align-items: center; gap: var(--sp-2); font-weight: 600; }
.role-option .field-hint { margin-top: 2px; }

.role-diff {
  display: grid; gap: var(--sp-2); margin: var(--sp-4) 0; padding: var(--sp-3) var(--sp-4);
  border: 1px dashed var(--border-strong); border-radius: var(--radius-sm); background: var(--surface-2);
}
.role-diff-head { display: flex; justify-content: space-between; gap: var(--sp-3); font-size: var(--fs-13); font-weight: 600; }
.role-diff-row { display: grid; grid-template-columns: 52px minmax(0, 1fr); align-items: center; gap: var(--sp-2); }
.role-diff-label { color: var(--muted); font-size: var(--fs-12); }
.diff-del { text-decoration: line-through; }

/* ------------------------------------------------------------------ Sign-in / first-time setup */
main.auth {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: var(--sp-5); min-height: 100vh; max-width: none; padding: var(--sp-7) var(--sp-4);
  overflow: hidden;
}
.auth-waves { position: absolute; left: 0; bottom: 0; width: 100%; height: 34vh; min-height: 160px; pointer-events: none; }
.auth-card {
  position: relative; z-index: 1; width: min(420px, 100%); padding: var(--sp-6);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-2);
}
.auth-card-wide { width: min(560px, 100%); }
.auth-brand { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-5); }
.auth-brand .brand-mark { width: 40px; height: 40px; }
.auth-brand-name { font-size: var(--fs-18); font-weight: 700; line-height: 22px; }
.auth-brand-org { color: var(--muted); font-size: var(--fs-12); line-height: 16px; }
.auth-card .subtitle { margin-bottom: var(--sp-5); }
.auth-card .badge-group { margin-top: var(--sp-4); }
.auth-foot {
  margin-top: var(--sp-5); padding-top: var(--sp-4); border-top: 1px solid var(--border);
  color: var(--muted); font-size: var(--fs-12); line-height: 20px;
}
.auth-legal { position: relative; z-index: 1; color: var(--muted); font-size: var(--fs-12); }
@media (max-width: 767.98px) {
  main.auth { justify-content: flex-start; padding-top: var(--sp-6); }
  .auth-card { padding: var(--sp-5); }
}

.steps { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-5); padding: 0; list-style: none; }
.step { display: flex; align-items: center; gap: var(--sp-2); color: var(--muted); font-size: var(--fs-13); font-weight: 600; }
.step + .step::before { content: ""; width: 32px; height: 1px; margin-right: var(--sp-1); background: var(--border-strong); }
.step-num {
  display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%;
  border: 1px solid var(--border-strong); background: var(--surface); font-size: var(--fs-12); font-variant-numeric: tabular-nums;
}
.step[aria-current="step"] { color: var(--text); }
.step[aria-current="step"] .step-num { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }

/* ------------------------------------------------------------------ Workbench */
.welcome { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(0, 1fr); gap: var(--sp-4); }
.identity {
  position: relative; display: flex; align-items: center; gap: var(--sp-5);
  overflow: hidden; padding-bottom: 72px;
}
.identity > div { position: relative; min-width: 0; }
.identity-waves { position: absolute; left: 0; bottom: 0; width: 100%; height: 64px; pointer-events: none; }
.wave-back { fill: var(--wave-back); }
.wave-front { fill: var(--wave-front); }
.identity h1 { overflow-wrap: anywhere; }
.identity .badge-group { margin-top: var(--sp-3); }
.session .kv { font-size: var(--fs-13); }
.completeness { margin-top: var(--sp-4); padding-top: var(--sp-4); border-top: 1px solid var(--border); }
.completeness-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--sp-3); margin-bottom: var(--sp-2); }
.completeness .badge-group { margin-top: var(--sp-3); }
.completeness .subtitle { font-size: var(--fs-13); }
@media (max-width: 767.98px) {
  .welcome { grid-template-columns: minmax(0, 1fr); }
  .identity { gap: var(--sp-4); padding-bottom: 56px; }
  .identity-waves { height: 44px; }
}

.feature {
  display: flex; flex-direction: column; gap: var(--sp-3); min-width: 0; padding: var(--sp-5);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-1); color: inherit;
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.feature:hover { transform: translateY(-2px); border-color: var(--border-strong); box-shadow: var(--shadow-2); text-decoration: none; }
.feature:active { transform: translateY(0); }
.feature-top { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-3); }
.feature-icon {
  display: grid; place-items: center; flex: none; width: 40px; height: 40px; border-radius: var(--radius);
  background: var(--tone-bg); color: var(--tone-fg);
}
.feature-icon .icon { width: 20px; height: 20px; }
.feature-go { color: var(--muted); transition: transform var(--dur) var(--ease), color var(--dur) var(--ease); }
.feature:hover .feature-go { transform: translateX(2px); color: var(--primary-text); }
.feature-title { color: var(--text); font-size: var(--fs-15); font-weight: 600; line-height: 22px; }
.feature-desc { margin-top: 2px; color: var(--muted); font-size: var(--fs-13); line-height: 20px; }
.feature .badge-group { margin-top: auto; }
@media (max-width: 767.98px) {
  /* Phones: icon on the left, text on the right, more compact cards */
  .feature { display: grid; grid-template-columns: 40px minmax(0, 1fr); gap: var(--sp-2) var(--sp-3); padding: var(--sp-4); }
  .feature-top { display: contents; }
  .feature-icon { grid-row: span 2; }
  .feature-go { display: none; }
}

/* ------------------------------------------------------------------ My profile */
.profile-layout { display: grid; grid-template-columns: 300px minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.avatar-card { display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); text-align: center; }
.avatar-card .progress { width: 160px; }
.avatar-card .field-hint { margin-top: 0; }
@media (max-width: 1023.98px) {
  .profile-layout { grid-template-columns: 260px minmax(0, 1fr); gap: var(--sp-4); }
}
@media (max-width: 767.98px) {
  .profile-layout { grid-template-columns: minmax(0, 1fr); }
}

/* ------------------------------------------------------------------ Audit log */
.action-cell { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.action-cell > div { min-width: 0; }
.cat-dot { flex: none; width: 8px; height: 8px; margin-top: 7px; border-radius: 50%; background: var(--muted); }
.cat-login { background: var(--info); }
.cat-role { background: var(--tone-2-fg); }
.cat-access { background: var(--danger); }
.cat-profile { background: var(--accent); }
.cat-account { background: var(--warning); }
.legend { display: flex; flex-wrap: wrap; gap: var(--sp-1) var(--sp-4); margin-top: var(--sp-3); color: var(--muted); font-size: var(--fs-12); }
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend .cat-dot { margin-top: 0; }
.json-details summary {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; cursor: pointer;
  color: var(--text-2); font-family: var(--font-mono); font-size: var(--fs-12);
}
.json-details summary:hover { color: var(--primary-text); }
.json-details pre {
  margin: var(--sp-2) 0 0; padding: var(--sp-2) var(--sp-3); max-height: 260px; overflow: auto;
  border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-2);
  color: var(--text-2); font-family: var(--font-mono); font-size: var(--fs-12); line-height: 18px;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
tbody tr:has(details[open]) > td { vertical-align: top; }

/* ------------------------------------------------------------------ Placeholder module */
.page-title { display: flex; align-items: center; gap: var(--sp-4); min-width: 0; }
.page-title .feature-icon { width: 48px; height: 48px; }
.placeholder {
  display: flex; flex-direction: column; align-items: center; gap: var(--sp-3); text-align: center;
  padding: var(--sp-7) var(--sp-5); border: 2px dashed var(--border-strong); border-radius: var(--radius);
  background: var(--surface-2);
}
.placeholder .empty-icon { width: 56px; height: 56px; background: var(--warning-bg); color: var(--warning); }
.placeholder > p { color: var(--muted); }
.placeholder .kv {
  margin: var(--sp-2) 0; padding: var(--sp-4) var(--sp-5); text-align: left;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm);
}
@media (max-width: 767.98px) {
  .placeholder { padding: var(--sp-6) var(--sp-4); }
  .placeholder .kv { align-self: stretch; padding: var(--sp-3) var(--sp-4); column-gap: var(--sp-4); }
}

/* ------------------------------------------------------------------ Reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important; animation-iteration-count: 1 !important;
    transition-duration: .01ms !important; scroll-behavior: auto !important;
  }
}
