/* mimiai portal. One stylesheet, no build step (docs/18 §二 第 7 条). */

:root {
  --bg: #0d1017;
  --bg-raised: #161b26;
  --border: #262d3b;
  --fg: #e8ecf4;
  --fg-muted: #9aa4b8;
  --accent: #5b8cff;
  --accent-fg: #0a0d14;
  --danger: #ff8a8a;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

/*
 * `hidden` has to beat the display rules components set for themselves.
 *
 * The UA stylesheet's `[hidden] { display: none }` loses to any author rule:
 * `.btn` is `display: inline-block` and `.hero-actions` is a flex container, so
 * an element with the `hidden` attribute and a class of ours would still be laid
 * out. That is not theoretical - it is what the hero's signed-in control did
 * before this rule existed, and the browser assertion in tests/ui/portal-entry.mjs
 * is what caught it. Declared once, here, rather than by giving every component
 * a `[hidden]` variant that the next component will forget.
 */
[hidden] {
  display: none !important;
}

body {
  background: var(--bg);
  color: var(--fg);
  font: 16px/1.65 -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans SC",
    "PingFang SC", "Microsoft YaHei", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ------------------------------------------------------------------ topbar */

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 28px;
  border-bottom: 1px solid var(--border);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: var(--fg);
  text-decoration: none;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: 8px;
  background: var(--accent);
  color: var(--accent-fg);
  font-weight: 700;
}

.topnav-link {
  color: var(--fg-muted);
  text-decoration: none;
}

.topnav-link:hover {
  color: var(--fg);
}

/*
 * The language switcher (docs/18 §八). Three plain links rendered by bff-api,
 * the current one marked with aria-current - so it works with JavaScript off,
 * which is the same promise the rest of this page makes. Deliberately quiet: it
 * sits next to 登录/登出 and must not compete with them.
 */
.topbar-nav {
  display: inline-flex;
  align-items: center;
  gap: 16px;
}

.lang-switch {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.lang-link {
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
  line-height: 1.2;
}

.lang-link:hover {
  color: var(--fg);
}

.lang-link.is-current {
  color: var(--fg);
  font-weight: 600;
}

/* ------------------------------------------------------------------ buttons */

.btn {
  display: inline-block;
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: 10px;
  font: inherit;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: var(--accent-fg);
}

.btn-primary:hover {
  filter: brightness(1.08);
}

.btn-ghost {
  background: transparent;
  color: var(--fg);
  border-color: var(--border);
}

.btn-ghost:hover {
  border-color: var(--fg-muted);
}

.btn-lg {
  padding: 13px 24px;
  font-size: 17px;
}

.btn-block {
  display: block;
  width: 100%;
}

.btn[disabled] {
  opacity: 0.6;
  cursor: progress;
}

/*
 * A control that is present, clickable and deliberately inert - the payment
 * placeholder (docs/18 §5.1). It looks unavailable because it is, but a real
 * click still lands, because the click is what prints「支付通道尚未接入」. Hence
 * a class rather than the `disabled` attribute, which would swallow the event.
 */
.btn-muted {
  opacity: 0.65;
  color: var(--fg-muted);
  cursor: not-allowed;
}

/* --------------------------------------------------------------------- hero */

main {
  flex: 1;
}

.hero {
  max-width: 880px;
  margin: 0 auto;
  padding: 96px 28px 48px;
  text-align: center;
}

.eyebrow {
  margin: 0 0 12px;
  color: var(--accent);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.hero h1 {
  margin: 0;
  font-size: clamp(32px, 5vw, 52px);
  line-height: 1.2;
  letter-spacing: -0.01em;
}

.lede {
  max-width: 620px;
  margin: 20px auto 0;
  color: var(--fg-muted);
  font-size: 18px;
}

.hero-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 34px;
}

/* ----------------------------------------------------------------- features */

.features {
  max-width: 1040px;
  margin: 0 auto 72px;
  padding: 0 28px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 18px;
}

.card {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 17px;
}

.card p {
  margin: 0;
  color: var(--fg-muted);
  font-size: 15px;
}

/* --------------------------------------------------------------------- auth */

.auth {
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  padding: 72px 28px;
}

.auth h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.auth-form {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 28px 0 18px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
}

.auth-form label {
  font-size: 14px;
  color: var(--fg-muted);
  margin-top: 6px;
}

.auth-form input {
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.auth-form input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.auth-form .btn {
  margin-top: 18px;
}

.field-hint {
  margin: 0;
  color: var(--fg-muted);
  font-size: 13px;
}

.muted {
  color: var(--fg-muted);
  font-size: 15px;
}

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

.form-error {
  margin: 12px 0 0;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 14px;
}

/* ------------------------------------------------------------------- footer */

.footer {
  border-top: 1px solid var(--border);
  padding: 18px 28px;
  color: var(--fg-muted);
  font-size: 14px;
}

/* ------------------------------------------------------------------ pending */

/* The console's "reconciler has not finished" state - never a blank page
   (docs/18 §五 注册最小闭环). */
.pending {
  max-width: 560px;
  margin: 0 auto;
  padding: 96px 28px;
  text-align: center;
}

.pending h1 {
  font-size: 24px;
  margin: 0 0 12px;
}

/* -------------------------------------------------------------------- admin */

/* The administrator console (docs/19). It reuses every primitive above - the
   buttons, the cards, the form and error styles - and adds only what a table
   needs, so there is one visual system rather than two. */

main.admin {
  width: 100%;
  max-width: 1040px;
  margin: 0 auto;
  padding: 48px 28px 72px;
}

.admin h1 {
  margin: 0 0 8px;
  font-size: 26px;
}

.admin h2 {
  margin: 0 0 12px;
  font-size: 18px;
}

.admin-section {
  margin-top: 28px;
}

/* A wide form (the invite generator has four fields) is not the narrow centred
   one the login page uses. */
.auth-form.admin-form {
  max-width: 520px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
}

table.data th,
table.data td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

table.data th {
  color: var(--fg-muted);
  font-weight: 600;
  font-size: 13px;
}

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

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

/* Small buttons for table rows - the full-size ones would dominate the table. */
.btn-xs {
  padding: 5px 10px;
  font-size: 13px;
  border-radius: 8px;
}

/*
 * The invite code, shown once (docs/18 §5.1). It is a credential on screen, so
 * it gets the one treatment in this stylesheet that says "read this now, it will
 * not be here again": monospace, selectable, and impossible to mistake for text.
 */
.code-once {
  margin: 12px 0 0;
  padding: 14px 16px;
  border: 1px dashed var(--accent);
  border-radius: 10px;
  background: var(--bg);
  color: var(--fg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 20px;
  letter-spacing: 0.06em;
  word-break: break-all;
  user-select: all;
}

.notice {
  margin: 26px 0 0;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--fg-muted);
  font-size: 14px;
}

.table-empty {
  color: var(--fg-muted);
  font-size: 14px;
}

/*
 * The bar above a table: the search box and how many rows the current filter
 * has. The count is the answer to "did my search narrow anything?", which is
 * otherwise only visible by scrolling.
 */
.table-tools {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 12px;
}

/* Same treatment as the form inputs above, but outside `.auth-form`. */
.table-search {
  flex: 1 1 240px;
  max-width: 320px;
  padding: 9px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
  font-size: 14px;
}

.table-search:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.table-count {
  color: var(--fg-muted);
  font-size: 13px;
}

.pager {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
}

.pager-label {
  color: var(--fg-muted);
  font-size: 13px;
}

/*
 * A pager button that is out of range is inert, not busy. `.btn[disabled]` is
 * `cursor: progress` for the buttons whose click starts a request - reusing it
 * here would make「上一页」on page 1 look like a request in flight.
 */
.pager .btn[disabled] {
  cursor: default;
}

/* ------------------------------------------------- the console's two columns */

/*
 * 管理台 is a menu and a page, not one long scroll (docs/19 §四). It started as
 * a single page with two sections on it; the third one is where "one long
 * page" stops working, and a menu is what the next ten settings will need
 * anyway.
 *
 * The menu is a fixed-width column and the content takes the rest. `min-width:
 * 0` on the content is the load-bearing part and not decoration: a flex item
 * defaults to `min-width: auto`, which means the account table's intrinsic
 * width would push the column wider than the screen instead of scrolling
 * inside it.
 */
.admin-layout {
  display: flex;
  align-items: flex-start;
  gap: 28px;
}

.admin-menu {
  flex: 0 0 148px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  /* Follows the reader down a long list - the menu is the way out of a page,
     so it cannot be something you have to scroll back up to reach. */
  position: sticky;
  top: 24px;
}

.admin-menu-link {
  display: block;
  padding: 9px 12px;
  border-radius: 9px;
  color: var(--fg-muted);
  text-decoration: none;
  font-size: 14px;
  border: 1px solid transparent;
}

.admin-menu-link:hover {
  color: var(--fg);
  background: var(--bg-raised);
}

/*
 * The selected item. `aria-current` rather than a class: it is the attribute
 * that already MEANS "this is the page you are on", so the styling and what a
 * screen reader announces cannot drift apart.
 */
.admin-menu-link[aria-current="page"] {
  color: var(--accent-fg);
  background: var(--accent);
  font-weight: 600;
}

.admin-menu-link:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.admin-content {
  flex: 1 1 auto;
  min-width: 0;
}

/* The first section of a page is not indented the way a section that follows
   another one is - the heading belongs at the top of the column. */
.admin-page > .admin-section:first-child {
  margin-top: 0;
}

/*
 * Narrow screens: the menu becomes a horizontal strip above the content rather
 * than a column eating a third of a phone's width. Same markup, same links,
 * same hash - only the direction changes, and nothing is hidden.
 */
@media (max-width: 719px) {
  .admin-layout {
    flex-direction: column;
    gap: 16px;
  }

  .admin-menu {
    /* Undoes the sticky column: a horizontal bar that follows the reader down
       the page would sit on top of the content it is scrolling past. */
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    gap: 6px;
  }

  .admin-menu-link {
    flex: 0 0 auto;
  }
}

/* ----------------------------------------------------------------- switches */

/*
 * A checkbox and its sentence. The 备用模型 / 系统兜底 switches are the only
 * boolean controls in the console, and a bare checkbox with the label to its
 * right is what they are - no toggle-track imitation that has to be re-taught
 * to a keyboard.
 */
.switch,
.switch-inline {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 14px;
  cursor: pointer;
}

.switch {
  margin: 14px 0 0;
}

.switch input,
.switch-inline input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex: 0 0 auto;
}

.switch-inline {
  margin-top: 8px;
  color: var(--fg-muted);
}

/* A select is an input with a different drawing, so it gets the same one. */
.auth-form select {
  padding: 11px 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--fg);
  font: inherit;
}

.auth-form select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

/* Button rows outside a table (the model page's 保存 / 保存并验证). */
.admin-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

/* 第三方应用 (docs/20 §3.7).
   A list of rows that is also a set of controls: the name is what it is, the
   status is what the platform last knew, and the button is the only thing here
   that does anything. `margin-left: auto` on the button is what puts it at the
   far end without an empty spacer cell. */
.apps-list {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.apps-list li {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

.apps-list li:last-child {
  border-bottom: 0;
}

.apps-name {
  font-weight: 600;
}

.apps-status {
  color: var(--fg-muted);
  font-size: 0.9em;
}

.apps-list li .btn {
  margin-left: auto;
}
