:root {
  --ink: #1e2a3b;
  --muted: #6f7c90;
  --paper: #fffdf9;
  --paper-2: #fff7ee;
  --line: #e9dccf;
  --brand: #ff6a00;
  --brand-strong: #d95400;
  --accent: #17406d;
  --accent-soft: #edf4ff;
  --ok: #1f9d5a;
  --danger: #be2f2f;
  --radius-xl: 24px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --shadow-a: 0 10px 24px rgba(23, 41, 66, 0.08);
  --shadow-b: 0 20px 45px rgba(23, 41, 66, 0.12);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  color: var(--ink);
  font-family: "Space Grotesk", "Manrope", "Segoe UI", sans-serif;
  background:
    radial-gradient(1300px 460px at 10% -12%, rgba(255, 106, 0, 0.2), rgba(255, 106, 0, 0)),
    radial-gradient(1100px 420px at 100% 0%, rgba(23, 64, 109, 0.15), rgba(23, 64, 109, 0)),
    linear-gradient(160deg, #fff9f1 0%, #f7fbff 72%);
}

.hidden {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.login-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(660px, 100%);
  padding: 28px;
  border-radius: var(--radius-xl);
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.98), rgba(255, 248, 239, 0.94));
  box-shadow: var(--shadow-b);
}

.login-card h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 3.1rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
  color: var(--ink);
}

.sub {
  margin: 10px 0 18px;
  color: var(--muted);
}

.login-grid {
  grid-template-columns: 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  border-bottom: 1px solid #ffe0ca;
  background: linear-gradient(180deg, rgba(255, 248, 239, 0.98), rgba(255, 255, 255, 0.98));
  box-shadow: 0 6px 16px rgba(30, 42, 59, 0.05);
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: 16px;
  padding: 12px 16px;
}

.sidebar h1 {
  margin: 0;
  font-size: 2rem;
  line-height: 0.9;
  letter-spacing: -0.04em;
}

.sidebar .sub {
  margin: 0;
  color: #8e98a9;
  font-size: 0.85rem;
}

.session-box {
  display: grid;
  grid-auto-flow: column;
  gap: 16px;
  align-items: center;
  padding: 8px 12px;
  border: 1px solid #f1dcc8;
  border-radius: 999px;
  background: #fff8f0;
  color: #5f6f85;
  font-size: 12px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.tab {
  border: 1px solid #edd7c2;
  border-radius: 999px;
  padding: 9px 14px;
  background: #fff;
  color: #5d6f86;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.tab:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 16px rgba(23, 41, 66, 0.1);
}

.tab.active {
  color: #fff;
  border-color: transparent;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  box-shadow: 0 10px 20px rgba(217, 84, 0, 0.25);
}

.logout-btn {
  margin: 0;
}

.content {
  padding: 18px;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  min-height: 0;
}

.content-topbar {
  display: flex;
  align-items: center;
  gap: 10px;
}

.menu-toggle {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 10px;
  padding: 10px;
  display: inline-flex;
  flex-direction: column;
  justify-content: space-between;
  background: linear-gradient(135deg, var(--accent), #255889);
  box-shadow: 0 8px 16px rgba(23, 64, 109, 0.3);
}

.menu-toggle span {
  width: 100%;
  height: 3px;
  border-radius: 999px;
  background: #fff;
  transition: transform 0.2s ease, opacity 0.2s ease;
}

.app-shell.sidebar-open .menu-toggle span:nth-child(1) {
  transform: translateY(8px) rotate(45deg);
}

.app-shell.sidebar-open .menu-toggle span:nth-child(2) {
  opacity: 0;
}

.app-shell.sidebar-open .menu-toggle span:nth-child(3) {
  transform: translateY(-8px) rotate(-45deg);
}

.topbar-badge {
  border-radius: 999px;
  padding: 8px 14px;
  background: #fff;
  border: 1px solid #e2ebf7;
  color: #35547a;
  font-size: 13px;
  font-weight: 700;
}

.content-body {
  min-height: 0;
  display: flex;
}

.tab-panel {
  display: none;
  width: 100%;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-xl);
  padding: 22px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.96), rgba(255, 250, 244, 0.88));
  box-shadow: var(--shadow-a);
  animation: appear 0.25s ease;
}

.tab-panel.active {
  display: block;
}

h2 {
  margin-top: 0;
  margin-bottom: 12px;
  font-size: clamp(2rem, 4.8vw, 3.2rem);
  line-height: 0.95;
  letter-spacing: -0.04em;
  color: var(--ink);
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.full {
  grid-column: 1 / -1;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid #ebd9c8;
  border-radius: var(--radius-md);
  background: #fff;
  color: var(--ink);
  font: inherit;
  padding: 10px 12px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(255, 106, 0, 0.13);
  transform: translateY(-1px);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 14px;
}

.checkbox-row > label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--ink);
}

.actions {
  margin-top: 14px;
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

button {
  border: 0;
  border-radius: 10px;
  padding: 11px 16px;
  font: inherit;
  color: #fff;
  cursor: pointer;
  background: linear-gradient(135deg, var(--brand), var(--brand-strong));
  box-shadow: 0 10px 20px rgba(217, 84, 0, 0.24);
  transition: transform 0.12s ease, filter 0.2s ease, box-shadow 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
  filter: brightness(1.03);
  box-shadow: 0 14px 24px rgba(217, 84, 0, 0.3);
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  box-shadow: none;
  transform: none;
}

button.secondary {
  background: linear-gradient(135deg, #2b6cb0, #205286);
  box-shadow: 0 10px 20px rgba(32, 82, 134, 0.24);
}

button.danger {
  background: linear-gradient(135deg, #ce4343, #a02a2a);
  box-shadow: 0 10px 20px rgba(160, 42, 42, 0.24);
}

.output {
  margin-top: 12px;
  min-height: 92px;
  max-height: 260px;
  overflow: auto;
  border: 1px solid #d7e2f0;
  border-radius: var(--radius-md);
  padding: 10px;
  color: #edf4ff;
  background: linear-gradient(180deg, #18426f, #133458);
}

.users-list {
  margin-top: 12px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
  overflow: hidden;
}

.user-row {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border-top: 1px solid var(--line);
}

.user-row:first-child {
  border-top: 0;
}

.chat-panel {
  display: none;
  height: 100%;
  overflow: hidden;
}

.chat-panel.active {
  display: grid;
  grid-template-rows: auto 1fr;
}

.chat-workspace {
  min-height: 0;
  display: grid;
  grid-template-columns: 290px 1fr;
  gap: 14px;
}

.chat-conversations {
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: linear-gradient(180deg, #fff5eb, #fff);
  padding: 10px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-height: 0;
}

.conversation-create {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 10px;
}

.conversation-list {
  overflow: auto;
  display: grid;
  gap: 8px;
  align-content: start;
}

.conversation-item {
  border: 1px solid #ebddcf;
  border-radius: var(--radius-md);
  background: #fff;
  padding: 10px;
  display: grid;
  gap: 4px;
  transition: transform 0.12s ease, box-shadow 0.2s ease;
}

.conversation-item:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 18px rgba(23, 41, 66, 0.08);
}

.conversation-item.active {
  border-color: var(--brand);
  background: var(--paper-2);
  box-shadow: inset 0 0 0 1px rgba(255, 106, 0, 0.5);
}

.conversation-title {
  font-weight: 700;
}

.conversation-meta {
  font-size: 12px;
  color: var(--muted);
}

.conversation-actions {
  display: flex;
  gap: 6px;
  margin-top: 4px;
}

.conversation-actions button {
  flex: 1;
  padding: 7px 8px;
  font-size: 12px;
}

.chat-main {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat-main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
}

.chat-log {
  border: 1px solid #dbe4f0;
  border-radius: var(--radius-lg);
  overflow: auto;
  padding: 14px;
  background: linear-gradient(180deg, #fff, #f8fbff);
}

.msg {
  margin-bottom: 12px;
  padding: 12px 14px;
  border: 1px solid #dbe3ef;
  border-radius: 14px;
}

.msg.user {
  background: linear-gradient(180deg, #fff5ea, #fff0e2);
  border-color: #ffd3b1;
}

.msg.assistant {
  background: linear-gradient(180deg, #f5f9ff, #edf5ff);
  border-color: #d2deef;
}

.msg-header {
  display: flex;
  align-items: center;
  margin-bottom: 8px;
}

.msg-role {
  display: inline-flex;
  align-items: center;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.msg.user .msg-role {
  background: rgba(255, 106, 0, 0.2);
  color: #994100;
}

.msg.assistant .msg-role {
  background: rgba(23, 64, 109, 0.18);
  color: #204a77;
}

.msg-body {
  color: #1d3652;
  line-height: 1.56;
}

.msg-body p {
  margin: 0 0 8px;
}

.msg-body p:last-child {
  margin-bottom: 0;
}

.msg-body ul,
.msg-body ol {
  margin: 6px 0 10px;
  padding-left: 20px;
}

.msg-body code {
  background: #edf3fb;
  border: 1px solid #d4dfed;
  border-radius: 6px;
  padding: 1px 5px;
  font-family: "Consolas", "Courier New", monospace;
  font-size: 0.9em;
}

.meta {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px dashed #d4dfee;
  color: #4c6482;
  font-size: 12px;
}

.meta ul {
  margin: 4px 0 8px;
  padding-left: 18px;
}

.composer {
  margin-top: 12px;
  display: grid;
  gap: 8px;
}

@keyframes appear {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 1200px) {
  .sidebar {
    grid-template-columns: 1fr;
    align-items: start;
    gap: 10px;
  }
}

@media (max-width: 1000px) {
  .app-shell {
    grid-template-rows: 1fr;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(84vw, 340px);
    z-index: 40;
    display: block;
    border-right: 1px solid rgba(255, 255, 255, 0.3);
    border-bottom: 0;
  }

  .tabs {
    display: grid;
    gap: 10px;
  }

  .session-box {
    display: grid;
    white-space: normal;
  }

  .content {
    min-height: 100vh;
    padding: 14px;
  }

  .card-grid {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    height: auto;
    overflow: visible;
  }

  .chat-workspace {
    grid-template-columns: 1fr;
  }

  .chat-log {
    min-height: 340px;
  }
}
