:root {
  --paper: #f4f1eb;
  --surface: #fffdf9;
  --ink: #282725;
  --muted: #77736d;
  --line: #ded9d1;
  --accent: #ce684c;
  --accent-dark: #a94d37;
  --accent-soft: #f7e5de;
  --green: #287a5b;
  --green-soft: #e1f0e9;
  --blue: #486d9a;
  --blue-soft: #e6edf6;
  --red: #ac403d;
  --shadow: 0 18px 50px rgba(56, 48, 39, .09);
}

* { box-sizing: border-box; }
html { color-scheme: light; }
body { margin: 0; min-height: 100vh; background: var(--paper); color: var(--ink); font-family: Vazirmatn, Tahoma, Arial, sans-serif; }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.eyebrow { margin: 0 0 7px; color: var(--accent); font-size: 12px; font-weight: 800; letter-spacing: .02em; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px 18px; background:
  radial-gradient(circle at 82% 15%, rgba(206,104,76,.14), transparent 28%),
  radial-gradient(circle at 12% 85%, rgba(72,109,154,.1), transparent 28%), var(--paper); }
.login-card { width: min(100%, 430px); padding: 38px; border: 1px solid var(--line); border-radius: 26px; background: rgba(255,253,249,.92); box-shadow: var(--shadow); }
.login-card h1 { margin: 12px 0 8px; font-size: clamp(26px, 7vw, 34px); }
.brand-mark { width: 58px; height: 58px; display: grid; place-items: center; border-radius: 18px; background: var(--accent); color: white; box-shadow: 0 9px 22px rgba(206,104,76,.26); font-size: 28px; font-weight: 900; transform: rotate(-3deg); }
.brand-mark span { transform: rotate(3deg); }
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 20px; }
.stack { display: grid; gap: 10px; margin-top: 28px; }
label { display: block; margin: 16px 0 8px; font-size: 13px; font-weight: 800; }
input, textarea, select { width: 100%; border: 1px solid var(--line); border-radius: 14px; background: #fff; color: var(--ink); outline: none; transition: border .2s, box-shadow .2s; }
input { height: 50px; padding: 0 14px; }
textarea { min-height: 156px; padding: 15px; line-height: 1.9; resize: vertical; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); box-shadow: 0 0 0 4px rgba(206,104,76,.11); }
.password-wrap { display: flex; align-items: center; gap: 8px; }
.password-wrap input { flex: 1; direction: ltr; }
.primary, .secondary, .danger, .ghost { border: 0; border-radius: 12px; padding: 12px 17px; font-weight: 800; }
.primary { background: var(--accent); color: white; box-shadow: 0 9px 18px rgba(206,104,76,.2); }
.primary:hover { background: var(--accent-dark); }
.primary:disabled { opacity: .55; cursor: wait; }
.secondary { background: var(--ink); color: white; }
.danger { background: #f6dfdd; color: var(--red); }
.ghost { background: #ebe7e0; color: var(--ink); }
.compact { padding: 8px 11px; font-size: 12px; white-space: nowrap; }
.wide { width: 100%; margin-top: 8px; }
.error { min-height: 18px; margin: 2px 0 0; color: var(--red); font-size: 13px; }
.secure-note { display: flex; align-items: center; justify-content: center; gap: 7px; margin-top: 22px; color: var(--muted); font-size: 12px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }

.topbar { position: sticky; top: 0; z-index: 10; height: 74px; padding: 0 max(20px, calc((100vw - 1120px) / 2)); display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(222,217,209,.88); background: rgba(244,241,235,.88); backdrop-filter: blur(16px); }
.brand { display: flex; align-items: center; gap: 12px; }
.brand div:last-child { display: grid; gap: 2px; }
.brand strong { font-size: 15px; }
.brand span { font-size: 11px; color: var(--muted); direction: ltr; text-align: right; }
.top-actions { display: flex; align-items: center; gap: 10px; }
.server-state { display: flex; align-items: center; gap: 7px; padding: 7px 10px; border-radius: 99px; background: var(--green-soft); color: var(--green); font-size: 11px; font-weight: 800; }
.server-state i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; animation: breathe 2s infinite; }
@keyframes breathe { 50% { opacity: .38; } }
.icon-button { width: 38px; height: 38px; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--muted); font-size: 20px; }

.layout { width: min(100% - 36px, 980px); margin: 38px auto 90px; display: grid; gap: 42px; }
.composer-card { padding: clamp(22px, 4vw, 36px); background: var(--surface); border: 1px solid var(--line); border-radius: 24px; box-shadow: var(--shadow); }
.section-heading, .jobs-header, .composer-footer, .modal-header, .thread-toolbar, .modal-actions { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.section-heading h1, .jobs-header h2 { margin: 0; font-size: clamp(22px, 4vw, 30px); }
.independent-badge { padding: 8px 11px; border: 1px solid #bdd8cc; border-radius: 99px; color: var(--green); background: var(--green-soft); font-size: 11px; font-weight: 800; white-space: nowrap; }
.select-wrap { position: relative; }
.select-wrap select { height: 52px; appearance: none; padding: 0 15px 0 44px; }
.select-wrap > span { position: absolute; left: 16px; top: 12px; font-size: 20px; pointer-events: none; }
.resume-banner { margin: 18px 0 6px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; border-radius: 13px; background: var(--blue-soft); color: var(--blue); }
.resume-banner div { display: grid; gap: 3px; }
.resume-banner small { opacity: .8; }
.composer-footer { margin-top: 16px; }
.composer-footer p { margin: 0; color: var(--muted); font-size: 12px; }
.composer-footer .primary { min-width: 176px; display: flex; align-items: center; justify-content: center; gap: 12px; }
.spark { color: var(--accent); }

.jobs-header { align-items: flex-end; }
.filters { display: flex; gap: 5px; padding: 4px; border-radius: 12px; background: #e9e5de; overflow-x: auto; }
.filter { border: 0; border-radius: 9px; background: transparent; color: var(--muted); padding: 8px 12px; font-size: 11px; font-weight: 800; white-space: nowrap; }
.filter.active { background: var(--surface); color: var(--ink); box-shadow: 0 2px 8px rgba(40,39,37,.08); }
.jobs-list { display: grid; gap: 12px; margin-top: 18px; }
.job-card { position: relative; display: grid; grid-template-columns: 1fr auto; gap: 10px 18px; padding: 19px 20px; border: 1px solid var(--line); border-radius: 17px; background: rgba(255,253,249,.75); transition: transform .18s, box-shadow .18s; cursor: pointer; }
.job-card:hover { transform: translateY(-2px); box-shadow: 0 10px 24px rgba(56,48,39,.07); }
.job-card h3 { margin: 0 0 7px; font-size: 15px; line-height: 1.7; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.job-meta { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 11px; }
.job-preview { grid-column: 1 / -1; margin: 2px 0 0; padding-top: 11px; border-top: 1px solid #ebe7e1; color: var(--muted); font-size: 12px; line-height: 1.8; white-space: pre-wrap; unicode-bidi: plaintext; max-height: 64px; overflow: hidden; }
.status-pill { display: inline-flex; align-items: center; gap: 6px; width: max-content; padding: 6px 10px; border-radius: 99px; font-size: 10px; font-weight: 900; white-space: nowrap; }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status-running { color: var(--blue); background: var(--blue-soft); }
.status-running::before { animation: breathe 1s infinite; }
.status-queued { color: #8b6828; background: #f4ecd8; }
.status-completed { color: var(--green); background: var(--green-soft); }
.status-failed, .status-cancelled { color: var(--red); background: #f6dfdd; }
.empty-state { margin-top: 18px; padding: 42px; text-align: center; border: 1px dashed #cfc8be; border-radius: 18px; color: var(--muted); }
.empty-state div { font-size: 32px; color: var(--accent); }
.empty-state strong { display: block; margin-top: 8px; color: var(--ink); }
.empty-state p { margin: 6px 0 0; font-size: 12px; }

.modal { position: fixed; inset: 0; z-index: 30; display: grid; align-items: end; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(30,28,25,.44); backdrop-filter: blur(3px); }
.modal-panel { position: relative; z-index: 1; width: min(100%, 820px); max-height: 92vh; margin: 0 auto; overflow-y: auto; padding: 24px; border-radius: 25px 25px 0 0; background: var(--surface); box-shadow: 0 -20px 70px rgba(25,22,19,.2); animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(35px); opacity: .5; } }
.modal-header { align-items: flex-start; }
.modal-header h2 { margin: 10px 0 3px; font-size: 22px; }
.modal-header p { margin: 0; font-size: 11px; }
.thread-toolbar { margin: 20px 0 9px; color: var(--muted); font-size: 11px; font-weight: 800; }
.conversation-thread { min-height: 210px; max-height: 55vh; padding: 17px; overflow-y: auto; border: 1px solid var(--line); border-radius: 17px; background: #f0ece5; scroll-behavior: smooth; }
.message { display: grid; gap: 6px; margin-bottom: 18px; }
.message:last-child { margin-bottom: 0; }
.message-label { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 10px; font-weight: 800; }
.message-label i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.message.user .message-label { color: var(--blue); }
.message.assistant .message-label { color: var(--accent); }
.message-bubble { max-width: 92%; padding: 13px 15px; border-radius: 16px; line-height: 1.9; overflow-wrap: anywhere; unicode-bidi: plaintext; }
.message.user .message-bubble { justify-self: start; background: #dfe8f3; border-bottom-right-radius: 5px; white-space: pre-wrap; }
.message.assistant .message-bubble { justify-self: stretch; max-width: 100%; background: var(--surface); border: 1px solid #e2ddd5; border-bottom-left-radius: 5px; }
.message.assistant.running .message-label i { animation: breathe 1s infinite; }
.message.assistant.pending .message-bubble { color: var(--muted); }
.message-error { margin-top: 8px; padding: 9px 11px; border-radius: 10px; background: #f6dfdd; color: var(--red); font-size: 12px; }
.markdown { direction: rtl; text-align: start; }
.markdown > :first-child { margin-top: 0; }
.markdown > :last-child { margin-bottom: 0; }
.markdown p { margin: 0 0 12px; }
.markdown h1, .markdown h2, .markdown h3, .markdown h4 { margin: 20px 0 9px; line-height: 1.5; }
.markdown h1 { font-size: 1.45rem; }
.markdown h2 { font-size: 1.25rem; border-bottom: 1px solid var(--line); padding-bottom: 6px; }
.markdown h3 { font-size: 1.1rem; }
.markdown ul, .markdown ol { margin: 8px 0 14px; padding-right: 23px; }
.markdown li { margin: 4px 0; }
.markdown blockquote { margin: 12px 0; padding: 8px 13px; border-right: 3px solid var(--accent); background: var(--accent-soft); color: #61534e; }
.markdown pre { direction: ltr; text-align: left; margin: 13px 0; padding: 14px; overflow-x: auto; border-radius: 12px; background: #22211f; color: #eeeae4; font: 12px/1.7 ui-monospace, SFMono-Regular, Consolas, monospace; unicode-bidi: isolate; }
.markdown code:not(pre code) { direction: ltr; unicode-bidi: isolate; padding: 2px 5px; border-radius: 5px; background: #ece7df; color: #9b4534; font: .9em ui-monospace, SFMono-Regular, Consolas, monospace; }
.markdown a { color: var(--blue); text-decoration-thickness: 1px; text-underline-offset: 3px; }
.markdown hr { border: 0; border-top: 1px solid var(--line); margin: 18px 0; }
.markdown table { width: 100%; margin: 13px 0; border-collapse: collapse; display: block; overflow-x: auto; }
.markdown th, .markdown td { min-width: 100px; padding: 8px 10px; border: 1px solid var(--line); text-align: right; }
.markdown th { background: var(--paper); }
.error-box { padding: 12px; border-radius: 12px; background: #f6dfdd; color: var(--red); }
.modal-actions { margin-top: 16px; justify-content: flex-start; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: 24px; transform: translateX(-50%); max-width: calc(100vw - 32px); padding: 11px 16px; border-radius: 12px; background: var(--ink); color: white; box-shadow: var(--shadow); font-size: 12px; }

@media (min-width: 760px) {
  .modal { align-items: center; padding: 25px; }
  .modal-panel { border-radius: 25px; }
}
@media (max-width: 620px) {
  .topbar { height: 66px; padding: 0 14px; }
  .server-state { font-size: 0; width: 30px; height: 30px; justify-content: center; padding: 0; }
  .layout { width: min(100% - 22px, 980px); margin-top: 18px; gap: 32px; }
  .composer-card { border-radius: 19px; padding: 19px 16px; }
  .section-heading { align-items: flex-start; }
  .independent-badge { font-size: 9px; }
  .composer-footer { align-items: stretch; flex-direction: column; }
  .composer-footer .primary { width: 100%; }
  .jobs-header { align-items: flex-start; flex-direction: column; }
  .filters { width: 100%; }
  .filter { flex: 1; }
  .job-card { padding: 16px; }
  .login-card { padding: 28px 22px; }
  .modal-panel { padding: 19px 15px max(19px, env(safe-area-inset-bottom)); }
  .modal-actions { align-items: stretch; flex-direction: column; }
}
