/* ============================================================
   RESILIENTE.LIVE — Design System
   Tema: Orgânico, sólido, confiável. Verde floresta + tons terrosos.
   Tipografia: Fraunces (display) + DM Sans (corpo)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:wght@400;600;700&family=DM+Sans:wght@300;400;500;600&display=swap');

:root {
  --green-900: #1b4332;
  --green-800: #2d6a4f;
  --green-700: #40916c;
  --green-500: #52b788;
  --green-300: #95d5b2;
  --green-100: #d8f3dc;
  --green-50:  #f0faf3;

  --earth-800: #3d2b1f;
  --earth-600: #6b4c3b;
  --earth-300: #c4a882;
  --earth-100: #f5efe6;

  --amber:     #f59e0b;
  --red:       #dc2626;
  --red-soft:  #fee2e2;
  --blue:      #2563eb;

  --bg:        #f8faf8;
  --surface:   #ffffff;
  --border:    #e2ece4;
  --text:      #1a2e1e;
  --text-2:    #4a6651;
  --text-3:    #8aab8e;

  --shadow-sm: 0 1px 3px rgba(29,75,44,.08);
  --shadow:    0 4px 16px rgba(29,75,44,.10);
  --shadow-lg: 0 12px 40px rgba(29,75,44,.14);

  --radius:    12px;
  --radius-sm: 8px;
  --radius-lg: 20px;

  --nav-height: 60px;
  --sidebar-w:  240px;
}

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

html { font-size: 16px; scroll-behavior: smooth; }

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ---- TIPOGRAFIA ---- */
h1, h2, h3 { font-family: 'Fraunces', serif; font-weight: 600; line-height: 1.2; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
h3 { font-size: 1.15rem; }
p  { color: var(--text-2); }

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

/* ---- BOTÕES ---- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 20px; border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif; font-size: .9rem; font-weight: 600;
  cursor: pointer; border: none; transition: all .2s ease;
  white-space: nowrap;
}
.btn-primary   { background: var(--green-800); color: #fff; }
.btn-primary:hover { background: var(--green-900); transform: translateY(-1px); box-shadow: var(--shadow); }
.btn-secondary { background: var(--green-100); color: var(--green-800); }
.btn-secondary:hover { background: var(--green-300); }
.btn-ghost     { background: transparent; color: var(--text-2); }
.btn-ghost:hover { background: var(--green-50); }
.btn-danger    { background: var(--red-soft); color: var(--red); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn-sm { padding: 6px 14px; font-size: .82rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none !important; }

/* ---- INPUTS ---- */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 18px; }
.form-group label { font-size: .85rem; font-weight: 600; color: var(--text); }

input, select, textarea {
  width: 100%; padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: 'DM Sans', sans-serif; font-size: .95rem;
  color: var(--text); background: var(--surface);
  transition: border-color .2s, box-shadow .2s;
  outline: none;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--green-500);
  box-shadow: 0 0 0 3px rgba(82,183,136,.15);
}
textarea { resize: vertical; min-height: 90px; }

/* ---- CARDS ---- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 14px;
  border-bottom: 1px solid var(--border);
}

/* ---- BADGES / TAGS ---- */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 10px; border-radius: 99px;
  font-size: .75rem; font-weight: 600;
}
.badge-green  { background: var(--green-100); color: var(--green-800); }
.badge-amber  { background: #fef3c7; color: #92400e; }
.badge-red    { background: var(--red-soft); color: var(--red); }
.badge-gray   { background: #f3f4f6; color: #6b7280; }

/* ---- ALERTAS ---- */
.alert {
  padding: 12px 16px; border-radius: var(--radius-sm);
  font-size: .9rem; margin-bottom: 16px; border-left: 4px solid;
}
.alert-success { background: var(--green-50); border-color: var(--green-500); color: var(--green-800); }
.alert-error   { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.alert-warning { background: #fffbeb; border-color: var(--amber); color: #92400e; }

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

.sidebar {
  width: var(--sidebar-w); min-height: 100vh;
  background: var(--green-900);
  display: flex; flex-direction: column;
  position: fixed; left: 0; top: 0; bottom: 0;
  z-index: 100;
}
.sidebar-logo {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
.sidebar-logo h2 {
  font-family: 'Fraunces', serif; color: #fff; font-size: 1.3rem;
}
.sidebar-logo span { color: var(--green-300); font-size: .8rem; display: block; }

.sidebar-nav { flex: 1; padding: 16px 0; overflow-y: auto; }
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 20px; color: rgba(255,255,255,.7);
  font-size: .9rem; font-weight: 500;
  cursor: pointer; transition: all .15s;
  border-left: 3px solid transparent;
  text-decoration: none;
}
.nav-item:hover  { background: rgba(255,255,255,.07); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--green-300); }
.nav-item .badge-count {
  margin-left: auto; background: var(--amber); color: #fff;
  border-radius: 99px; font-size: .7rem; padding: 1px 7px; font-weight: 700;
}

.sidebar-footer {
  padding: 16px 20px; border-top: 1px solid rgba(255,255,255,.1);
}
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: var(--radius-sm);
  background: rgba(255,255,255,.07); cursor: pointer;
  transition: background .15s;
}
.user-chip:hover { background: rgba(255,255,255,.12); }
.user-chip img   { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.user-chip .initials {
  width: 34px; height: 34px; border-radius: 50%;
  background: var(--green-500); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: .8rem; font-weight: 700;
}
.user-chip .info { flex: 1; min-width: 0; }
.user-chip .info .name { color: #fff; font-size: .85rem; font-weight: 600; truncate: ellipsis; }
.user-chip .info .role { color: var(--green-300); font-size: .72rem; }

.main-content {
  margin-left: var(--sidebar-w);
  flex: 1; min-height: 100vh;
  padding: 28px;
  max-width: calc(100vw - var(--sidebar-w));
}

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 28px;
}
.page-header h1 { font-size: 1.6rem; }

/* ---- TABELA ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 14px; text-align: left; font-size: .88rem; }
th { font-weight: 600; color: var(--text-2); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; border-bottom: 2px solid var(--border); }
tr:hover td { background: var(--green-50); }
td { border-bottom: 1px solid var(--border); }

/* ---- MODAL ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
  opacity: 0; pointer-events: none; transition: opacity .2s;
  overflow-y: auto;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  padding: 28px; width: 100%; max-width: 500px;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px); transition: transform .2s;
  /* Garante que modal nao ultrapasse a tela e tenha scroll proprio */
  max-height: calc(100vh - 40px);
  overflow-y: auto;
  margin: auto;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
  /* Fixa o header no topo da modal */
  position: sticky; top: -28px;
  background: var(--surface);
  padding-top: 28px; margin-top: -28px;
  z-index: 1;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 20px;
}
.modal-close {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--border); border: none; cursor: pointer;
  font-size: 1.1rem; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Mobile: modal ocupa mais espaço */
@media (max-width: 768px) {
  .modal-overlay {
    padding: 0;
    align-items: flex-end;
  }
  .modal {
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    max-width: 100%;
    max-height: 92vh;
    padding: 20px 16px;
    padding-bottom: max(20px, env(safe-area-inset-bottom));
  }
  .modal-header {
    top: -20px;
    padding-top: 20px;
    margin-top: -20px;
  }
}

/* ---- AUTONOMIA VISUAL ---- */
.autonomy-bar {
  height: 8px; background: var(--border); border-radius: 99px; overflow: hidden;
}
.autonomy-bar-fill {
  height: 100%; border-radius: 99px; transition: width .5s ease;
}
.autonomy-low    .autonomy-bar-fill { background: var(--red); }
.autonomy-medium .autonomy-bar-fill { background: var(--amber); }
.autonomy-high   .autonomy-bar-fill { background: var(--green-500); }

/* ---- FEED ---- */
.post-card { margin-bottom: 16px; }
.post-header { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.post-avatar { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--green-300); }
.post-meta .author { font-weight: 600; font-size: .9rem; }
.post-meta .time   { font-size: .78rem; color: var(--text-3); }
.post-body  { font-size: .95rem; margin-bottom: 12px; white-space: pre-wrap; }
.post-media { display: grid; gap: 6px; margin-bottom: 12px; border-radius: var(--radius-sm); overflow: hidden; }
.post-media img, .post-media video { width: 100%; max-height: 400px; object-fit: cover; }
.post-yt    { border-radius: var(--radius-sm); overflow: hidden; margin-bottom: 12px; }
.post-yt iframe { width: 100%; height: 280px; border: none; display: block; }
.post-actions { display: flex; gap: 4px; }
.action-btn {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  background: none; border: none; cursor: pointer;
  font-size: .85rem; color: var(--text-2); transition: all .15s;
  font-family: 'DM Sans', sans-serif;
}
.action-btn:hover     { background: var(--green-50); color: var(--green-800); }
.action-btn.liked     { color: var(--red); }
.action-btn.liked svg { fill: var(--red); }

/* ---- CHAT ---- */
.chat-list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .15s;
  border-bottom: 1px solid var(--border);
}
.chat-list-item:hover { background: var(--green-50); }
.chat-list-item.pinned { background: #fffbeb; border-left: 3px solid var(--amber); }
.chat-pin-icon { color: var(--amber); font-size: .8rem; }
.messages-area {
  flex: 1; overflow-y: auto; padding: 16px;
  display: flex; flex-direction: column; gap: 12px;
}
.msg-bubble {
  max-width: 70%; padding: 10px 14px;
  border-radius: 16px; font-size: .9rem;
}
.msg-bubble.own  { align-self: flex-end; background: var(--green-800); color: #fff; border-bottom-right-radius: 4px; }
.msg-bubble.other { align-self: flex-start; background: var(--surface); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.msg-author { font-size: .72rem; font-weight: 700; margin-bottom: 2px; color: var(--green-300); }
.msg-time   { font-size: .68rem; opacity: .65; text-align: right; margin-top: 4px; }

/* ---- MOBILE ---- */
.mobile-nav {
  display: none; position: fixed; bottom: 0; left: 0; right: 0;
  background: var(--surface); border-top: 1px solid var(--border);
  padding: 8px 0 env(safe-area-inset-bottom);
  z-index: 100;
}
.mobile-nav-items { display: flex; justify-content: space-around; }
.mobile-nav-item {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  padding: 6px 12px; border-radius: var(--radius-sm);
  color: var(--text-3); font-size: .68rem; font-weight: 600;
  cursor: pointer; transition: color .15s; position: relative;
  border: none; background: none; font-family: 'DM Sans', sans-serif;
}
.mobile-nav-item.active { color: var(--green-700); }
.mobile-nav-item svg { width: 22px; height: 22px; }
.mobile-badge {
  position: absolute; top: 2px; right: 6px;
  background: var(--red); color: #fff; border-radius: 99px;
  font-size: .6rem; padding: 1px 5px; font-weight: 700;
}

/* ---- TOAST ---- */
#toast-container {
  position: fixed; top: 20px; right: 20px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  padding: 12px 18px; border-radius: var(--radius-sm);
  font-size: .88rem; font-weight: 500; min-width: 240px;
  box-shadow: var(--shadow); animation: slideIn .25s ease;
}
.toast-success { background: var(--green-800); color: #fff; }
.toast-error   { background: var(--red); color: #fff; }
.toast-warning { background: var(--amber); color: #fff; }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }

/* ---- SPINNER ---- */
.spinner {
  width: 24px; height: 24px; border: 3px solid var(--border);
  border-top-color: var(--green-700); border-radius: 50%;
  animation: spin .7s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- EMPTY STATE ---- */
.empty-state {
  text-align: center; padding: 60px 20px;
  color: var(--text-3);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; display: block; }
.empty-state h3 { color: var(--text-2); margin-bottom: 8px; }

/* ---- RESPONSIVE ---- */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .main-content { margin-left: 0; padding: 16px 16px 80px; max-width: 100vw; }
  .mobile-nav { display: block; }
  .page-header { flex-direction: column; align-items: flex-start; gap: 12px; }
}
@media (min-width: 769px) {
  .mobile-nav { display: none !important; }
}

/* ---- UTILITÁRIOS ---- */
.flex     { display: flex; }
.items-center { align-items: center; }
.gap-2    { gap: 8px; }
.gap-3    { gap: 12px; }
.mt-1     { margin-top: 6px; }
.mt-2     { margin-top: 12px; }
.mt-3     { margin-top: 20px; }
.mb-3     { margin-bottom: 20px; }
.text-sm  { font-size: .85rem; }
.text-xs  { font-size: .75rem; }
.text-muted { color: var(--text-3); }
.font-bold  { font-weight: 700; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grid-2   { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3   { display: grid; grid-template-columns: repeat(3,1fr); gap: 16px; }
.grid-4   { display: grid; grid-template-columns: repeat(4,1fr); gap: 16px; }
@media(max-width:768px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

/* Nav section title */
.nav-section-title {
  padding: 10px 20px 4px;
  font-size: .68rem;
  font-weight: 700;
  color: rgba(255,255,255,.3);
  text-transform: uppercase;
  letter-spacing: .08em;
}

#productTable TD {
    height: 135px;
}

@media (min-width: 769px) {
    #productTable TD {
        height: 100px;
    }
}