/* ═══════════════════════════════════════════
   WhaBot — Design System
═══════════════════════════════════════════ */

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

:root {
  --bg-base: #0a0a0f;
  --bg-surface: #111118;
  --bg-card: #16161f;
  --bg-elevated: #1c1c28;
  --border: rgba(255,255,255,0.08);
  --border-active: rgba(37,211,102,0.5);

  --green: #25D366;
  --green-dark: #128C7E;
  --purple: #6366f1;
  --purple-light: #818cf8;
  --red: #ef4444;
  --amber: #f59e0b;
  --blue: #3b82f6;

  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #475569;

  --sidebar-w: 240px;
  --radius: 12px;
  --radius-sm: 8px;
}

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

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.6;
  min-height: 100vh;
}

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

/* ─── SIDEBAR ─── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
}

.sidebar-header {
  padding: 24px 20px 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.logo {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}

.logo-icon { font-size: 22px; }
.logo-text {
  font-size: 18px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo-badge {
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 20px;
  letter-spacing: 0.5px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  text-decoration: none;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-item:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(37, 211, 102, 0.12);
  color: var(--green);
  border: 1px solid rgba(37,211,102,0.2);
}

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

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-user {
  flex: 1;
  font-size: 12px;
  color: var(--text-muted);
}

.btn-logout {
  font-size: 12px;
  color: var(--red);
  text-decoration: none;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid rgba(239,68,68,0.3);
  transition: all 0.2s;
}

.btn-logout:hover {
  background: rgba(239,68,68,0.1);
}

/* ─── MAIN CONTENT ─── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  padding: 32px;
  max-width: calc(100vw - var(--sidebar-w));
}

/* ─── PAGE HEADER ─── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 28px;
  gap: 16px;
  flex-wrap: wrap;
}

.page-header h1 {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 2px;
}

/* ─── CARDS ─── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.card-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h2 { font-size: 16px; font-weight: 600; }

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

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
  transition: border-color 0.2s, transform 0.2s;
}

.stat-card:hover {
  border-color: rgba(255,255,255,0.15);
  transform: translateY(-2px);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  flex-shrink: 0;
}

.stat-info { display: flex; flex-direction: column; }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 4px;
}

/* ─── RULES GRID ─── */
.rules-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.rule-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s, transform 0.2s;
}

.rule-card:hover { border-color: rgba(255,255,255,0.15); transform: translateY(-1px); }
.rule-inactive { opacity: 0.6; }

.rule-card-header { margin-bottom: 12px; }
.rule-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.rule-title-row h3 { font-size: 16px; font-weight: 600; }
.rule-date { font-size: 11px; color: var(--text-muted); }

.rule-message {
  background: var(--bg-elevated);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 16px;
  border-left: 3px solid var(--green);
}

.rule-message-label { font-size: 10px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.rule-message p { font-size: 13px; color: var(--text-secondary); margin-top: 4px; line-height: 1.5; max-height: 72px; overflow: hidden; }

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

/* ─── BUTTONS ─── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all 0.2s;
  font-family: inherit;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--green), var(--green-dark));
  color: white;
}
.btn-primary:hover { opacity: 0.9; transform: translateY(-1px); }

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { background: var(--bg-elevated); color: var(--text-primary); }

.btn-warning {
  background: rgba(245,158,11,0.15);
  color: var(--amber);
  border: 1px solid rgba(245,158,11,0.3);
}
.btn-warning:hover { background: rgba(245,158,11,0.25); }

.btn-danger {
  background: rgba(239,68,68,0.15);
  color: var(--red);
  border: 1px solid rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ─── TABLE ─── */
.table-wrapper { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th {
  text-align: left;
  padding: 12px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}

.table td {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: rgba(255,255,255,0.02); }

/* ─── BADGES ─── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.badge-green { background: rgba(37,211,102,0.15); color: var(--green); }
.badge-gray  { background: rgba(255,255,255,0.08); color: var(--text-muted); }
.badge-blue  { background: rgba(59,130,246,0.15); color: var(--blue); }
.badge-amber { background: rgba(245,158,11,0.15); color: var(--amber); }

.phone-badge {
  font-family: monospace;
  font-size: 12px;
  color: var(--purple-light);
  background: rgba(99,102,241,0.1);
  padding: 2px 8px;
  border-radius: 4px;
}

/* ─── FORMS ─── */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; font-weight: 500; color: var(--text-primary); margin-bottom: 6px; }
.form-hint { font-size: 11px; color: var(--text-muted); margin-top: 5px; display: block; }

.form-control {
  width: 100%;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 10px 14px;
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}
.form-control:focus { border-color: var(--green); box-shadow: 0 0 0 3px rgba(37,211,102,0.1); }

.form-textarea { min-height: 140px; resize: vertical; line-height: 1.6; }

.form-checkbox { display: flex; align-items: center; gap: 10px; cursor: pointer; font-size: 14px; }
.form-checkbox input { width: 16px; height: 16px; accent-color: var(--green); }

.form-vertical { display: flex; flex-direction: column; padding: 24px; }
.form-actions { display: flex; gap: 12px; justify-content: flex-end; margin-top: 8px; }

/* ─── SEARCH BAR ─── */
.search-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}
.search-bar .form-control { max-width: 380px; }

/* ─── CONTACT CELL ─── */
.contact-cell { display: flex; align-items: center; gap: 10px; }

.contact-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--purple), var(--purple-light));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  color: white;
  flex-shrink: 0;
}

/* ─── RULE SELECT (inline) ─── */
.rule-select {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  padding: 6px 10px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  outline: none;
  transition: border-color 0.2s;
  max-width: 200px;
}
.rule-select:focus { border-color: var(--green); }

/* ─── MISC ─── */
.msg-cell { max-width: 280px; color: var(--text-secondary); font-size: 13px; }
.time-cell { font-size: 11px; color: var(--text-muted); white-space: nowrap; }
.log-replied { color: #4ade80; font-size: 13px; }

.empty-state {
  padding: 48px 24px;
  text-align: center;
  color: var(--text-secondary);
}
.empty-icon { font-size: 40px; display: block; margin-bottom: 12px; }
.empty-state p { font-size: 16px; margin-bottom: 8px; }
.empty-state small { font-size: 12px; color: var(--text-muted); }
.empty-state code {
  background: var(--bg-elevated);
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 11px;
  color: var(--green);
}

/* ─── FLASH MESSAGES ─── */
.flash-container { margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; }

.flash {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  animation: slideIn 0.3s ease;
}

@keyframes slideIn { from { opacity:0; transform:translateY(-6px); } to { opacity:1; transform:translateY(0); } }

.flash-success { background: rgba(37,211,102,0.12); border: 1px solid rgba(37,211,102,0.3); color: #4ade80; }
.flash-error   { background: rgba(239,68,68,0.12); border: 1px solid rgba(239,68,68,0.3); color: #f87171; }
.flash-info    { background: rgba(59,130,246,0.12); border: 1px solid rgba(59,130,246,0.3); color: #60a5fa; }
.flash-close   { background: none; border: none; cursor: pointer; color: inherit; opacity: 0.7; padding: 0; font-size: 14px; }
.flash-close:hover { opacity: 1; }

/* ─── LOGIN PAGE ─── */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 60% 20%, rgba(37,211,102,0.07) 0%, transparent 60%),
              radial-gradient(ellipse at 20% 80%, rgba(99,102,241,0.07) 0%, transparent 60%),
              var(--bg-base);
}

.login-container { width: 100%; max-width: 400px; padding: 24px; }

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px 36px;
  box-shadow: 0 25px 60px rgba(0,0,0,0.5);
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-logo { font-size: 48px; margin-bottom: 12px; }
.login-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 6px; }
.login-header p { color: var(--text-secondary); font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 16px; }
