:root {
  color-scheme: light;
  --ink: #172424;
  --muted: #64706d;
  --paper: #f3f0e8;
  --surface: #fffdf8;
  --line: #d9d4c8;
  --deep: #173c3a;
  --deep-soft: #285451;
  --accent: #d9673f;
  --accent-soft: #f4d9ca;
  --danger: #a33d31;
  --shadow: 0 22px 65px rgba(29, 50, 47, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 8%, rgba(217, 103, 63, 0.11), transparent 23rem),
    radial-gradient(circle at 92% 90%, rgba(23, 60, 58, 0.1), transparent 30rem),
    var(--paper);
}

button, input, textarea { font: inherit; }
button { cursor: pointer; }
[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-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem;
}

.login-card {
  width: min(100%, 29rem);
  padding: 3.25rem;
  background: rgba(255, 253, 248, 0.92);
  border: 1px solid rgba(217, 212, 200, 0.9);
  border-radius: 2rem;
  box-shadow: var(--shadow);
  backdrop-filter: blur(20px);
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 3.6rem;
  height: 3.6rem;
  margin-bottom: 2rem;
  color: #fffaf3;
  background: var(--deep);
  border-radius: 1.15rem 1.15rem 1.15rem 0.35rem;
  font: 700 1.55rem/1 Georgia, serif;
  box-shadow: 0 10px 24px rgba(23, 60, 58, 0.2);
}

.brand-mark.small {
  width: 2.5rem;
  height: 2.5rem;
  margin: 0;
  border-radius: 0.8rem 0.8rem 0.8rem 0.25rem;
  font-size: 1.1rem;
}

.eyebrow {
  margin: 0 0 0.35rem;
  color: var(--accent);
  font-size: 0.72rem;
  font-weight: 750;
  letter-spacing: 0.15em;
  text-transform: uppercase;
}

.login-card h1,
.panel-header h1,
.panel-header h2 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 500;
  letter-spacing: -0.025em;
}

.login-card h1 { font-size: clamp(2.2rem, 8vw, 3.25rem); line-height: 1.02; }
.login-copy { margin: 1rem 0 2rem; color: var(--muted); line-height: 1.6; }

label { display: block; margin-bottom: 0.45rem; font-size: 0.82rem; font-weight: 700; }

input, textarea {
  width: 100%;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 0.8rem;
  outline: none;
  transition: border-color 160ms ease, box-shadow 160ms ease;
}

input { height: 3rem; padding: 0 0.9rem; }
textarea { padding: 1rem 7rem 1rem 1rem; line-height: 1.45; resize: none; }
input:focus, textarea:focus { border-color: var(--deep-soft); box-shadow: 0 0 0 3px rgba(40, 84, 81, 0.12); }

.primary-button, .secondary-button, .quiet-button, .send-button, .icon-button {
  border: 0;
  border-radius: 0.75rem;
  font-weight: 750;
  transition: transform 150ms ease, background 150ms ease, opacity 150ms ease;
}

.primary-button, .send-button { color: #fff; background: var(--deep); }
.primary-button { min-height: 2.85rem; padding: 0.65rem 1rem; }
.wide-button { width: 100%; margin-top: 0.8rem; }
.primary-button:hover, .send-button:hover { background: var(--deep-soft); transform: translateY(-1px); }
.secondary-button { padding: 0.65rem 0.9rem; color: var(--deep); background: #e6ebe7; }
.secondary-button:hover { background: #dbe3de; }
.quiet-button, .icon-button { padding: 0.55rem 0.75rem; color: var(--muted); background: transparent; }
.quiet-button:hover, .icon-button:hover { color: var(--ink); background: rgba(23, 60, 58, 0.07); }
button:disabled { cursor: wait; opacity: 0.55; transform: none !important; }

.form-error { min-height: 1.25rem; margin: 0.75rem 0 0; color: var(--danger); font-size: 0.82rem; }
.privacy-note { margin: 1.25rem 0 0; color: var(--muted); font-size: 0.76rem; line-height: 1.5; }

.topbar {
  height: 4.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2.25rem;
  background: rgba(243, 240, 232, 0.86);
  border-bottom: 1px solid rgba(217, 212, 200, 0.85);
  backdrop-filter: blur(18px);
}

.brand { display: flex; align-items: center; gap: 0.8rem; color: inherit; text-decoration: none; }
.brand strong { display: block; font: 600 1.25rem/1.05 Georgia, serif; }
.brand small { color: var(--muted); font-size: 0.7rem; }
.topbar-actions { display: flex; align-items: center; gap: 1rem; }
.connection { color: var(--muted); font-size: 0.78rem; }
.status-dot { display: inline-block; width: 0.48rem; height: 0.48rem; margin-right: 0.45rem; background: #4a8b68; border-radius: 50%; box-shadow: 0 0 0 4px rgba(74, 139, 104, 0.12); }

.workspace {
  width: min(100%, 96rem);
  height: calc(100vh - 4.75rem);
  min-height: 38rem;
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 22rem;
}

.chat-panel { min-width: 0; display: flex; flex-direction: column; padding: 2rem 2.5rem 1.5rem; }
.library-panel { overflow: auto; padding: 2rem 1.6rem; background: rgba(255, 253, 248, 0.66); border-left: 1px solid var(--line); }
.panel-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; }
.panel-header h1 { font-size: clamp(1.8rem, 3vw, 2.65rem); }
.panel-header h2 { font-size: 2rem; }
.file-count { margin-top: 0.3rem; padding: 0.32rem 0.6rem; color: var(--muted); background: #ebe7dd; border-radius: 99px; font-size: 0.72rem; }

.session-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin: 1.25rem 0 0;
  padding: 0.6rem 0;
  color: var(--muted);
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  font-size: 0.74rem;
}

.current-session { min-width: 0; display: flex; align-items: center; gap: 0.6rem; }
.current-session code { overflow: hidden; color: var(--ink); text-overflow: ellipsis; white-space: nowrap; }
.resume-control { position: relative; flex: none; }
.resume-control summary { cursor: pointer; color: var(--deep); font-weight: 700; list-style: none; }
.resume-control summary::-webkit-details-marker { display: none; }
.resume-control form { position: absolute; z-index: 5; right: 0; top: 1.8rem; width: 23rem; display: flex; gap: 0.5rem; padding: 0.75rem; background: var(--surface); border: 1px solid var(--line); border-radius: 0.9rem; box-shadow: var(--shadow); }
.resume-control input { min-width: 0; height: 2.5rem; font-size: 0.78rem; }

.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 1.6rem max(0.25rem, calc((100% - 48rem) / 2)); scrollbar-color: #cbc5b8 transparent; }
.empty-chat { height: 100%; min-height: 15rem; display: grid; place-content: center; justify-items: center; text-align: center; }
.empty-chat h2 { margin: 1.2rem 0 0.4rem; font: 500 clamp(1.6rem, 4vw, 2.25rem)/1.1 Georgia, serif; }
.empty-chat p { max-width: 28rem; margin: 0; color: var(--muted); line-height: 1.6; }
.empty-orbit { width: 4.5rem; height: 4.5rem; display: grid; place-items: center; border: 1px solid #c4beb0; border-radius: 50%; }
.empty-orbit::before { content: ""; width: 2.3rem; height: 2.3rem; border: 1px solid var(--accent); border-radius: 50%; }
.empty-orbit span { position: absolute; width: 0.7rem; height: 0.7rem; margin: -3rem 0 0 2.6rem; background: var(--accent); border-radius: 50%; }

.message { display: grid; grid-template-columns: 4rem minmax(0, 1fr); gap: 1rem; margin-bottom: 1.5rem; }
.message-role { padding-top: 0.2rem; color: var(--muted); font-size: 0.72rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; }
.message-content { min-width: 0; white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.68; }
.message.user .message-content { color: var(--deep); font-weight: 600; }
.message.assistant { padding: 1.1rem; background: rgba(255, 253, 248, 0.72); border: 1px solid rgba(217, 212, 200, 0.8); border-radius: 1rem; }
.message.failed { border-color: rgba(163, 61, 49, 0.35); }

.usage-line { min-height: 1.35rem; color: var(--muted); font-size: 0.7rem; text-align: right; }
.composer { position: relative; width: min(100%, 52rem); margin: 0 auto; }
.composer textarea { min-height: 3.5rem; max-height: 10rem; background: var(--surface); border-radius: 1rem; box-shadow: 0 10px 28px rgba(38, 54, 51, 0.08); }
.send-button { position: absolute; right: 0.55rem; top: 0.55rem; height: 2.45rem; display: flex; align-items: center; gap: 0.5rem; padding: 0 0.9rem; }
.composer-hint { margin: 0.45rem 0 0; color: var(--muted); font-size: 0.68rem; text-align: center; }

.library-copy { margin: 1rem 0 1.25rem; color: var(--muted); font-size: 0.82rem; line-height: 1.55; }
.upload-form { margin-bottom: 1.5rem; }
.upload-form input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.upload-drop { padding: 1.25rem; color: var(--muted); background: rgba(255, 255, 255, 0.62); border: 1px dashed #b9b4a8; border-radius: 1rem; text-align: center; cursor: pointer; transition: border 150ms ease, background 150ms ease; }
.upload-drop:hover { background: #fff; border-color: var(--deep-soft); }
.upload-drop strong, .upload-drop small, .selected-file { display: block; }
.upload-drop strong { margin: 0.5rem 0 0.2rem; color: var(--ink); font-size: 0.85rem; }
.upload-drop small { font-weight: 400; line-height: 1.45; }
.upload-plus { display: inline-grid; place-items: center; width: 2rem; height: 2rem; color: #fff; background: var(--accent); border-radius: 50%; font-size: 1.25rem; }
.selected-file { margin-top: 0.6rem; color: var(--deep); font-size: 0.72rem; overflow-wrap: anywhere; }

.library-list { border-top: 1px solid var(--line); }
.file-row { display: grid; grid-template-columns: 2.15rem minmax(0, 1fr) auto; align-items: center; gap: 0.7rem; padding: 0.85rem 0; border-bottom: 1px solid var(--line); }
.file-icon { display: grid; place-items: center; width: 2.15rem; height: 2.15rem; color: var(--deep); background: #e4e9e5; border-radius: 0.65rem; font: 700 0.64rem/1 ui-monospace, monospace; text-transform: uppercase; }
.file-name { min-width: 0; overflow: hidden; font-size: 0.8rem; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.delete-file { width: 1.9rem; height: 1.9rem; padding: 0; color: var(--muted); background: transparent; border: 0; border-radius: 0.5rem; }
.delete-file:hover { color: var(--danger); background: rgba(163, 61, 49, 0.08); }
.empty-library { padding: 1.25rem 0; color: var(--muted); font-size: 0.78rem; text-align: center; }

.toast { position: fixed; z-index: 20; left: 50%; bottom: 1.5rem; transform: translateX(-50%); max-width: min(90vw, 30rem); padding: 0.8rem 1rem; color: #fff; background: var(--deep); border-radius: 0.8rem; box-shadow: var(--shadow); font-size: 0.82rem; }
.toast.error { background: var(--danger); }

@media (max-width: 850px) {
  .workspace { height: auto; min-height: calc(100vh - 4.75rem); grid-template-columns: 1fr; }
  .chat-panel { min-height: calc(100vh - 4.75rem); padding: 1.5rem 1rem 1rem; }
  .library-panel { border-top: 1px solid var(--line); border-left: 0; }
  .messages { min-height: 24rem; }
}

@media (max-width: 560px) {
  .login-view { padding: 1rem; }
  .login-card { padding: 2rem 1.4rem; border-radius: 1.4rem; }
  .topbar { padding: 0 1rem; }
  .connection { display: none; }
  .chat-header { align-items: center; }
  .panel-header h1 { font-size: 1.75rem; }
  .session-bar { align-items: flex-start; }
  .current-session > span { display: none; }
  .resume-control form { position: fixed; left: 1rem; right: 1rem; top: 8.5rem; width: auto; }
  .message { grid-template-columns: 1fr; gap: 0.35rem; }
  .message.assistant { padding: 0.9rem; }
  .composer-hint { display: none; }
}

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