/* Ghostwriter. Zinc neutrals, one muted cobalt accent, Geist + Geist Mono.
   Radius system: 8px surfaces/inputs/buttons, pill chips. */

:root {
  --bg: #f6f6f7;
  --surface: #ffffff;
  --surface-2: #efeff1;
  --border: #e3e3e7;
  --text: #1b1b1f;
  --text-2: #6d6d78;
  --accent: #3b5bcc;
  --accent-strong: #3350b4;
  --accent-soft: #e9edfa;
  --ok: #217a4b;
  --ok-soft: #e4f2ea;
  --danger: #b3402f;
  --shadow: 0 12px 40px rgba(27, 27, 31, 0.14);
  --radius: 8px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101013;
    --surface: #17171b;
    --surface-2: #1e1e24;
    --border: #29292f;
    --text: #ececee;
    --text-2: #98989f;
    --accent: #8aa2ee;
    --accent-strong: #a4b7f3;
    --accent-soft: #222a41;
    --ok: #67c290;
    --ok-soft: #1b2f24;
    --danger: #e08573;
    --shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Geist", -apple-system, "Segoe UI", sans-serif;
  font-size: 14px;
  line-height: 1.55;
  overflow: hidden;
}
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
::placeholder { color: var(--text-2); opacity: 1; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

.mono { font-family: "Geist Mono", ui-monospace, monospace; }

/* ============ App grid: full viewport, three panes ============ */
.app {
  display: grid;
  grid-template-columns: 250px 380px 1fr;
  height: 100dvh;
  width: 100vw;
}

/* ============ Sidebar ============ */
.sidebar {
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 18px 14px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 6px; }
.brand-mark {
  width: 30px; height: 30px; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-size: 17px;
}
@media (prefers-color-scheme: dark) {
  .brand-mark { color: #101013; }
}
.brand-name { font-weight: 600; font-size: 15px; letter-spacing: -0.01em; }

.compose-btn {
  display: flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 12px;
  border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  font-weight: 500;
  transition: background 0.15s ease, transform 0.1s ease;
}
@media (prefers-color-scheme: dark) {
  .compose-btn { color: #101013; }
}
.compose-btn:hover { background: var(--accent-strong); }
.compose-btn:active { transform: scale(0.98); }

.folders { display: flex; flex-direction: column; gap: 2px; }
.folder {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border: none; border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  text-align: left;
  transition: background 0.12s ease, color 0.12s ease;
}
.folder:hover { background: var(--surface-2); color: var(--text); }
.folder.active { background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.folder i { font-size: 17px; }
.folder .count {
  margin-left: auto;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11.5px;
  color: var(--text-2);
}
.folder.active .count { color: var(--accent); }

/* Agent activity */
.agent-panel {
  margin-top: auto;
  display: flex; flex-direction: column; gap: 8px;
  min-height: 0; flex: 0 1 300px;
  border-top: 1px solid var(--border);
  padding-top: 14px;
}
.agent-panel-head { display: flex; align-items: center; justify-content: space-between; padding: 0 4px; }
.agent-title { font-size: 12px; font-weight: 600; color: var(--text-2); }
.agent-status {
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 10.5px;
  padding: 3px 8px;
  border-radius: 999px;
}
.agent-status.on { background: var(--ok-soft); color: var(--ok); }
.agent-status.off { background: var(--surface-2); color: var(--text-2); }
.agent-log {
  overflow-y: auto;
  display: flex; flex-direction: column; gap: 6px;
  padding: 0 4px 4px;
}
.agent-log-empty { font-size: 12px; color: var(--text-2); margin: 0; }
.log-entry {
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.5;
  padding: 6px 8px;
  background: var(--surface-2);
  border-radius: var(--radius);
  word-break: break-word;
}
.log-entry .tool { color: var(--accent); font-weight: 500; }
.log-entry .args { color: var(--text-2); }

/* ============ Thread list ============ */
.list-pane {
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--surface);
  min-height: 0;
}
.list-head { padding: 14px; border-bottom: 1px solid var(--border); }
.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 8px 12px;
  color: var(--text-2);
}
.search input {
  border: none; background: transparent; outline: none;
  flex: 1; color: var(--text); min-width: 0;
}
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }

.thread-list { overflow-y: auto; min-height: 0; }
.thread-item {
  width: 100%;
  display: block;
  text-align: left;
  border: none; background: transparent;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  transition: background 0.12s ease;
}
.thread-item:hover { background: var(--surface-2); }
.thread-item.active { background: var(--accent-soft); }
.thread-top { display: flex; align-items: baseline; gap: 8px; }
.thread-from {
  font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item.unread .thread-from { font-weight: 600; }
.thread-time {
  margin-left: auto; flex-shrink: 0;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px; color: var(--text-2);
}
.thread-subject {
  margin: 2px 0 1px;
  color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.thread-item.unread .thread-subject { font-weight: 600; }
.thread-item.unread .thread-subject::before {
  content: "";
  display: inline-block;
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  margin-right: 7px;
  vertical-align: 1px;
}
.thread-snippet {
  font-size: 12.5px; color: var(--text-2);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.list-empty { padding: 40px 20px; text-align: center; color: var(--text-2); font-size: 13px; }

/* ============ Reading pane ============ */
.read-pane { min-height: 0; overflow-y: auto; background: var(--bg); }
.read-empty {
  height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; color: var(--text-2);
}
.read-empty i { font-size: 44px; opacity: 0.5; }
.read-empty h2 { margin: 8px 0 0; font-size: 17px; font-weight: 600; color: var(--text); }
.read-empty p { margin: 0; font-size: 13.5px; max-width: 32ch; text-align: center; }

.thread-view { max-width: 860px; padding: 28px 36px 60px; }
.thread-view-head { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.thread-view-head h1 {
  font-size: 21px; font-weight: 600; letter-spacing: -0.01em;
  margin: 0; line-height: 1.3; flex: 1;
}
.thread-actions { display: flex; gap: 6px; flex-shrink: 0; }
.icon-btn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  color: var(--text-2);
  font-size: 16px;
  transition: background 0.12s ease, color 0.12s ease;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

.message {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 12px;
}
.message.mine { background: var(--accent-soft); border-color: transparent; }
.message-head { display: flex; align-items: baseline; gap: 10px; margin-bottom: 8px; }
.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-2);
  display: grid; place-items: center;
  font-size: 12px; font-weight: 600;
  flex-shrink: 0;
  align-self: center;
}
.message.mine .avatar { background: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) {
  .message.mine .avatar { color: #101013; }
}
.msg-from { font-weight: 600; }
.msg-email { color: var(--text-2); font-size: 12.5px; }
.msg-time {
  margin-left: auto;
  font-family: "Geist Mono", ui-monospace, monospace;
  font-size: 11px; color: var(--text-2);
}
.message-body p { margin: 0 0 10px; white-space: pre-wrap; }
.message-body p:last-child { margin-bottom: 0; }

.reply-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 9px 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface);
  font-weight: 500;
  transition: background 0.12s ease;
}
.reply-btn:hover { background: var(--surface-2); }

/* ============ Composer ============ */
.composer {
  position: fixed;
  right: 24px; bottom: 0;
  width: min(600px, calc(100vw - 48px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: var(--radius) var(--radius) 0 0;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  z-index: 30;
}
.composer-head {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}
.composer-title { font-weight: 600; font-size: 13.5px; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.agent-chip {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 500;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
  flex-shrink: 0;
}
.composer-field {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px;
  border-bottom: 1px solid var(--border);
}
.composer-field span { font-size: 12px; color: var(--text-2); width: 48px; flex-shrink: 0; }
.composer-field input { border: none; background: transparent; outline: none; flex: 1; min-width: 0; }
.composer textarea {
  border: none; background: transparent; outline: none; resize: none;
  padding: 14px;
  height: 240px;
  line-height: 1.6;
}
.composer-foot {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
}
.composer-hint { font-size: 12px; color: var(--text-2); }
.primary-btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 16px;
  border: none; border-radius: var(--radius);
  background: var(--accent); color: #fff;
  font-weight: 500;
  transition: background 0.15s ease, transform 0.1s ease;
}
@media (prefers-color-scheme: dark) {
  .primary-btn { color: #101013; }
}
.primary-btn:hover { background: var(--accent-strong); }
.primary-btn:active { transform: scale(0.98); }
.ghost-btn {
  padding: 8px 16px;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: transparent;
  color: var(--text-2);
  font-weight: 500;
}
.ghost-btn:hover { background: var(--surface-2); color: var(--text); }

/* ============ Agent send modal ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(16, 16, 19, 0.45);
  display: grid; place-items: center;
  z-index: 50;
}
.modal {
  width: min(560px, calc(100vw - 40px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}
.modal h3 {
  margin: 0 0 14px;
  font-size: 16px; font-weight: 600;
  display: flex; align-items: center; gap: 8px;
}
.modal h3 i { color: var(--accent); }
.modal-preview {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg);
  padding: 14px 16px;
  max-height: 300px;
  overflow-y: auto;
}
.modal-meta { margin: 0 0 10px; font-size: 12.5px; color: var(--text-2); }
.modal-body { white-space: pre-wrap; font-size: 13.5px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ============ Toasts ============ */
.toasts {
  position: fixed; left: 50%; bottom: 24px;
  transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 8px;
  z-index: 60;
  pointer-events: none;
}
.toast {
  background: var(--text); color: var(--bg);
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 13.5px; font-weight: 500;
  box-shadow: var(--shadow);
  animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .toast { animation: none; }
  * { transition-duration: 0s !important; }
}

/* ============ Narrow screens: stack panes ============ */
@media (max-width: 1024px) {
  .app { grid-template-columns: 220px 1fr; }
  .read-pane { display: none; }
  body.reading .read-pane { display: block; }
  body.reading .list-pane { display: none; }
}
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
}
