*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: system-ui, sans-serif;
  background: #111827;
  color: #f3f4f6;
}

/* Login */
.login-wrap {
  max-width: 360px;
  margin: 10vh auto;
  padding: 2rem;
  background: #1f2937;
  border-radius: 8px;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
.login-wrap h1 { margin-bottom: 1.5rem; }
.login-wrap input {
  display: block;
  width: 100%;
  padding: .6rem .8rem;
  margin-bottom: .75rem;
  border: 1px solid #374151;
  border-radius: 4px;
  font-size: 1rem;
  background: #111827;
  color: #f3f4f6;
}
.login-wrap button {
  width: 100%;
  padding: .7rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
  font-size: 1rem;
}
.login-wrap button:hover { background: #1d4ed8; }
.error { color: #f87171; margin-bottom: .75rem; font-size: .9rem; }

/* Chat layout */
.page-wrap {
  display: flex;
  height: 100vh;
  height: 100dvh;
  max-width: 960px;
  margin: 0 auto;
}
.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
header {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: .75rem 1rem;
  background: #1f2937;
  border-bottom: 1px solid #374151;
  flex-shrink: 0;
}
.brand { font-weight: 600; margin-right: auto; }
.tokens { font-size: .8rem; color: #9ca3af; }
header a { font-size: .85rem; color: #60a5fa; text-decoration: none; }
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.message {
  max-width: 80%;
  padding: .6rem .9rem;
  border-radius: 12px;
  font-size: .95rem;
  line-height: 1.5;
  white-space: pre-wrap;
}
.message.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 3px;
}
.message.assistant {
  align-self: flex-start;
  background: #1f2937;
  border: 1px solid #374151;
  color: #f3f4f6;
  border-bottom-left-radius: 3px;
}
.message.error { background: #450a0a; border-color: #7f1d1d; color: #fca5a5; }
.chat-form {
  display: flex;
  gap: .5rem;
  padding: .75rem 1rem;
  background: #1f2937;
  border-top: 1px solid #374151;
  flex-shrink: 0;
}
.chat-form textarea {
  flex: 1;
  padding: .6rem .8rem;
  border: 1px solid #374151;
  border-radius: 6px;
  font-size: .95rem;
  resize: none;
  font-family: inherit;
  background: #111827;
  color: #f3f4f6;
}
.chat-form button {
  padding: .6rem 1.2rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .95rem;
}
.chat-form button:hover { background: #1d4ed8; }

/* Sessions sidebar */
.sessions-sidebar {
  width: 200px;
  flex-shrink: 0;
  background: #111827;
  border-right: 1px solid #374151;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.new-session-btn {
  width: 100%;
  padding: .5rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  text-align: left;
}
.new-session-btn:hover { background: #1d4ed8; }
.session-list { display: flex; flex-direction: column; gap: .25rem; }
.session-item {
  display: flex;
  align-items: center;
  gap: .25rem;
  border-radius: 5px;
  padding: .3rem .4rem;
}
.session-item:hover { background: #1f2937; }
.session-item.active { background: #1e3a5f; }
.session-title {
  display: block;
  flex: 1;
  font-size: .8rem;
  color: #d1d5db;
  text-decoration: none;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.session-item.active .session-title { color: #93c5fd; }
.session-delete-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: .75rem;
  color: #4b5563;
  padding: .25rem .4rem;
  flex-shrink: 0;
  line-height: 1;
}
.session-delete-btn:hover { color: #f87171; }
.sidebar-toggle {
  background: none;
  border: none;
  color: #9ca3af;
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0 .25rem;
  line-height: 1;
}
.sidebar-toggle:hover { color: #f3f4f6; }
@media (max-width: 600px) {
  .sessions-sidebar {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    z-index: 100;
    width: 220px;
    box-shadow: 2px 0 12px rgba(0,0,0,.5);
  }
  .sessions-sidebar.open { display: flex; }
}

/* Tools sidebar */
.tools-sidebar {
  width: 220px;
  flex-shrink: 0;
  background: #1f2937;
  border-left: 1px solid #374151;
  padding: 1rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: .75rem;
}
.tools-label {
  font-size: .7rem;
  font-weight: 600;
  color: #6b7280;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.tool-buttons {
  display: flex;
  flex-direction: column;
  gap: .35rem;
}
.tool-btn {
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .5rem .75rem;
  background: #111827;
  border: 1px solid #374151;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  color: #d1d5db;
  text-align: left;
}
.tool-btn:hover { background: #374151; }
.tool-btn.active { background: #2563eb; color: #fff; border-color: #2563eb; }
.tool-form { display: flex; flex-direction: column; gap: .5rem; }
.tool-form-label { font-size: .75rem; color: #9ca3af; }
.tool-form textarea {
  width: 100%;
  padding: .5rem .6rem;
  border: 1px solid #374151;
  border-radius: 5px;
  font-size: .85rem;
  resize: none;
  font-family: inherit;
  background: #111827;
  color: #f3f4f6;
}
.tool-form button {
  padding: .45rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: .85rem;
}
.tool-form button:hover { background: #1d4ed8; }
.image-counter { font-size: .75rem; color: #6b7280; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.image-spinner { font-size: .8rem; color: #6b7280; font-style: italic; }
.create-error { font-size: .8rem; color: #dc2626; }
.create-image-result { display: flex; flex-direction: column; gap: .5rem; }
.create-image-result img { max-width: 100%; border-radius: 6px; }
.create-image-result button {
  padding: .4rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: .8rem;
}
@media (max-width: 600px) {
  .tools-sidebar { display: none; }
}

/* Admin */
.admin-wrap { max-width: 900px; margin: 0 auto; padding: 1.5rem; }
.admin-wrap h2 { margin: 1.5rem 0 .75rem; }
table { width: 100%; border-collapse: collapse; background: #1f2937; border-radius: 8px; overflow: hidden; }
th, td { padding: .6rem .9rem; text-align: left; border-bottom: 1px solid #374151; }
th { background: #111827; font-weight: 600; font-size: .85rem; color: #9ca3af; }
tr.inactive td { color: #4b5563; }
.admin-wrap form input[type="text"],
.admin-wrap form input[type="password"],
.admin-wrap form input[type="number"],
.admin-wrap form textarea {
  padding: .5rem .7rem;
  border: 1px solid #374151;
  border-radius: 4px;
  font-size: .9rem;
  font-family: inherit;
  background: #111827;
  color: #f3f4f6;
}
.admin-wrap form button {
  padding: .45rem .9rem;
  background: #2563eb;
  color: #fff;
  border: none;
  border-radius: 4px;
  cursor: pointer;
}
.admin-wrap form button:hover { background: #1d4ed8; }
