:root {
  --bg: #08080a;
  --panel: #0d0d0f;
  --ink: #f2f2f3;
  --ink-2: #9d9da6;
  --ink-3: #6b6b75;
  --line: rgba(255, 255, 255, 0.085);
  --line-2: rgba(255, 255, 255, 0.16);
  --live: #79e2a8;
  --warn: #e7b549;
  --err: #e37373;
  --accent: #8b7cff;
  --accent-2: #5ec2ff;
  --danger: #e5484d;
  --danger-2: #ff6369;
  --sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  overflow-x: hidden;
  background:
    radial-gradient(900px 420px at 12% -8%, rgba(139, 124, 255, 0.13), transparent 70%),
    radial-gradient(700px 380px at 95% -5%, rgba(94, 194, 255, 0.09), transparent 70%),
    var(--bg);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--sans);
  font-size: 14px;
  line-height: 1.45;
  letter-spacing: -0.003em;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  margin: 0;
  font-weight: 600;
}

a {
  color: inherit;
}

[hidden] {
  display: none !important;
}

:focus-visible {
  outline: 1px solid var(--ink);
  outline-offset: 2px;
}

.ta-r {
  text-align: right;
}

.dim {
  color: var(--ink-3) !important;
}

.label {
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- top bar ---------- */

.bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  height: 58px;
  padding: 0 clamp(14px, 3vw, 30px);
  border-bottom: 1px solid var(--line);
  background: rgba(8, 8, 10, 0.72);
  backdrop-filter: blur(14px);
}

.bar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.wordmark {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.24em;
  white-space: nowrap;
  background: linear-gradient(90deg, var(--ink), var(--accent-2));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.live {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--ink-3);
  font-family: var(--mono);
  font-size: 11px;
  white-space: nowrap;
}

.live-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--ink-3);
}

.live {
  padding: 3px 9px 3px 8px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.03);
}

.live-dot {
  width: 6px;
  height: 6px;
}

.live[data-level="ok"] .live-dot {
  background: var(--live);
  box-shadow: 0 0 0 0 rgba(121, 226, 168, 0.6);
  animation: pulse 2s ease-out infinite;
}

@keyframes pulse {
  70% {
    box-shadow: 0 0 0 6px rgba(121, 226, 168, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(121, 226, 168, 0);
  }
}

.live[data-level="warn"] .live-dot {
  background: var(--warn);
}

.live[data-level="bad"] .live-dot {
  background: var(--err);
}

.btn-solid {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 9px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #07070b;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  cursor: pointer;
  box-shadow: 0 4px 18px -6px rgba(139, 124, 255, 0.6);
  transition: transform 0.12s ease, box-shadow 0.12s ease, opacity 0.12s ease;
}

.btn-solid:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 22px -6px rgba(139, 124, 255, 0.7);
}

.btn-danger {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 170px;
  height: 36px;
  padding: 0 16px;
  border: 1px solid var(--danger);
  border-radius: 9px;
  background: var(--danger);
  color: #fff;
  font: inherit;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: background 0.12s ease, opacity 0.12s ease, box-shadow 0.12s ease;
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-2);
}

.btn-danger:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-danger[data-phase="ready"] {
  box-shadow: 0 0 0 3px rgba(229, 72, 77, 0.35);
}

.danger {
  margin-top: 34px;
}

.danger-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.btn-solid:disabled {
  opacity: 0.5;
  cursor: progress;
}

.btn-block {
  width: 100%;
}

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--ink-3);
  font: inherit;
  font-size: 11.5px;
  cursor: pointer;
}

.link-btn:hover {
  color: var(--ink);
}

/* ---------- sheet ---------- */

.sheet {
  max-width: 940px;
  margin: 0 auto;
  padding: 26px clamp(14px, 3vw, 30px) 96px;
}

.sheet-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 14px;
}

.sheet-head h1 {
  font-size: 22px;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.sheet-count {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

/* ---------- roster ---------- */

.roster {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.018);
  box-shadow: 0 20px 50px -30px rgba(0, 0, 0, 0.8);
}

.row:last-child {
  border-bottom: 0;
}

.cell-label {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.cell-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(135deg, rgba(139, 124, 255, 0.35), rgba(94, 194, 255, 0.25));
  border: 1px solid var(--line-2);
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
}

.row {
  display: grid;
  grid-template-columns: minmax(110px, 1.05fr) minmax(140px, 1.4fr) minmax(100px, 1fr) 62px;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 13px 16px;
  border: 0;
  border-bottom: 1px solid var(--line);
  background: none;
  color: inherit;
  font: inherit;
  text-align: left;
  cursor: pointer;
  transition: background 0.12s ease;
}

.row:hover {
  background: rgba(139, 124, 255, 0.07);
}

.row.is-selected {
  background: rgba(255, 255, 255, 0.05);
  box-shadow: inset 2px 0 0 var(--accent);
}

.row-head {
  padding: 10px 16px;
  background: rgba(255, 255, 255, 0.025);
  cursor: default;
  color: var(--ink-3);
  font-size: 9.5px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.row-head:hover {
  background: none;
}

.cell-label {
  font-size: 13px;
  font-weight: 550;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-now {
  font-family: var(--mono);
  font-size: 12.5px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-was {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.cell-when {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.empty {
  margin: 0;
  padding: 28px 10px;
  border-bottom: 1px solid var(--line);
  color: var(--ink-3);
  font-size: 12.5px;
}

/* ---------- bottom tabs ---------- */

.tabs {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 45;
  border-top: 1px solid var(--line);
  background: rgba(8, 8, 10, 0.96);
  backdrop-filter: blur(10px);
}

.tabs-inner {
  display: flex;
  align-items: center;
  max-width: 940px;
  margin: 0 auto;
  padding: 0 clamp(6px, 3vw, 26px);
  height: 44px;
}

.tabs-scroll {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 1 1 auto;
  height: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}

.tabs-scroll::-webkit-scrollbar {
  display: none;
}

.tab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex: 0 0 auto;
  height: 44px;
  padding: 0 9px;
  border: 0;
  background: none;
  color: var(--ink-2);
  font: inherit;
  font-size: 12px;
  white-space: nowrap;
  cursor: pointer;
  transition: color 0.12s ease;
}

.tab:hover {
  color: var(--ink);
}

.tab.is-active {
  color: var(--ink);
}

.tab.is-active::after {
  content: "";
  position: absolute;
  right: 9px;
  bottom: 0;
  left: 9px;
  height: 1.5px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}

.tab-n {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.tab-signout {
  flex: 0 0 auto;
  margin-left: 10px;
  padding-left: 14px;
  border-left: 1px solid var(--line);
  color: var(--ink-3);
}

.tab-signout:hover {
  color: var(--err);
}

/* ---------- drawer ---------- */

.scrim {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  transition: opacity 0.18s ease;
}

.scrim.is-visible {
  opacity: 1;
}

.drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 60;
  display: flex;
  flex-direction: column;
  width: min(420px, 100%);
  border-left: 1px solid var(--line-2);
  background: var(--panel);
  transform: translateX(100%);
  transition: transform 0.24s cubic-bezier(0.32, 0.72, 0, 1);
}

.drawer.is-open {
  transform: none;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 20px;
  height: 54px;
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.drawer-body {
  flex: 1 1 auto;
  padding: 22px 20px 40px;
  overflow-y: auto;
}

.drawer-name {
  font-size: 21px;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.drawer-id {
  display: inline-block;
  margin-top: 4px;
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  text-decoration: none;
}

.drawer-id:hover {
  color: var(--ink-2);
  text-decoration: underline;
  text-underline-offset: 2px;
}

.facts {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  margin: 22px 0 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.facts > div {
  min-width: 0;
  padding: 12px 12px 13px 0;
}

.facts > div + div {
  padding-left: 13px;
  border-left: 1px solid var(--line);
}

.facts dt {
  margin-bottom: 5px;
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.facts dd {
  margin: 0;
  font-family: var(--mono);
  font-size: 12.5px;
  overflow-wrap: anywhere;
}

.section-label {
  display: block;
  margin: 26px 0 8px;
}

.log {
  margin: 0;
  padding: 0;
  list-style: none;
}

.log-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
  padding: 10px 0;
  border-top: 1px solid var(--line);
}

.log-item:last-child {
  border-bottom: 1px solid var(--line);
}

.log-time {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--ink-3);
  font-variant-numeric: tabular-nums;
}

.log-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 7px;
  font-family: var(--mono);
  font-size: 12px;
}

.log-from {
  color: var(--ink-3);
}

.log-arrow {
  color: var(--ink-3);
}

.log-to {
  color: var(--ink);
}

.log-note {
  font-family: var(--sans);
  font-size: 9.5px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
}

/* ---------- add dialog ---------- */

.sheet-dialog {
  width: min(380px, calc(100vw - 28px));
  padding: 0;
  border: 1px solid var(--line-2);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
}

.sheet-dialog::backdrop {
  background: rgba(0, 0, 0, 0.6);
}

.dialog-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 20px;
}

.dialog-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.dialog-title {
  font-size: 14px;
}

.dialog-note {
  margin: 0;
  color: var(--ink-3);
  font-size: 11px;
  line-height: 1.4;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.field > span {
  font-size: 9px;
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.field input {
  height: 32px;
  padding: 0 9px;
  border: 1px solid var(--line-2);
  border-radius: 6px;
  background: #06060a;
  color: var(--ink);
  font: inherit;
  font-size: 12.5px;
}

.field input[name="profileId"],
.field input[name="category"] {
  font-family: var(--mono);
  font-size: 12px;
}

.field input::placeholder {
  color: #55555e;
}

.field input:focus {
  outline: none;
  border-color: var(--ink-2);
}

.alert {
  margin: 0;
  padding: 2px 0 2px 10px;
  border-left: 2px solid var(--err);
  color: var(--err);
  font-size: 11.5px;
  line-height: 1.45;
}

/* ---------- login ---------- */

.login-page {
  display: flex;
  align-items: center;
  min-height: 100vh;
}

.login {
  width: 100%;
  max-width: 330px;
  margin: 0 auto;
  padding: 40px 20px;
}

.login .wordmark {
  display: block;
  margin-bottom: 40px;
}

.login h1 {
  font-size: 19px;
  letter-spacing: -0.02em;
}

.login-hint {
  margin: 7px 0 0;
  color: var(--ink-3);
  font-size: 12px;
}

.login-form {
  display: flex;
  flex-direction: column;
  gap: 18px;
  margin-top: 26px;
}

/* Underline-style field: more specific than .field input on purpose. */
.login .field input.input-line {
  width: 100%;
  height: 36px;
  padding: 0;
  border: 0;
  border-bottom: 1px solid var(--line-2);
  border-radius: 0;
  background: none;
  color: var(--ink);
  font-family: var(--mono);
  font-size: 14px;
}

.login .field input.input-line:focus {
  outline: none;
  border-bottom-color: var(--ink);
}

.login .field input.input-line::placeholder {
  color: #4e4e57;
}

.login .alert {
  margin-top: 18px;
}

.login-foot {
  margin: 46px 0 0;
  color: #4a4a53;
  font-family: var(--mono);
  font-size: 10.5px;
  letter-spacing: 0.06em;
}

/* ---------- responsive ---------- */

@media (max-width: 700px) {
  .row,
  .row-head {
    grid-template-columns: minmax(0, 1fr) auto;
    column-gap: 10px;
    row-gap: 2px;
  }

  .row-head {
    display: none;
  }

  .row {
    grid-template-areas:
      "label when"
      "now now"
      "was was";
    padding: 13px 10px;
  }

  .cell-label {
    grid-area: label;
  }

  .cell-when {
    grid-area: when;
  }

  .cell-now {
    grid-area: now;
  }

  .cell-was {
    grid-area: was;
  }

  /* Don't leave an empty third line on rows with no previous name. */
  .cell-was.is-empty {
    display: none;
  }

  .wordmark {
    letter-spacing: 0.18em;
  }

  .facts {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 420px) {
  .bar-left {
    gap: 10px;
  }

  .live {
    font-size: 10px;
  }
}

@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
}
