/* Look and feel adopted from the repo's original styles.css:
   light theme, #0078d7 blue accent, #f5f5f5 panels, subtle shadows, system font. */

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  height: 100vh;
  color: #333;
  background: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, "Open Sans", "Helvetica Neue", sans-serif;
}

/* the hidden attribute must always win over the display rules below */
[hidden] {
  display: none !important;
}

/* app shell is the full-height flex column: header / messages / composer */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* --- header (panel styling from the original) --- */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  background-color: #f5f5f5;
  border-bottom: 1px solid #ddd;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

header h1 {
  margin: 0;
  font-size: 18px;
}

.brand {
  line-height: 0;
}

.brand img {
  display: block;
  height: 36px;
  width: auto;
}

.controls {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

label {
  font-weight: 500;
}

/* --- form controls (from the original) --- */
select,
textarea {
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: 4px;
  box-sizing: border-box;
  font: inherit;
  color: #333;
  background: #fff;
}

select {
  max-width: 320px;
}

button {
  background-color: #0078d7;
  color: white;
  border: none;
  padding: 10px 15px;
  border-radius: 4px;
  cursor: pointer;
  font-weight: 500;
}

button:hover:not(:disabled) {
  background-color: #006cc1;
}

button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

#reset {
  background-color: #fff;
  color: #333;
  border: 1px solid #ddd;
}

#reset:hover:not(:disabled) {
  background-color: #f0f0f0;
}

/* --- conversation --- */
main {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

/* welcome hero — shown only while the conversation is empty */
.empty-state {
  margin: auto;
  text-align: center;
  color: #888;
  user-select: none;
}

.empty-state img {
  width: 140px;
  height: 140px;
  opacity: 0.9;
}

.empty-state p {
  margin: 12px 0 0;
  font-size: 15px;
}

#messages:has(.bubble) .empty-state {
  display: none;
}

.bubble {
  max-width: 760px;
  padding: 10px 14px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.bubble.user {
  align-self: flex-end;
  background-color: #0078d7;
  color: white;
}

.bubble.assistant {
  align-self: flex-start;
  background-color: #f5f5f5;
  color: #333;
}

/* error bubble reuses the original .error treatment */
.bubble.error {
  align-self: flex-start;
  color: #d32f2f;
  background-color: #ffebee;
  border-left: 4px solid #d32f2f;
  box-shadow: none;
}

/* --- composer --- */
#composer {
  display: flex;
  gap: 10px;
  padding: 16px 20px;
  background-color: #f5f5f5;
  border-top: 1px solid #ddd;
}

#input {
  flex: 1;
  resize: none;
  max-height: 200px;
  line-height: 1.4;
}

#send {
  align-self: flex-end;
}

/* --- secondary buttons in the header --- */
#share,
#shared,
#usage {
  background-color: #fff;
  color: #333;
  border: 1px solid #ddd;
}

#share:hover:not(:disabled),
#shared:hover:not(:disabled),
#usage:hover:not(:disabled) {
  background-color: #f0f0f0;
}

/* --- account (person icon + dropdown) --- */
.account {
  position: relative;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  padding: 0;
  background-color: #fff;
  color: #333;
  border: 1px solid #ddd;
  border-radius: 50%;
}

.icon-btn:hover {
  background-color: #f0f0f0;
}

.account-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  min-width: 220px;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  padding: 6px;
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.account-name {
  padding: 8px 10px;
  font-size: 13px;
  color: #666;
  border-bottom: 1px solid #eee;
  margin-bottom: 4px;
  white-space: nowrap;
}

#admin,
#signout {
  background-color: #fff;
  color: #333;
  border: none;
  text-align: left;
  padding: 8px 10px;
  border-radius: 6px;
}

#admin:hover,
#signout:hover {
  background-color: #f0f0f0;
}

/* --- modal (usage / admin) --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 100;
}

.modal {
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 820px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  border-bottom: 1px solid #eee;
}

.modal-head h2 {
  margin: 0;
  font-size: 16px;
}

.modal-close {
  background: transparent;
  border: none;
  color: #666;
  font-size: 16px;
  padding: 4px 8px;
}

.modal-body {
  padding: 16px 20px;
  overflow-y: auto;
  overflow-x: auto;
}

.usage-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.usage-table th,
.usage-table td {
  padding: 8px 10px;
  border-bottom: 1px solid #eee;
  text-align: left;
}

.usage-table th {
  white-space: nowrap;
}

.usage-table th.num,
.usage-table td.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.usage-table td.nowrap {
  white-space: nowrap;
}

.limit-input {
  width: 80px;
  padding: 4px 6px;
}

/* compact buttons inside the admin table */
.usage-table button {
  padding: 4px 10px;
  font-size: 13px;
  background-color: #fff;
  color: #333;
  border: 1px solid #ddd;
}

.usage-table button:hover {
  background-color: #f0f0f0;
}

.usage-table .save {
  background-color: #0078d7;
  color: #fff;
  border-color: #0078d7;
}

.admin-status {
  margin: 0 0 12px;
  font-size: 13px;
  color: #2e7d32;
}

/* --- shared chats list + read-only view --- */
.shared-list {
  list-style: none;
  margin: 0;
  padding: 0;
}

.shared-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  width: 100%;
  text-align: left;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 10px 12px;
  margin-bottom: 8px;
  color: #333;
}

.shared-item:hover {
  background: #f0f0f0;
}

.shared-title {
  font-weight: 500;
}

.shared-meta {
  font-size: 12px;
  color: #888;
}

.shared-back {
  background: transparent;
  border: none;
  color: #0078d7;
  padding: 0 0 8px;
}

.shared-view-title {
  margin: 0 0 12px;
  font-size: 16px;
}

.shared-view {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.shared-msg {
  padding: 8px 12px;
  border-radius: 4px;
  white-space: pre-wrap;
  word-wrap: break-word;
  line-height: 1.5;
  max-width: 90%;
}

.shared-msg.user {
  align-self: flex-end;
  background-color: #0078d7;
  color: #fff;
}

.shared-msg.assistant {
  align-self: flex-start;
  background-color: #f5f5f5;
}

/* --- login view --- */
.login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 340px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f5f5f5;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 28px 24px;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.login-logo {
  width: 72px;
  height: 72px;
  align-self: center;
}

.login-card h2 {
  margin: 0;
  text-align: center;
  font-size: 18px;
}

.login-hint {
  margin: 0;
  font-size: 13px;
  color: #666;
}

.login-error {
  margin: 0;
  color: #d32f2f;
  background-color: #ffebee;
  border-left: 4px solid #d32f2f;
  padding: 8px 10px;
  border-radius: 4px;
  font-size: 13px;
}

.totp-secret {
  display: block;
  word-break: break-all;
  background: #fff;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
}

.totp-uri {
  font-size: 13px;
  color: #0078d7;
}
