@import url("https://fonts.googleapis.com/css2?family=Figtree:wght@400;500;600;700&family=Fraunces:opsz,wght@9..144,500;9..144,700&display=swap");

:root {
  --bg: #eef1ee;
  --bg-soft: #e4e9e5;
  --bg-elev: #fbfcfb;
  --bg-elev2: #f3f6f3;
  --ink: #15201a;
  --muted: #5c6b63;
  --line: #d5ddd7;
  --accent: #2d6a4f;
  --accent-deep: #1f4d39;
  --accent-soft: rgba(45, 106, 79, 0.12);
  --ok: #1f7a4d;
  --err: #b42318;
  --shadow: 0 18px 50px rgba(21, 32, 26, 0.08);
  --radius: 8px;
  --radius-sm: 6px;
  --font: "Figtree", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --sidebar: 240px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 3px; }
button, .chat-item, .app-tab, .btn-primary, .btn-ghost, .logout-btn, .new-chat-btn, .send-btn { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}
@keyframes drift {
  from { transform: translate3d(0, 0, 0); }
  to { transform: translate3d(-48px, -48px, 0); }
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Auth / landing ===== */
.auth-body, .landing-body {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 80% 55% at 15% 10%, rgba(45, 106, 79, 0.16), transparent 55%),
    radial-gradient(ellipse 70% 50% at 90% 85%, rgba(21, 32, 26, 0.08), transparent 50%),
    linear-gradient(160deg, #f7faf7 0%, var(--bg) 45%, #e7ece8 100%);
  position: relative;
  overflow: hidden;
}
.auth-body::before, .landing-body::before {
  content: "";
  position: absolute;
  inset: 0;
  background-image:
    linear-gradient(rgba(21, 32, 26, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(21, 32, 26, 0.03) 1px, transparent 1px);
  background-size: 48px 48px;
  mask-image: radial-gradient(circle at center, black 30%, transparent 78%);
  pointer-events: none;
  animation: drift 28s linear infinite;
}
.landing-body { display: flex; align-items: center; justify-content: center; padding: 32px 20px; }
.landing { position: relative; z-index: 1; width: min(720px, 100%); text-align: center; animation: rise 0.7s var(--ease) both; }
.landing-mark { width: 56px; height: 56px; margin: 0 auto 22px; color: var(--accent); }
.landing-brand { font-family: var(--display); font-size: clamp(3.2rem, 9vw, 5rem); font-weight: 700; letter-spacing: -0.03em; line-height: 0.95; margin-bottom: 18px; }
.landing-line { font-size: clamp(1.05rem, 2.4vw, 1.25rem); color: var(--muted); max-width: 34ch; margin: 0 auto 32px; line-height: 1.5; }
.landing-actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.btn-primary, .btn-ghost {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 48px; padding: 0 22px; border-radius: 999px;
  font-size: 15px; font-weight: 600; font-family: var(--font);
  transition: transform 0.18s var(--ease), background 0.18s, color 0.18s, border-color 0.18s;
}
.btn-primary { background: var(--accent); color: #fff; border: none; }
.btn-primary:hover { background: var(--accent-deep); text-decoration: none; transform: translateY(-1px); }
.btn-ghost { background: transparent; color: var(--ink); border: 1px solid var(--line); }
.btn-ghost:hover { border-color: var(--accent); color: var(--accent); text-decoration: none; transform: translateY(-1px); }

.auth-body { display: flex; align-items: center; justify-content: center; padding: 24px; }
.auth-card {
  position: relative; z-index: 1; width: min(400px, 100%);
  background: rgba(251, 252, 251, 0.88); backdrop-filter: blur(12px);
  border: 1px solid var(--line); border-radius: 20px; padding: 36px 32px;
  box-shadow: var(--shadow); text-align: center; animation: rise 0.55s var(--ease) both;
}
.auth-logo { width: 44px; height: 44px; margin: 0 auto 14px; color: var(--accent); }
.auth-card h1 { font-family: var(--display); font-size: 2rem; font-weight: 700; letter-spacing: -0.02em; }
.subtitle { color: var(--muted); font-size: 14px; margin: 8px 0 24px; line-height: 1.45; }
.auth-card form { display: flex; flex-direction: column; gap: 12px; text-align: left; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.auth-card input {
  width: 100%; background: var(--bg-elev); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 13px 15px; color: var(--ink); font-size: 15px; font-family: var(--font); outline: none;
}
.auth-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.auth-card .btn-primary { width: 100%; margin-top: 4px; border-radius: var(--radius-sm); }
.form-error {
  background: rgba(180, 35, 24, 0.08); color: var(--err); border: 1px solid rgba(180, 35, 24, 0.2);
  border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; text-align: left;
}
.auth-switch { color: var(--muted); font-size: 14px; margin-top: 20px; }

/* ===== App shell — canvas left, chat right ===== */
:root {
  --chat: 380px;
  --chrome: 48px;
  --pad-x: 28px;
  --radius: 0;
  --radius-sm: 0;
}

.app-shell {
  display: grid;
  grid-template-columns: 1fr var(--chat);
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.canvas-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  border-right: 1px solid var(--line);
  background: var(--bg);
}
.chat-pane {
  display: flex; flex-direction: column;
  min-width: 0; min-height: 0;
  background: var(--bg-elev);
}

.topbar {
  display: flex; align-items: center;
  height: var(--chrome); min-height: var(--chrome);
  padding: 0;
  border-bottom: 1px solid var(--line);
  background: var(--bg-elev);
}
.topbar.has-tabs { display: flex; }

.tab-strip {
  flex: 1; min-width: 0;
  display: flex; align-items: center; gap: 0;
  overflow-x: auto; height: 100%;
  padding: 0;
}
.tab-chip {
  display: inline-flex; align-items: center;
  height: 100%; max-width: 200px;
  border: 0; border-right: 1px solid var(--line); border-radius: 0;
  background: transparent; color: var(--muted);
  flex-shrink: 0;
}
.tab-chip.active { background: var(--bg); color: var(--ink); }
.tab-open {
  display: inline-flex; align-items: center; gap: 6px;
  border: 0; background: transparent; color: inherit;
  padding: 0 4px 0 12px; height: 100%;
  font-size: 12px; font-weight: 600; font-family: var(--font);
  min-width: 0; cursor: pointer;
}
.tab-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 120px; }
.tab-close {
  width: 28px; height: 100%; border: 0; border-radius: 0;
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 14px; line-height: 1; cursor: pointer;
}
.tab-close:hover { background: rgba(180,35,24,.08); color: var(--err); }
.ico { width: 16px; height: 16px; display: block; flex-shrink: 0; }

.canvas-area {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  min-height: 0;
  scrollbar-gutter: stable;
  scrollbar-width: thin;
  scrollbar-color: var(--muted) transparent;
}
.canvas-area::-webkit-scrollbar { width: 10px; }
.canvas-area::-webkit-scrollbar-track { background: transparent; }
.canvas-area::-webkit-scrollbar-thumb {
  background: color-mix(in srgb, var(--muted) 45%, transparent);
  border: 2px solid transparent;
  background-clip: padding-box;
}
.canvas-area::-webkit-scrollbar-thumb:hover {
  background: color-mix(in srgb, var(--muted) 70%, transparent);
  background-clip: padding-box;
  border: 2px solid transparent;
}
.canvas-empty {
  height: 100%;
  min-height: 100%;
  display: grid;
  place-items: center;
  margin: 0;
  padding: 0;
  color: var(--accent);
  opacity: 0.55;
}
.canvas-logo { width: 56px; height: 56px; display: block; }

.chat-panel {
  flex: 1; overflow-y: auto; min-height: 0;
  scrollbar-width: none; /* Firefox */
  -ms-overflow-style: none; /* IE/Edge */
}
.chat-panel::-webkit-scrollbar { display: none; width: 0; height: 0; }

.composer-wrap {
  display: flex;
  min-height: var(--chrome);
  max-height: min(40vh, 220px);
  border-top: 1px solid var(--line);
  background: var(--bg-elev);
  padding: 0;
  align-items: stretch;
}
#composer-form {
  display: flex; align-items: stretch; width: 100%;
  margin: 0; padding: 0; min-height: var(--chrome);
}
#msg {
  flex: 1; border: 0 !important; box-shadow: none !important;
  background: transparent !important; border-radius: 0 !important;
  padding: 14px !important;
  font-size: 13.5px; line-height: 1.4; color: var(--ink); font-family: var(--font);
  width: auto !important; outline: none !important;
  min-height: var(--chrome); max-height: min(40vh, 220px);
  height: var(--chrome);
  resize: none !important; overflow-y: auto;
  white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere;
  box-sizing: border-box;
}
#msg:focus { border: 0 !important; box-shadow: none !important; }
.composer-actions {
  display: flex; align-items: stretch; flex-shrink: 0;
  align-self: stretch;
  border-left: 1px solid var(--line);
  background: var(--bg-elev);
  min-height: 100%;
}
.send-btn {
  width: var(--chrome); min-height: var(--chrome); height: auto; border: 0; border-radius: 0;
  background: var(--accent); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  position: relative; cursor: pointer;
  align-self: stretch;
}
.send-btn:hover { background: var(--accent-deep); }
.mic-btn {
  width: var(--chrome); min-height: var(--chrome); height: auto; border: 0; border-radius: 0;
  background: transparent; color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0;
  border-left: 0; cursor: pointer;
  align-self: stretch;
}
.mic-btn:hover { color: var(--ink); background: var(--bg-soft); }
.mic-btn.is-listening {
  color: var(--accent); background: var(--accent-soft);
}
.mic-btn:disabled { opacity: 0.35; cursor: not-allowed; }

.chat-view { min-height: 100%; display: flex; flex-direction: column; }
.messages {
  display: flex; flex-direction: column; gap: 0;
  padding: 0; width: 100%;
}
.chat-empty { text-align: center; padding: 40px 16px; }
.chat-empty-title { font-family: var(--display); font-size: 1.15rem; margin-bottom: 6px; }

.msg {
  display: block; width: 100%;
  border-bottom: 1px solid var(--line);
}
.msg.user { justify-content: stretch; }
.msg.assistant[data-reply-to]:not([data-reply-to="0"]) {
  border-left: 2px solid var(--accent-soft);
}
.bubble {
  width: 100%; max-width: none;
  padding: 12px 14px; border-radius: 0; font-size: 13px; line-height: 1.5;
  word-wrap: break-word; overflow-wrap: anywhere;
  box-sizing: border-box;
}
.user-bubble {
  background: var(--accent-soft);
  color: var(--ink);
  white-space: pre-wrap;
  border: 0;
  position: relative;
  overflow: hidden;
}
.user-bubble .bubble-text {
  position: relative;
  z-index: 1;
}
.user-bubble.working::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  z-index: 0;
  width: 55%;
  background: linear-gradient(
    90deg,
    transparent 0%,
    color-mix(in srgb, var(--bg-elev) 55%, transparent) 45%,
    color-mix(in srgb, var(--bg-elev) 70%, transparent) 50%,
    color-mix(in srgb, var(--bg-elev) 55%, transparent) 55%,
    transparent 100%
  );
  animation: sheen 1.7s linear infinite;
  pointer-events: none;
}
@keyframes sheen {
  from { transform: translateX(-120%); }
  to { transform: translateX(220%); }
}
.assistant-bubble {
  background: transparent; border: 0; color: var(--ink);
}
.chat-run {
  width: 8px; height: 8px; border-radius: 50%;
  border: 1.5px solid var(--accent); border-top-color: transparent;
  animation: spin .7s linear infinite; flex-shrink: 0;
}

.md > *:first-child { margin-top: 0; }
.md > *:last-child { margin-bottom: 0; }
.md p { margin: .4em 0; }
.md h1, .md h2, .md h3 { font-family: var(--display); letter-spacing: -.02em; margin: .6em 0 .2em; }
.md h1 { font-size: 1.05rem; } .md h2 { font-size: 1rem; } .md h3 { font-size: .95rem; }
.md ul, .md ol { margin: .3em 0; padding-left: 1.1rem; }
.md code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .86em;
  background: var(--bg-soft); border: 1px solid var(--line); padding: .05em .25em;
}
.md pre {
  margin: .5em 0; padding: 8px 10px; background: #15201a; color: #e8eee9; overflow-x: auto;
}
.md pre code { background: none; border: 0; padding: 0; color: inherit; font-size: .8rem; }

.tab-view {
  width: 100%;
  max-width: none;
  margin: 0;
  padding: 16px var(--pad-x) 40px;
  box-sizing: border-box;
  animation: rise .25s var(--ease) both;
}
.app-header { margin-bottom: 14px; }
.tab-title { font-family: var(--display); font-size: 1.25rem; font-weight: 700; letter-spacing: -.02em; }
.panel, .card, .form-panel {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 0;
  padding: 14px; margin: 10px 0;
}
.panel h3, .card h3, .form-panel h3, .tab-view h3 { font-size: 13px; font-weight: 650; margin-bottom: 10px; }
.stack { display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: end; }
.row > * { flex: 1; min-width: 120px; }

.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px; margin: 10px 0;
  background: var(--bg-elev); border: 1px solid var(--line);
}
.data-table th {
  text-align: left; padding: 8px 10px; background: var(--bg-elev2); color: var(--muted);
  font-weight: 650; font-size: 11px; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid var(--line);
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: rgba(45,106,79,.04); }

.muted { color: var(--muted); font-size: 13px; }
.ok { color: var(--ok); font-weight: 600; }
.err { color: var(--err); font-weight: 600; }

input[type="text"], input[type="email"], input[type="password"], input[type="date"],
input[type="number"], input:not([type]), select, textarea {
  background: var(--bg-elev); border: 1px solid var(--line); border-radius: 0;
  padding: 8px 10px; color: var(--ink); font-size: 13px; font-family: var(--font); outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: none; }
button[type="submit"]:not(.send-btn):not(.tab-close):not(.tab-open) {
  background: var(--accent); color: #fff; border: none; border-radius: 0;
  padding: 8px 12px; font-size: 13px; font-weight: 600; font-family: var(--font); cursor: pointer;
}
button[type="submit"]:not(.send-btn):not(.tab-close):not(.tab-open):hover { background: var(--accent-deep); }

@media (max-width: 900px) {
  :root { --chat: 100%; --pad-x: 16px; }
  .app-shell { grid-template-columns: 1fr; grid-template-rows: 1fr 45vh; }
  .canvas-pane { border-right: 0; border-bottom: 1px solid var(--line); }
  .messages, .tab-view { padding-left: 14px; padding-right: 14px; }
}

/* ===== App kit (agent-built UIs) — helpers, not a cage ===== */
.tab-view { max-width: none; }
.app-header { display: none; }

.akit { display: flex; flex-direction: column; gap: 16px; width: 100%; animation: rise .35s var(--ease) both; }
.akit-hero { padding-top: 4px; width: 100%; }
.akit-eyebrow {
  font-size: 11px; font-weight: 700; letter-spacing: .08em; text-transform: uppercase;
  color: var(--accent); margin-bottom: 6px;
}
.akit-title {
  font-family: var(--display); font-size: clamp(1.35rem, 2.5vw, 1.6rem);
  font-weight: 700; letter-spacing: -.03em; line-height: 1.1; margin: 0;
}
.akit-sub { color: var(--muted); font-size: 15px; margin-top: 8px; line-height: 1.45; max-width: none; }

.akit-compose, .akit-section {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: 0;
  padding: 14px;
  width: 100%;
  box-sizing: border-box;
  box-shadow: 0 10px 28px rgba(21,32,26,.04);
}
.akit-section-title {
  font-size: 13px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); margin: 0 0 14px;
}
.akit-form { display: flex; flex-direction: column; gap: 12px; }
.akit-fields { display: grid; gap: 10px; }
@media (min-width: 640px) {
  .akit-fields.akit-fields-2 { grid-template-columns: 1fr 1fr; }
  .akit-fields.akit-fields-3 { grid-template-columns: 1.4fr 1fr auto; align-items: end; }
}
.akit-field { display: flex; flex-direction: column; gap: 6px; }
.akit-field label {
  font-size: 12px; font-weight: 650; color: var(--muted);
}
.akit-field input, .akit-field select, .akit-field textarea {
  border-radius: 0 !important; padding: 12px 13px !important; font-size: 14.5px !important;
}
.akit-field textarea { min-height: 88px; resize: vertical; }
.akit-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 2px; }
.akit-btn {
  background: var(--accent) !important; color: #fff !important; border: none !important;
  border-radius: 0 !important; padding: 11px 18px !important;
  font-size: 14px !important; font-weight: 650 !important; font-family: var(--font) !important;
}
.akit-btn:hover { background: var(--accent-deep) !important; }
.akit-btn-ghost {
  background: transparent !important; color: var(--muted) !important;
  border: 1px solid var(--line) !important; border-radius: 0 !important;
  padding: 10px 14px !important; font-size: 13px !important; font-weight: 600 !important;
}
.akit-btn-ghost:hover { border-color: var(--err) !important; color: var(--err) !important; }

.akit-list { display: flex; flex-direction: column; gap: 8px; }
.akit-item {
  display: grid; grid-template-columns: 1fr auto; gap: 12px; align-items: center;
  padding: 14px 14px; border: 1px solid var(--line); border-radius: 0;
  background: var(--bg-elev); transition: border-color .15s, background .15s;
}
.akit-item:hover { border-color: color-mix(in srgb, var(--accent) 35%, var(--line)); background: var(--accent-soft); }
.akit-item-main { min-width: 0; }
.akit-item-title { font-weight: 650; font-size: 15px; line-height: 1.3; }
.akit-item-meta { color: var(--muted); font-size: 12.5px; margin-top: 3px; }
.akit-item-actions { display: flex; gap: 6px; flex-shrink: 0; }
.akit-pill {
  display: inline-flex; align-items: center; border-radius: 0;
  padding: 3px 10px; font-size: 11px; font-weight: 700; letter-spacing: .02em;
  background: var(--accent-soft); color: var(--accent-deep);
}
.akit-pill.warn { background: rgba(180,35,24,.08); color: var(--err); }
.akit-pill.muted { background: var(--bg-soft); color: var(--muted); }
.akit-empty {
  text-align: center; padding: 36px 16px; color: var(--muted);
  border: 1px dashed var(--line); border-radius: 0; background: rgba(255,255,255,.5);
}
.akit-empty strong { display: block; color: var(--ink); font-size: 15px; margin-bottom: 4px; }

/* nicer default tables inside apps */
.akit .data-table { border-radius: 0; overflow: hidden; }
.akit .data-table th { font-size: 11px; }
