/* =============================================================
   Habitat Shell · Habitats v0.2
   Shared stylesheet — one file for the main page and solo pages.
   Visual language: habitats.thefocus.ai design.md (v0.2). Ported
   here; this repo does not depend on the private habitats source.
   ============================================================= */

@font-face {
  font-family: "Geist";
  src: url("./fonts/Geist-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("./fonts/Geist-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist";
  src: url("./fonts/Geist-SemiBold.woff2") format("woff2");
  font-weight: 600;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("./fonts/GeistMono-Regular.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Geist Mono";
  src: url("./fonts/GeistMono-Medium.woff2") format("woff2");
  font-weight: 500;
  font-style: normal;
  font-display: swap;
}

:root {
  /* === SURFACES === */
  --bg: #fafafa;
  --bg-subtle: #f5f5f5;
  --surface: #ffffff;
  --border: #ececec;
  --border-strong: #e0e0e0;

  /* === INK === */
  --ink: #0a0a0a;
  --ink-2: #404040;
  --ink-3: #737373;
  --ink-4: #a3a3a3;
  --ink-5: #d4d4d4;

  /* === ACTION === */
  --action: #0a0a0a;
  --action-hover: #000000;
  --on-action: #ffffff;

  /* === STATE === */
  --live: #00875a;
  --live-bg: #f0f9f4;
  --live-border: #c6e7d5;
  --warn: #b45309;
  --warn-bg: #fef7e6;
  --warn-border: #fde7b8;
  --info: #0070f3;
  --info-bg: #eff6ff;
  --info-border: #bfdbfe;
  --danger: #c1121f;
  --danger-bg: #fef2f2;
  --danger-border: #fecaca;

  /* === SHADOWS === */
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.04);
  --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.05), 0 1px 2px 0 rgb(0 0 0 / 0.03);
  --shadow-md: 0 4px 12px -2px rgb(0 0 0 / 0.08), 0 2px 4px -1px rgb(0 0 0 / 0.04);
  --shadow-lg: 0 10px 30px -8px rgb(0 0 0 / 0.18);

  /* === TYPE === */
  --font-sans: "Geist", -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: "Geist Mono", ui-monospace, "SF Mono", Monaco, monospace;
  --font-display: Georgia, "Times New Roman", serif;

  /* === RADIUS === */
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 10px;
  --r-xl: 14px;

  /* === LAYOUT === */
  --rail-left: 240px;
  --frame-max: 1320px;
  --gutter: 12px;

  /* === MOTION === */
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease: cubic-bezier(0.4, 0, 0.2, 1);
  --dur-fast: 0.12s;
  --dur: 0.18s;
  --dur-slow: 0.28s;

  /* Back-compat aliases — agent-written and peer components still use these. */
  --panel: var(--surface);
  --line: var(--border);
  --muted: var(--ink-3);
  --accent: var(--action);
  --error: var(--danger);
}

* { box-sizing: border-box; }

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

body {
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.005em;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

:focus-visible {
  outline: 2px solid var(--ink);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

/* === TOPBAR === */
.topbar,
body > header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  flex-shrink: 0;
}
.topbar h1,
body > header h1 {
  font-size: 14px;
  margin: 0;
  font-weight: 600;
  letter-spacing: -0.015em;
}
.crumb {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--ink-3);
  min-width: 0;
}
.crumb .org {
  color: var(--ink);
  font-weight: 500;
  font-family: var(--font-sans);
}
.crumb .sep { color: var(--ink-4); }
.crumb .current,
header .sub,
#host-name {
  color: var(--ink);
  font-family: var(--font-mono);
  font-size: 12px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#shell-status,
#solo-status {
  padding: 4px 2px 0;
  color: var(--ink-3);
  font-size: 12px;
  font-family: var(--font-mono);
}
#shell-status .err,
#solo-status .err { color: var(--danger); }

main#region {
  display: grid;
  gap: 12px;
  padding: 14px;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  align-items: start;
}

/* === CARDS (back-compat class; v0.2 look) === */
.shell-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: 24px;
}
.shell-card h2 {
  margin: 0 0 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 600;
  line-height: 1.4;
  letter-spacing: -0.005em;
  color: var(--ink);
  text-transform: none;
}
.shell-card dl {
  margin: 0;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 12px;
}
.shell-card dt {
  color: var(--ink-3);
  font-size: 13px;
}
.shell-card dd { margin: 0; }
.shell-card p.note,
.shell-card .note {
  margin: 0 0 8px;
  color: var(--ink-3);
  font-size: 13px;
}

/* === BUTTONS === */
.btn {
  font-family: var(--font-sans);
  font-weight: 500;
  font-size: 13.5px;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: -0.005em;
  text-decoration: none;
  white-space: nowrap;
  padding: 7px 14px;
  height: 36px;
  background: transparent;
  color: var(--ink);
  transition:
    background var(--dur-fast) var(--ease),
    border-color var(--dur-fast) var(--ease),
    color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.btn.sm {
  font-size: 12.5px;
  padding: 4px 10px;
  height: 28px;
  border-radius: var(--r-sm);
}
.btn.primary {
  background: var(--action);
  color: var(--on-action);
  border-color: var(--action);
}
.btn.primary:hover:not(:disabled) {
  background: var(--action-hover);
  box-shadow: var(--shadow-md);
}
.btn.secondary {
  background: var(--surface);
  color: var(--ink);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn.secondary:hover:not(:disabled) {
  background: var(--bg-subtle);
  border-color: var(--ink-4);
}
.btn.ghost { color: var(--ink-2); }
.btn.ghost:hover:not(:disabled) {
  background: var(--bg-subtle);
  color: var(--ink);
}
.btn.danger {
  background: var(--surface);
  color: var(--danger);
  border-color: var(--danger-border);
}
.btn.danger:hover:not(:disabled) { background: var(--danger-bg); }

/* === INPUTS === */
.input {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  padding: 9px 12px;
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--ink);
  outline: none;
  letter-spacing: -0.005em;
  transition:
    border-color var(--dur-fast) var(--ease),
    box-shadow var(--dur-fast) var(--ease);
}
.input::placeholder { color: var(--ink-4); }
.input:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgb(10 10 10 / 0.05);
}
.input:disabled { opacity: 0.55; }

/* === TAGS === */
.tag {
  display: inline-flex;
  align-items: center;
  background: var(--bg-subtle);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.5;
}
.tag.live {
  background: var(--live-bg);
  color: var(--live);
  border-color: var(--live-border);
}
.tag.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: var(--warn-border);
}
.tag.info {
  background: var(--info-bg);
  color: var(--info);
  border-color: var(--info-border);
}
.tag.danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: var(--danger-border);
}
.tag.dark {
  background: var(--ink);
  color: var(--surface);
  border-color: var(--ink);
}

.live-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--live);
  box-shadow: 0 0 0 2.5px rgb(0 135 90 / 0.18);
  display: inline-block;
  flex-shrink: 0;
}
.live-dot.off {
  background: var(--ink-4);
  box-shadow: none;
}
.live-dot.warn {
  background: var(--warn);
  box-shadow: 0 0 0 2.5px rgb(180 83 9 / 0.18);
}
.live-dot.danger {
  background: var(--danger);
  box-shadow: 0 0 0 2.5px rgb(193 18 31 / 0.18);
}

/* === LIST ROWS === */
.list-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 4px;
  background: transparent;
  color: var(--ink);
  border: 0;
  border-bottom: 1px solid var(--border);
  width: 100%;
  text-align: left;
  font: inherit;
  cursor: pointer;
  border-radius: 0;
}
.list-row:last-child { border-bottom: 0; }
.list-row:hover { background: var(--bg-subtle); }
.list-row .name { font-weight: 500; }
.list-row .sub {
  display: block;
  font-size: 12px;
  color: var(--ink-3);
}
.list-row .meta,
.list-row .btn {
  margin-left: auto;
}
.list-row .meta {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--ink-3);
}
.shell-card ul,
.secret-list {
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}
.msg .meta {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.msg[data-role="user"] .meta { color: rgb(255 255 255 / 0.65); }

/* === STOCK LAYOUT (ADR 0034) === */
body.shell-railed {
  display: grid;
  grid-template-columns: var(--rail-left) minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: var(--gutter);
  height: 100vh;
  height: 100dvh;
  max-width: var(--frame-max);
  margin: 0 auto;
  padding: 12px 14px 14px;
  overflow: hidden;
}
body.shell-railed > header { grid-column: 1 / -1; }
body.shell-railed > main#region {
  grid-row: 2;
  grid-column: 2;
  align-content: start;
  overflow: auto;
  min-height: 0;
  padding: 0;
}
body.shell-railed > #shell-status { grid-column: 1 / -1; }

aside.shell-rail {
  grid-row: 2;
  grid-column: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 8px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  overflow-y: auto;
  min-width: 0;
  min-height: 0;
}
.shell-rail .rail-stack,
.shell-rail .rail-admin {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 0 8px;
}
.shell-rail .rail-admin {
  margin-top: auto;
  padding-top: 8px;
  border-top: 1px solid var(--border);
}
.shell-rail .shell-card {
  border: 0;
  padding: 12px 8px;
  box-shadow: none;
  background: transparent;
}
.shell-rail .shell-card h2 { margin-bottom: 8px; }
.shell-rail .composer {
  flex-direction: column;
  align-items: stretch;
}
.shell-rail .input { width: 100%; min-width: 0; }
.shell-rail .composer .btn.primary { width: 100%; }
.prompt-list .btn {
  width: 100%;
  justify-content: flex-start;
  height: auto;
  white-space: normal;
  text-align: left;
}
[data-component="sessions"] ul {
  max-height: 16rem;
  overflow-y: auto;
}

body.shell-railed.rail-collapsed { grid-template-columns: 0 1fr; }
body.rail-collapsed aside.shell-rail { display: none; }

button.rail-toggle {
  margin-left: auto;
  flex-shrink: 0;
}

/* === CHAT / CONVERSATION === */
habitat-chat {
  display: flex;
  flex-direction: column;
  min-height: 0;
}
habitat-chat .log,
.chat-log {
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-height: 50vh;
  overflow-y: auto;
  padding: 4px 0 12px;
}
.msg {
  align-self: flex-start;
  max-width: 85%;
  padding: 10px 14px;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--surface);
}
.msg[data-role="user"] {
  align-self: flex-end;
  background: var(--ink);
  color: var(--on-action);
  border-color: var(--ink);
}
.msg[data-role="user"] a { color: var(--on-action); }
.composer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
  align-items: center;
}
.composer .input { flex: 1; min-width: 8rem; }
.attach-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  color: var(--ink-2);
  border-radius: var(--r-md);
  cursor: pointer;
}
.attach-btn:hover { background: var(--bg-subtle); color: var(--ink); }
.attach-btn input[type="file"] {
  position: absolute;
  inset: 0;
  width: 100%;
  opacity: 0;
  cursor: pointer;
}
.attachments {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.attachments > div {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.attachments img {
  width: 6rem;
  height: 5rem;
  object-fit: contain;
  display: block;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
  background: var(--bg-subtle);
}
.attachment-error {
  color: var(--danger);
  margin: 6px 0 0;
  font-size: 13px;
}

code, .mono {
  font-family: var(--font-mono);
  font-size: 12px;
}

a { color: var(--ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: rgb(0 0 0 / 0.08);
  border-radius: 999px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background-color: rgb(0 0 0 / 0.15);
  background-clip: padding-box;
}
