/* Same palette as chatdl so both Indure tools feel like one product */
:root {
  --bg: #f4f4f6;
  --sidebar: #ebebef;
  --surface: #ffffff;
  --text: #1c1c1f;
  --muted: #6b6b75;
  --border: #dcdce2;
  --accent: #2457d6;
  --accent-text: #ffffff;
  --user-bubble: #e4e7f0;
  --code-bg: #f0f0f3;
  --danger: #c62d2d;
  --ok: #1f7a46;
  --warn: #a86400;
  --shadow: 0 2px 12px rgba(20, 20, 40, 0.07);
  --radius: 14px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono: ui-monospace, "Cascadia Code", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #141416;
    --sidebar: #19191c;
    --surface: #1e1e22;
    --text: #ececf1;
    --muted: #9a9aa6;
    --border: #34343c;
    --accent: #5b8cff;
    --accent-text: #0b0b0e;
    --user-bubble: #2a2d38;
    --code-bg: #121214;
    --danger: #ff6b6b;
    --ok: #6ed69a;
    --warn: #f0b354;
    --shadow: 0 2px 12px rgba(0, 0, 0, 0.35);
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.6 var(--font); }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
[hidden] { display: none !important; }

/* The Indure logo is white; darken it on light backgrounds */
.logo { display: block; height: 22px; width: auto; filter: invert(1); }
@media (prefers-color-scheme: dark) { .logo { filter: none; } }

/* ---------- Forms and buttons ---------- */
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
input, select {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: transparent; color: var(--text); font-size: 15px; font-weight: 400;
}
select option { background: var(--surface); }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn {
  padding: 9px 14px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
.btn.danger { color: var(--danger); }
.alert { padding: 10px 12px; border-radius: 8px; background: color-mix(in srgb, var(--danger) 12%, transparent); color: var(--danger); margin: 12px 0; font-size: 14px; }
.alert.ok { background: color-mix(in srgb, var(--ok) 12%, transparent); color: var(--ok); }
.muted { color: var(--muted); }

/* ---------- Sign in / setup ---------- */
body.auth { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.auth-card { width: 100%; max-width: 360px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; }
.auth-card .logo { margin-bottom: 14px; }
.auth-card h1 { margin: 0 0 4px; font-size: 20px; line-height: 1.2; }
.tagline { margin: 0 0 6px; font-size: 11px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }
.auth-card form { display: flex; flex-direction: column; gap: 14px; margin-top: 18px; }
.auth-card .btn { margin-top: 6px; padding: 11px; }

/* ---------- Home (portal) ---------- */
body.home { min-height: 100vh; }
.home-head {
  display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px;
  max-width: 960px; margin: 0 auto; padding: 24px 16px 0;
}
.home-brand { display: flex; flex-direction: column; gap: 8px; }
.home-brand .logo { height: 26px; }
.home-brand .tagline { margin: 0; }
.home-nav { display: flex; align-items: center; gap: 14px; font-size: 14px; }
.home-main { max-width: 960px; margin: 0 auto; padding: 40px 16px; }
.home-main h1 { font-size: 28px; font-weight: 600; margin: 0 0 4px; letter-spacing: -0.01em; }
.app-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 16px; margin-top: 24px; }
.app-card {
  display: flex; flex-direction: column; gap: 6px; padding: 22px; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--border); color: var(--text); text-decoration: none;
  transition: border-color 0.15s, transform 0.15s, box-shadow 0.15s;
}
.app-card:hover { border-color: var(--accent); box-shadow: var(--shadow); transform: translateY(-2px); }
.app-card h2 { margin: 6px 0 0; font-size: 18px; }
.app-card p { margin: 0 0 8px; font-size: 14px; }
.app-card .server-status { margin-left: 0; margin-top: auto; }
.app-icon {
  width: 42px; height: 42px; border-radius: 10px; display: grid; place-items: center; font-size: 20px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent);
}
a.brand { color: inherit; text-decoration: none; }

/* ---------- Admin ---------- */
body.admin { padding: 16px; }
.admin-wrap { max-width: 1000px; margin: 0 auto; }
.admin-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 8px; padding: 8px 0; }
.admin-head h1 { font-size: 22px; margin: 0; }
.admin-brand { display: flex; flex-direction: column; gap: 10px; }
.admin-brand .logo { height: 26px; }
.admin-head nav { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.link-btn { border: 0; background: none; color: var(--accent); cursor: pointer; padding: 0; text-decoration: underline; }
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; margin: 16px 0; }
.panel h2 { margin: 0 0 14px; font-size: 17px; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; align-items: end; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; }
td.actions { display: flex; gap: 8px; flex-wrap: wrap; }
form.inline { display: flex; gap: 6px; }
form.inline input { padding: 7px 10px; width: 170px; font-size: 14px; }
form.inline .btn { padding: 7px 12px; font-size: 14px; }

/* ---------- Chat ---------- */
body.chat { overflow: hidden; }
.layout { display: flex; height: 100vh; height: 100dvh; }

.sidebar {
  width: 270px; flex-shrink: 0; background: var(--sidebar); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 16px 10px 12px;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px 16px; font-weight: 600; }
.btn-new {
  display: flex; align-items: center; gap: 6px; padding: 10px 12px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 500;
}
.btn-new:hover { border-color: var(--accent); }
.conv-heading { font-size: 12px; color: var(--muted); padding: 18px 10px 6px; }
.conv-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 1px; }
.conv { display: flex; align-items: center; border-radius: 8px; }
.conv:hover, .conv.active { background: color-mix(in srgb, var(--text) 7%, transparent); }
.conv-title {
  flex: 1; min-width: 0; text-align: left; border: 0; background: none; padding: 8px 10px; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px;
}
.conv-del { border: 0; background: none; color: var(--muted); cursor: pointer; padding: 4px 10px; font-size: 16px; opacity: 0; }
.conv:hover .conv-del, .conv.active .conv-del { opacity: 1; }
.conv-del:hover { color: var(--danger); }
.user-box { display: flex; align-items: center; gap: 10px; padding: 12px 8px 0; border-top: 1px solid var(--border); margin-top: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--accent); color: var(--accent-text);
  display: grid; place-items: center; font-weight: 600; flex-shrink: 0;
}
.user-meta { min-width: 0; }
.user-name { font-size: 14px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-links { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.user-links a, .user-links .link-btn { color: var(--muted); font-size: 12px; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px; }
.topbar select { border: 0; background: transparent; font-size: 14px; color: var(--muted); max-width: 60vw; cursor: pointer; padding: 6px 4px; }
.topbar select:hover { color: var(--text); }
.server-status { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--muted); white-space: nowrap; }
.server-status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); }
.server-status.online::before { background: var(--ok); }
.server-status.offline::before { background: var(--danger); }
.icon-btn { display: none; border: 0; background: none; font-size: 20px; cursor: pointer; padding: 4px 8px; }

.messages { flex: 1; overflow-y: auto; padding: 8px 16px 24px; }
.messages > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.empty { text-align: center; margin-top: 18vh; }
.empty h1 { font-weight: 500; font-size: 32px; margin: 0 0 6px; letter-spacing: -0.01em; }
.empty p { color: var(--muted); margin: 0; }

.msg { display: flex; margin: 18px auto; }
.msg.user { justify-content: flex-end; }
.msg.user .body {
  background: var(--user-bubble); padding: 10px 16px; border-radius: 16px; max-width: 85%;
  white-space: pre-wrap; overflow-wrap: anywhere;
}
.msg.assistant .body { width: 100%; overflow-wrap: anywhere; font-size: 15.5px; line-height: 1.7; }
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.body pre {
  position: relative; background: var(--code-bg); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px; overflow-x: auto; font-size: 13.5px; line-height: 1.5;
}
.body code { font-family: var(--mono); font-size: 0.88em; }
.body :not(pre) > code { background: var(--code-bg); padding: 1px 5px; border-radius: 5px; }
.body table { border-collapse: collapse; font-size: 14px; display: block; overflow-x: auto; }
.body th, .body td { border: 1px solid var(--border); padding: 6px 10px; }
.body blockquote { border-left: 3px solid var(--border); margin-left: 0; padding-left: 14px; color: var(--muted); }
.copy {
  position: absolute; top: 8px; right: 8px; font: 12px var(--font); padding: 3px 8px; border-radius: 6px;
  border: 1px solid var(--border); background: var(--surface); cursor: pointer; opacity: 0.85;
}
.copy:hover { opacity: 1; }
.error { color: var(--danger); font-size: 14px; margin-top: 8px; }
.status-line { color: var(--muted); font-size: 14px; display: flex; align-items: center; gap: 10px; }
.status-line::before {
  content: ""; width: 9px; height: 9px; border-radius: 50%; background: var(--accent);
  animation: pulse 1s ease-in-out infinite;
}
@keyframes pulse { 50% { opacity: 0.25; transform: scale(0.8); } }

.composer-wrap { padding: 0 16px 10px; }
.composer {
  max-width: 760px; margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 20px;
  padding: 10px 10px 10px 16px; box-shadow: var(--shadow);
}
.composer:focus-within { border-color: color-mix(in srgb, var(--accent) 60%, var(--border)); }
.composer textarea {
  flex: 1; border: 0; background: transparent; resize: none; outline: none;
  max-height: 220px; padding: 6px 0; line-height: 1.5; font-size: 15px;
}
.send {
  width: 36px; height: 36px; flex-shrink: 0; border-radius: 10px; border: 0; cursor: pointer;
  background: var(--accent); color: var(--accent-text); font-size: 18px; font-weight: 700;
}
.send:disabled { opacity: 0.4; cursor: default; }
.send.stop { background: var(--text); color: var(--bg); font-size: 13px; }
.disclaimer { text-align: center; font-size: 12px; color: var(--muted); margin: 8px 0 0; }

.scrim { display: none; }

@media (max-width: 800px) {
  .sidebar {
    position: fixed; inset: 0 auto 0 0; z-index: 20; transform: translateX(-100%);
    transition: transform 0.2s ease; box-shadow: var(--shadow);
  }
  .sidebar.open { transform: none; }
  .sidebar.open + .scrim { display: block; position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.4); }
  .icon-btn { display: block; }
  .conv-del { opacity: 1; }
  .empty { margin-top: 12vh; }
  .empty h1 { font-size: 26px; }
}
