:root {
  color-scheme: light;
  --ink: #17352f;
  --ink-soft: #557069;
  --forest: #244c42;
  --forest-deep: #163a32;
  --sage: #dfe9e3;
  --sage-light: #eef3ef;
  --paper: #fbfaf6;
  --white: #ffffff;
  --sand: #e8e0cf;
  --gold: #b58a45;
  --danger: #a13c35;
  --success: #2b6a4f;
  --line: #dfe4dd;
  --shadow: 0 18px 45px rgba(23, 53, 47, 0.1);
  font-family: "Aptos", "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--paper);
  color: var(--ink);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; margin: 0; }
body { min-height: 100vh; background: var(--paper); }
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.56; }
::selection { color: var(--white); background: var(--forest); }
:focus-visible { outline: 3px solid rgba(181, 138, 69, 0.55); 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; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 32px 20px;
  background:
    linear-gradient(125deg, rgba(223, 233, 227, 0.82), transparent 48%),
    var(--paper);
}

.login-card {
  width: min(100%, 450px);
  padding: 46px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 14px;
  color: var(--white);
  background: var(--forest);
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  letter-spacing: -0.03em;
}
.brand-mark.small { width: 40px; height: 40px; border-radius: 12px; font-size: 14px; }
.product-name { margin: 26px 0 8px; color: var(--gold); font-size: 13px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.login-card h1 { margin: 0; max-width: 12ch; font-family: Georgia, "Times New Roman", serif; font-size: clamp(32px, 7vw, 45px); line-height: 1.04; letter-spacing: -0.03em; }
.login-copy { margin: 18px 0 30px; color: var(--ink-soft); line-height: 1.55; }
.login-form { display: grid; gap: 10px; }
.login-form label { margin-top: 7px; font-size: 13px; font-weight: 700; }
.login-form input, .composer textarea, .search-box input {
  width: 100%;
  border: 1px solid var(--line);
  color: var(--ink);
  background: var(--white);
}
.login-form input { min-height: 48px; padding: 0 14px; border-radius: 12px; }
.login-form input:hover, .login-form input:focus, .composer textarea:focus { border-color: #91aa9f; }
.primary-button { min-height: 49px; margin-top: 16px; border: 0; border-radius: 12px; color: var(--white); background: var(--forest); font-weight: 750; box-shadow: 0 9px 22px rgba(36, 76, 66, 0.2); }
.primary-button:hover { background: var(--forest-deep); }
.form-error, .global-error { color: var(--danger); }
.form-error { margin: 4px 0 0; font-size: 13px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 245px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 26px 20px; color: #eff5f1; background: var(--forest-deep); }
.brand-lockup { display: flex; align-items: center; gap: 12px; padding: 0 5px 30px; }
.brand-lockup .brand-mark { color: var(--forest-deep); background: #f3ead8; }
.brand-lockup strong, .brand-lockup span { display: block; }
.brand-lockup strong { font-family: Georgia, "Times New Roman", serif; font-size: 18px; }
.brand-lockup span { margin-top: 3px; color: #aac0b8; font-size: 11px; letter-spacing: 0.04em; }
.sidebar nav { display: grid; gap: 8px; }
.nav-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 12px 13px; border: 0; border-radius: 12px; color: #bdd0c9; background: transparent; text-align: left; font-weight: 650; }
.nav-item.active { color: var(--forest-deep); background: #f3ead8; }
.nav-item svg, .search-box svg, .send-button svg { width: 20px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.sidebar-foot { margin-top: auto; padding: 18px 6px 2px; border-top: 1px solid rgba(255, 255, 255, 0.12); }
.connection-state { display: flex; align-items: center; gap: 8px; margin-bottom: 13px; color: #c7d7d1; font-size: 12px; }
.connection-state span { width: 8px; height: 8px; border-radius: 50%; background: #75c99c; box-shadow: 0 0 0 4px rgba(117, 201, 156, 0.1); }
.text-button { padding: 0; border: 0; color: #9db5ac; background: transparent; font-size: 12px; text-decoration: underline; text-underline-offset: 3px; }
.text-button:hover { color: var(--white); }

.workspace { min-width: 0; padding: 34px clamp(22px, 4vw, 54px) 44px; }
.workspace-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; max-width: 1500px; margin: 0 auto 26px; }
.workspace-header h1 { margin: 0 0 7px; font-family: Georgia, "Times New Roman", serif; font-size: clamp(30px, 4vw, 43px); letter-spacing: -0.03em; }
.workspace-header p, .panel-heading p { margin: 0; color: var(--ink-soft); line-height: 1.5; }
.publication-status { display: flex; align-items: baseline; gap: 8px; padding-bottom: 5px; color: var(--ink-soft); }
.publication-status span { color: var(--ink); font-family: Georgia, "Times New Roman", serif; font-size: 29px; font-variant-numeric: tabular-nums; }
.publication-status small { font-size: 12px; }
.global-error { max-width: 1500px; margin: -8px auto 18px; padding: 12px 14px; border-radius: 12px; background: #f7e8e5; font-size: 13px; }

.panel-grid { display: grid; grid-template-columns: minmax(0, 1.45fr) minmax(330px, 0.75fr); gap: 20px; max-width: 1500px; min-height: calc(100vh - 155px); margin: 0 auto; }
.chat-panel, .library-panel { min-width: 0; background: var(--white); border-radius: 16px; box-shadow: 0 13px 38px rgba(23, 53, 47, 0.07); }
.chat-panel { display: grid; grid-template-rows: auto minmax(380px, 1fr) auto; overflow: hidden; }
.library-panel { padding: 25px; overflow: hidden; }
.panel-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 18px; padding: 24px 26px 20px; border-bottom: 1px solid var(--line); }
.library-heading { padding: 0 0 18px; }
.panel-heading h2 { margin: 0 0 5px; font-size: 17px; letter-spacing: -0.01em; }
.panel-heading p { font-size: 13px; }
.model-status { flex: none; padding: 6px 9px; border-radius: 999px; color: var(--success); background: #e7f2eb; font-size: 11px; font-weight: 750; }

.messages { max-height: calc(100vh - 360px); min-height: 420px; overflow-y: auto; padding: 26px; scrollbar-color: #c9d4cd transparent; scrollbar-width: thin; }
.welcome-message { max-width: 520px; padding: 18px 20px; border-radius: 14px; color: var(--ink); background: var(--sage-light); }
.welcome-message p { margin: 7px 0 0; color: var(--ink-soft); font-size: 14px; line-height: 1.55; }
.message { max-width: 78%; margin: 0 0 16px; padding: 13px 16px; border-radius: 14px; white-space: pre-wrap; line-height: 1.48; font-size: 14px; }
.message.admin { margin-left: auto; border-bottom-right-radius: 5px; color: var(--white); background: var(--forest); }
.message.assistant { border-bottom-left-radius: 5px; background: var(--sage-light); }
.message.system { max-width: 100%; padding: 9px 12px; color: var(--success); background: transparent; text-align: center; font-size: 12px; }
.thinking { display: flex; align-items: center; gap: 5px; width: max-content; }
.thinking span { width: 6px; height: 6px; border-radius: 50%; background: #799087; animation: pulse 1s ease-in-out infinite; }
.thinking span:nth-child(2) { animation-delay: 0.15s; }
.thinking span:nth-child(3) { animation-delay: 0.3s; }
@keyframes pulse { 0%, 100% { opacity: 0.35; transform: translateY(0); } 50% { opacity: 1; transform: translateY(-3px); } }
@media (prefers-reduced-motion: reduce) { .thinking span { animation: none; } }

.proposal { max-width: 88%; margin: -4px 0 20px; padding: 18px; border: 1px solid #c9d8cf; border-radius: 14px; background: var(--white); box-shadow: 0 9px 25px rgba(23, 53, 47, 0.07); }
.proposal-label { display: inline-block; margin-bottom: 9px; color: var(--gold); font-size: 11px; font-weight: 800; letter-spacing: 0.07em; text-transform: uppercase; }
.proposal h3 { margin: 0 0 7px; font-size: 15px; }
.proposal p { margin: 0; color: var(--ink-soft); font-size: 13px; line-height: 1.5; white-space: pre-wrap; }
.proposal-actions { display: flex; gap: 9px; margin-top: 16px; }
.confirm-button, .discard-button { min-height: 38px; padding: 0 14px; border-radius: 10px; font-size: 13px; font-weight: 750; }
.confirm-button { border: 0; color: var(--white); background: var(--forest); }
.confirm-button:hover { background: var(--forest-deep); }
.discard-button { border: 1px solid var(--line); color: var(--ink-soft); background: var(--white); }
.discard-button:hover { color: var(--danger); border-color: #dfbbb6; }

.composer { position: relative; padding: 18px 26px 17px; border-top: 1px solid var(--line); background: #fdfcf9; }
.composer textarea { min-height: 76px; resize: vertical; padding: 13px 55px 13px 14px; border-radius: 13px; line-height: 1.45; }
.composer textarea::placeholder, .search-box input::placeholder { color: #83968f; }
.send-button { position: absolute; top: 29px; right: 38px; display: grid; place-items: center; width: 38px; height: 38px; border: 0; border-radius: 11px; color: var(--white); background: var(--forest); }
.send-button:hover { background: var(--forest-deep); }
.send-button svg { width: 18px; }
.composer-note { margin: 8px 2px 0; color: var(--ink-soft); font-size: 11px; }

.search-box { display: flex; align-items: center; gap: 9px; margin: 18px 0; padding: 0 12px; border: 1px solid var(--line); border-radius: 12px; color: var(--ink-soft); background: var(--paper); }
.search-box svg { width: 17px; }
.search-box input { height: 43px; padding: 0; border: 0; outline: 0; background: transparent; }
.knowledge-list { max-height: calc(100vh - 280px); overflow-y: auto; padding-right: 3px; scrollbar-color: #c9d4cd transparent; scrollbar-width: thin; }
.knowledge-entry { padding: 16px 2px; border-bottom: 1px solid var(--line); }
.knowledge-entry:last-child { border-bottom: 0; }
.entry-meta { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 7px; }
.category { color: var(--gold); font-size: 10px; font-weight: 800; letter-spacing: 0.065em; text-transform: uppercase; }
.version { color: #8a9a94; font-size: 10px; font-variant-numeric: tabular-nums; }
.knowledge-entry h3 { margin: 0 0 6px; font-size: 14px; }
.knowledge-entry p { display: -webkit-box; margin: 0; overflow: hidden; color: var(--ink-soft); font-size: 12.5px; line-height: 1.52; -webkit-box-orient: vertical; -webkit-line-clamp: 4; }
.empty-library { padding: 34px 14px; color: var(--ink-soft); text-align: center; }
.empty-library strong { display: block; margin-bottom: 7px; color: var(--ink); }
.empty-library p { margin: 0; font-size: 13px; line-height: 1.5; }

@media (max-width: 1020px) {
  .app-shell { grid-template-columns: 82px minmax(0, 1fr); }
  .sidebar { padding-inline: 14px; }
  .brand-lockup { justify-content: center; padding-inline: 0; }
  .brand-lockup > div:last-child, .nav-item:not(.active)::after, .nav-item { font-size: 0; }
  .nav-item { justify-content: center; padding: 12px; }
  .nav-item svg { width: 22px; }
  .connection-state { justify-content: center; font-size: 0; }
  .text-button { display: block; width: 100%; font-size: 11px; }
  .panel-grid { grid-template-columns: minmax(0, 1fr); }
  .knowledge-list { max-height: none; }
  .messages { max-height: 590px; }
}

@media (max-width: 680px) {
  .app-shell { display: block; }
  .sidebar { position: static; width: 100%; height: auto; flex-direction: row; align-items: center; padding: 13px 16px; }
  .brand-lockup { padding: 0; }
  .brand-lockup > div:last-child { display: none; }
  .sidebar nav { margin-left: auto; }
  .sidebar-foot { margin: 0 0 0 10px; padding: 0; border: 0; }
  .connection-state { display: none; }
  .workspace { padding: 24px 14px 30px; }
  .workspace-header { align-items: flex-start; }
  .publication-status { display: none; }
  .workspace-header h1 { font-size: 32px; }
  .panel-grid { min-height: 0; }
  .chat-panel { grid-template-rows: auto minmax(360px, 55vh) auto; }
  .panel-heading { padding: 20px; }
  .messages { min-height: 360px; max-height: 55vh; padding: 20px; }
  .message, .proposal { max-width: 92%; }
  .composer { padding: 15px 20px 14px; }
  .send-button { top: 26px; right: 31px; }
  .library-panel { padding: 21px; }
  .login-card { padding: 34px 25px; }
}
