/* RESET & BASE */
*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
  background: #050816;
  color: #f9fafb;
  line-height: 1.5;
  display: flex;
  flex-direction: column;
}

body.theme-light {
  background: #f5f7fb;
  color: #0b0f19;
}

.hidden {
  display: none !important;
}

/* APP LAYOUT */
.app-shell {
  flex: 1;
  display: flex;
  min-height: 0;
}

/* SIDEBAR */
.sidebar {
  width: 260px;
  background: #050814;
  border-right: 1px solid rgba(148, 163, 184, 0.35);
  padding: 12px;
  display: flex;
  flex-direction: column;
  z-index: 40;
}

body.theme-light .sidebar {
  background: #ffffff;
  border-right-color: rgba(15, 23, 42, 0.12);
}

.sidebar-inner {
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Sidebar mobile drawer */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease-out;
    box-shadow: 8px 0 30px rgba(0, 0, 0, 0.55);
  }
  .sidebar.open {
    transform: translateX(0%);
  }
}

/* Sidebar header */
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  margin-bottom: 12px;
  border-radius: 10px;
  background: rgba(15, 23, 42, 0.7);
}

body.theme-light .sidebar-header {
  background: rgba(15, 23, 42, 0.06);
}

.logo img {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  object-fit: cover;
}

.brand-name {
  font-size: 0.98rem;
  font-weight: 600;
}

.brand-sub {
  font-size: 0.8rem;
  opacity: 0.7;
}

/* Sidebar sections */
.sidebar-section {
  margin-top: 16px;
}

.sidebar-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  opacity: 0.7;
  margin-bottom: 4px;
}

/* Sidebar buttons */
.sidebar-btn {
  width: 100%;
  border-radius: 999px;
  border: none;
  padding: 8px 12px;
  margin-bottom: 6px;
  font-size: 0.9rem;
  text-align: left;
  cursor: pointer;
  background: rgba(148, 163, 184, 0.15);
  color: inherit;
  transition: background 0.17s ease, transform 0.08s ease;
}

.sidebar-btn.primary {
  background: #0057ff;
  color: #ffffff;
}

.sidebar-btn.danger {
  background: rgba(248, 113, 113, 0.15);
  color: #fecaca;
}

.sidebar-btn:hover {
  background: rgba(148, 163, 184, 0.35);
  transform: translateY(-1px);
}

.sidebar-btn.primary:hover {
  background: #2563eb;
}

.sidebar-btn.danger:hover {
  background: rgba(248, 113, 113, 0.28);
}

/* Model select */
.model-select {
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: #020617;
  color: inherit;
  padding: 6px 8px;
  font-size: 0.86rem;
}

body.theme-light .model-select {
  background: #ffffff;
  border-color: rgba(15, 23, 42, 0.18);
}

.locked-model {
  color: #9ca3af !important;
  background: #0b1120 !important;
}

body.theme-light .locked-model {
  color: #6b7280 !important;
  background: #e5e7eb !important;
}

/* Premium model notice */
.premium-model-notice {
  margin-top: 6px;
  font-size: 0.8rem;
  opacity: 0.8;
}

.premium-model-notice a {
  color: #38bdf8;
  text-decoration: none;
  font-weight: 600;
}

/* Conversation search */
.conv-search {
  width: 100%;
  padding: 6px 10px;
  margin-top: 4px;
  margin-bottom: 6px;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.6);
  background: #020617;
  color: inherit;
  font-size: 0.86rem;
}

body.theme-light .conv-search {
  background: #f9fafb;
  border-color: rgba(15, 23, 42, 0.15);
  color: #020617;
}

/* Conversation list */
.conversations {
  margin-top: 4px;
  border-radius: 8px;
  padding: 4px;
  background: rgba(15, 23, 42, 0.7);
  max-height: calc(100vh - 260px);
  overflow-y: auto;
}

body.theme-light .conversations {
  background: rgba(15, 23, 42, 0.03);
}

.conv-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  margin-bottom: 2px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.9rem;
}

.conv-item.active {
  background: rgba(59, 130, 246, 0.3);
}

.conv-item:hover {
  background: rgba(148, 163, 184, 0.35);
}

.conv-title {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-del-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  opacity: 0.6;
  font-size: 0.9rem;
  padding: 2px 4px;
}

.conv-del-btn:hover {
  opacity: 1;
}

/* MAIN PANEL */
.main-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

/* TOP NAV (ChatGPT style) */
.top-nav {
  height: 56px;
  padding: 0 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #050814;
  border-bottom: 1px solid rgba(148, 163, 184, 0.4);
  position: sticky;
  top: 0;
  z-index: 20;
}

body.theme-light .top-nav {
  background: #ffffff;
  border-bottom-color: rgba(15, 23, 42, 0.12);
}

.nav-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.nav-title {
  display: flex;
  flex-direction: column;
}

.nav-title span:first-child {
  font-weight: 600;
  font-size: 0.98rem;
}

/* Usage indicator */
.usage-inline {
  font-size: 0.75rem;
  opacity: 0.8;
}

.usage-progress-wrap {
  width: 130px;
  height: 5px;
  background: rgba(30, 64, 175, 0.6);
  border-radius: 999px;
  margin-top: 2px;
}

.usage-progress {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, #22c55e, #eab308);
  border-radius: inherit;
  transition: width 0.25s ease-out;
}

/* Buttons */
.pill-btn {
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: transparent;
  color: inherit;
  font-size: 0.8rem;
  padding: 6px 10px;
  cursor: pointer;
}

.pill-btn:hover {
  background: rgba(148, 163, 184, 0.2);
}

.pill-btn.primary {
  border-color: #2563eb;
  background: #2563eb;
  color: #ffffff;
}

.pill-btn.primary:hover {
  filter: brightness(1.05);
}

/* Mobile hamburger */
.icon-btn {
  display: none;
}

@media (max-width: 900px) {
  .icon-btn {
    display: inline-flex;
  }
}

/* Premium badge & status text */
.premium-badge {
  background: linear-gradient(90deg, #22c55e, #22d3ee);
  color: #0f172a;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.status-text {
  font-size: 0.78rem;
  opacity: 0.9;
}

/* CHAT AREA */
.chat-layout {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.chat-messages {
  flex: 1;
  padding: 20px 18px 100px;
  overflow-y: auto;
}

.empty-hint {
  margin-top: 40px;
  text-align: center;
  opacity: 0.8;
  font-size: 0.95rem;
}

.msg-row {
  display: flex;
  margin-bottom: 10px;
}

.msg-bubble {
  max-width: 820px;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 0.96rem;
}

.msg-bubble.user {
  margin-left: auto;
  background: #1d4ed8;
  color: #eff6ff;
}

.msg-bubble.assistant {
  margin-right: auto;
  background: rgba(15, 23, 42, 0.85);
}

body.theme-light .msg-bubble.assistant {
  background: #ffffff;
  border: 1px solid rgba(148, 163, 184, 0.4);
}

/* FLOATING INPUT (B1 ChatGPT style) */
.input-floating {
  position: sticky;
  bottom: 0;
  z-index: 20;
  padding: 14px;
  backdrop-filter: blur(10px);
}

.input-shadow-box {
  max-width: 840px;
  margin: 0 auto;
  border-radius: 999px;
  border: 1px solid rgba(148, 163, 184, 0.7);
  background: rgba(15, 23, 42, 0.96);
  box-shadow: 0 10px 30px rgba(15, 23, 42, 0.8);
  padding: 10px 12px 8px;
}

body.theme-light .input-shadow-box {
  background: rgba(255, 255, 255, 0.95);
  border-color: rgba(15, 23, 42, 0.15);
  box-shadow: 0 10px 25px rgba(15, 23, 42, 0.15);
}

.toolbar-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  font-size: 0.78rem;
}

.hint-small {
  opacity: 0.7;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

#chatInput {
  flex: 1;
  resize: none;
  border-radius: 999px;
  border: none;
  padding: 12px 14px;
  font-size: 0.98rem;
  color: #f9fafb;
  background: rgba(15, 23, 42, 0.9);
  min-height: 56px;
  max-height: 180px;
  outline: none;
}

body.theme-light #chatInput {
  background: #f3f4f6;
  color: #020617;
}

#chatInput:focus {
  box-shadow: 0 0 0 1px #2563eb;
}

.send-btn {
  border: none;
  border-radius: 999px;
  padding: 11px 14px;
  font-size: 1.1rem;
  cursor: pointer;
  background: #2563eb;
  color: #ffffff;
  display: flex;
  align-items: center;
  justify-content: center;
}

.send-btn:disabled {
  opacity: 0.4;
  cursor: default;
}

.send-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

/* Icon buttons (mic & image) */
.icon-btn-square {
  border: none;
  border-radius: 999px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  cursor: pointer;
  background: rgba(15, 23, 42, 0.8);
  color: #e5e7eb;
}

body.theme-light .icon-btn-square {
  background: #e5e7eb;
  color: #111827;
}

.icon-btn-square:hover {
  background: rgba(37, 99, 235, 0.8);
}

.icon-btn-square.recording {
  background: #ef4444 !important;
  color: #fff;
}

.icon-btn-square.locked {
  opacity: 0.4;
  cursor: not-allowed;
}

/* Hint row */
.hint-row {
  margin-top: 4px;
  font-size: 0.75rem;
  opacity: 0.7;
  padding-left: 4px;
}

/* FOOTER */
.footer {
  height: 44px;
  padding: 8px 16px;
  border-top: 1px solid rgba(148, 163, 184, 0.25);
  background: #020617;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.78rem;
}

body.theme-light .footer {
  background: #ffffff;
  border-top-color: rgba(15, 23, 42, 0.12);
}

.cookie-link {
  cursor: pointer;
  text-decoration: underline;
  opacity: 0.8;
}

.footer-text {
  opacity: 0.8;
}

/* MODALS */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}

.modal-box {
  width: 100%;
  max-width: 420px;
  background: #020617;
  color: #e5e7eb;
  border-radius: 20px;
  padding: 18px 18px 14px;
  border: 1px solid rgba(148, 163, 184, 0.4);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.7);
}

body.theme-light .modal-box {
  background: #ffffff;
  color: #020617;
  border-color: rgba(15, 23, 42, 0.15);
}

.modal-box h2 {
  margin: 0 0 6px;
}

.modal-box p {
  margin: 4px 0;
  font-size: 0.9rem;
}

.modal-field {
  margin-top: 8px;
}

.modal-field label {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 2px;
}

.modal-field input {
  width: 100%;
  border-radius: 8px;
  border: 1px solid rgba(148, 163, 184, 0.8);
  padding: 6px 8px;
  font-size: 0.9rem;
  background: #020617;
  color: #e5e7eb;
}

body.theme-light .modal-field input {
  background: #f9fafb;
  color: #020617;
}

.modal-actions {
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.premium-benefits {
  margin: 6px 0;
  padding-left: 18px;
  font-size: 0.9rem;
}

/* MOBILE REFINEMENTS */
@media (max-width: 900px) {
  .chat-messages {
    padding: 16px 12px 100px;
  }

  .input-floating {
    padding: 10px;
  }

  .input-shadow-box {
    max-width: 100%;
  }
}

@media (max-width: 640px) {
  .top-nav {
    padding: 0 8px;
  }

  .status-text {
    display: none;
  }

  .nav-right .pill-btn {
    padding: 4px 8px;
    font-size: 0.75rem;
  }

  .nav-right #registerBtn {
    display: none;
  }

  .modal-box {
    max-width: 95%;
    margin: 0 8px;
  }

  .msg-bubble {
    max-width: 100%;
  }

  .usage-progress-wrap {
    width: 100px;
  }
}

@media (max-width: 480px) {
  .top-nav {
    height: 52px;
  }

  .nav-title span:first-child {
    font-size: 0.9rem;
  }

  #chatInput {
    min-height: 52px;
    font-size: 0.95rem;
  }

  .icon-btn-square {
    width: 34px;
    height: 34px;
  }

  .send-btn {
    padding: 9px 12px;
  }
}
