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

:root {
  --bg:        #0d0f14;
  --bg2:       #13161e;
  --bg3:       #1a1e2a;
  --border:    #252a38;
  --text:      #d0d4e0;
  --text2:     #7a819a;
  --accent:    #00e5a0;
  --accent2:   #0099ff;
  --danger:    #ff4d6a;
  --warn:      #ffb830;
  --success:   #00e5a0;
  --mono:      'IBM Plex Mono', monospace;
  --sans:      'IBM Plex Sans', sans-serif;
}

html.theme-light {
  --bg:        #f4f5f7;
  --bg2:       #ffffff;
  --bg3:       #ebedf1;
  --border:    #dde1e8;
  --text:      #1b1e27;
  --text2:     #5b6275;
  --accent:    #00a87a;
  --accent2:   #0077cc;
  --danger:    #d6304b;
  --warn:      #b8780f;
  --success:   #00a87a;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  min-height: 100vh;
  display: flex;
  transition: background-color .15s ease, color .15s ease;
}

/* esconde elementos não relevantes para a role atual */
body:not(.role-admin) .admin-only { display: none !important; }
body:not(.role-cliente) .cliente-only { display: none !important; }

/* ── LOGIN ── */
#login-screen {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
}
#login-screen.hidden { display: none; }

.login-card {
  width: 360px;
  max-width: 90vw;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 36px 32px;
}

.login-logo {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  margin-bottom: 6px;
}
.login-logo span { color: var(--text2); font-weight: 400; }

.login-sub {
  text-align: center;
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 28px;
}

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 11px;
  font-family: var(--mono);
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  margin-bottom: 6px;
}
.field input[type=text], .field input[type=password], .field input[type=email] {
  width: 100%;
}

#login-error {
  display: none;
  background: #ff4d6a18;
  border: 1px solid var(--danger);
  color: var(--danger);
  font-size: 12px;
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
}

.btn-full { width: 100%; justify-content: center; }

/* ── APP SHELL ── */
#app-shell { display: flex; width: 100%; }
#app-shell.hidden { display: none; }

/* ── SIDEBAR ── */
#sidebar {
  width: 220px;
  min-height: 100vh;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 24px 20px 16px;
  font-family: var(--mono);
  font-size: 13px;
  font-weight: 600;
  color: var(--accent);
  letter-spacing: 2px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
.sidebar-logo span { color: var(--text2); font-weight: 400; }

nav { padding: 12px 0; flex: 1; }

nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--text2);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  border-left: 2px solid transparent;
}
nav a:hover { color: var(--text); background: var(--bg3); }
nav a.active { color: var(--accent); border-left-color: var(--accent); background: var(--bg3); }

nav a .icon { font-size: 16px; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  font-family: var(--mono);
  font-size: 11px;
  color: var(--text2);
}

/* ── MAIN ── */
#main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  overflow: hidden;
}

#topbar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  padding: 14px 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

#topbar h1 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

#topbar-right { display: flex; align-items: center; gap: 12px; }

#topbar .status-badge {
  font-family: var(--mono);
  font-size: 11px;
  padding: 3px 10px;
  border-radius: 20px;
  background: var(--bg3);
  color: var(--accent);
  border: 1px solid var(--accent);
}

#topbar-user {
  font-size: 12px;
  color: var(--text2);
  text-align: right;
}
#topbar-user strong { color: var(--text); font-weight: 500; }

#content {
  padding: 28px;
  flex: 1;
  overflow-y: auto;
}

/* ── SEÇÕES ── */
.section { display: none; }
.section.active { display: block; }

/* ── CARDS GRID ── */
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px 20px;
}

.card-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  font-family: var(--mono);
  margin-bottom: 8px;
}

.card-value {
  font-size: 28px;
  font-weight: 600;
  font-family: var(--mono);
  color: var(--text);
}

.card-sub {
  font-size: 11px;
  color: var(--text2);
  margin-top: 4px;
}

.card.accent .card-value { color: var(--accent); }
.card.danger .card-value { color: var(--danger); }
.card.warn   .card-value { color: var(--warn); }

/* ── CONTAINERS GRID ── */
.containers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 14px;
  margin-bottom: 28px;
}

.container-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.container-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 3px; height: 100%;
  background: var(--text2);
}

.container-card.running::before  { background: var(--success); }
.container-card.exited::before   { background: var(--danger); }
.container-card.error::before    { background: var(--danger); }

.container-name {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 4px;
}

.container-image {
  font-family: var(--mono);
  font-size: 10px;
  color: var(--text2);
  margin-bottom: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.container-status {
  display: inline-block;
  font-family: var(--mono);
  font-size: 10px;
  padding: 2px 8px;
  border-radius: 4px;
  margin-bottom: 10px;
}
.container-card.running .container-status { background: #00e5a022; color: var(--success); }
.container-card.exited  .container-status { background: #ff4d6a22; color: var(--danger); }
.container-card.error   .container-status { background: #ff4d6a22; color: var(--danger); }

.bar-wrap { margin-top: 6px; }
.bar-label { font-size: 10px; color: var(--text2); display: flex; justify-content: space-between; margin-bottom: 3px; }
.bar { height: 4px; background: var(--bg3); border-radius: 2px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--accent2); border-radius: 2px; transition: width .5s; }
.bar-fill.warn-bar { background: var(--warn); }
.bar-fill.danger-bar { background: var(--danger); }

/* ── CHART ── */
.chart-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 28px;
}

.chart-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  font-family: var(--mono);
  margin-bottom: 16px;
}

.bar-chart {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  height: 80px;
}

.bar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  height: 100%;
  justify-content: flex-end;
}

.bar-col-fill {
  width: 100%;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-height: 2px;
  opacity: 0.7;
  transition: height .5s;
}

.bar-col-label {
  font-family: var(--mono);
  font-size: 9px;
  color: var(--text2);
}

/* ── TABLE ── */
.table-wrap {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.table-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.table-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  font-family: var(--mono);
}

.table-actions { display: flex; gap: 8px; flex-wrap: wrap; }

input[type=text], input[type=password], input[type=email], select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 12px;
  border-radius: 5px;
  font-family: var(--sans);
  font-size: 13px;
  outline: none;
  transition: border .15s;
}
input[type=text]:focus, input[type=password]:focus, input[type=email]:focus, select:focus { border-color: var(--accent); }
select option { background: var(--bg2); }

table { width: 100%; border-collapse: collapse; }
thead th {
  padding: 10px 16px;
  text-align: left;
  font-family: var(--mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  border-bottom: 1px solid var(--border);
  background: var(--bg3);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }
tbody td { padding: 11px 16px; font-size: 13px; vertical-align: middle; }

.mono { font-family: var(--mono); font-size: 11px; }

/* Estado badge */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: var(--mono);
  font-size: 10px;
}
.badge.bot              { background: #00e5a018; color: var(--accent); }
.badge.agendamento_dia  { background: #ffb83018; color: var(--warn); }
.badge.agendamento      { background: #0099ff18; color: var(--accent2); }
.badge.on               { background: #00e5a018; color: var(--accent); }
.badge.off              { background: #ff4d6a18; color: var(--danger); }
.badge.teste            { background: #ffb83018; color: var(--warn); }
.badge.producao         { background: #00e5a018; color: var(--accent); }

/* Botões */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg3);
  color: var(--text);
  font-size: 12px;
  cursor: pointer;
  font-family: var(--sans);
  transition: all .15s;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.primary { background: var(--accent); color: #000; border-color: var(--accent); font-weight: 600; }
.btn.primary:hover { background: #00c888; }
.btn.danger  { border-color: var(--danger); color: var(--danger); }
.btn.danger:hover { background: #ff4d6a18; }

.btn-group { display: flex; gap: 4px; }

/* ── PAGINATION ── */
.pagination {
  display: flex;
  gap: 6px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  justify-content: flex-end;
  align-items: center;
}

.pagination span {
  font-size: 12px;
  color: var(--text2);
  font-family: var(--mono);
}

/* ── LOGS ── */
#log-terminal {
  background: #080a0f;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.7;
  color: #8fa0b8;
  height: 540px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

#log-terminal .log-error  { color: var(--danger); }
#log-terminal .log-warn   { color: var(--warn); }
#log-terminal .log-info   { color: var(--accent); }

.log-controls {
  display: flex;
  gap: 10px;
  margin-bottom: 12px;
  flex-wrap: wrap;
  align-items: center;
}

/* ── MODAL ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 100;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 680px;
  max-width: 95vw;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
}
.modal.narrow { width: 420px; }

.modal-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-head h2 { font-size: 14px; font-weight: 600; }
.modal-close { background: none; border: none; color: var(--text2); font-size: 20px; cursor: pointer; }
.modal-close:hover { color: var(--text); }

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

.modal-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── MENSAGENS ── */
.msg-list { display: flex; flex-direction: column; gap: 8px; }
.msg-bubble {
  max-width: 80%;
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
}
.msg-bubble.user      { background: var(--bg3); align-self: flex-start; }
.msg-bubble.assistant { background: #00e5a012; align-self: flex-end; border: 1px solid #00e5a030; }
.msg-time { font-size: 10px; color: var(--text2); font-family: var(--mono); margin-top: 3px; }

/* ── WHATSAPP ── */
.wpp-status-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 28px;
  text-align: center;
  max-width: 420px;
  margin: 0 auto 24px;
}

.wpp-dot {
  width: 14px; height: 14px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 8px;
}
.wpp-dot.open        { background: var(--success); box-shadow: 0 0 8px var(--success); }
.wpp-dot.close       { background: var(--danger); }
.wpp-dot.connecting  { background: var(--warn); }

.wpp-status-text {
  font-family: var(--mono);
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 20px;
}

#qrcode-img, .qrcode-img {
  max-width: 220px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px;
  background: #fff;
  margin: 16px auto;
  display: block;
}

.wpp-actions { display: flex; gap: 10px; justify-content: center; margin-top: 16px; flex-wrap: wrap; }

/* Pill switch teste/produção */
.pill-switch {
  display: inline-flex;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px;
  margin: 12px auto;
}
.pill-switch button {
  border: none;
  background: none;
  color: var(--text2);
  font-family: var(--mono);
  font-size: 11px;
  padding: 6px 16px;
  border-radius: 16px;
  cursor: pointer;
  transition: all .15s;
}
.pill-switch button.active.teste    { background: #ffb83022; color: var(--warn); }
.pill-switch button.active.producao { background: #00e5a022; color: var(--accent); }

/* ── LOADING ── */
.loading {
  text-align: center;
  padding: 40px;
  color: var(--text2);
  font-family: var(--mono);
  font-size: 13px;
}
.loading::after {
  content: '';
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin-left: 8px;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty { text-align: center; padding: 40px; color: var(--text2); font-size: 13px; }

/* ── SECTION TITLE ── */
.section-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 4px;
}
.section-sub {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 24px;
}

/* toggle switch */
.toggle {
  position: relative;
  display: inline-block;
  width: 36px; height: 20px;
}
.toggle input { display: none; }
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  cursor: pointer;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 14px; height: 14px;
  left: 2px; top: 2px;
  background: var(--text2);
  border-radius: 50%;
  transition: .2s;
}
.toggle input:checked + .toggle-slider { background: #00e5a022; border-color: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); background: var(--accent); }

/* Credenciais geradas */
.creds-box {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 16px;
}
.creds-row { display: flex; justify-content: space-between; align-items: center; padding: 4px 0; }
.creds-row span:first-child { color: var(--text2); font-size: 12px; }
.creds-row span:last-child { font-family: var(--mono); font-size: 13px; }

/* Logo preview no painel cliente */
.logo-preview {
  width: 64px; height: 64px;
  border-radius: 10px;
  object-fit: cover;
  border: 1px solid var(--border);
  background: var(--bg3);
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text2); }

/* ── BOTTOM NAV (mobile only) ── */
#bottom-nav { display: none; }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  #sidebar { display: none; }

  #topbar { padding: 12px 16px; }
  #topbar h1 { font-size: 14px; }
  #topbar-user { display: none; }

  #content { padding: 16px 12px 80px; }

  .cards-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    margin-bottom: 16px;
  }
  .card { padding: 14px 16px; }
  .card-value { font-size: 22px; }
  .card-sub { font-size: 10px; }

  .containers-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
  }

  .table-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .table-actions { flex-direction: column; width: 100%; gap: 6px; }
  .table-actions input[type=text],
  .table-actions select { width: 100%; box-sizing: border-box; }

  #leads-table-body,
  #reunioes-table-body,
  #clientes-table-body { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  #log-terminal { height: 340px; font-size: 11px; }
  .log-controls { gap: 8px; }
  .log-controls select { flex: 1; min-width: 0; }

  .section-title { font-size: 16px; }
  .wpp-status-card { max-width: 100%; }

  /* Bottom navigation */
  #bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    background: var(--bg2);
    border-top: 1px solid var(--border);
    z-index: 50;
    height: 60px;
    padding-bottom: env(safe-area-inset-bottom);
  }
  #bottom-nav a {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    color: var(--text2);
    text-decoration: none;
    cursor: pointer;
    transition: color .15s;
    border-top: 2px solid transparent;
    -webkit-tap-highlight-color: transparent;
  }
  #bottom-nav a .nav-icon { font-size: 18px; }
  #bottom-nav a .nav-label {
    font-size: 9px;
    font-family: var(--mono);
    text-transform: uppercase;
    letter-spacing: 0.5px;
  }
  #bottom-nav a.active {
    color: var(--accent);
    border-top-color: var(--accent);
  }
}
