:root {
  --green: #2d6a4f;
  --green-dark: #1b4332;
  --green-light: #52b788;
  --green-pale: #d8f3dc;
  --bg: #f6faf7;
  --white: #ffffff;
  --gray: #6c757d;
  --gray-light: #e9ecef;
  --text: #212529;
  --danger: #dc3545;
  --warning: #fd7e14;
  --radius: 10px;
  --shadow: 0 2px 12px rgba(0,0,0,0.08);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* --- Auth --- */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.auth-card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 40px;
  width: 100%;
  max-width: 420px;
}

.auth-logo {
  text-align: center;
  margin-bottom: 32px;
}

.auth-logo h1 { color: var(--green-dark); font-size: 1.8rem; }
.auth-logo p  { color: var(--gray); font-size: 0.9rem; margin-top: 4px; }

.auth-tabs {
  display: flex;
  border-bottom: 2px solid var(--gray-light);
  margin-bottom: 24px;
}

.auth-tab {
  flex: 1;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  color: var(--gray);
  font-weight: 500;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .2s;
}

.auth-tab.active { color: var(--green); border-bottom-color: var(--green); }

/* --- Forms --- */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; color: var(--green-dark); }

.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid #ced4da;
  border-radius: 6px;
  font-size: 0.95rem;
  transition: border-color .2s;
  background: var(--white);
}

.form-group input:focus, .form-group select:focus {
  outline: none;
  border-color: var(--green-light);
  box-shadow: 0 0 0 3px rgba(82,183,136,.15);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 20px;
  border-radius: 6px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .2s;
}

.btn-primary { background: var(--green); color: var(--white); width: 100%; padding: 12px; }
.btn-primary:hover { background: var(--green-dark); }
.btn-danger  { background: var(--danger); color: var(--white); }
.btn-danger:hover  { background: #b02a37; }
.btn-outline { background: transparent; border: 1px solid var(--green); color: var(--green); }
.btn-outline:hover { background: var(--green-pale); }
.btn-sm { padding: 6px 12px; font-size: 0.85rem; }
.btn:disabled { opacity: .6; cursor: not-allowed; }

/* --- Alert --- */
.alert { padding: 12px 16px; border-radius: 6px; font-size: 0.9rem; margin-bottom: 16px; }
.alert-error   { background: #f8d7da; color: #842029; }
.alert-success { background: #d1e7dd; color: #0f5132; }
.alert-warning { background: #fff3cd; color: #664d03; }

/* --- Layout principal --- */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* --- Sidebar --- */
.sidebar {
  width: 260px;
  background: var(--green-dark);
  color: var(--white);
  display: flex;
  flex-direction: column;
  padding: 24px 0;
  flex-shrink: 0;
}

.sidebar-logo { padding: 0 24px 24px; border-bottom: 1px solid rgba(255,255,255,.1); }
.sidebar-logo h2 { font-size: 1.3rem; }
.sidebar-logo p  { font-size: 0.75rem; opacity: .7; margin-top: 2px; }

.sidebar-user {
  padding: 16px 24px;
  border-bottom: 1px solid rgba(255,255,255,.1);
  font-size: 0.85rem;
}

.sidebar-user .user-email { opacity: .85; word-break: break-all; }

.quota-bar { margin-top: 10px; }
.quota-label { display: flex; justify-content: space-between; font-size: 0.78rem; opacity: .75; margin-bottom: 4px; }
.quota-track { background: rgba(255,255,255,.2); border-radius: 4px; height: 6px; }
.quota-fill  { background: var(--green-light); border-radius: 4px; height: 6px; transition: width .3s; }
.quota-fill.danger { background: var(--warning); }

.sidebar-nav { padding: 16px 0; flex: 1; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 24px;
  cursor: pointer;
  opacity: .8;
  transition: all .2s;
  font-size: 0.9rem;
}
.nav-item:hover, .nav-item.active { opacity: 1; background: rgba(255,255,255,.1); }
.nav-item .icon { font-size: 1.1rem; width: 20px; text-align: center; }

.sidebar-footer { padding: 16px 24px; border-top: 1px solid rgba(255,255,255,.1); }
.btn-logout { background: transparent; border: 1px solid rgba(255,255,255,.3); color: var(--white); width: 100%; }
.btn-logout:hover { background: rgba(255,255,255,.1); }

/* --- Main content --- */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  background: var(--white);
  padding: 16px 24px;
  border-bottom: 1px solid var(--gray-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.topbar h2 { font-size: 1.1rem; color: var(--green-dark); }

/* --- Chat --- */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 24px;
  overflow: hidden;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding-right: 8px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message { display: flex; gap: 12px; max-width: 80%; }
.message.user { align-self: flex-end; flex-direction: row-reverse; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.message.user .msg-avatar { background: var(--green); color: var(--white); }
.message.bot  .msg-avatar { background: var(--green-pale); color: var(--green-dark); }

.msg-bubble {
  background: var(--white);
  border-radius: var(--radius);
  padding: 12px 16px;
  box-shadow: var(--shadow);
  font-size: 0.92rem;
  line-height: 1.6;
}

.message.user .msg-bubble { background: var(--green); color: var(--white); }

.msg-bubble pre  { background: rgba(0,0,0,.06); border-radius: 4px; padding: 8px; overflow-x: auto; }
.msg-bubble code { font-family: monospace; font-size: 0.88rem; }
.msg-bubble table { border-collapse: collapse; width: 100%; margin: 8px 0; font-size: 0.85rem; }
.msg-bubble th, .msg-bubble td { border: 1px solid #dee2e6; padding: 6px 10px; text-align: left; }
.msg-bubble th { background: var(--green-pale); }

.typing { display: flex; align-items: center; gap: 6px; color: var(--gray); font-size: 0.85rem; }
.dot { width: 6px; height: 6px; background: var(--green-light); border-radius: 50%; animation: bounce .8s infinite; }
.dot:nth-child(2) { animation-delay: .15s; }
.dot:nth-child(3) { animation-delay: .3s; }
@keyframes bounce { 0%,80%,100%{transform:scale(.8)} 40%{transform:scale(1.2)} }

.chat-input-area {
  padding-top: 16px;
  border-top: 1px solid var(--gray-light);
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.chat-input-area textarea {
  flex: 1;
  border: 1px solid #ced4da;
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 0.95rem;
  resize: none;
  min-height: 44px;
  max-height: 160px;
  font-family: inherit;
  transition: border-color .2s;
}

.chat-input-area textarea:focus { outline: none; border-color: var(--green-light); }

.btn-send {
  background: var(--green);
  color: var(--white);
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 1.1rem;
  cursor: pointer;
  transition: background .2s;
  height: 44px;
}
.btn-send:hover { background: var(--green-dark); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; }

/* --- Admin panels --- */
.panel { padding: 24px; }
.panel-title { font-size: 1.1rem; color: var(--green-dark); font-weight: 700; margin-bottom: 20px; }

.card {
  background: var(--white);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 20px;
}

.card-title { font-size: 0.95rem; font-weight: 700; color: var(--green-dark); margin-bottom: 16px; }

.upload-area {
  border: 2px dashed var(--green-light);
  border-radius: var(--radius);
  padding: 32px;
  text-align: center;
  cursor: pointer;
  transition: background .2s;
}
.upload-area:hover { background: var(--green-pale); }
.upload-area p { color: var(--gray); font-size: 0.9rem; margin-top: 8px; }

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
table.data-table th { background: var(--green-pale); color: var(--green-dark); padding: 10px 12px; text-align: left; font-weight: 600; }
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--gray-light); }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: var(--bg); }

.badge {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
}
.badge-demo    { background: #e9ecef; color: #495057; }
.badge-starter { background: #cff4fc; color: #055160; }
.badge-pro     { background: var(--green-pale); color: var(--green-dark); }
.badge-admin   { background: #fff3cd; color: #664d03; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card  { background: var(--white); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; text-align: center; }
.stat-value { font-size: 2rem; font-weight: 700; color: var(--green); }
.stat-label { font-size: 0.8rem; color: var(--gray); margin-top: 4px; }

/* --- Plan upgrade banner --- */
.upgrade-banner {
  background: linear-gradient(135deg, var(--green), var(--green-light));
  color: white;
  border-radius: var(--radius);
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.upgrade-banner p { font-size: 0.9rem; opacity: .9; margin-top: 4px; }
.btn-upgrade { background: white; color: var(--green-dark); border: none; border-radius: 6px; padding: 8px 16px; font-weight: 700; cursor: pointer; }

/* --- Quick chips --- */
.quick-chips {
  padding: 4px 0 8px;
}
.chips-label {
  font-size: 0.8rem;
  color: var(--gray);
  margin-bottom: 8px;
}
.chips-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.chip {
  background: var(--white);
  border: 1.5px solid var(--green-light);
  color: var(--green-dark);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all .2s;
  font-weight: 500;
}
.chip:hover {
  background: var(--green-pale);
  border-color: var(--green);
}

/* --- Botão de imagem --- */
.btn-img {
  background: var(--white);
  border: 1px solid #ced4da;
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 1.1rem;
  cursor: pointer;
  height: 44px;
  transition: all .2s;
  flex-shrink: 0;
}
.btn-img:hover { background: var(--green-pale); border-color: var(--green-light); }
.btn-img:disabled { opacity: .5; cursor: not-allowed; }

/* --- Preview de imagem --- */
.img-preview-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 0 4px;
}
.img-preview-wrap {
  position: relative;
  display: inline-block;
}
.img-preview-wrap img {
  width: 64px;
  height: 64px;
  object-fit: cover;
  border-radius: 8px;
  border: 2px solid var(--green-light);
  display: block;
}
.img-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  background: var(--danger);
  color: white;
  border: none;
  border-radius: 50%;
  width: 18px;
  height: 18px;
  font-size: 0.65rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}
.img-preview-label {
  font-size: 0.8rem;
  color: var(--gray);
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* --- Imagem dentro da mensagem --- */
.msg-image {
  max-width: 220px;
  max-height: 180px;
  border-radius: 8px;
  display: block;
  margin-bottom: 8px;
  object-fit: cover;
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .message { max-width: 95%; }
}
