/* ERP-PM — drawing-film calm, one loud thing: the revision card */
:root {
  --film:    #EDF0EB;   /* page */
  --sheet:   #FFFFFF;   /* surfaces */
  --ink:     #1B2A41;   /* text, primary */
  --ink-2:   #4A5869;   /* secondary text */
  --rule:    #D3D9D1;   /* lines */
  --signal:  #C98A0B;   /* attention / warnings */
  --redline: #B3261E;   /* removed values, errors */
  --approve: #2F6B4F;   /* new values, confirm */
  --approve-wash: #E6F0EA;
  --signal-wash:  #FBF3E2;
  --red-wash:     #FBEAE8;

  --font: 'Barlow', 'Segoe UI', system-ui, sans-serif;
  --font-num: 'Barlow Semi Condensed', 'Barlow', 'Segoe UI', system-ui, sans-serif;
  --step--1: 0.875rem; --step-0: 1rem; --step-1: 1.125rem; --step-2: 1.5rem; --step-3: 2rem;
  --r-sm: 4px; --r-md: 8px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--film); color: var(--ink);
  font-family: var(--font); font-size: var(--step-0); line-height: 1.5;
  font-variant-numeric: tabular-nums; -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 600; letter-spacing: -0.01em; }
.muted { color: var(--ink-2); }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; }

/* ---------- buttons ---------- */
.btn {
  font: inherit; font-weight: 600; border-radius: var(--r-sm); padding: 0.55rem 1rem;
  border: 1px solid transparent; cursor: pointer; line-height: 1.2;
}
.btn.primary { background: var(--ink); color: var(--sheet); }
.btn.primary:hover { background: #24375A; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--rule); }
.btn.ghost:hover { border-color: var(--ink-2); }
.btn.confirm { background: var(--approve); color: #fff; }
.btn.confirm:hover { background: #255A41; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--ink); text-decoration: underline; text-underline-offset: 3px; cursor: pointer; }

/* ---------- sign in ---------- */
.login { min-height: 100%; display: grid; place-items: center; padding: 1.5rem; }
.login-card {
  width: min(380px, 100%); background: var(--sheet); border: 1px solid var(--rule);
  border-radius: var(--r-md); padding: 2rem; display: grid; gap: 0.9rem;
}
.login-card h1 { font-size: var(--step-3); }
.login-card p { margin: 0; }
.login-card .mark { width: 40px; height: 40px; }
label { display: grid; gap: 0.3rem; font-weight: 500; font-size: var(--step--1); }
input, select, textarea {
  font: inherit; color: var(--ink); background: var(--sheet);
  border: 1px solid var(--rule); border-radius: var(--r-sm); padding: 0.55rem 0.7rem;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(27, 42, 65, 0.12); }
.form-error { color: var(--redline); min-height: 1.2em; font-size: var(--step--1); }

/* ---------- app layout ---------- */
.app { display: grid; grid-template-columns: 248px 1fr; height: 100%; }
.side {
  border-right: 1px solid var(--rule); padding: 1.25rem 1rem; display: flex; flex-direction: column; gap: 1rem;
  background: var(--film);
}
.brand { display: flex; align-items: center; gap: 0.6rem; font-weight: 700; font-size: var(--step-1); }
.brand .mark { width: 28px; height: 28px; }
.project-pick { min-width: 0; }
.project-pick select { width: 100%; min-width: 0; text-overflow: ellipsis; }
.project-meta { margin: -0.4rem 0 0; font-size: var(--step--1); color: var(--ink-2); }
.side-foot { margin-top: auto; display: grid; gap: 0.35rem; font-size: var(--step--1); }
#who { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chat { display: grid; grid-template-rows: 1fr auto; min-height: 0; background: var(--sheet); }
.log { overflow-y: auto; padding: 2rem clamp(1rem, 4vw, 3rem) 1rem; }
.log > * { max-width: 46rem; }

/* ---------- empty state ---------- */
.empty { padding-top: 8vh; }
.empty h2 { font-size: var(--step-3); font-weight: 600; max-width: 18ch; }
.empty p { max-width: 34rem; margin: 0.8rem 0 1.6rem; }
.suggest { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.suggest button {
  font: inherit; font-size: var(--step--1); font-weight: 500; color: var(--ink);
  background: var(--film); border: 1px solid var(--rule); border-radius: 999px; padding: 0.4rem 0.85rem; cursor: pointer;
}
.suggest button:hover { border-color: var(--ink-2); }

/* ---------- messages ---------- */
.msg { margin: 0 0 1.4rem; }
.msg.user {
  margin-left: auto; width: fit-content; max-width: 34rem; background: var(--ink); color: var(--sheet);
  padding: 0.6rem 0.9rem; border-radius: var(--r-md) var(--r-md) var(--r-sm) var(--r-md); white-space: pre-wrap;
}
.msg.bot { line-height: 1.6; }
.msg.bot p { margin: 0 0 0.7rem; }
.msg.bot ul, .msg.bot ol { margin: 0 0 0.7rem; padding-left: 1.3rem; }
.msg.bot li { margin: 0.15rem 0; }
.msg.bot strong { font-weight: 600; }
.msg.bot code { font-family: var(--font-num); background: var(--film); padding: 0 0.3rem; border-radius: 3px; }
.msg.bot h3 { font-size: var(--step-1); margin: 1rem 0 0.4rem; }
.msg.error { color: var(--redline); }
.table-wrap { overflow-x: auto; margin: 0 0 0.8rem; }
.msg.bot table { border-collapse: collapse; font-family: var(--font-num); font-size: 0.95rem; min-width: 60%; }
.msg.bot th, .msg.bot td { border-bottom: 1px solid var(--rule); padding: 0.35rem 0.8rem 0.35rem 0; text-align: left; vertical-align: top; }
.msg.bot th { font-weight: 600; color: var(--ink-2); border-bottom-color: var(--ink-2); }
.msg.bot td.num, .msg.bot th.num { text-align: right; }

.thinking { display: flex; gap: 0.3rem; padding: 0.4rem 0; }
.thinking i { width: 7px; height: 7px; border-radius: 50%; background: var(--ink-2); opacity: 0.3; animation: blink 1.2s infinite; }
.thinking i:nth-child(2) { animation-delay: 0.2s; } .thinking i:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink { 50% { opacity: 1; } }

/* ---------- the revision card (redline) ---------- */
.rev {
  border: 1.5px solid var(--ink); border-radius: var(--r-sm); background: var(--sheet);
  margin: 0 0 1.4rem; position: relative;
}
.rev-head {
  display: flex; justify-content: space-between; align-items: baseline; gap: 1rem;
  padding: 0.7rem 1rem; border-bottom: 1.5px solid var(--ink); background: var(--film);
}
.rev-head h3 { font-size: var(--step-0); }
.rev-state { font-family: var(--font-num); font-weight: 600; font-size: var(--step--1); color: var(--signal); white-space: nowrap; }
.rev[data-state="applied"]   .rev-state { color: var(--approve); }
.rev[data-state="cancelled"] .rev-state,
.rev[data-state="failed"]    .rev-state,
.rev[data-state="blocked"]   .rev-state { color: var(--redline); }
.rev-body { padding: 0.6rem 1rem 0.8rem; }
.rev-op { margin: 0.4rem 0 0.7rem; }
.rev-op-title { font-weight: 600; font-size: var(--step--1); color: var(--ink-2); margin-bottom: 0.2rem; }
.rev-op table { border-collapse: collapse; width: 100%; font-family: var(--font-num); font-size: 0.95rem; }
.rev-op td { padding: 0.2rem 0.6rem 0.2rem 0; vertical-align: top; border-bottom: 1px dashed var(--rule); }
.rev-op td.field { color: var(--ink-2); width: 34%; }
.old { color: var(--redline); text-decoration: line-through; text-decoration-thickness: 1.5px; margin-right: 0.5rem; }
.new { color: var(--approve); font-weight: 600; }
.rev-note { margin: 0.5rem 0 0; padding: 0.45rem 0.7rem; border-left: 3px solid var(--signal); background: var(--signal-wash); font-size: var(--step--1); }
.rev-note.err { border-left-color: var(--redline); background: var(--red-wash); color: var(--redline); }
.rev-actions { display: flex; gap: 0.6rem; padding: 0.7rem 1rem; border-top: 1px solid var(--rule); }
.rev-result { padding: 0.6rem 1rem; border-top: 1px solid var(--rule); font-size: var(--step--1); }
.rev[data-state="applied"] { border-color: var(--approve); }
.rev[data-state="applied"] .rev-head { background: var(--approve-wash); border-bottom-color: var(--approve); }
.rev[data-state="applied"] .rev-result { color: var(--approve); font-weight: 600; }
.rev[data-state="cancelled"] { opacity: 0.6; }
.rev.flash { animation: settle 0.5s ease-out; }
@keyframes settle { from { transform: scale(0.99); box-shadow: 0 0 0 4px var(--approve-wash); } to { transform: none; box-shadow: none; } }

/* ---------- composer ---------- */
.composer {
  display: flex; gap: 0.6rem; align-items: flex-end;
  padding: 0.9rem clamp(1rem, 4vw, 3rem) calc(0.9rem + env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule); background: var(--sheet);
}
.composer textarea { flex: 1; max-width: 46rem; resize: none; max-height: 40vh; line-height: 1.45; padding: 0.65rem 0.8rem; }
.composer .btn { padding: 0.68rem 1.2rem; }

/* ---------- small screens ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .side {
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem;
    padding: 0.6rem 0.9rem; border-right: 0; border-bottom: 1px solid var(--rule);
  }
  .brand span { display: none; }
  .project-pick { flex: 1 1 8rem; min-width: 0; font-size: 0; gap: 0; }
  .project-pick select { font-size: var(--step--1); width: 100%; }
  .project-meta { display: none; }
  #new-chat { padding: 0.45rem 0.7rem; font-size: var(--step--1); }
  .side-foot { margin: 0; }
  #who { display: none; }
  .empty { padding-top: 2vh; }
  .empty h2 { font-size: var(--step-2); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
