:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f7f9fb;
  --surface-3: #eef1f5;
  --border: #dde2e8;
  --border-strong: #c6ced8;
  --text: #16202b;
  --text-muted: #5d6b7a;
  --text-faint: #8b97a4;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --accent-weak: #e8eefc;
  --danger: #d92d20;
  --danger-strong: #b42318;
  --danger-weak: #fdeceb;
  --success: #067647;
  --success-weak: #e4f4ec;
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow-md: 0 6px 20px rgba(16, 24, 40, .12);
  --radius: 8px;
  --radius-sm: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1419;
    --surface: #171d24;
    --surface-2: #1c232b;
    --surface-3: #232b35;
    --border: #2c353f;
    --border-strong: #3d4854;
    --text: #e6ebf1;
    --text-muted: #9aa8b6;
    --text-faint: #74828f;
    --accent: #5b8dff;
    --accent-strong: #7aa2ff;
    --accent-weak: #1c2942;
    --danger: #f87171;
    --danger-strong: #fca5a5;
    --danger-weak: #351d1e;
    --success: #4ade80;
    --success-weak: #16301f;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, .5);
    color-scheme: dark;
  }
}

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

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Hiragino Sans", "Noto Sans JP", Meiryo, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

[x-cloak] { display: none !important; }

.vh {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

button, input, select { font: inherit; color: inherit; }

/* boot */
.boot {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-muted);
}

.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 2s; }
}

/* login */
.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
}

.login__card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
  padding: 28px 26px 26px;
}

.login__title {
  margin: 0;
  font-size: 20px;
  letter-spacing: .02em;
}

.login__lead {
  margin: 4px 0 22px;
  color: var(--text-muted);
  font-size: 13px;
}

/* fields */
.field {
  display: block;
  margin-bottom: 16px;
}

.field__label {
  display: block;
  margin-bottom: 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.req, .opt {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  border-radius: 999px;
  font-size: 10px;
  font-weight: 700;
  vertical-align: 1px;
}

.req { background: var(--danger-weak); color: var(--danger-strong); }
.opt { background: var(--surface-3); color: var(--text-faint); }

.field__hint {
  display: block;
  margin-top: 5px;
  color: var(--text-faint);
  font-size: 12px;
}

.periodgrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

.input {
  width: 100%;
  padding: 9px 11px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  outline: none;
}

.input:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

.input::placeholder { color: var(--text-faint); }

/* buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--surface-3);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s;
}

.btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.btn:disabled { opacity: .6; cursor: default; }

.btn--sm { padding: 5px 10px; font-size: 12px; }
.btn--block { width: 100%; padding: 10px 14px; margin-top: 4px; }

.btn--primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--accent-strong); border-color: var(--accent-strong); }

.btn--ghost { background: var(--surface); border-color: var(--border-strong); color: var(--text); }
.btn--ghost:hover:not(:disabled) { background: var(--surface-3); }

.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover:not(:disabled) { background: var(--danger-strong); border-color: var(--danger-strong); }

.btn--danger-ghost { background: var(--surface); border-color: var(--border-strong); color: var(--danger-strong); }
.btn--danger-ghost:hover:not(:disabled) { background: var(--danger-weak); border-color: var(--danger); }

.iconbtn {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}

.iconbtn:hover { background: var(--surface-3); color: var(--text); }

/* alerts */
.alert {
  margin: 0 0 14px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.alert--error {
  background: var(--danger-weak);
  border: 1px solid var(--danger);
  color: var(--danger-strong);
}

/* topbar */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  height: 56px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.topbar__brand {
  display: flex;
  align-items: center;
  gap: 9px;
  font-weight: 700;
  letter-spacing: .02em;
}

.topbar__logo {
  display: grid;
  place-items: center;
  width: 26px;
  height: 26px;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #fff;
  font-size: 15px;
}

.topbar__user {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.topbar__who {
  font-size: 13px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* main */
.main {
  max-width: 1280px;
  margin: 0 auto;
  padding: 20px;
}

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

.toolbar__right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.count { color: var(--text-muted); font-size: 12px; font-variant-numeric: tabular-nums; }

.search {
  position: relative;
  flex: 1 1 260px;
  max-width: 420px;
}

.search__icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-faint);
  font-size: 15px;
  pointer-events: none;
}

.search__input { padding-left: 30px; padding-right: 30px; }
.search__input::-webkit-search-cancel-button { display: none; }

.search__clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-faint);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}

.search__clear:hover { background: var(--surface-3); color: var(--text); }

/* table */
.tablewrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.table {
  width: 100%;
  min-width: 1230px;
  table-layout: fixed;
  border-collapse: collapse;
}

.table th:nth-child(1) { width: 16%; }
.table th:nth-child(2) { width: 8%; }
.table th:nth-child(3) { width: 15%; }
.table th:nth-child(4) { width: 14%; }
.table th:nth-child(5) { width: 7%; }
.table th:nth-child(6) { width: 11%; }
.table th:nth-child(7) { width: 14%; }
.table th:nth-child(8) { width: 186px; }

.table th, .table td {
  padding: 0;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.table thead th {
  position: sticky;
  top: 0;
  z-index: 10;
  background: var(--surface-2);
  padding: 9px 14px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.th--sortable { padding: 0 !important; }

.th--sortable button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 9px 14px;
  border: 0;
  background: transparent;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  white-space: nowrap;
}

.th--sortable button:hover { background: var(--surface-3); color: var(--text); }
.th--sortable button.is-active { color: var(--accent); }
.th--num button { justify-content: flex-end; }
.sortmark { font-size: 9px; }

.table tbody td {
  padding: 10px 14px;
  vertical-align: middle;
}

.table tbody tr:hover td { background: var(--surface-2); }
.table tbody tr:last-child td { border-bottom: 0; }

.td--title { font-weight: 600; }
.td--num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.td--date { color: var(--text-muted); white-space: nowrap; font-size: 12.5px; font-variant-numeric: tabular-nums; }

.td--period { color: var(--text-muted); font-size: 12.5px; font-variant-numeric: tabular-nums; }

.period {
  display: flex;
  align-items: center;
  gap: 3px 6px;
  flex-wrap: wrap;
}

.period__part { white-space: nowrap; }
.period__none { color: var(--text-faint); }
.td--actions { white-space: nowrap; }
.td--actions .btn + .btn { margin-left: 6px; }
.th--actions { text-align: right; }
.td--actions { text-align: right; }

.ellip {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

a.ellip { color: var(--accent); text-decoration: none; }
a.ellip:hover { text-decoration: underline; }
.ellip--warn { color: var(--danger-strong); }

.copybtn {
  display: inline-flex;
  align-items: baseline;
  gap: 0;
  max-width: 100%;
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  cursor: pointer;
  text-align: left;
}

.copybtn:hover { border-color: var(--accent); background: var(--accent-weak); }

.copybtn__base {
  flex: 0 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: nowrap;
}

.copybtn__slug {
  flex: 0 0 auto;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  font-weight: 700;
  white-space: nowrap;
}

.copybtn__hint {
  flex: 0 0 auto;
  margin-left: 8px;
  font-size: 10px;
  color: var(--text-faint);
  white-space: nowrap;
}

.copybtn.is-copied { border-color: var(--success); background: var(--success-weak); }
.copybtn.is-copied .copybtn__hint { color: var(--success); font-weight: 700; }

.td--state {
  padding: 40px 14px !important;
  text-align: center;
  color: var(--text-muted);
}

.empty__title { display: block; font-weight: 600; color: var(--text); }
.empty__lead { display: block; margin-top: 4px; font-size: 13px; }

/* pager */
.pager {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 14px;
  margin-top: 14px;
}

.pager__btn { min-width: 84px; }

.pager__status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  min-width: 108px;
  justify-content: center;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.pager__sep { color: var(--text-faint); }
.pager__unit { color: var(--text-faint); font-weight: 400; }

/* modal */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: rgba(16, 24, 40, .5);
  overflow-y: auto;
}

.modal {
  width: 100%;
  max-width: 520px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow-md);
}

.modal--sm { max-width: 420px; }

.modal__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.modal__title { margin: 0; font-size: 15px; }

.modal__body { padding: 20px; }

.modal__foot {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}

.slugrow {
  display: flex;
  align-items: center;
  gap: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.slugrow:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-weak); }

.slugrow__base {
  padding: 9px 0 9px 11px;
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
  white-space: nowrap;
}

.slugrow .input {
  border: 0;
  border-radius: 0;
  background: transparent;
  padding-left: 2px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

.slugrow .input:focus-visible { box-shadow: none; }

.confirm__lead { margin: 0 0 14px; color: var(--text-muted); }

.confirm__meta {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 4px 14px;
  margin: 0 0 16px;
  padding: 12px 14px;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  font-size: 13px;
}

.confirm__meta dt { color: var(--text-muted); white-space: nowrap; }
.confirm__meta dd { margin: 0; overflow-wrap: anywhere; }

/* account menu */
.menu { position: relative; }

.menu__trigger {
  display: flex;
  align-items: center;
  gap: 5px;
  max-width: 200px;
  padding: 5px 9px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}

.menu__trigger:hover { background: var(--surface-3); }
.menu__trigger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.menu__caret { color: var(--text-faint); font-size: 10px; }

.menu__list {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  z-index: 30;
  min-width: 160px;
  padding: 5px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-md);
}

.menu__item {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  font-size: 13px;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
  white-space: nowrap;
}

.menu__item:hover:not(:disabled) { background: var(--surface-3); }
.menu__item:disabled { opacity: .6; cursor: default; }

/* owner filter */
.ownerfilter {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 1 240px;
}

.ownerfilter__label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  white-space: nowrap;
}

.ownerfilter__select { min-width: 0; }
.statusfilter { flex: 0 1 170px; }

select.input {
  appearance: none;
  padding-right: 28px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 16px) calc(50% + 1px), calc(100% - 11px) calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.input--sm { padding: 5px 26px 5px 8px; font-size: 12px; }
.input--sm.input, select.input--sm { background-position: calc(100% - 14px) calc(50% + 1px), calc(100% - 9px) calc(50% + 1px); }

/* users */
.modal--lg { max-width: 1040px; }

.toolbar--modal { margin-bottom: 12px; }

.userform {
  margin-bottom: 16px;
  padding: 16px 16px 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.userform__grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0 14px;
}

.table--users { min-width: 760px; }
.table--users th:nth-child(1) { width: 13%; }
.table--users th:nth-child(2) { width: 13%; }
.table--users th:nth-child(3) { width: 18%; }
.table--users th:nth-child(4) { width: 13%; }
.table--users th:nth-child(5) { width: 8%; }
.table--users th:nth-child(6) { width: 15%; }
.table--users th:nth-child(7) { width: 170px; }

.table--users thead th, .table--users tbody td { padding-left: 10px; padding-right: 10px; }
.table--users .td--date { font-size: 12.5px; }
.table--users .btn--sm { padding: 5px 8px; }

.td--mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
}

.badge--ok { background: var(--success-weak); color: var(--success); }
.badge--wait { background: var(--accent-weak); color: var(--accent); }
.badge--muted { background: var(--surface-3); color: var(--text-faint); }

/* trash & revisions */
.note {
  margin: 0 0 14px;
  padding: 9px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13px;
}

.table--trash { min-width: 840px; }
.table--trash th:nth-child(1) { width: 20%; }
.table--trash th:nth-child(2) { width: 12%; }
.table--trash th:nth-child(3) { width: 14%; }
.table--trash th:nth-child(4) { width: 22%; }
.table--trash th:nth-child(5) { width: 14%; }
.table--trash th:nth-child(6) { width: 176px; }

.table--history { min-width: 990px; }
.table--history th:nth-child(1) { width: 13%; }
.table--history th:nth-child(2) { width: 10%; }
.table--history th:nth-child(3) { width: 13%; }
.table--history th:nth-child(4) { width: 9%; }
.table--history th:nth-child(5) { width: 11%; }
.table--history th:nth-child(6) { width: 16%; }
.table--history th:nth-child(7) { width: 15%; }
.table--history th:nth-child(8) { width: 132px; }

.table--trash thead th, .table--trash tbody td,
.table--history thead th, .table--history tbody td { padding-left: 10px; padding-right: 10px; }

.table--trash .td--date, .table--history .td--date { font-size: 12.5px; }
.table--trash .btn--sm, .table--history .btn--sm { padding: 5px 8px; }

.history__lead { margin: 0 0 14px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.history__slug {
  color: var(--text-faint);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12.5px;
}

/* invite */
.overlay--top { z-index: 55; }

.invite__lead { margin: 0 0 14px; color: var(--text-muted); }
.invite__lead strong { color: var(--text); }

.invite__box {
  padding: 14px;
  background: var(--accent-weak);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
}

.invite__caption {
  display: block;
  margin-bottom: 6px;
  font-size: 11px;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: .04em;
}

.invite__url {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  overflow-wrap: anywhere;
}

.invite__copy { width: 100%; margin-top: 10px; }
.invite__copy.is-copied { background: var(--success); border-color: var(--success); }

.invite__notes {
  margin: 14px 0 16px;
  padding-left: 18px;
  color: var(--text-muted);
  font-size: 13px;
}

.invite__notes li + li { margin-top: 4px; }
.invite__notes strong { color: var(--danger-strong); }

.invite__hint { margin: 0; color: var(--text-muted); font-size: 13px; }

.login__card .input[readonly] { background: var(--surface-2); color: var(--text-muted); cursor: default; }

/* toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 60;
  transform: translateX(-50%);
  padding: 9px 18px;
  border-radius: 999px;
  background: var(--text);
  color: var(--bg);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
}

@media (max-width: 640px) {
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar__name { display: none; }
  .topbar__user { gap: 6px; }
  .menu__trigger { max-width: 120px; }
  .main { padding: 14px; }
  .toolbar { align-items: stretch; }
  .search { max-width: none; }
  .ownerfilter { flex: 1 1 auto; }
  .statusfilter { flex: 1 1 auto; }
  .periodgrid { grid-template-columns: minmax(0, 1fr); }
  .toolbar__right { justify-content: space-between; }
  .pager { gap: 8px; }
  .pager__btn { min-width: 0; flex: 0 1 auto; }
  .pager__status { min-width: 0; }
  .pager__unit { display: none; }
  .overlay { padding: 12px; align-items: flex-start; }
  .userform__grid { grid-template-columns: minmax(0, 1fr); }
}
