:root {
  --bg: #f0f2f5;
  --accent: #1f7a4d;
  --accent-dark: #17633e;
  --line: #d1d7db;
  --text: #111b21;
  --muted: #667781;
}

* { box-sizing: border-box; }

body { 
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; 
  background: var(--bg); 
  color: var(--text); 
  margin: 0; 
  line-height: 1.5;
}

.hidden { display: none !important; }

/* --- FIX: INPUT TEXT VISIBILITY --- */
input, textarea, select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin-bottom: 12px;
  color: #000000 !important; /* Forces black text */
  background: #ffffff !important; /* Forces white background */
  font-size: 14px;
}

label {
  display: block;
  margin-bottom: 5px;
  font-weight: bold;
  font-size: 13px;
}

/* --- AUTH SCREEN --- */
.authScreen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  background: var(--accent);
}

.authBox {
  background: #fff;
  padding: 30px;
  border-radius: 12px;
  width: 360px;
  box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

.authBox h1 {
  text-align: center;
  color: var(--accent);
  margin-top: 0;
}

/* --- LAYOUT & TABS --- */
.topbar {
  background: #fff;
  padding: 15px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--line);
}

.tabs {
  background: #fff;
  display: flex;
  gap: 8px;
  padding: 10px 24px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  position: sticky;
  top: 0;
  z-index: 100;
}

.tabs button {
  background: none;
  border: 1px solid var(--line);
  padding: 8px 16px;
  border-radius: 5px;
  cursor: pointer;
  white-space: nowrap;
  color: var(--text);
  font-weight: 500;
}

.tabs button.active {
  background: #eef7f2;
  border-color: var(--accent);
  color: var(--accent);
  font-weight: bold;
}

/* --- GRID SYSTEM (Restores side-by-side boxes) --- */
.grid { display: grid; gap: 20px; }
.grid.two { grid-template-columns: 1fr 1fr; }
.grid.three { grid-template-columns: 1fr 1fr 1fr; }

@media (max-width: 768px) {
  .grid.two, .grid.three { grid-template-columns: 1fr; }
}

.compact { max-width: 500px; }

.box {
  background: #fff;
  padding: 20px;
  border-radius: 8px;
  border: 1px solid var(--line);
  margin-bottom: 20px;
}

.box h3 { margin-top: 0; font-size: 16px; color: var(--accent); }

/* --- HOME DASHBOARD --- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 20px;
  margin-top: 15px;
}

.card {
  background: #fff;
  padding: 20px;
  border-radius: 10px;
  text-align: center;
  border: 1px solid var(--line);
}

.card h3 { margin: 0; font-size: 13px; color: var(--muted); text-transform: uppercase; }
.card p { font-size: 32px; font-weight: bold; color: var(--accent); margin: 5px 0 0; }

/* --- LIVE CRM SPLIT VIEW --- */
.crm-split {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 75vh;
  background: #fff;
  border-radius: 10px;
  overflow: hidden;
  border: 1px solid var(--line);
}

.crm-sidebar {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  background: #fff;
}

.chat-row {
  padding: 15px;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  transition: background 0.2s;
}

.chat-row:hover { background: #f9f9f9; }
.chat-row.active {
  background: #f0f2f5;
  border-left: 4px solid var(--accent);
}

.crm-main {
  background: #e5ddd5; /* WhatsApp beige */
  display: flex;
  flex-direction: column;
}

.msg-list {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 1px 1px rgba(0,0,0,0.1);
  position: relative;
}

.msg-bubble.inbound {
  background: #fff;
  align-self: flex-start;
}

.msg-bubble.outbound {
  background: #dcf8c6;
  align-self: flex-end;
}

.msg-bubble .meta {
  font-size: 10px;
  color: var(--muted);
  text-align: right;
  margin-top: 4px;
}

.chat-input {
  padding: 15px;
  background: #f0f2f5;
  display: flex;
  gap: 10px;
  border-top: 1px solid var(--line);
}

.chat-input input {
  margin-bottom: 0;
  border-radius: 20px;
}

/* --- COMPONENTS --- */
button, .button {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 10px 20px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: bold;
  text-decoration: none;
  display: inline-block;
  text-align: center;
}

button:hover { background: var(--accent-dark); }
button:disabled { background: #ccc; cursor: not-allowed; }

button.secondary, .button.secondary {
  background: #fff;
  color: var(--text);
  border: 1px solid var(--line);
}

.badge {
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: bold;
}

/* --- TABLES --- */
.tableWrap {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 15px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 600px;
}

th, td {
  padding: 12px 15px;
  text-align: left;
  border-bottom: 1px solid var(--line);
}

th {
  background: #f8fafc;
  font-weight: bold;
  color: var(--muted);
  text-transform: uppercase;
  font-size: 12px;
}

tr:last-child td { border-bottom: none; }

/* --- UTILS --- */
.panel { display: none; padding: 20px; }
.panel.active { display: block; }

#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: #333;
  color: #fff;
  padding: 12px 24px;
  border-radius: 8px;
  opacity: 0;
  transition: 0.3s;
  z-index: 9999;
}

#toast.show { opacity: 1; }