* {
  box-sizing: border-box;
}

:root {
  --bg: #212121;
  --sidebar: #171717;
  --sidebar-hover: #242424;
  --sidebar-active: #2a2a2a;
  --panel: #2f2f2f;
  --panel-hover: #3a3a3a;
  --border: #3f3f3f;
  --text: #ececec;
  --muted: #a6a6a6;
  --muted-2: #7f7f7f;
  --accent: #10a37f;
  --accent-hover: #0d8d6f;
  --user-bubble: #303030;
}

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

body {
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

button,
input,
textarea {
  font: inherit;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.app {
  display: flex;
  width: 100%;
  height: 100vh;
  background: var(--bg);
}

/* =========================================================
   SIDEBAR
   ========================================================= */

.sidebar {
  width: 260px;
  min-width: 260px;
  height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid #252525;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: width .2s ease, min-width .2s ease, transform .2s ease;
}

.sidebar.hidden {
  display: none !important;
}

.sidebar-top {
  padding: 10px 10px 4px;
}

.brand-row {
  min-height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}

.sidebar-icon-button,
.open-sidebar-btn {
  border: 0;
  background: transparent;
  color: #bdbdbd;
  cursor: pointer;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.sidebar-icon-button {
  width: 36px;
  height: 36px;
}

.sidebar-icon-button:hover,
.open-sidebar-btn:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.brand {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 9px;
  min-width: 0;
}

.brand-mark {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #fff;
  color: #111;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 700;
  font-size: 15px;
}

.brand-name {
  font-size: 16px;
  font-weight: 650;
  letter-spacing: -0.2px;
}

.main-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  width: 100%;
  min-height: 38px;
  border: 0;
  background: transparent;
  color: #e1e1e1;
  border-radius: 8px;
  padding: 8px 9px;
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  cursor: pointer;
  font-size: 14px;
}

.nav-item:hover,
.nav-item.active:hover {
  background: var(--sidebar-hover);
}

.nav-item.active {
  color: #fff;
}

.nav-icon {
  width: 20px;
  min-width: 20px;
  display: inline-flex;
  justify-content: center;
  font-size: 18px;
  line-height: 1;
  color: #cfcfcf;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 3px 8px 12px;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.sidebar-section {
  margin-top: 16px;
}

.sidebar-section-header {
  min-height: 28px;
  padding: 0 7px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: #9b9b9b;
  font-size: 12px;
  font-weight: 600;
}

.section-action {
  width: 25px;
  height: 25px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #a5a5a5;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.section-action:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar-list li,
.conversation-item {
  width: 100%;
  min-height: 34px;
  border-radius: 7px;
  color: #d7d7d7;
  padding: 7px 9px;
  margin: 1px 0;
  font-size: 13px;
  line-height: 20px;
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-list li:hover,
.conversation-item:hover {
  background: var(--sidebar-hover);
}

.conversation-item.active {
  background: var(--sidebar-active);
  color: #fff;
}

.sidebar-empty-text {
  padding: 7px 9px;
  color: #6f6f6f;
  font-size: 12px;
}

.sidebar-footer {
  border-top: 1px solid #292929;
  min-height: 62px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 32px;
  min-width: 32px;
  height: 32px;
  border-radius: 50%;
  background: #444;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.user-info {
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.user-info strong {
  font-size: 13px;
  font-weight: 600;
  color: #ececec;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.user-info span {
  font-size: 11px;
  color: #868686;
  margin-top: 1px;
}

.open-sidebar-btn {
  position: fixed;
  left: 10px;
  top: 10px;
  z-index: 20;
  width: 38px;
  height: 38px;
  background: rgba(23, 23, 23, .92);
}

/* =========================================================
   ÁREA PRINCIPAL
   ========================================================= */

.main-content {
  flex: 1;
  min-width: 0;
  height: 100vh;
  position: relative;
  background: var(--bg);
  overflow: hidden;
}

.empty-state {
  width: 100%;
  height: 100%;
  padding: 0 24px 26px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.greeting {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
  font-size: clamp(27px, 3vw, 34px);
  line-height: 1.2;
  color: #f2f2f2;
  margin: 0 0 28px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.greeting-icon {
  font-size: 25px;
}

/* =========================================================
   MENSAGENS
   ========================================================= */

#messages {
  display: none;
}

.empty-state.conversation-active {
  justify-content: flex-start;
  padding-top: 0;
}

.empty-state.conversation-active .greeting,
.empty-state.conversation-active .quick-actions {
  display: none;
}

.empty-state.conversation-active #messages {
  display: block;
  width: 100%;
  max-width: 820px;
  flex: 1;
  overflow-y: auto;
  padding: 30px 10px 40px;
  scrollbar-width: thin;
  scrollbar-color: #444 transparent;
}

.message {
  width: 100%;
  max-width: 100%;
  margin-bottom: 25px;
  color: var(--text);
}

.message.user {
  display: flex;
  justify-content: flex-end;
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-weight: 500;
}

.message.user .message-content {
  max-width: 72%;
  background: var(--user-bubble);
  border: 1px solid #383838;
  border-radius: 18px;
  padding: 10px 15px;
  color: #f3f3f3;
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant {
  position: relative;
  padding: 0 44px 0 4px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.72;
  font-weight: 400;
  color: #e8e8e8;
}

.message.assistant .message-content {
  white-space: pre-wrap;
  word-break: break-word;
}

.message.assistant img {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.message.system {
  width: 100%;
  text-align: center;
  color: #878787;
  font-size: 13px;
  line-height: 1.4;
  margin: 4px auto 20px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

.copy-response-btn {
  position: absolute;
  right: 2px;
  top: 0;
  min-width: 34px;
  height: 34px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #8c8c8c;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: background .15s ease, color .15s ease;
}

.copy-response-btn:hover {
  background: #303030;
  color: #ececec;
}

.copy-response-btn.copied {
  color: #9fd3c2;
}

.copy-response-btn .copy-label {
  display: none;
}

/* =========================================================
   CAIXA CENTRAL
   ========================================================= */

.input-bar-center {
  width: 100%;
  max-width: 760px;
  background: #303030;
  border: 1px solid #424242;
  border-radius: 24px;
  padding: 14px 15px 10px;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}

#messageInputCenter {
  width: 100%;
  min-height: 26px;
  max-height: 180px;
  border: none;
  outline: none;
  resize: none;
  background: transparent;
  color: #ededed;
  font-size: 15px;
  line-height: 1.45;
  padding: 2px 5px 5px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#messageInputCenter::placeholder {
  color: #909090;
}

.input-bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 7px;
}

.input-bar-row .spacer {
  flex: 1;
}

.round-btn {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: #b9b9b9;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.round-btn:hover {
  background: #3d3d3d;
  color: #fff;
}

.round-btn.accent {
  background: #f1f1f1;
  color: #181818;
}

.round-btn.accent:hover {
  background: #fff;
}

.model-name {
  color: #8f8f8f;
  font-size: 12px;
  margin-right: 3px;
}

.quick-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: 760px;
  margin-top: 20px;
}

.quick-btn {
  background: transparent;
  border: 1px solid #3b3b3b;
  color: #c4c4c4;
  border-radius: 18px;
  padding: 7px 12px;
  font-size: 12px;
  cursor: pointer;
}

.quick-btn:hover {
  background: #292929;
  border-color: #474747;
}

/* =========================================================
   INPUT ANTIGO / COMPATIBILIDADE
   ========================================================= */

.chat-view {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.input-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #303030;
  border: 1px solid #424242;
  border-radius: 18px;
  margin: auto 24px 24px;
  padding: 10px 14px;
  position: relative;
}

#messageInput {
  flex: 1;
  min-width: 0;
  min-height: 24px;
  max-height: 160px;
  background: transparent;
  border: none;
  outline: none;
  color: #ececec;
  font-size: 15px;
  line-height: 22px;
  resize: none;
  overflow-y: auto;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

#messageInput::placeholder {
  color: #8b8b8b;
}

.input-bar button {
  background: transparent;
  border: none;
  color: #b8b8b8;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 6px;
  display: flex;
  align-items: center;
}

.input-bar button:hover {
  background: #3a3a3a;
}

#sendBtn {
  background: #f1f1f1;
  color: #181818;
  border-radius: 50%;
  width: 30px;
  height: 30px;
  justify-content: center;
}

#micBtn.recording,
#micBtnCenter.recording {
  color: #ff7b72;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0% { opacity: 1; }
  50% { opacity: .4; }
  100% { opacity: 1; }
}

#attachMenu {
  position: absolute;
  bottom: 56px;
  left: 0;
  min-width: 180px;
  background: #292929;
  border: 1px solid #444;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: 0 12px 30px rgba(0,0,0,.4);
}

#attachMenu button {
  padding: 11px 16px;
  border: 0;
  background: transparent;
  text-align: left;
  cursor: pointer;
  color: #e9e9e9;
  font-size: 14px;
  border-radius: 0;
}

#attachMenu button:hover {
  background: #373737;
}

.hidden {
  display: none !important;
}

/* =========================================================
   RESPONSIVO
   ========================================================= */

/* Camada usada apenas quando o menu mobile estiver aberto */
.sidebar-overlay {
  display: none;
}

@media (max-width: 700px) {
  html, body, .app, .main-content {
    width: 100%;
    max-width: 100%;
    height: 100%;
    min-height: 100%;
    overflow-x: hidden;
  }

  .app {
    height: 100dvh;
  }

  .main-content {
    flex: 1 1 100%;
    width: 100vw;
    height: 100dvh;
  }

  .sidebar {
    position: fixed;
    z-index: 50;
    left: 0;
    top: 0;
    width: min(86vw, 320px);
    min-width: 0;
    max-width: 320px;
    height: 100dvh;
    box-shadow: 10px 0 30px rgba(0,0,0,.42);
  }

  .sidebar.hidden {
    display: flex !important;
    transform: translateX(-105%);
    pointer-events: none;
  }

  .sidebar:not(.hidden) {
    transform: translateX(0);
    pointer-events: auto;
  }

  .sidebar-overlay {
    position: fixed;
    inset: 0;
    z-index: 45;
    display: block;
    background: rgba(0,0,0,.55);
  }

  .sidebar-overlay.hidden {
    display: none !important;
  }

  .open-sidebar-btn {
    position: fixed;
    left: 10px;
    top: max(10px, env(safe-area-inset-top));
    z-index: 35;
    width: 40px;
    height: 40px;
  }

  .sidebar-top {
    padding-top: max(10px, env(safe-area-inset-top));
  }

  .sidebar-footer {
    padding-bottom: max(10px, env(safe-area-inset-bottom));
    flex-shrink: 0;
  }

  .empty-state {
    width: 100%;
    min-width: 0;
    padding: 0 14px max(18px, env(safe-area-inset-bottom));
  }

  .greeting {
    max-width: 100%;
    font-size: clamp(25px, 7.5vw, 31px);
    text-align: center;
    margin-bottom: 24px;
  }

  .input-bar-center {
    width: 100%;
    max-width: 100%;
    border-radius: 22px;
    padding: 12px 12px 9px;
  }

  #messageInputCenter {
    font-size: 16px;
  }

  .empty-state.conversation-active #messages {
    width: 100%;
    max-width: 100%;
    padding: max(58px, calc(env(safe-area-inset-top) + 48px)) 0 30px;
  }

  .message {
    max-width: 100%;
  }

  .message.assistant {
    padding: 0 38px 0 2px;
    font-size: 15.5px;
    line-height: 1.65;
  }

  .message.user .message-content {
    max-width: 88%;
    font-size: 15px;
  }

  .quick-actions {
    width: 100%;
    max-width: 100%;
    gap: 6px;
    margin-top: 16px;
  }

  .quick-btn {
    max-width: 100%;
  }

  .input-bar {
    width: auto;
    margin: auto 12px max(12px, env(safe-area-inset-bottom));
  }
}

/* =========================================================
   SESI • ASSISTENTE MESC
   Aplicado somente quando a Sesi é aberta pelo sistema MESC
   ========================================================= */

body.modo-mesc {
  --mesc-azul: #123a73;
  --mesc-azul-hover: #0d2f60;
  --mesc-dourado: #b99754;
  --mesc-creme: #f8f5ee;
  --mesc-texto: #24364b;
  --mesc-muted: #6d7783;
  --mesc-borda: rgba(185, 151, 84, .32);

  background: #f8f5ee;
  color: var(--mesc-texto);
}

body.modo-mesc .app {
  background:
    linear-gradient(
      90deg,
      rgba(250, 248, 242, .94) 0%,
      rgba(250, 248, 242, .89) 32%,
      rgba(255, 255, 255, .72) 60%,
      rgba(255, 255, 255, .58) 100%
    ),
    url('/static/fundo_mesc.png') center center / cover no-repeat;
}

/* SIDEBAR */

body.modo-mesc .sidebar {
  width: 280px;
  min-width: 280px;
  background: rgba(255, 255, 255, .88);
  border-right: 1px solid var(--mesc-borda);
  box-shadow: 6px 0 30px rgba(31, 48, 72, .08);
  backdrop-filter: blur(12px);
}

body.modo-mesc .brand-row {
  margin-bottom: 14px;
}

body.modo-mesc .brand-mark {
  background: var(--mesc-azul);
  color: #fff;
  box-shadow: 0 3px 10px rgba(18, 58, 115, .18);
}

body.modo-mesc .brand-name {
  color: var(--mesc-azul);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 17px;
  font-weight: 700;
}

body.modo-mesc .sidebar-icon-button,
body.modo-mesc .open-sidebar-btn {
  color: var(--mesc-azul);
}

body.modo-mesc .sidebar-icon-button:hover,
body.modo-mesc .open-sidebar-btn:hover {
  background: rgba(18, 58, 115, .08);
  color: var(--mesc-azul);
}

body.modo-mesc .nav-item {
  color: #3e536c;
}

body.modo-mesc .nav-icon {
  color: var(--mesc-azul);
}

body.modo-mesc .nav-item:hover,
body.modo-mesc .nav-item.active:hover {
  background: rgba(18, 58, 115, .07);
}

body.modo-mesc .nav-item.active {
  color: var(--mesc-azul);
  font-weight: 600;
}

body.modo-mesc .sidebar-section-header {
  color: #788390;
}

body.modo-mesc .section-action {
  color: var(--mesc-azul);
}

body.modo-mesc .section-action:hover {
  background: rgba(18, 58, 115, .08);
  color: var(--mesc-azul);
}

body.modo-mesc .sidebar-list li,
body.modo-mesc .conversation-item {
  color: #42566e;
}

body.modo-mesc .sidebar-list li:hover,
body.modo-mesc .conversation-item:hover {
  background: rgba(18, 58, 115, .07);
}

body.modo-mesc .conversation-item.active {
  background: rgba(18, 58, 115, .11);
  color: var(--mesc-azul);
}

body.modo-mesc .sidebar-empty-text {
  color: #89929d;
}

body.modo-mesc .sidebar-scroll {
  scrollbar-color: rgba(18, 58, 115, .22) transparent;
}

body.modo-mesc .sidebar-footer {
  border-top: 1px solid var(--mesc-borda);
  background: rgba(255, 255, 255, .38);
}

body.modo-mesc .avatar {
  background: var(--mesc-azul);
  color: #fff;
}

body.modo-mesc .user-info strong {
  color: var(--mesc-azul);
}

body.modo-mesc .user-info span {
  color: #7b8794;
}

/* ÁREA PRINCIPAL */

body.modo-mesc .main-content {
  background: transparent;
}

body.modo-mesc .empty-state {
  position: relative;
}

body.modo-mesc .greeting {
  color: var(--mesc-azul);
  text-shadow: 0 1px 0 rgba(255, 255, 255, .9);
  margin-bottom: 26px;
}

body.modo-mesc .greeting-icon {
  color: var(--mesc-dourado);
}

/* CAIXA CENTRAL */

body.modo-mesc .input-bar-center {
  background: rgba(255, 255, 255, .91);
  border: 1px solid var(--mesc-borda);
  box-shadow:
    0 12px 35px rgba(47, 56, 70, .10),
    0 2px 8px rgba(47, 56, 70, .05);
  backdrop-filter: blur(10px);
}

body.modo-mesc #messageInputCenter {
  color: #26384d;
}

body.modo-mesc #messageInputCenter::placeholder {
  color: #7c8792;
}

body.modo-mesc .round-btn {
  color: var(--mesc-azul);
}

body.modo-mesc .round-btn:hover {
  background: rgba(18, 58, 115, .08);
  color: var(--mesc-azul);
}

body.modo-mesc .round-btn.accent {
  background: var(--mesc-azul);
  color: #fff;
}

body.modo-mesc .round-btn.accent:hover {
  background: var(--mesc-azul-hover);
}

body.modo-mesc .model-name {
  color: var(--mesc-dourado);
  font-weight: 600;
}

/* AÇÕES RÁPIDAS */

body.modo-mesc .quick-btn {
  background: rgba(255, 255, 255, .76);
  border: 1px solid var(--mesc-borda);
  color: #40566e;
  box-shadow: 0 3px 12px rgba(47, 56, 70, .04);
  backdrop-filter: blur(7px);
}

body.modo-mesc .quick-btn:hover {
  background: rgba(255, 255, 255, .96);
  border-color: rgba(185, 151, 84, .60);
  color: var(--mesc-azul);
}

/* CONVERSAS */

body.modo-mesc .empty-state.conversation-active #messages {
  scrollbar-color: rgba(18, 58, 115, .22) transparent;
}

body.modo-mesc .message {
  color: var(--mesc-texto);
}

body.modo-mesc .message.user .message-content {
  background: rgba(18, 58, 115, .93);
  border: 1px solid rgba(18, 58, 115, .15);
  color: #fff;
  box-shadow: 0 4px 14px rgba(18, 58, 115, .12);
}

body.modo-mesc .message.assistant {
  color: #26384d;
  background: rgba(255, 255, 255, .72);
  border: 1px solid rgba(185, 151, 84, .18);
  border-radius: 15px;
  padding: 14px 50px 14px 16px;
  box-shadow: 0 4px 18px rgba(47, 56, 70, .05);
  backdrop-filter: blur(8px);
}

body.modo-mesc .message.system {
  color: #74808d;
}

body.modo-mesc .copy-response-btn {
  color: #78879a;
}

body.modo-mesc .copy-response-btn:hover {
  background: rgba(18, 58, 115, .08);
  color: var(--mesc-azul);
}

/* INPUT DE CONVERSA */

body.modo-mesc .input-bar {
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--mesc-borda);
  box-shadow: 0 8px 28px rgba(47, 56, 70, .10);
  backdrop-filter: blur(10px);
}

body.modo-mesc #messageInput {
  color: #26384d;
}

body.modo-mesc #messageInput::placeholder {
  color: #7c8792;
}

body.modo-mesc .input-bar button {
  color: var(--mesc-azul);
}

body.modo-mesc .input-bar button:hover {
  background: rgba(18, 58, 115, .08);
}

body.modo-mesc #sendBtn {
  background: var(--mesc-azul);
  color: #fff;
}

body.modo-mesc #attachMenu {
  background: rgba(255, 255, 255, .98);
  border: 1px solid var(--mesc-borda);
  box-shadow: 0 12px 30px rgba(31, 48, 72, .15);
}

body.modo-mesc #attachMenu button {
  color: #344b64;
}

body.modo-mesc #attachMenu button:hover {
  background: rgba(18, 58, 115, .07);
}

/* BOTÃO DE ABRIR SIDEBAR */

body.modo-mesc .open-sidebar-btn {
  background: rgba(255, 255, 255, .92);
  border: 1px solid var(--mesc-borda);
  box-shadow: 0 4px 15px rgba(31, 48, 72, .10);
}

/* MOBILE */

@media (max-width: 700px) {
  body.modo-mesc .sidebar {
    width: min(88vw, 320px);
    min-width: 0;
    background: rgba(255, 255, 255, .96);
    box-shadow: 10px 0 30px rgba(31, 48, 72, .18);
  }

  body.modo-mesc .sidebar-overlay {
    background: rgba(18, 38, 64, .30);
  }

  body.modo-mesc .app {
    background:
      linear-gradient(
        rgba(255, 255, 255, .76),
        rgba(250, 248, 242, .82)
      ),
      url('/static/fundo_mesc.png') center center / cover no-repeat;
  }

  body.modo-mesc .greeting {
    color: var(--mesc-azul);
  }

  body.modo-mesc .input-bar-center {
    background: rgba(255, 255, 255, .94);
  }

  body.modo-mesc .message.assistant {
    padding: 12px 42px 12px 13px;
  }
}

