:root {
  --bg: #0f172a;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #475569;
  --line: #e2e8f0;
  --accent: #2563eb;
  /* Resolve Energia — solar amber accent */
  --solar: #f59e0b;
  --solar-dark: #d97706;
  --solar-glow: rgba(245, 158, 11, 0.35);
}
* { box-sizing: border-box; }
html, body { height: 100%; overflow: hidden; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: #f0f2f5;
  color: var(--text);
  min-height: 100dvh;
}

/* === APP SHELL === */
.app-shell { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }
.app-header { display: none; }
.app-body { display: flex; flex: 1; overflow: hidden; width: 100%; min-height: 0; }

/* === SIDEBAR === */
.sidebar {
  width: 220px;
  min-width: 220px;
  background: #0f172a;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .18s ease, min-width .18s ease;
}
.sidebar::-webkit-scrollbar { width: 4px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.12); border-radius: 2px; }

.sidebar-brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex; align-items: center; gap: 10px;
  flex-shrink: 0;
  position: relative;
}
.sidebar-brand-text { min-width: 0; flex: 1; }
.sidebar-brand-icon {
  width: 34px; height: 34px; border-radius: 9px;
  background: linear-gradient(135deg, var(--solar), var(--solar-dark));
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; flex-shrink: 0;
  box-shadow: 0 2px 8px var(--solar-glow);
}
.sidebar-brand-name {
  font-size: 14px; font-weight: 700; color: #f1f5f9;
  letter-spacing: -0.01em; line-height: 1.2;
}
.sidebar-brand-sub { font-size: 10px; color: #64748b; margin-top: 1px; }
.sidebar-toggle {
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  border: 1px solid rgba(148,163,184,0.2);
  background: rgba(255,255,255,0.04);
  color: #cbd5e1;
  display: inline-flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.sidebar-toggle:hover { background: rgba(255,255,255,0.08); color: #f8fafc; }

.sidebar-section {
  padding: 14px 16px 4px;
  font-size: 9.5px; font-weight: 700;
  color: #475569; text-transform: uppercase; letter-spacing: 0.09em;
}
.sidebar-divider { height: 1px; background: rgba(255,255,255,0.06); margin: 6px 0; }
.sidebar-spacer { flex: 1; min-height: 12px; }
.sidebar-bottom { padding: 8px 0 12px; border-top: 1px solid rgba(255,255,255,0.06); }

.nav-btn {
  width: 100%; height: 38px;
  background: transparent; border: none; border-radius: 0;
  cursor: pointer;
  display: flex; align-items: center;
  padding: 0 16px; gap: 10px;
  color: #64748b; font-size: 13px; font-weight: 500;
  text-align: left; white-space: nowrap;
  transition: background .12s, color .12s;
  position: relative;
}
.nav-btn:hover { background: rgba(255,255,255,0.05); color: #cbd5e1; }
.nav-btn.active { background: rgba(245, 158, 11, 0.15); color: var(--solar); }
.nav-btn.active::before {
  content: ''; position: absolute;
  left: 0; top: 6px; bottom: 6px;
  width: 3px; background: var(--solar); border-radius: 0 2px 2px 0;
}
.nav-icon { width: 17px; height: 17px; flex-shrink: 0; display: block; }
.nav-label { font-size: 13px; font-weight: 500; }
.nav-btn-danger { color: #f87171 !important; }
.nav-btn-danger:hover { background: rgba(239,68,68,0.1) !important; color: #fca5a5 !important; }

.app-shell.sidebar-collapsed .sidebar { width: 72px; min-width: 72px; }
.app-shell.sidebar-collapsed .sidebar-brand { padding-left: 12px; padding-right: 12px; justify-content: center; }
.app-shell.sidebar-collapsed .sidebar-brand-text,
.app-shell.sidebar-collapsed .sidebar-section,
.app-shell.sidebar-collapsed .nav-label,
.app-shell.sidebar-collapsed #sidebarLoggedAdmin { display: none !important; }
.app-shell.sidebar-collapsed .sidebar-toggle {
  position: absolute; top: 8px; right: 8px; width: 30px; height: 30px;
  border-color: rgba(148,163,184,0.35); background: rgba(15,23,42,0.96);
  box-shadow: 0 0 0 1px rgba(15,23,42,0.4); z-index: 3;
}
.app-shell.sidebar-collapsed .nav-btn { justify-content: center; padding: 0; }
.app-shell.sidebar-collapsed .sidebar-bottom { padding-top: 10px; }
.app-shell.sidebar-collapsed .nav-btn.active::before { top: 8px; bottom: 8px; }

/* === PANELS === */
.panels-area { flex: 1; overflow: hidden; position: relative; min-width: 0; min-height: 0; }
.panel { display: none; flex-direction: column; height: 100%; overflow: hidden; min-width: 0; min-height: 0; }
.panel.active { display: flex; }

.panel-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 20px;
  background: #fff;
  border-bottom: 1px solid var(--line);
  flex-shrink: 0;
}
.panel-hdr h2 { margin: 0; font-size: 16px; }
.panel-body { flex: 1; overflow-y: auto; padding: 20px; }
.panel-stack { width: 100%; display: flex; flex-direction: column; gap: 16px; align-items: stretch; }
.panel-card {
  width: 100%; max-width: none; box-sizing: border-box;
  background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 20px;
}
.panel-card.subtle { background: #f8fafc; border-color: #e2e8f0; }
.panel-form-grid {
  display: grid; grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px; align-items: start;
}
.panel-form-grid > .full { grid-column: 1 / -1; }
.panel-card input[type=text],
.panel-card input[type=password],
.panel-card input[type=number],
.panel-card input[type=tel],
.panel-card input[type=date],
.panel-card select,
.panel-card textarea { width: 100%; }

h1, h2 { margin-top: 0; }

/* === FORMS === */
textarea, input[type=text], input[type=password], input[type=number], input[type=tel], input[type=date], select {
  font-family: inherit; font-size: 14px;
  border: 1px solid #cbd5e1; border-radius: 8px;
  padding: 12px 14px; background: #ffffff; color: var(--text);
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  box-sizing: border-box;
  box-shadow: 0 1px 2px rgba(0,0,0, 0.03);
}
textarea:focus, input[type=text]:focus, input[type=password]:focus,
input[type=number]:focus, input[type=tel]:focus, input[type=date]:focus, select:focus {
  outline: none; background: #ffffff;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
textarea { width: 100%; min-height: 120px; resize: vertical; }

label[style*="display:block"] {
  font-size: 13px !important; font-weight: 600 !important;
  color: #1e293b !important; margin-bottom: 6px !important;
}

/* === BUTTONS === */
button {
  padding: 10px 18px; border-radius: 8px; border: none;
  background: var(--accent); color: #fff; cursor: pointer;
  font-weight: 600; font-size: 14px;
  transition: all 0.2s ease;
  box-shadow: 0 2px 5px rgba(37,99,235, 0.2);
}
button:active { transform: scale(0.96); box-shadow: 0 1px 2px rgba(37,99,235, 0.2); }
button:hover { filter: brightness(1.1); box-shadow: 0 3px 8px rgba(37,99,235, 0.3); }
button.secondary { background: #64748b; box-shadow: 0 2px 5px rgba(100,116,139, 0.2); }
button.danger { background: #dc2626; box-shadow: 0 2px 5px rgba(220,38,38, 0.2); }
button.success { background: #16a34a; box-shadow: 0 2px 5px rgba(22,163,74, 0.2); }

.actions { display: flex; gap: 10px; flex-wrap: wrap; }
.muted { color: var(--muted); font-size: 13px; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px; border-radius: 8px; overflow: auto; }

/* === TABS === */
.tab-bar { display: flex; gap: 4px; }
.tab-btn {
  background: transparent; border: 1px solid var(--line);
  color: var(--muted); padding: 5px 14px;
  border-radius: 6px; font-size: 13px; cursor: pointer;
}
.tab-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* === TABLES === */
table.data-table {
  width: 100%; border-collapse: collapse; font-size: 13px;
}
table.data-table th {
  text-align: left; padding: 10px 12px;
  background: #f8fafc; border-bottom: 2px solid var(--line);
  font-weight: 700; color: #334155; white-space: nowrap;
}
table.data-table td {
  padding: 10px 12px; border-bottom: 1px solid var(--line);
  color: #1e293b; vertical-align: middle;
}
table.data-table tr:hover td { background: #f8fafc; }

/* === BADGES === */
.badge {
  display: inline-block; font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}
.badge-pending  { background: #fef3c7; color: #92400e; }
.badge-confirmed{ background: #dbeafe; color: #1e40af; }
.badge-completed{ background: #dcfce7; color: #166534; }
.badge-cancelled{ background: #fee2e2; color: #991b1b; }
.badge-active   { background: #dcfce7; color: #166534; }
.badge-inactive { background: #f1f5f9; color: #64748b; }
.badge-info     { background: #e0f2fe; color: #0369a1; }

/* === LOGIN OVERLAY === */
.login-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.88);
  z-index: 9999;
  display: flex; align-items: center; justify-content: center;
}
.login-box {
  background: #fff; border-radius: 16px; padding: 36px 32px;
  width: 360px; max-width: 92vw;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: grid; gap: 12px; box-sizing: border-box;
}
.login-box h2 { margin: 0; font-size: 20px; }
.login-box p  { margin: 0; color: var(--muted); font-size: 14px; }
.login-box input[type=text],
.login-box input[type=password] {
  width: 100%; padding: 11px 14px; font-size: 14px;
  border-radius: 8px; border: 1px solid var(--line);
  display: block; box-sizing: border-box;
}
.login-password-wrap {
  display: grid; grid-template-columns: 1fr auto;
  gap: 8px; align-items: center;
}
.login-password-wrap input[type=password],
.login-password-wrap input[type=text] { margin: 0; }
.login-toggle-btn {
  width: auto !important; padding: 11px 12px !important;
  font-size: 12px !important; white-space: nowrap;
  background: #475569; border-color: #475569;
}
.login-box button { width: 100%; padding: 11px; font-size: 14px; box-sizing: border-box; }
.login-error { color: #dc2626; font-size: 13px; margin: 0; min-height: 18px; }

/* === DASHBOARD CARDS === */
.dash-cards {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px; margin-bottom: 20px;
}
.dash-card {
  background: #fff; border: 1px solid var(--line);
  border-radius: 12px; padding: 20px;
  display: flex; flex-direction: column; gap: 4px;
}
.dash-card-num { font-size: 28px; font-weight: 800; color: var(--solar-dark); }
.dash-card-label { font-size: 13px; color: var(--muted); font-weight: 500; }

/* === MODAL === */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,0.6);
  z-index: 9000;
  display: flex; align-items: center; justify-content: center;
}
.modal-box {
  background: #fff; border-radius: 16px;
  width: 520px; max-width: 92vw; max-height: 88vh;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-hdr {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
}
.modal-hdr h3 { margin: 0; font-size: 16px; }
.modal-close {
  background: transparent; box-shadow: none; color: var(--muted);
  font-size: 22px; padding: 0; width: 32px; height: 32px;
  border-radius: 8px; display: flex; align-items: center; justify-content: center;
}
.modal-close:hover { background: #f1f5f9; filter: none; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
  padding: 14px 20px; border-top: 1px solid var(--line);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* === CONVERSATIONS === */
.conv-layout { display: flex; gap: 0; height: 100%; overflow: hidden; }
.conv-list {
  width: 280px; min-width: 220px;
  border-right: 1px solid var(--line);
  overflow-y: auto; background: #fff;
}
.conv-list-item {
  padding: 12px 16px; border-bottom: 1px solid var(--line);
  cursor: pointer; transition: background .12s;
}
.conv-list-item:hover { background: #f8fafc; }
.conv-list-item.active { background: #fffbeb; border-left: 3px solid var(--solar); }
.conv-list-item .phone { font-weight: 600; font-size: 13px; color: var(--text); }
.conv-list-item .preview { font-size: 12px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-detail {
  flex: 1; overflow-y: auto; padding: 20px;
  background: #f8fafc;
}
.conv-msg {
  max-width: 70%; padding: 10px 14px; border-radius: 12px;
  margin-bottom: 8px; font-size: 14px; word-wrap: break-word;
}
.conv-msg.user {
  background: #fff; margin-right: auto;
  border-bottom-left-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}
.conv-msg.assistant {
  background: var(--solar); color: #fff; margin-left: auto;
  border-bottom-right-radius: 2px;
}
.conv-msg .tag {
  display: inline-block; font-size: 10px; font-weight: 700;
  padding: 1px 6px; border-radius: 999px;
  background: rgba(0,0,0,0.1); margin-right: 6px;
}
.conv-msg.user .tag { background: rgba(37,99,235,0.15); color: #1d4ed8; }

/* === WORKFLOW EDITOR === */
.wf-toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 12px;
}
.wf-editor {
  width: 100%; min-height: 420px; resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; background: #0f172a; color: #e2e8f0;
  border: 1px solid #334155; border-radius: 8px; padding: 14px;
}

/* === TOAST === */
.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 10000;
  background: #0f172a; color: #f1f5f9;
  padding: 12px 20px; border-radius: 10px;
  font-size: 14px; font-weight: 500;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  opacity: 0; transform: translateY(10px);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: #16a34a; }
.toast.error { background: #dc2626; }

/* === RESPONSIVE === */
@media (max-width: 768px) {
  .sidebar { position: absolute; z-index: 100; height: 100%; }
  .app-shell:not(.sidebar-collapsed) .sidebar { width: 220px; }
  .conv-list { width: 200px; }
}
