:root {
  --bg: #f7f7f5;
  --surface: #ffffff;
  --text: #1d1d1b;
  --muted: #6b6b66;
  --border: #e3e3de;
  --accent: #2f6f5e;
  --accent-text: #ffffff;
  --user-bg: #e8f0ed;
  --error: #b3261e;
  --code-bg: #f0f0ec;
  --warn: #8a5a00;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #161615;
    --surface: #1f1f1d;
    --text: #ececea;
    --muted: #9a9a94;
    --border: #33332f;
    --accent: #5fb39b;
    --accent-text: #0e1a16;
    --user-bg: #22332d;
    --error: #f2b8b5;
    --code-bg: #2a2a27;
    --warn: #e8c170;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex; flex-direction: column;
  background: var(--bg); color: var(--text);
  font: 15px/1.55 system-ui, -apple-system, "Segoe UI", sans-serif;
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border); background: var(--surface);
}
h1 { font-size: 16px; margin: 0; font-weight: 600; }
h1.brand { display: flex; align-items: center; gap: 10px; font-size: 17px; }
h1.brand .propela { height: 24px; width: auto; display: block; }
h1.brand .slash { color: var(--muted); font-weight: 300; font-size: 22px; line-height: 1; }
h1.brand .everhour-mark { height: 22px; width: 22px; display: block; margin-right: -4px; }

button {
  font: inherit; cursor: pointer; border-radius: 8px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 6px 12px;
}
button:hover { border-color: var(--accent); }
button:disabled { opacity: .5; cursor: default; }

main {
  flex: 1; overflow-y: auto;
  padding: 24px 16px;
}
.msg, .empty { max-width: 820px; margin: 0 auto 18px; }

.empty { text-align: center; color: var(--muted); margin-top: 12vh; }
.suggestions { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 8px; margin-top: 16px; }
.suggestions button { text-align: left; padding: 10px 12px; color: var(--text); }

.msg.user .bubble {
  background: var(--user-bg); padding: 10px 14px; border-radius: 12px;
  white-space: pre-wrap; margin-left: auto; width: fit-content; max-width: 85%;
}
.msg.assistant .bubble { overflow-x: auto; }
.bubble > :first-child { margin-top: 0; }
.bubble > :last-child { margin-bottom: 0; }
.bubble table { border-collapse: collapse; margin: 8px 0; font-size: 14px; }
.bubble th, .bubble td { border: 1px solid var(--border); padding: 5px 10px; text-align: left; }
.bubble th { background: var(--code-bg); }
.bubble code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: 13px; }
.bubble pre { background: var(--code-bg); padding: 10px; border-radius: 8px; overflow-x: auto; }
.bubble pre code { padding: 0; }

.status { color: var(--muted); font-size: 13px; font-style: italic; }
.error { color: var(--error); font-size: 14px; margin: 6px 0; }
.stopped { color: var(--muted); font-size: 13px; margin: 6px 0; }

details.tool {
  font-size: 13px; color: var(--muted); margin: 4px 0;
  border: 1px solid var(--border); border-radius: 8px; padding: 4px 10px; background: var(--surface);
}
details.tool summary { cursor: pointer; }
details.tool .tool-label { margin: 8px 0 -4px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.04em; }
details.tool pre.requests { white-space: pre-wrap; word-break: break-all; }
details.tool.pending summary::after { content: " …"; }
details.tool.failed summary { color: var(--error); }
details.tool pre {
  white-space: pre-wrap; word-break: break-word; max-height: 280px; overflow-y: auto;
  background: var(--code-bg); padding: 8px; border-radius: 6px; font-size: 12px;
}

#composer {
  display: flex; gap: 8px; padding: 12px 16px 16px;
  max-width: 852px; width: 100%; margin: 0 auto;
}
#input {
  flex: 1; resize: none; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; max-height: 200px;
}
#input:focus { outline: none; border-color: var(--accent); }
#send { background: var(--accent); color: var(--accent-text); border-color: var(--accent); padding: 0 18px; }
#send.stop { background: var(--error); border-color: var(--error); color: #fff; }

[hidden] { display: none !important; }

.account { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.who { color: var(--muted); }
.usage { color: var(--muted); font-variant-numeric: tabular-nums; }
.usage.warn { color: var(--warn); font-weight: 600; }

.login { flex: 1; display: flex; align-items: flex-start; justify-content: center; padding: 12vh 16px 0; }
.login form {
  width: 100%; max-width: 440px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 12px; padding: 24px;
}
.login h2 { font-size: 17px; margin: 0 0 8px; }
.login p { color: var(--muted); font-size: 14px; margin: 0 0 16px; }
.login input {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; margin-bottom: 12px;
}
.login input:focus { outline: none; border-color: var(--accent); }
.login button[type=submit] { background: var(--accent); color: var(--accent-text); border-color: var(--accent); width: 100%; padding: 9px; }

/* Reports and Requests panels */
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(460px, 100vw); overflow-y: auto; z-index: 10;
  background: var(--surface); border-left: 1px solid var(--border); padding: 16px 18px 24px;
  box-shadow: -8px 0 24px rgba(0, 0, 0, .12);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; }
.panel h2 { font-size: 17px; margin: 0; }
.panel h3 { font-size: 14px; margin: 22px 0 8px; }
.panel .hint { color: var(--muted); font-size: 13px; margin: 6px 0 12px; }
.panel textarea, .save-form input, .save-form select {
  width: 100%; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
.panel .row, .save-form .row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 8px; font-size: 14px; }
.panel .row button[type=submit], .save-form button[type=submit] {
  margin-left: auto; background: var(--accent); color: var(--accent-text); border-color: var(--accent);
}
.list { display: flex; flex-direction: column; gap: 8px; }
.list .empty-note { color: var(--muted); font-size: 13px; }
.item { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; font-size: 14px; }
.item .title { font-weight: 600; }
.item .meta { color: var(--muted); font-size: 12px; margin-top: 2px; }
.item .note { font-size: 13px; margin-top: 4px; }
.item .actions { display: flex; gap: 6px; margin-top: 6px; flex-wrap: wrap; }
.item .actions button { padding: 3px 10px; font-size: 13px; }
.badge { display: inline-block; font-size: 11px; padding: 0 6px; border-radius: 6px; border: 1px solid var(--border); color: var(--muted); margin-left: 6px; font-weight: 400; }
.badge.open { color: var(--accent); border-color: var(--accent); }
.more { margin-top: 8px; width: 100%; }
.account button.active { border-color: var(--accent); color: var(--accent); }
.badge.bad { background: #b3261e; color: #fff; }
.log-detail { margin-top: 8px; font-size: 13px; }
.log-detail details { margin: 4px 0; }
.log-detail details details { margin-left: 12px; }
.log-detail summary { cursor: pointer; }
.log-detail .tool-error > summary { color: #b3261e; }
.log-detail pre { white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
  background: var(--code-bg, rgba(127,127,127,.08)); padding: 6px 8px; border-radius: 6px; margin: 4px 0; font-size: 12px; }
.list-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin: 22px 0 8px; }
.list-head h3 { margin: 0; }
.tabs { display: flex; }
.tabs button { padding: 2px 10px; font-size: 13px; border-radius: 0; }
.tabs button:first-child { border-radius: 6px 0 0 6px; }
.tabs button:last-child { border-radius: 0 6px 6px 0; border-left: 0; }
.tabs button.active { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }

.building {
  max-width: 820px; width: calc(100% - 32px); margin: 0 auto; display: flex; align-items: center; gap: 10px;
  font-size: 13px; background: var(--user-bg); border-radius: 8px; padding: 6px 10px;
}
.building span { flex: 1; }
.building button { padding: 2px 10px; font-size: 13px; }

/* A canned report's output, and the admin's save form */
.canned-head { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.canned-head strong { color: var(--text); }
.canned-step { margin: 10px 0; }
.canned-step .step-name { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.canned-step dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 6px 0; font-size: 14px; }
.canned-step dt { color: var(--muted); }
.canned-step dd { margin: 0; }
.canned-step .truncated { color: var(--muted); font-size: 12px; }
.save-bar { margin-top: 8px; }
.msg-actions { margin-top: 6px; }
.msg-actions button { padding: 2px 10px; font-size: 13px; color: var(--muted); }
.msg-actions button:hover { color: var(--text); }
.plan-note { color: var(--muted); font-size: 13px; margin-top: 8px; }
.save-form { border: 1px solid var(--border); border-radius: 8px; padding: 10px; margin-top: 8px; background: var(--surface); font-size: 14px; }
.save-form label { display: block; margin-top: 6px; }
.save-form .steps { font-size: 13px; margin: 8px 0 0; }
.save-form .steps label { display: flex; gap: 6px; align-items: baseline; }
.save-form .steps code { font-size: 12px; word-break: break-all; }
.save-form .ok { color: var(--accent); margin-top: 6px; }
.save-form .result-build { margin-top: 10px; border-top: 1px solid var(--border); padding-top: 8px; }
.save-form .result-build .row button { margin-left: 0; }
.save-form .preview { max-height: 360px; overflow: auto; margin-top: 6px; }
.save-form .meta, .save-form .use-transform { color: var(--muted); font-size: 13px; }
.save-form .use-transform { display: flex; gap: 6px; align-items: baseline; }
.save-form .use-transform input { width: auto; }
details.raw-data { margin-top: 10px; font-size: 13px; }
details.raw-data summary { cursor: pointer; color: var(--muted); }

@media (max-width: 640px) {
  header { flex-wrap: wrap; gap: 8px; }
  .who { display: none; }
}
