/* The team portal's page (ARCHITECTURE.md §40, contract v1.1 §11 + v2 §G). Plain CSS: no imports, no outside URLs. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #f0efeb;
  --text: #1d1d1f;
  --muted: #5f6368;
  --border: #dddcd6;
  --accent: #2f5fd0;
  --accent-text: #ffffff;
  --accent-soft: #e6ecfb;
  --member: #e9effc;
  --member-border: #cad6f3;
  --hermes: #ffffff;
  --error: #b3261e;
  --error-soft: #fbeceb;
  --warn: #7a4b00;
  --warn-soft: #fff3dc;
  --mark: #7a4b00;
  --mark-soft: #fff1d6;
  --focus: #2f5fd0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141517;
    --surface: #1d1f22;
    --surface-2: #26292d;
    --text: #ecebe8;
    --muted: #a3a6ab;
    --border: #34373c;
    --accent: #7ea2ff;
    --accent-text: #0f1420;
    --accent-soft: #24304d;
    --member: #222c40;
    --member-border: #33415f;
    --hermes: #1d1f22;
    --error: #ff8a80;
    --error-soft: #3a1f1d;
    --warn: #ffcf7a;
    --warn-soft: #3a2e17;
    --mark: #ffd28a;
    --mark-soft: #3b2f18;
    --focus: #9db8ff;
    --shadow: none;
  }
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  overflow-wrap: anywhere;
}

h1, h2, h3 { line-height: 1.25; margin: 0; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1.05rem; }
p { margin: 0; }
a { color: var(--accent); }
a:hover { text-decoration-thickness: 2px; }

:focus { outline: none; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 6px; }

.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%);
  white-space: nowrap; border: 0;
}

/* --- header ---------------------------------------------------------------------------------------------------- */
.top { background: var(--surface); border-bottom: 1px solid var(--border); }
.top-inner {
  max-width: 52rem; margin: 0 auto; padding: 0.75rem 1rem;
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
}
.brand { font-size: 1.15rem; font-weight: 650; letter-spacing: -0.01em; }
.brand-sub { color: var(--muted); font-weight: 500; }
.me-line { flex: 1 1 14rem; color: var(--muted); font-size: 0.95rem; }
#sign-out { margin-left: auto; }

/* --- banner ---------------------------------------------------------------------------------------------------- */
.banner {
  background: var(--warn-soft); color: var(--warn); border-bottom: 1px solid var(--border);
  display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: 0.5rem 1rem;
  padding: 0.6rem 1rem;
}
.banner-text { font-weight: 600; }

/* --- layout ---------------------------------------------------------------------------------------------------- */
.app { max-width: 52rem; margin: 0 auto; padding: 1rem; }
.loading { color: var(--muted); padding: 2rem 0; text-align: center; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1rem; box-shadow: var(--shadow);
}
.stack { display: flex; flex-direction: column; gap: 0.5rem; }
.muted { color: var(--muted); }
.empty { padding: 0.75rem 0; }
.spacer { flex: 1 1 auto; }
.hint { color: var(--muted); font-size: 0.8rem; }
.notice { color: var(--muted); font-size: 0.9rem; min-height: 0; }
.notice:empty, .error:empty { display: none; }
.error { color: var(--error); background: var(--error-soft); border-radius: 8px; padding: 0.5rem 0.75rem; }

/* --- controls -------------------------------------------------------------------------------------------------- */
label { font-weight: 600; font-size: 0.92rem; }
input, select, textarea, button { font: inherit; color: inherit; }
input[type="text"], input[type="date"], input[type="time"], select, textarea {
  width: 100%; min-height: 2.75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 0.55rem 0.75rem;
}
textarea { resize: vertical; line-height: 1.45; }
input:focus-visible, select:focus-visible, textarea:focus-visible { outline-offset: 0; border-color: var(--focus); }

.button {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.35rem;
  min-height: 2.75rem; min-width: 2.75rem; padding: 0.45rem 1rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); cursor: pointer;
  font-weight: 600; white-space: nowrap;
}
.button:hover { border-color: var(--muted); }
.button:disabled { opacity: 0.55; cursor: default; }
.button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.button.quiet { background: transparent; }
.button.small { min-height: 2.25rem; padding: 0.3rem 0.75rem; font-size: 0.9rem; }
.button.icon { padding: 0.45rem 0.6rem; font-size: 1.15rem; }
.button.toggle[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }

/* --- sign in --------------------------------------------------------------------------------------------------- */
.sign-in { max-width: 26rem; margin: 2rem auto; display: flex; flex-direction: column; gap: 0.75rem; }
#code-input { letter-spacing: 0.06em; font-variant-numeric: tabular-nums; text-transform: uppercase; }
#code-input::placeholder { text-transform: none; letter-spacing: 0.02em; }

/* --- tabs ------------------------------------------------------------------------------------------------------ */
.workspace { display: flex; flex-direction: column; gap: 1rem; }
.tabs {
  display: flex; flex-wrap: wrap; gap: 0.25rem;
  border-bottom: 1px solid var(--border);
}
.tab {
  min-height: 2.75rem; padding: 0.5rem 0.9rem;
  background: transparent; border: 0; border-bottom: 3px solid transparent; border-radius: 8px 8px 0 0;
  color: var(--muted); font-weight: 600; cursor: pointer;
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); border-bottom-color: var(--accent); }
.panel { display: flex; flex-direction: column; gap: 0.75rem; }
.panel-title { font-size: 1.1rem; }
.toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.toolbar select { width: auto; flex: 1 1 12rem; max-width: 100%; }

/* --- chat ------------------------------------------------------------------------------------------------------ */
.chat { position: relative; }
.messages {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column; gap: 0.6rem;
  max-height: calc(100vh - 19rem); min-height: 12rem; overflow-y: auto; overscroll-behavior: contain;
}
@supports (height: 100dvh) {
  .messages { max-height: calc(100dvh - 19rem); }
}
.msg {
  max-width: 92%; padding: 0.6rem 0.85rem; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--hermes); box-shadow: var(--shadow);
}
.msg-member { align-self: flex-end; background: var(--member); border-color: var(--member-border); }
.msg-hermes { align-self: flex-start; }
.msg-meta { display: block; color: var(--muted); font-size: 0.78rem; margin-bottom: 0.2rem; }
.msg-body { white-space: normal; }
.msg-plain { white-space: pre-wrap; }
.msg-working { color: var(--muted); font-style: italic; }
.msg-working::after {
  content: ""; display: inline-block; width: 0.5em; height: 0.5em; margin-left: 0.4em; vertical-align: middle;
  border-radius: 50%; background: var(--accent); animation: pulse 1.4s ease-in-out infinite;
}
.msg-unsent { border-style: dashed; }
.msg-status { display: block; margin-top: 0.3rem; color: var(--muted); font-size: 0.8rem; }
.msg-error { color: var(--error); }
@keyframes pulse { 0%, 100% { opacity: 0.25; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) { .msg-working::after { animation: none; opacity: 0.6; } }

.composer {
  display: flex; flex-direction: column; gap: 0.4rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.6rem;
}
.composer textarea { border: 0; padding: 0.35rem 0.4rem; min-height: 3rem; max-height: 14rem; }
.composer textarea:focus-visible { outline: 2px solid var(--focus); outline-offset: 0; }
.composer-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem; }
.attachments { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.35rem; }
.attachment {
  display: inline-flex; align-items: center; gap: 0.3rem; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.15rem 0.25rem 0.15rem 0.7rem; font-size: 0.85rem;
}
.attachment.failed { border-color: var(--error); color: var(--error); }
.attachment .button { min-height: 1.9rem; min-width: 1.9rem; padding: 0 0.4rem; border-radius: 999px; }
.chat.dragging .composer { border-color: var(--accent); border-style: dashed; background: var(--accent-soft); }
.drop-hint { text-align: center; color: var(--accent); font-weight: 600; }

/* --- rich text (replies, documents) ---------------------------------------------------------------------------- */
.rich p + p, .rich p + ul, .rich p + ol, .rich ul + p, .rich ol + p, .rich pre, .rich hr { margin-top: 0.5rem; }
.rich ul, .rich ol { margin: 0.35rem 0 0; padding-left: 1.4rem; }
.rich ul { list-style: disc; }
.rich ol { list-style: decimal; }
.rich li + li { margin-top: 0.15rem; }
.rich .heading { font-weight: 700; }
.rich code {
  font: 0.88em/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  background: var(--surface-2); border-radius: 5px; padding: 0.05rem 0.3rem;
}
.rich pre {
  background: var(--surface-2); border-radius: 8px; padding: 0.6rem 0.75rem; overflow-x: auto;
  white-space: pre; font: 0.85rem/1.45 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}
.rich pre code { background: none; padding: 0; }
.rich hr { border: 0; border-top: 1px solid var(--border); }

.chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin-top: 0.4rem; }
.chip {
  display: inline-flex; align-items: center; gap: 0.3rem; max-width: 100%;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 999px;
  padding: 0.2rem 0.7rem; font-size: 0.85rem; color: var(--text);
}
button.chip { cursor: pointer; min-height: 2rem; }
button.chip:hover { border-color: var(--accent); }

/* --- documents and files ---------------------------------------------------------------------------------------- */
.list-title { margin-top: 0.5rem; }
.rows { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.4rem 0.75rem;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.7rem 0.85rem;
}
.row-main { flex: 1 1 14rem; min-width: 0; display: flex; flex-direction: column; gap: 0.15rem; }
.row-title { font-weight: 600; }
.row-meta { color: var(--muted); font-size: 0.85rem; }
.row-actions { display: flex; flex-wrap: wrap; gap: 0.35rem; }
.marker {
  display: inline-block; background: var(--mark-soft); color: var(--mark); border: 1px solid currentColor;
  border-radius: 999px; padding: 0 0.55rem; font-size: 0.78rem; font-weight: 700; white-space: nowrap;
}
.viewer { display: flex; flex-direction: column; gap: 0.6rem; }
.viewer-head { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; }
.viewer-title { font-size: 1.1rem; }
.viewer-body { max-height: 60vh; overflow: auto; }
.viewer-body img { max-width: 100%; height: auto; border-radius: 8px; }
.viewer-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.sheet { border-collapse: collapse; font-size: 0.88rem; }
.sheet th, .sheet td { border: 1px solid var(--border); padding: 0.25rem 0.5rem; text-align: left; vertical-align: top; }
.sheet th { background: var(--surface-2); }

/* --- reminders -------------------------------------------------------------------------------------------------- */
.when { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.field { flex: 1 1 9rem; display: flex; flex-direction: column; gap: 0.3rem; }
.form-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.state {
  display: inline-block; border-radius: 999px; padding: 0 0.55rem; font-size: 0.8rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.state-open { background: var(--accent-soft); border-color: var(--accent); }
.state-done { color: var(--muted); }
.state-cancelled { color: var(--muted); text-decoration: line-through; }
.state-snoozed, .state-waiting { background: var(--warn-soft); color: var(--warn); }

/* --- narrow screens (down to 320 px) ---------------------------------------------------------------------------- */
@media (max-width: 30rem) {
  .app { padding: 0.75rem; }
  .top-inner { padding: 0.6rem 0.75rem; }
  .me-line { order: 3; flex: 1 1 100%; font-size: 0.88rem; }
  #sign-out { min-height: 2.25rem; padding: 0.3rem 0.75rem; }
  .msg { max-width: 100%; }
  .tab { padding: 0.5rem 0.6rem; font-size: 0.95rem; }
  .messages { max-height: calc(100vh - 21rem); }
  .sign-in { margin: 1rem auto; }
}
