/*
 * Waypost Dashboard.
 *
 * Shares the marketing site's system: Apple's neutrals, one restrained brand
 * accent, hairline separators, and hierarchy carried by type scale and
 * whitespace. Body copy is Chinese, so tracking is set in em, never in px.
 */

:root {
  color-scheme: light;

  --bg: #f5f5f7;
  --panel: #fff;
  --border: #e3e3e8;
  --border-strong: #d2d2d7;
  --field: #d2d2d7;

  --text: #1d1d1f;
  --muted: #6e6e73;
  --faint: #86868b;

  --accent: #bb4d30;
  --accent-deep: #a3432a;
  --tint: #faf1ee;
  --tint-line: #e9cdc1;

  --danger: #a03328;
  --danger-tint: #fdf0ee;
  --danger-line: #f0cfca;

  --sans: system-ui, -apple-system, "SF Pro Text", "SF Pro Display",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, monospace;
  --ease: cubic-bezier(0.28, 0.11, 0.32, 1);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.65 var(--sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

a { color: inherit; text-decoration: none; }

h1, h2, h3 { color: var(--text); line-height: 1.3; text-wrap: balance; letter-spacing: -0.015em; }
h1 { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -0.018em; }
h2 { margin: 0; font-size: 20px; font-weight: 600; }
h3 { margin: 0; font-size: 17px; font-weight: 600; }
p { color: var(--muted); }

.fine { color: var(--faint); font-size: 12px; line-height: 1.75; }

/* ------------------------------------------------------------ Buttons */

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 980px;
  padding: 9px 19px;
  background: var(--text);
  color: #fff;
  font-size: 14px;
  font-weight: 400;
  letter-spacing: -0.01em;
  white-space: nowrap;
  transition: background-color 0.3s var(--ease), color 0.3s var(--ease),
    border-color 0.3s var(--ease), opacity 0.3s var(--ease);
}
button:hover { background: #3a3a3c; }
button:disabled { opacity: 0.45; cursor: progress; }

button.secondary {
  background: var(--panel);
  color: var(--accent);
  border-color: var(--border);
}
button.secondary:hover { background: var(--tint); border-color: var(--tint-line); }

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
summary:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ------------------------------------------------------------- Fields */

input, select, textarea {
  max-width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--field);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  transition: border-color 0.3s var(--ease), box-shadow 0.3s var(--ease);
}
input:hover, select:hover, textarea:hover { border-color: var(--faint); }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(187, 77, 48, 0.12);
  outline: none;
}
input:not([type="checkbox"]), textarea { width: 100%; }

label { display: grid; gap: 7px; margin: 14px 0; color: var(--muted); }

::placeholder { color: var(--faint); }

/* -------------------------------------------------------------- Brand */

.brand {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
  font-size: 23px;
  font-weight: 600;
  letter-spacing: -0.022em;
}
.brand-dot { color: var(--accent); }
.brand-mark { border-radius: 9px; flex-shrink: 0; }

/* -------------------------------------------------------------- Login */

#login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--panel);
}
.login-card { width: 100%; max-width: 460px; padding: 40px; }
.login-card h1 { margin: 44px 0 14px; font-size: 40px; }
.login-lang { display: flex; justify-content: flex-end; margin-top: 26px; }

/* Language switch: compact segmented control shared by login and sidebar. */
.lang-switch {
  display: inline-flex;
  gap: 2px;
  padding: 2px;
  border-radius: 980px;
  background: rgba(120, 120, 128, 0.12);
}
.lang-switch button {
  border: 0;
  background: transparent;
  border-radius: 980px;
  padding: 6px 12px;
  font-size: 12px;
  color: var(--muted);
  white-space: nowrap;
}
.lang-switch button:hover { background: transparent; color: var(--text); }
.lang-switch button[aria-pressed="true"] {
  background: var(--panel);
  color: var(--text);
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 1px 2px rgba(0, 0, 0, 0.06);
}
.login-card .lang-switch button,
.aside-bottom .lang-switch button {
  width: auto;
  margin: 0;
}
.lede { font-size: 18px; line-height: 1.7; }
.login-card form { margin-top: 32px; }
.login-card button { width: 100%; margin: 10px 0; }
.login-card .fine { margin-top: 28px; }

/* Inline error slot: reserve no space until it has something to say. */
.notice-inline { margin: 0; }
.notice-inline:empty { display: none; }

.notice {
  padding: 13px 18px;
  border: 1px solid var(--danger-line);
  border-radius: 12px;
  background: var(--danger-tint);
  color: var(--danger);
  font-size: 13px;
  white-space: pre-wrap;
}
#notice { margin-bottom: 20px; }

/* ----------------------------------------------------------- App shell */

#app { display: flex; min-height: 100vh; }
#app[hidden], #login[hidden] { display: none; }

aside {
  position: sticky;
  top: 0;
  height: 100vh;
  height: 100dvh;
  min-height: 0;
  align-self: flex-start;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  width: 236px;
  padding: 28px 22px;
  border-right: 1px solid var(--border);
  background: var(--panel);
}
aside .brand { margin-bottom: 28px; flex-shrink: 0; }
.sidebar-scroll { flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.space select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.space { margin: 0 0 10px; }

nav { display: grid; gap: 2px; margin-top: 24px; }
nav button {
  text-align: left;
  padding: 9px 14px;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
nav button:hover { background: var(--bg); color: var(--text); }
nav button.active { background: var(--tint); color: var(--accent); font-weight: 500; }

#management, #service-management { margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }
summary { cursor: pointer; color: var(--muted); }
#management summary, #service-management summary { font-size: 13px; }
#management nav, #service-management nav { margin-top: 10px; }
.service-actions { display: grid; gap: 8px; }
.service-actions button { padding: 9px 12px; white-space: normal; }

.aside-bottom { display: grid; flex-shrink: 0; gap: 8px; margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--border); }
.aside-bottom .lang-switch { justify-self: start; }
.aside-bottom p { margin: 0; }
.role-guide { display: grid; gap: 10px; padding: 22px 24px; background: var(--tint); border: 1px solid var(--tint-line); border-radius: 18px; }
.role-guide p { margin: 0; }
.connection-status { font-size: 13px; line-height: 1.7; color: var(--text); }
#new-messages { margin-bottom: 18px; }
.memory-library { display: grid; gap: 14px; }
.memory-library > p { margin: 0; }
.memory-items { display: grid; gap: 8px; }
.memory-items button { text-align: left; overflow-wrap: anywhere; }
[data-memory-editor] { min-height: 260px; max-width: 100%; resize: vertical; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; line-height: 1.6; }
.save-confirmation { color: var(--accent); }

main { flex: 1; min-width: 0; max-width: 1450px; padding: 44px 48px; }

header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 36px;
}
header h1 { margin: 8px 0 6px; }
header p { margin: 0; font-size: 15px; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: 0.08em; color: var(--faint); }
.actions { display: flex; flex-wrap: wrap; gap: 10px; }

section { display: grid; gap: 16px; }
#more { margin-top: 18px; }

/* -------------------------------------------------------------- Cards */

.card {
  padding: 24px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
}
.card h2 { margin-bottom: 6px; }
/* Cap the track so a lone card does not stretch across the full canvas. */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(272px, 360px));
  gap: 18px;
}

.agent { display: flex; flex-direction: column; gap: 10px; }
.avatar {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 13px;
  background: var(--tint);
  color: var(--accent);
  font-size: 22px;
  font-weight: 500;
}

.pill {
  display: inline-block;
  width: fit-content;
  margin-right: 6px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg);
  color: var(--muted);
  font-size: 12px;
}
.pill.disabled { background: var(--danger-tint); color: var(--danger); }

.empty {
  padding: 64px 28px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: var(--panel);
  text-align: center;
}
.empty h2 { margin-bottom: 10px; }
.empty button { margin-top: 14px; }

.row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; }

/* -------------------------------------------------------------- Table */

.table-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--panel);
}
table { width: 100%; min-width: 600px; border-collapse: collapse; text-align: left; }
td, th {
  max-width: 370px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  overflow-wrap: anywhere;
}
th { font-size: 12px; font-weight: 500; color: var(--muted); }
tbody tr:last-child td { border-bottom: 0; }
td button { padding: 5px 13px; font-size: 13px; }

code, pre { font-family: var(--mono); font-size: 12px; }
code { overflow-wrap: anywhere; }
pre {
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

/* ----------------------------------------------------------- Messages */

.message-row {
  display: flex;
  align-items: center;
  gap: 18px;
  width: 100%;
  padding: 20px 22px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--panel);
  color: var(--text);
  text-align: left;
  white-space: normal;
  transition: background-color 0.3s var(--ease), border-color 0.3s var(--ease);
}
.message-row:hover { background: var(--bg); border-color: var(--border-strong); }
.message-copy { flex: 1; min-width: 0; }
.message-copy strong { display: block; font-size: 17px; font-weight: 500; overflow-wrap: anywhere; }
.message-copy small { display: block; margin-top: 5px; color: var(--muted); font-size: 13px; }
.message-time { color: var(--faint); font-size: 12px; white-space: nowrap; }
.message-text { color: var(--text); font-size: 16px; line-height: 1.9; white-space: pre-wrap; overflow-wrap: anywhere; }
.message-meta { margin-bottom: 22px; padding-bottom: 16px; border-bottom: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.message-attachments { display: grid; gap: 12px; margin-top: 24px; padding-top: 18px; border-top: 1px solid var(--border); }

/* Collapsed-by-default provenance, so the letter stays the subject. */
.technical { margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); font-size: 13px; }
.technical summary { font-size: 13px; }

/* ------------------------------------------------------------ Privacy */

.privacy-form { max-width: 850px; }
.checks { display: flex; flex-wrap: wrap; gap: 8px 20px; }
.checks label { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--text); }
.privacy-form textarea { min-height: 100px; }
.privacy-form select { width: 100%; }

/* ------------------------------------------------------ Connections */

.connection-form fieldset {
  margin: 18px 0;
  padding: 14px 18px;
  border: 1px solid var(--border);
  border-radius: 12px;
}
.connection-form legend { font-weight: 600; }
.connection-form .checks { display: grid; gap: 4px; }
.connection-form select { width: 100%; }
.connection-form button[type="submit"] { margin-top: 14px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ------------------------------------------------------------- Dialog */

dialog {
  width: min(760px, 92vw);
  max-height: 88vh;
  padding: 28px;
  border: 1px solid var(--border);
  border-radius: 22px;
  background: var(--panel);
  color: var(--text);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.2); backdrop-filter: blur(3px); }
.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}
.dialog-header h2 { margin: 0; }
#detail-body > p:first-child { margin-top: 0; }

/* --------------------------------------------------------- Responsive */

@media (max-width: 800px) {
  #app { display: block; }
  aside {
    position: static;
    height: auto;
    width: auto;
    padding: 18px;
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-scroll { overflow: visible; flex: none; }
  aside .brand { margin-bottom: 12px; }
  .space { margin: 8px 0 10px; }
  nav { display: flex; overflow: auto; margin-top: 14px; gap: 4px; }
  nav button { white-space: nowrap; }
  .grid { grid-template-columns: 1fr; }
  #management, #service-management { margin-top: 12px; padding-top: 12px; }
  #management nav { flex-wrap: wrap; }
  .aside-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 0;
    flex-wrap: wrap;
  }
  main { padding: 26px 18px; }
  header { align-items: flex-start; flex-direction: column; gap: 16px; }
  h1 { font-size: 28px; }
  .form-grid { grid-template-columns: 1fr; }
  .message-row { flex-wrap: wrap; gap: 12px; padding: 18px; }
  .message-time { margin-left: 60px; }
  .message-copy strong { font-size: 16px; }
  dialog { padding: 22px; }
  .login-card { padding: 32px 24px; }
  .login-card h1 { font-size: 33px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    scroll-behavior: auto !important;
    animation: none !important;
    transition: none !important;
  }
}
