:root {
  --bg: #faf8f4;
  --surface: #ffffff;
  --ink: #111111;
  --ink-2: #4a4a4a;
  --ink-3: #8a8780;
  --line: #e9e4da;
  --sand: #d4be9d;
  --sand-2: #f3ece1;
  --sand-ink: #8a6d43;
  --danger: #b4372f;
  --ok: #2f7a4a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(17, 17, 17, 0.04), 0 6px 24px rgba(17, 17, 17, 0.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: "Cairo", system-ui, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--sand-ink); }
.boot { min-height: 100vh; display: grid; place-items: center; }
.boot-logo { width: 220px; opacity: 0.85; animation: pulse 1.4s ease-in-out infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* Layout */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 20px; background: rgba(250, 248, 244, 0.92); backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar .logo { height: 22px; cursor: pointer; display: block; }
.topbar .who { display: flex; align-items: center; gap: 8px; color: var(--ink-2); font-size: 14px; }
.container { max-width: 1080px; margin: 0 auto; padding: 28px 20px 60px; }
.narrow { max-width: 560px; }
h1 { font-size: 28px; line-height: 1.35; margin: 0 0 8px; font-weight: 800; }
h2 { font-size: 20px; margin: 28px 0 12px; font-weight: 700; }
.muted { color: var(--ink-3); }
.lead { color: var(--ink-2); margin: 0 0 24px; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 18px; border-radius: 10px; border: 1px solid var(--ink);
  background: var(--ink); color: #fff; font-weight: 700; cursor: pointer; text-decoration: none;
  transition: transform .05s ease, opacity .15s;
}
.btn:hover { opacity: 0.9; }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--line); }
.btn.ghost:hover { border-color: var(--ink-3); }
.btn.sand { background: var(--sand); border-color: var(--sand); color: var(--ink); }
.btn.danger { background: transparent; color: var(--danger); border-color: #ecc9c5; }
.btn.small { padding: 6px 12px; font-size: 14px; border-radius: 8px; }
.btn.block { width: 100%; }
.linkbtn { background: none; border: 0; color: var(--sand-ink); cursor: pointer; padding: 0; font-weight: 600; }

/* Cards & forms */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 24px; box-shadow: var(--shadow); }
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-weight: 700; margin-bottom: 6px; font-size: 15px; }
.field small { display: block; color: var(--ink-3); margin-top: 4px; font-size: 13px; }
.input, textarea.input, select.input {
  width: 100%; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: #fff; outline: none; transition: border-color .15s, box-shadow .15s;
}
.input:focus { border-color: var(--sand); box-shadow: 0 0 0 3px rgba(212, 190, 157, .35); }
textarea.input { resize: vertical; min-height: 96px; }
.ltr { direction: ltr; text-align: left; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 14px; }
.divider { display: flex; align-items: center; gap: 12px; color: var(--ink-3); margin: 18px 0; font-size: 14px; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.notice { background: var(--sand-2); border: 1px solid #eadcc5; border-radius: 12px; padding: 14px 16px; color: #5b4a30; }
.notice.danger { background: #fbefee; border-color: #f0cfcb; color: var(--danger); }
.steps { counter-reset: s; list-style: none; padding: 0; margin: 0 0 20px; }
.steps li { counter-increment: s; position: relative; padding: 0 40px 14px 0; }
.steps li::before {
  content: counter(s); position: absolute; right: 0; top: 2px; width: 28px; height: 28px; border-radius: 50%;
  background: var(--ink); color: #fff; display: grid; place-items: center; font-weight: 700; font-size: 14px;
}

/* Auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 420px; text-align: center; }
.auth-card .logo { width: 210px; margin: 6px auto 22px; display: block; }
.auth-card .field { text-align: right; }
.gbtn { background: #fff; color: var(--ink); border-color: var(--line); }

/* Assistants grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.a-card {
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; cursor: pointer; text-align: right; transition: border-color .15s, transform .1s, box-shadow .15s;
  display: flex; flex-direction: column; gap: 6px; min-height: 120px;
}
.a-card:hover { border-color: var(--sand); box-shadow: var(--shadow); transform: translateY(-1px); }
.a-card .name { font-weight: 800; font-size: 18px; display: flex; align-items: center; gap: 8px; }
.a-card .tag { color: var(--ink-2); font-size: 14px; }
.a-card.featured { background: var(--ink); color: #fff; border-color: var(--ink); }
.a-card.featured .tag { color: #d9d2c5; }
.badge { display: inline-block; font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 99px; background: var(--sand-2); color: var(--sand-ink); }
.a-card.featured .badge { background: var(--sand); color: var(--ink); }

.list { display: flex; flex-direction: column; gap: 6px; }
.row-item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; cursor: pointer;
}
.row-item:hover { border-color: var(--sand); }
.row-item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Workspace */
.ws { display: grid; grid-template-columns: 270px 1fr; height: calc(100vh - 51px); }
.side { border-left: 1px solid var(--line); background: #f6f3ed; display: flex; flex-direction: column; min-height: 0; }
.side-head { padding: 16px; border-bottom: 1px solid var(--line); }
.side-head .aname { font-weight: 800; font-size: 18px; }
.side-list { overflow-y: auto; padding: 10px; flex: 1; display: flex; flex-direction: column; gap: 4px; }
.conv-link { padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 14px; display: flex; justify-content: space-between; gap: 6px; align-items: center; }
.conv-link:hover { background: #ede7dc; }
.conv-link.active { background: var(--ink); color: #fff; }
.conv-link .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-link .x { opacity: 0; border: 0; background: none; cursor: pointer; color: inherit; font-size: 15px; padding: 0 4px; }
.conv-link:hover .x { opacity: .6; }
.main { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread { flex: 1; overflow-y: auto; padding: 24px 20px; }
.thread-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.msg { display: flex; flex-direction: column; gap: 6px; }
.msg.user { align-items: flex-start; }
.msg .bubble { border-radius: 16px; padding: 12px 16px; max-width: 100%; overflow-wrap: anywhere; }
.msg.user .bubble { background: var(--ink); color: #fff; max-width: 85%; white-space: pre-wrap; border-top-right-radius: 4px; }
.msg.assistant .bubble { background: var(--surface); border: 1px solid var(--line); border-top-left-radius: 4px; }
.msg .tools { display: flex; gap: 8px; }
.md h1, .md h2, .md h3 { margin: 18px 0 8px; line-height: 1.4; }
.md h1 { font-size: 22px; } .md h2 { font-size: 19px; } .md h3 { font-size: 17px; }
.md p { margin: 0 0 10px; } .md ul, .md ol { margin: 0 0 10px; padding-right: 22px; padding-left: 0; }
.md table { border-collapse: collapse; width: 100%; margin: 10px 0; font-size: 14px; display: block; overflow-x: auto; }
.md th, .md td { border: 1px solid var(--line); padding: 6px 10px; text-align: right; }
.md th { background: var(--sand-2); }
.md blockquote { margin: 0 0 10px; padding: 6px 14px; border-right: 3px solid var(--sand); background: #fbf8f3; }
.md code { background: #f2eee7; padding: 1px 5px; border-radius: 5px; font-size: 90%; }
.md pre { background: #f2eee7; padding: 12px; border-radius: 10px; overflow-x: auto; direction: ltr; }
.md hr { border: 0; border-top: 1px solid var(--line); margin: 16px 0; }
.typing::after { content: "▍"; animation: blink 1s steps(1) infinite; color: var(--sand-ink); }
@keyframes blink { 50% { opacity: 0; } }
.composer { border-top: 1px solid var(--line); background: var(--bg); padding: 12px 20px 16px; }
.composer-inner { max-width: 820px; margin: 0 auto; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { flex: 1; min-height: 52px; max-height: 220px; resize: none; }
.form-panel { max-width: 720px; margin: 0 auto; }
.empty { text-align: center; color: var(--ink-3); padding: 50px 10px; }

/* Admin */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--line); margin-bottom: 20px; flex-wrap: wrap; }
.tab { padding: 10px 16px; border: 0; background: none; cursor: pointer; font-weight: 700; color: var(--ink-3); border-bottom: 2px solid transparent; }
.tab.active { color: var(--ink); border-bottom-color: var(--ink); }
.table-wrap { overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); }
table.t { border-collapse: collapse; width: 100%; font-size: 14px; }
table.t th, table.t td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: right; white-space: nowrap; }
table.t th { background: #f6f3ed; font-weight: 700; color: var(--ink-2); }
table.t tr:last-child td { border-bottom: 0; }
.pill { display: inline-block; padding: 1px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.pill.ok { background: #e6f2ea; color: var(--ok); }
.pill.bad { background: #fbefee; color: var(--danger); }
.pill.neutral { background: #efece6; color: var(--ink-2); }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; }
.stat .v { font-size: 24px; font-weight: 800; }
.stat .l { color: var(--ink-3); font-size: 13px; }
.toolbar { display: flex; gap: 10px; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; }

/* Modal */
.modal-back { position: fixed; inset: 0; background: rgba(17, 17, 17, .45); z-index: 50; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 640px; max-height: 92vh; overflow-y: auto; padding: 24px; }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.modal-head h3 { margin: 0; font-size: 19px; }
.xbtn { border: 0; background: none; font-size: 22px; cursor: pointer; line-height: 1; color: var(--ink-3); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; cursor: pointer; }

/* Toast */
.toast { position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: #fff; padding: 10px 18px; border-radius: 10px; opacity: 0; pointer-events: none; transition: all .2s; z-index: 60; max-width: 90vw; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--danger); }

.only-mobile { display: none; }
@media (max-width: 760px) {
  .ws { grid-template-columns: 1fr; }
  .side { display: none; position: fixed; inset: 51px 0 0 0; z-index: 30; }
  .side.open { display: flex; }
  .only-mobile { display: inline-flex; }
  h1 { font-size: 23px; }
  .row2 { grid-template-columns: 1fr; }
  .container { padding: 20px 14px 50px; }
}
