:root {
  --navy: #1C2B3A;
  --ink: #1C2B3A;
  --muted: #4A6275;
  --blue-deep: #2D4A60;
  --blue: #2B6CB0;
  --blue-bright: #3182CE;
  --bg: #F5F7FA;
  --surface: #ffffff;
  --agent: #F1F4F7;
  --line: rgba(28, 43, 58, 0.08);
  --shadow: 0 10px 40px rgba(28, 43, 58, 0.08);
  --column: 820px;
  --header-h: 64px;
  --sidebar-w: 256px;
  --font: "Barlow", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(900px 420px at 50% -80px, rgba(49, 130, 206, 0.09), transparent 70%),
    var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  color-scheme: light;
}

button, textarea { font-family: inherit; }

::selection {
  background: rgba(43, 108, 176, 0.18);
}

button:focus,
textarea:focus { outline: none; }

:focus-visible {
  outline: 2px solid rgba(49, 130, 206, 0.45);
  outline-offset: 2px;
}

[hidden] { display: none !important; }

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app {
  position: relative;
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: row;
  overflow: hidden;
}

.app::after {
  content: "";
  position: absolute;
  z-index: 6;
  top: var(--header-h);
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, var(--blue-deep), var(--blue) 55%, var(--blue-bright));
  pointer-events: none;
}

.workspace {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.sidebar {
  width: var(--sidebar-w);
  flex: none;
  display: flex;
  flex-direction: column;
  background: #F3F6FA;
  overflow: hidden;
  transition: width 0.22s ease;
}

html:not(.sidebar-open) .sidebar {
  width: 0;
  visibility: hidden;
}

html.sidebar-open .sidebar { visibility: visible; }

.sidebar-head {
  height: var(--header-h);
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 8px 0 14px;
}

.sidebar-title {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.icon-btn {
  width: 34px;
  height: 34px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--navy);
  cursor: pointer;
}

.icon-btn:hover { background: rgba(28, 43, 58, 0.06); }

html.sidebar-open #sidebar-open { display: none; }

.sidebar-new {
  margin: 12px 10px 8px;
  width: calc(100% - 20px);
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid rgba(43, 108, 176, 0.28);
  background: var(--surface);
  color: var(--navy);
  border-radius: 12px;
  padding: 9px 12px;
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.sidebar-new:hover {
  border-color: var(--blue);
  color: var(--blue);
  box-shadow: 0 8px 18px rgba(43, 108, 176, 0.1);
}

.history {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  padding: 4px 10px 12px;
}

.history-group {
  margin: 14px 6px 6px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.history-empty {
  margin: 14px 8px;
  color: var(--muted);
  font-size: 14px;
}

.history-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 4px;
  width: 100%;
  margin-bottom: 2px;
  padding: 8px 8px 8px 10px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--navy);
  transition: background 0.16s ease, border-color 0.16s ease;
}

.history-item:hover {
  background: rgba(43, 108, 176, 0.06);
}

.history-item.is-active {
  background: rgba(43, 108, 176, 0.12);
  border-color: rgba(43, 108, 176, 0.16);
}

.history-item.is-active:hover {
  background: rgba(43, 108, 176, 0.16);
}

.history-open {
  flex: 1;
  min-width: 0;
  display: block;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
  font: inherit;
  padding: 2px 0;
}

.history-title {
  display: block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 14.5px;
  font-weight: 600;
  line-height: 1.3;
}

.history-actions {
  display: flex;
  flex: none;
  gap: 2px;
  opacity: 0;
}

.history-item:hover .history-actions,
.history-item:focus-within .history-actions,
.history-item.is-confirming .history-actions { opacity: 1; }

.history-actions button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.history-actions button:hover { background: rgba(28, 43, 58, 0.06); color: var(--navy); }
.history-actions .is-danger:hover,
.history-actions .is-confirm { color: #B42318; background: rgba(180, 35, 24, 0.08); }

.history-actions .is-confirm {
  width: auto;
  padding: 0 8px;
  font-size: 12px;
  font-weight: 600;
}

.history-rename {
  flex: 1;
  min-width: 0;
  width: auto;
  border: 1px solid rgba(43, 108, 176, 0.45);
  border-radius: 8px;
  padding: 7px 8px;
  font: inherit;
  font-size: 14px;
  color: var(--navy);
  background: #fff;
}

.sidebar-foot {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 56px;
  padding: 10px 14px 12px;
  border-top: 1px solid var(--line);
  background: #F3F6FA;
}

.sidebar-foot img {
  height: 28px;
  width: auto;
  display: block;
}

.sidebar-foot span {
  color: var(--navy);
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.backdrop {
  display: none;
  border: 0;
  padding: 0;
}

.topbar {
  position: relative;
  flex: none;
  height: var(--header-h);
  background: rgba(255, 255, 255, 0.92);
  backdrop-filter: blur(16px);
  z-index: 2;
}

.bottom-inner,
.thread-inner {
  width: min(var(--column), 100%);
  margin: 0 auto;
}

.topbar-inner {
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: none;
}

.sap-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 5px 10px 5px 8px;
  border-radius: 999px;
  background: rgba(34, 160, 107, 0.1);
  color: var(--navy);
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.2;
  white-space: nowrap;
}

.sap-badge i {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22A06B;
  box-shadow: 0 0 0 3px rgba(34, 160, 107, 0.18);
  flex: none;
}

.brand-mark {
  height: 36px;
  width: auto;
  display: block;
  flex: none;
}

.brand-text { min-width: 0; }

.brand-name,
.brand-tag {
  margin: 0;
}

.brand-name {
  color: var(--navy);
  font-size: 17px;
  font-weight: 600;
  letter-spacing: -0.015em;
  line-height: 1.2;
}

.brand-tag {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
  line-height: 1.3;
}

.ghost {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  flex: none;
  border: 1px solid rgba(28, 43, 58, 0.12);
  background: var(--surface);
  color: var(--navy);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: border-color 0.18s ease, color 0.18s ease, box-shadow 0.18s ease;
}

.ghost:hover {
  border-color: rgba(43, 108, 176, 0.45);
  color: var(--blue);
  box-shadow: 0 6px 16px rgba(43, 108, 176, 0.08);
}

.thread {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.thread::-webkit-scrollbar { width: 10px; }
.thread::-webkit-scrollbar-thumb {
  background: rgba(28, 43, 58, 0.18);
  border-radius: 99px;
  border: 2px solid transparent;
  background-clip: padding-box;
}

.thread-inner {
  min-height: 100%;
  padding: 12px 24px 8px;
  display: flex;
  flex-direction: column;
}

html.is-chatting .welcome,
body.is-chatting .welcome {
  display: none;
}

.welcome {
  width: min(620px, 100%);
  margin: 0 auto;
  padding: 4px 0 8px;
  flex: 1 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  animation: rise 0.5s ease;
}

.welcome h1 {
  margin: 0 0 6px;
  color: var(--navy);
  font-size: 32px;
  font-weight: 600;
  letter-spacing: -0.03em;
  line-height: 1.1;
}

.lead {
  margin: 0;
  max-width: 520px;
  color: var(--navy);
  font-size: 16.5px;
  font-weight: 500;
  line-height: 1.35;
}

.sub {
  margin: 4px 0 0;
  max-width: 460px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.35;
}

.suggestions {
  width: 100%;
  margin-top: 14px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.suggest {
  width: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: flex-start;
  gap: 1px;
  text-align: left;
  background: var(--surface);
  color: var(--navy);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 14px;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(28, 43, 58, 0.04);
  transition: transform 0.18s ease, border-color 0.18s ease, box-shadow 0.18s ease;
}

.suggest-icon {
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  margin-bottom: 8px;
  border-radius: 9px;
  color: var(--blue);
  background: linear-gradient(160deg, rgba(45, 74, 96, 0.08), rgba(49, 130, 206, 0.16));
}

.suggest-icon svg { width: 18px; height: 18px; }

.suggest-domain {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.2;
}

.suggest-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 500;
}

.suggest:hover {
  transform: translateY(-2px);
  border-color: rgba(43, 108, 176, 0.35);
  box-shadow: 0 12px 28px rgba(43, 108, 176, 0.12);
}

.messages {
  display: flex;
  flex-direction: column;
  gap: 22px;
  width: 100%;
  padding: 18px 0 12px;
}

.messages:empty { display: none; }

.msg.is-new { animation: rise 0.35s ease; }

.msg-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.msg-user .msg-row { justify-content: flex-end; }

.avatar {
  width: 34px;
  height: 34px;
  margin-top: 24px;
  padding: 4px;
  object-fit: contain;
  flex: none;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 11px;
  box-shadow: 0 2px 8px rgba(28, 43, 58, 0.05);
}

.msg-content { max-width: min(92%, 760px); }

.msg-user .msg-content { max-width: min(78%, 640px); }

.msg-label,
.msg-meta {
  color: var(--muted);
  font-size: 12.5px;
  font-weight: 500;
}

.msg-label {
  margin: 0 0 6px 2px;
}

.bubble {
  padding: 12px 16px;
  box-shadow: 0 1px 2px rgba(28, 43, 58, 0.04);
}

.msg-agent .bubble {
  background: var(--agent);
  color: var(--ink);
  border-radius: 20px 20px 20px 6px;
  border: 1px solid rgba(28, 43, 58, 0.04);
}

.msg-user .bubble {
  background: linear-gradient(155deg, var(--blue-deep) 0%, var(--blue) 68%, var(--blue-bright) 100%);
  color: #fff;
  border-radius: 20px 20px 6px 20px;
  box-shadow: 0 8px 22px rgba(43, 108, 176, 0.2);
}

.body {
  font-size: 16.5px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-wrap: break-word;
}

.body.is-rich { white-space: normal; }

.body p { margin: 0 0 0.7em; }
.body p:last-child { margin-bottom: 0; }

.body ul,
.body ol {
  margin: 0.15em 0 0.45em;
  padding-left: 1.2em;
}

.body li { margin: 0.7em 0; }
.body li::marker { color: var(--blue); }
.li-meta {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 14.5px;
  line-height: 1.4;
}

.body strong { font-weight: 600; }

.table-wrap {
  overflow-x: auto;
  margin: 0.35em 0 0.55em;
  border: 1px solid rgba(28, 43, 58, 0.08);
  border-radius: 12px;
  background: #fff;
}

.body table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  font-size: 14px;
  line-height: 1.4;
}

.body th {
  padding: 10px 12px;
  background: #E7EEF5;
  color: var(--navy);
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
}

.body td {
  padding: 9px 12px;
  border-top: 1px solid rgba(28, 43, 58, 0.06);
  vertical-align: top;
}

.body tbody tr:nth-child(even) td { background: rgba(43, 108, 176, 0.045); }

.body th.num,
.body td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table-actions {
  display: flex;
  justify-content: flex-end;
  margin: 2px 2px 0;
}

.excel {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--blue);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.excel:hover { text-decoration: underline; }

.body code {
  font-family: inherit;
  font-weight: 600;
  background: rgba(28, 43, 58, 0.06);
  border-radius: 6px;
  padding: 0 0.3em;
}

.msg-user .body code {
  background: rgba(255, 255, 255, 0.16);
}

.status {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 14.5px;
  font-weight: 500;
  min-height: 24px;
}

.status.is-live { animation: step-in 0.28s ease; }

.status:not([hidden]) + .body:not(:empty) { margin-top: 8px; }

.dots {
  display: inline-flex;
  gap: 4px;
}

.dots i {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--blue);
  animation: pulse 1.1s infinite ease-in-out;
}

.dots i:nth-child(2) { animation-delay: 0.15s; }
.dots i:nth-child(3) { animation-delay: 0.3s; }

.cursor {
  display: inline-block;
  width: 7px;
  height: 1.05em;
  margin-left: 2px;
  vertical-align: text-bottom;
  border-radius: 2px;
  background: var(--blue);
  animation: blink 1s steps(1) infinite;
}

.msg-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin-top: 6px;
  padding-left: 2px;
}

.msg-user .msg-meta { justify-content: flex-end; padding-right: 2px; }

.source {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.source-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-deep), var(--blue-bright));
}

.copy {
  border: 0;
  padding: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 12.5px;
  font-weight: 500;
  cursor: pointer;
}

.copy:hover { color: var(--blue); }

.bottom {
  flex: none;
  position: relative;
  z-index: 2;
  background: var(--bg);
  padding-bottom: calc(12px + env(safe-area-inset-bottom));
}

.bottom-inner { padding: 0 24px; }

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--surface);
  border: 1px solid rgba(28, 43, 58, 0.1);
  border-radius: 28px;
  padding: 8px 8px 8px 18px;
  box-shadow: var(--shadow), 0 1px 2px rgba(28, 43, 58, 0.04);
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}

.composer:focus-within {
  border-color: rgba(43, 108, 176, 0.45);
  box-shadow: 0 12px 36px rgba(43, 108, 176, 0.12), 0 0 0 4px rgba(49, 130, 206, 0.12);
}

.composer textarea {
  flex: 1;
  border: 0;
  resize: none;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-size: 16px;
  line-height: 1.45;
  max-height: 180px;
  overflow: hidden;
  padding: 10px 4px;
}

.composer textarea::placeholder { color: rgba(74, 98, 117, 0.8); }

.send {
  width: 42px;
  height: 42px;
  flex: none;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(145deg, var(--blue-deep) 0%, var(--blue) 55%, var(--blue-bright) 100%);
  box-shadow: 0 6px 16px rgba(43, 108, 176, 0.35);
  transition: transform 0.15s ease, opacity 0.15s ease, box-shadow 0.15s ease;
}

.send:hover:not(:disabled) { transform: translateY(-1px); }

.send:disabled {
  opacity: 1;
  cursor: default;
  color: #8AA0B3;
  background: #E6EDF3;
  box-shadow: none;
}

.send .icon-stop { display: none; }
.send.is-stop .icon-send { display: none; }
.send.is-stop .icon-stop { display: block; }
.send.is-stop { opacity: 1; }

.hint,
.footer {
  margin: 0;
  text-align: center;
  color: var(--muted);
}

.hint {
  margin-top: 8px;
  font-size: 12.5px;
}

.footer {
  margin-top: 10px;
  font-size: 12.5px;
  line-height: 1.45;
}

.footer p { margin: 0; }

.footer-links {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 6px 8px;
}

.footer a {
  color: var(--blue);
  font-weight: 500;
  text-decoration: none;
}

.footer a:hover { text-decoration: underline; }

@keyframes step-in {
  from { opacity: 0; transform: translateY(3px); }
  to { opacity: 1; transform: none; }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: none; }
}

@keyframes blink {
  0%, 45% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

@keyframes pulse {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.35; }
  40% { transform: translateY(-3px); opacity: 1; }
}

@media (min-width: 900px) {
  html.sidebar-open #new-chat { display: none; }
}

@media (max-width: 899px) {
  .app::after { display: none; }

  .topbar {
    height: auto;
  }

  .topbar::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--blue-deep), var(--blue) 55%, var(--blue-bright));
  }

  .sidebar {
    position: fixed;
    z-index: 30;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(300px, 88vw);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    box-shadow: none;
  }

  html:not(.sidebar-open) .sidebar { width: min(300px, 88vw); }

  html.sidebar-open .sidebar {
    transform: none;
    visibility: visible;
    box-shadow: 16px 0 40px rgba(28, 43, 58, 0.14);
  }

  .sidebar-head::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 2px;
    background: linear-gradient(90deg, var(--blue-deep), var(--blue) 55%, var(--blue-bright));
  }

  .sidebar-head { position: relative; }

  html.sidebar-open .backdrop {
    display: block;
    position: fixed;
    z-index: 25;
    inset: 0;
    background: rgba(28, 43, 58, 0.32);
    cursor: pointer;
  }
}

@media (max-width: 720px) {
  .bottom-inner,
  .thread-inner { padding-left: 16px; padding-right: 16px; }

  .topbar-inner {
    height: auto;
    flex-wrap: wrap;
    row-gap: 6px;
    padding: 8px 16px;
  }
  .brand-name { font-size: 16px; }
  .brand-tag { font-size: 12px; }
  .top-actions { margin-left: auto; }
  .sap-badge { font-size: 12px; }
  .btn-label { display: none; }
  .ghost { padding: 8px; border-radius: 12px; }
  .welcome h1 { font-size: 28px; }
  .lead { font-size: 15.5px; }
  .suggestions { gap: 8px; margin-top: 12px; }
  .suggest { padding: 10px 12px; }
  .msg-content { max-width: calc(100% - 44px); }
  .msg-user .msg-content { max-width: 92%; }
  .hint { display: none; }
  .body { font-size: 16px; }
}

@media (hover: none) {
  .history-actions { opacity: 1; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
