/* Agent Relay app — ThatMgmt UI kit, dark theme.
   Tokens and component rules come from brand/ui-kit.md (UK-001..UK-013).
   Strictly black and white: no accent color, no rounded corners,
   no shadows. 1px hairlines; 3px bars mark selection; 2px focus rings.
   Type: Archivo for prose, JetBrains Mono for labels and literal values. */

:root {
  color-scheme: dark;

  /* UK-001 color tokens, dark theme */
  --color-background: #0a0a0a;
  --color-surface: #171717;
  --color-text: #f7f7f5;
  --color-text-secondary: #a9a9a5;
  --color-border: #41413f;
  --color-border-strong: #f7f7f5;
  --color-inverse-background: #f7f7f5;
  --color-inverse-text: #0a0a0a;

  /* UK-001 type roles (brand guide) */
  --font-display: "Archivo", "Helvetica Neue", Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --font-weight-display: 720;
  --font-weight-heading: 650;
  --font-weight-body: 400;
  --font-weight-label: 500;

  /* UK-001 spacing scale */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 40px;
  --space-8: 48px;

  /* UK-001 motion */
  --motion-instant: 0ms;
  --motion-fade: 160ms;
  --motion-ease: cubic-bezier(0.23, 1, 0.32, 1); /* strong ease-out: built-in easings are too weak */

  /* UK-001 state + UK-009 focus */
  --state-active-opacity: 0.8;
  --focus-outline-width: 2px;
  --focus-outline-offset: 2px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html {
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-display);
  font-weight: var(--font-weight-body);
  color: var(--color-text);
  background: var(--color-background);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button { font: inherit; cursor: pointer; color: inherit; }
button, a, [role="button"] {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
input, textarea { font: inherit; color: var(--color-text); }

/* UK-009: visible focus on every interactive element */
:focus-visible {
  outline: var(--focus-outline-width) solid var(--color-border-strong);
  outline-offset: var(--focus-outline-offset);
}
:focus:not(:focus-visible) { outline: none; }

.muted { color: var(--color-text-secondary); }
.small { font-size: 12px; }

/* UK-001: mono for literal values only, never paragraphs */
.addr-mono {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 12.5px;
  letter-spacing: -0.01em;
}
.thread-pill {
  display: inline-block;
  flex: none;
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 11px;
  color: var(--color-text-secondary);
  border: 1px solid var(--color-border);
  background: var(--color-background);
  border-radius: 0;
  padding: 2px 8px;
  vertical-align: 1px;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#app {
  display: grid;
  grid-template-columns: 60px 264px 1fr;
  height: 100dvh;
}
#mobilebar { display: none; }

/* ---------- Icon rail ---------- */
#rail {
  background: var(--color-background);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: var(--space-3) 0;
  min-height: 0;
}
.rail-logo {
  width: 36px;
  height: 36px;
  border-radius: 0;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--color-text);
}
.rail-logo .logo-img { width: 26px; height: 26px; border-radius: 0; display: block; }

/* ---------- Sidebar ---------- */
#sidebar {
  background: var(--color-background);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}
.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px var(--space-3) 10px var(--space-4);
}
.side-title {
  font-size: 15px;
  font-weight: var(--font-weight-heading);
  letter-spacing: -0.01em;
}
.side-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  padding: var(--space-1) 10px;
}
.nav-row {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
  padding: var(--space-2) 10px;
  font-size: 13.5px;
  text-align: left;
}
.nav-row svg { width: 16px; height: 16px; flex: none; }
.nav-row .nav-label { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-row .nav-count {
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 12px;
  color: var(--color-text-secondary);
}

/* UK-004/005/006: selection is a 3px solid bar, never a tinted fill */
.nav-row.active { background: var(--color-surface); color: var(--color-text); }
.nav-row.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  width: 3px;
  background: var(--color-text);
}
.nav-row:active { opacity: var(--state-active-opacity); }

.side-footer {
  margin-top: auto;
  padding: var(--space-3);
  border-top: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.my-address {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--color-border);
  padding: var(--space-2) 10px;
  border-radius: 0;
  background: var(--color-surface);
  color: var(--color-text);
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 12px;
  text-align: left;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.my-address:active { opacity: var(--state-active-opacity); }
#btnSignOut {
  border: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 13px;
  padding: var(--space-1);
  min-height: 44px;
  text-align: left;
}

.foot-row { display: flex; gap: var(--space-2); }
.foot-row button {
  flex: 1;
  min-height: 44px;
  border: 1px solid var(--color-border);
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
  font-size: 12px;
  padding: var(--space-2) var(--space-2);
}

.foot-row button:active { opacity: var(--state-active-opacity); }

/* ---------- Main ---------- */
#main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
#mainbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-3) 18px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-background);
}
#mainbar h1 {
  font-size: 18px;
  margin: 0;
  font-weight: var(--font-weight-heading);
  display: flex;
  align-items: center;
  gap: 10px;
  letter-spacing: -0.01em;
}
#mainbar h1 svg { width: 16px; height: 16px; color: var(--color-text-secondary); }
.mainbar-actions { display: flex; align-items: center; gap: var(--space-2); }

/* ---------- Buttons (UK-002) ---------- */
.btn-dark {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: 44px;
  background: var(--color-surface);
  color: var(--color-text);
  border: 1px solid var(--color-border);
  border-radius: 0;
  padding: var(--space-2) var(--space-4);
  font-weight: var(--font-weight-heading);
  font-size: 13.5px;
}

.btn-dark:active { opacity: var(--state-active-opacity); }
.btn-dark:disabled {
  color: var(--color-text-secondary);
  border-color: var(--color-border);
  background: var(--color-surface);
  cursor: not-allowed;
  opacity: 1;
}
.btn-dark svg { width: 16px; height: 16px; }
/* UK-002 primary: the one main action on the screen */
.btn-primary {
  background: var(--color-text);
  color: var(--color-background);
  border: 1px solid var(--color-border-strong);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--color-text-secondary);
}

.icon-btn:active { opacity: var(--state-active-opacity); }
.icon-btn svg { width: 16px; height: 16px; }

#columns {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(380px, 520px) 1fr;
  min-height: 0;
}

/* ---------- Thread list ---------- */
#listPane {
  background: var(--color-background);
  border-right: 1px solid var(--color-border);
  overflow-y: auto;
  overscroll-behavior: contain;
  min-height: 0;
  min-width: 0;
}
.msg-row {
  display: grid;
  grid-template-columns: 18px minmax(0, 1fr) auto;
  grid-template-areas: "dot sender time" "dot main main";
  column-gap: 10px;
  row-gap: 3px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--color-border);
  border-radius: 0;
  background: transparent;
  padding: 10px 14px;
}

.msg-row:active { opacity: var(--state-active-opacity); }
.msg-row.selected { background: var(--color-surface); }
.msg-row.selected .row-subject { color: var(--color-text); }
.row-dot { grid-area: dot; display: inline-flex; justify-content: center; }
/* UK-001: no color to communicate state — unread is a 3px bar + weight */
.msg-dot { width: 3px; height: 28px; background: transparent; flex: none; }
.msg-row.unread .msg-dot { background: var(--color-text); }
.row-sender {
  grid-area: sender;
  font-size: 13.5px;
  font-weight: var(--font-weight-heading);
  color: var(--color-text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.row-main {
  grid-area: main;
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  min-width: 0;
  white-space: nowrap;
  overflow: hidden;
}
.row-id {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 12px;
  color: var(--color-text-secondary);
  flex: none;
  max-width: 128px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.row-subject {
  font-size: 13.5px;
  font-weight: var(--font-weight-heading);
  color: var(--color-text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 2 1 auto;
  min-width: 0;
}
.row-preview {
  font-size: 13px;
  color: var(--color-text-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1 3 auto;
  min-width: 0;
}
.msg-row:not(.unread) .row-subject { font-weight: var(--font-weight-body); color: var(--color-text-secondary); }
.msg-row:not(.unread) .row-sender { font-weight: var(--font-weight-body); color: var(--color-text-secondary); }
.row-time {
  grid-area: time;
  font-variant-numeric: tabular-nums;
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 12px;
  color: var(--color-text-secondary);
  white-space: nowrap;
  flex: none;
}

.list-empty {
  padding: 56px 28px;
  text-align: center;
  color: var(--color-text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
}
.list-empty .logo-img { width: 56px; height: 56px; border-radius: 0; display: block; }
.list-empty p { margin: 0; line-height: 1.6; font-size: 13.5px; }

/* ---------- Reading pane ---------- */
#readingPane {
  background: var(--color-background);
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  position: relative;
}
/* UK-005: centered type is reserved for empty states */
.reading-empty {
  margin: auto;
  text-align: center;
  color: var(--color-text-secondary);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: var(--space-3);
  font-size: 13.5px;
}
.reading-empty .logo-img { width: 56px; height: 56px; border-radius: 0; display: block; }
#readingContent {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
}
.reading-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 14px 20px var(--space-3);
  border-bottom: 1px solid var(--color-border);
}
.reading-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: var(--font-weight-heading);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  letter-spacing: -0.01em;
}
#btnBack { display: none; }
.sender-card {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) 20px;
  border-bottom: 1px solid var(--color-border);
}
.sender-meta { flex: 1; min-width: 0; }
.sender-line {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  overflow: hidden;
  white-space: nowrap;
}
.sender-line .addr-mono { font-size: 13px; font-weight: var(--font-weight-heading); color: var(--color-text); overflow: hidden; text-overflow: ellipsis; }
#rTime { margin-top: 3px; color: var(--color-text-secondary); }
.body-card {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  margin: var(--space-4) 20px;
  border: 1px solid var(--color-border);
  border-radius: 0;
  background: var(--color-background);
  padding: 20px;
  min-height: 120px;
}
#rBody { white-space: pre-wrap; word-break: break-word; line-height: 1.65; font-size: 14px; }
.reply-wrap { padding: 0 20px 20px; display: flex; }

/* ---------- Modals (UK-013 dialog) ---------- */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 10, 10, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 400;
  padding: var(--space-4);
  transition: opacity var(--motion-fade) var(--motion-ease), display var(--motion-fade) allow-discrete;
}
.modal[hidden] { display: none; }
@starting-style { .modal { opacity: 0; } }
.modal-card {
  background: var(--color-background);
  border: 1px solid var(--color-border-strong);
  border-radius: 0;
  width: 520px;
  max-width: calc(100vw - var(--space-6));
  max-height: calc(100dvh - 64px);
  display: flex;
  flex-direction: column;
  padding: var(--space-6);
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding-bottom: var(--space-4);
  border-bottom: 1px solid var(--color-border);
  margin-bottom: var(--space-4);
}
.modal-head h2 {
  margin: 0;
  font-size: 18px;
  font-weight: var(--font-weight-heading);
  display: flex;
  align-items: center;
  gap: 10px;
}
.modal-head .logo-img { width: 26px; height: 26px; border-radius: 0; display: block; }
.field { display: flex; flex-direction: column; gap: var(--space-2); margin-bottom: var(--space-3); }
.field.grow { flex: 1; min-height: 0; }
.field > span {
  font-family: var(--font-mono);
  font-weight: var(--font-weight-label);
  font-size: 12px;
  color: var(--color-text-secondary);
}
.field input, .field textarea {
  border: 1px solid var(--color-border-strong);
  border-radius: 0;
  padding: 10px var(--space-3);
  outline: none;
  width: 100%;
  min-height: 44px;
  background: var(--color-background);
  font-size: 16px;
}
.field input:focus, .field textarea:focus { border-color: var(--color-text); }
.field textarea { min-height: 140px; resize: vertical; line-height: 1.5; }
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-top: var(--space-1);
  padding-top: var(--space-4);
  border-top: 1px solid var(--color-border);
}
#composeHint { font-family: var(--font-mono); font-weight: var(--font-weight-label); font-size: 12px; }
.tabs { display: flex; gap: var(--space-1); margin-bottom: var(--space-4); border-bottom: 1px solid var(--color-border); }
.tab {
  position: relative;
  border: 0;
  border-radius: 0;
  background: transparent;
  padding: 10px 14px;
  min-height: 44px;
  font-weight: var(--font-weight-heading);
  color: var(--color-text-secondary);
  margin-bottom: -1px;
}

.tab.active { color: var(--color-text); }
.tab.active::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -1px;
  height: 3px;
  background: var(--color-text);
}
#paneImport textarea { min-height: 120px; font-family: var(--font-mono); font-size: 12px; }

/* ---------- Toast (UK-005 feedback) ---------- */
.toast {
  position: fixed;
  bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  left: 50%;
  transform: translateX(-50%);
  background: var(--color-inverse-background);
  color: var(--color-inverse-text);
  padding: 10px 18px;
  border-radius: 0;
  font-size: 13px;
  font-weight: var(--font-weight-label);
  z-index: 500;
  transition: opacity var(--motion-fade) var(--motion-ease), display var(--motion-fade) allow-discrete;
}
.toast[hidden] { display: none; }
@starting-style { .toast { opacity: 0; } }

/* ---------- Mobile (<700px): single column, list <-> reading ---------- */
@media (max-width: 700px) {
  #app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  #mobilebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 14px;
    border-bottom: 1px solid var(--color-border);
    background: var(--color-background);
  }
  #mobilebar .brand { display: flex; align-items: center; gap: var(--space-2); font-weight: var(--font-weight-heading); font-size: 15px; }
  #mobilebar .logo-img { width: 26px; height: 26px; border-radius: 0; display: block; }
  #rail, #sidebar { display: none; }
  #mainbar { display: none; }
  #columns { grid-template-columns: 1fr; }
  #app[data-view="list"] #readingPane { display: none; }
  #app[data-view="message"] #listPane { display: none; }
  #btnBack { display: inline-flex; }
  .msg-row { grid-template-columns: 14px minmax(0, 1fr) auto; column-gap: var(--space-2); }
  .reading-head { padding: 10px var(--space-3); }
  .sender-card { padding: 10px var(--space-3); }
  .body-card { margin: var(--space-3); padding: var(--space-4); }
  .reply-wrap { padding: 0 var(--space-3) var(--space-3); }
  .thread-pill { max-width: 120px; }
  .modal { padding: 0; align-items: stretch; }
  .modal-card {
    width: 100%;
    max-width: 100%;
    max-height: 100dvh;
    height: 100dvh;
    border-radius: 0;
    border: 0;
    padding: var(--space-5);
    padding-bottom: calc(var(--space-5) + env(safe-area-inset-bottom, 0px));
  }
}

/* UK-001: removing animation loses no orientation here — honor the preference */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* mobile-native: hover states are meaningless on touch — a first tap
   applies :hover and leaves it stuck. Gate every hover behind capability. */
@media (hover: hover) and (pointer: fine) {
  .nav-row:hover { background: var(--color-surface); color: var(--color-text); }
  .my-address:hover { border-color: var(--color-border-strong); }
  #btnSignOut:hover { color: var(--color-text); }
  .foot-row button:hover { color: var(--color-text); border-color: var(--color-border-strong); }
  .btn-dark:hover { background: var(--color-background); border-color: var(--color-border-strong); }
  .btn-primary:hover { background: var(--color-text-secondary); border-color: var(--color-border-strong); }
  .icon-btn:hover { background: var(--color-surface); color: var(--color-text); }
  .msg-row:hover { background: var(--color-surface); }
  .tab:hover { color: var(--color-text); }
}
