.hidden{display:none!important}
:root {
  --bg-900: #0b0f14;
  --bg-850: #0f141b;
  --bg-800: #121925;
  --bg-750: #152031;
  --bg-700: #1a2536;
  --text-100: #e6edf3;
  --text-300: #b8c3cf;
  --text-500: #8793a1;
  --accent: #4f8cff;
  --accent-700: #3f74d1;
  --danger: #ff5d5d;
  --warning: #ffb020;
  --border: #223044;
  --surface: #0f1622;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
  --topbar-h: 48px;
}

* {
  box-sizing: border-box;
}

html, body {
  height: 100%;
}

body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text-100);
  background: radial-gradient(1200px 800px at 10% -10%, #0c1422 0%, var(--bg-900) 40%),
              radial-gradient(1000px 700px at 120% -20%, #0f1b2e 0%, transparent 50%),
              var(--bg-900);
}

/* Desktop defaults for mobile UI elements */
.mobile-toggle { display: none; }
.sidebar-overlay { display: none; }

.app {
  display: grid;
  grid-template-columns: 280px 1fr;
  grid-template-rows: 1fr;
  height: calc(100vh - var(--topbar-h));
}

.sidebar {
  border-right: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-850), var(--bg-900));
  display: flex;
  flex-direction: column;
  padding: 12px;
  gap: 12px;
}

.sidebar__header {
  display: flex;
  gap: 8px;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.brand__dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, #7fb3ff, var(--accent));
  box-shadow: 0 0 8px rgba(79, 140, 255, 0.8), 0 0 16px rgba(79, 140, 255, 0.35);
}

.chat-list {
  flex: 1;
  overflow: auto;
  padding: 6px 4px;
  border-radius: 8px;
}

.chat-list__item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 10px;
  color: var(--text-100);
  cursor: pointer;
  border: 1px solid transparent;
}

.chat-list__item:hover {
  background: var(--bg-800);
  border-color: var(--border);
}

.chat-list__item--active {
  background: linear-gradient(180deg, var(--bg-750), var(--bg-800));
  border-color: var(--accent);
}

.chat-list__title {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 180px;
}

.sidebar__footer {
  display: flex;
  gap: 8px;
}

.main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  height: 100%;
}

.topbar { height: var(--topbar-h); }

.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-850), transparent);
}

.chat-title {
  font-weight: 600;
}

.chat-actions {
  display: flex;
  gap: 6px;
}

.messages {
  overflow-y: auto;
  padding: 18px 18px 24px;
}

.message {
  display: grid;
  grid-template-columns: 40px 1fr;
  gap: 12px;
  padding: 14px;
  margin: 0 auto 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, var(--bg-850), var(--surface));
  max-width: 1100px;
  box-shadow: var(--shadow);
}

.message__avatar {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: 14px;
  color: var(--text-100);
  background: linear-gradient(135deg, #1f2a44, #101826);
  border: 1px solid var(--border);
}

.message__avatar[data-role="user"]::after { content: "🙂"; }
.message__avatar[data-role="assistant"]::after { content: "🤖"; }
.message__avatar[data-role="system"]::after { content: "⚙️"; }

.message__content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.message__text {
  color: var(--text-100);
  line-height: 1.6;
}

.message__text code {
  background: #0b1322;
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 6px;
}

.message__text pre {
  background: #0b1322;
  border: 1px solid var(--border);
  padding: 12px;
  border-radius: 10px;
  overflow: auto;
}

.message__text img {
  max-width: 100%;
  height: auto;
  border-radius: 8px;
  border: 1px solid var(--border);
  cursor: zoom-in;
}

/* thumbnails */
.message__text img.thumbnail {
  max-width: 240px;
}

.lightbox-body {
  display: grid;
  place-items: center;
  max-height: 70vh;
}
.lightbox-body img {
  max-width: 86vw;
  max-height: 68vh;
  border-radius: 10px;
  border: 1px solid var(--border);
}

.message__meta {
  display: flex;
  gap: 8px;
}

.composer {
  border-top: 1px solid var(--border);
  padding: 12px 16px 16px;
  background: linear-gradient(0deg, var(--bg-850), transparent);
}

.composer__controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: end;
  max-width: 1100px;
  margin: 0 auto;
}

.input {
  width: 100%;
  resize: none;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  outline: none;
  background: linear-gradient(180deg, var(--bg-850), var(--surface));
  color: var(--text-100);
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.2);
}

.composer__buttons {
  display: flex;
  gap: 8px;
}

.btn {
  height: 40px;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-100);
  background: var(--bg-800);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  text-decoration: none;
}

.btn:hover { filter: brightness(1.1); }
.btn:active { transform: translateY(1px); }

.btn--primary {
  background: linear-gradient(180deg, var(--accent), var(--accent-700));
  border-color: #3965ad;
}

.btn--ghost {
  background: transparent;
}

.btn--secondary {
  background: linear-gradient(180deg, var(--bg-800), var(--bg-750));
  border-color: var(--border);
}

.btn--warning {
  background: linear-gradient(180deg, #ff7b5e, #f04c3c);
  border-color: #c73a3a;
}

.icon-btn {
  height: 36px;
  padding: 0 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-800);
  color: var(--text-100);
  cursor: pointer;
}

.footer-brand {
  margin-top: 8px;
  font-size: 12px;
  color: var(--text-500);
  text-align: center;
}

.modal::backdrop {
  background: rgba(0,0,0,0.6);
}

.modal {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0;
  background: var(--bg-900);
  color: var(--text-100);
  box-shadow: var(--shadow);
}

.modal__content {
  padding: 0;
  min-width: 560px;
}

.modal__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal__footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px 16px;
}

.form-field {
  display: grid;
  gap: 6px;
}

.form-field--full {
  grid-column: 1 / -1;
}

label span {
  color: var(--text-300);
  font-size: 12px;
}

input, select, textarea {
  background: var(--surface);
  color: var(--text-100);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  outline: none;
}

input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79, 140, 255, 0.2);
}

.hidden { display: none; }

/* Scrollbars */
.messages::-webkit-scrollbar, .chat-list::-webkit-scrollbar, pre::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
.messages::-webkit-scrollbar-thumb, .chat-list::-webkit-scrollbar-thumb, pre::-webkit-scrollbar-thumb {
  background: #22344a;
  border-radius: 10px;
}
.messages::-webkit-scrollbar-thumb:hover, .chat-list::-webkit-scrollbar-thumb:hover, pre::-webkit-scrollbar-thumb:hover {
  background: #2a4261;
}

@media (max-width: 900px) {
  .app { grid-template-columns: 1fr; }
  .modal__content { min-width: 92vw; }

  .mobile-toggle {
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 50;
    border: 1px solid var(--border);
    background: var(--bg-800);
    color: var(--text-100);
    border-radius: 8px;
    padding: 8px 10px;
    cursor: pointer;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 40;
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 80vw;
    max-width: 320px;
    transform: translateX(-100%);
    transition: transform 200ms ease-in-out;
    z-index: 60;
  }

  .sidebar--open {
    transform: translateX(0%);
  }

  .hidden { display: none !important; }
}


/* Links (keep consistent theme, no default purple visited color) */
a.link {
  color: var(--text-300);
  text-decoration: none;
}
a.link:visited {
  color: var(--text-300);
}
a.link:hover {
  color: var(--text-100);
  text-decoration: underline;
}


/* Admin tables */
.table {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.table .row {
  display: grid;
  grid-template-columns: 2fr 1.2fr 0.7fr 0.7fr 0.9fr 2.2fr;
  gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.table .row:last-child {
  border-bottom: 0;
}

.table .row.header {
  position: sticky;
  top: 0;
  background: var(--bg-800);
  color: var(--text-300);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table .row.header div {
  font-weight: 600;
}

.table .row div {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.table .row .btn {
  height: 32px;
}

