:root {
  --accent: #10b981;
  --accent-dark: #059669;
  --sidebar-bg: #111827;
  --sidebar-hover: #1f2937;
  --bg: #f3f4f6;
  --card-bg: #ffffff;
  --text-dark: #111827;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
  background: var(--bg);
  color: var(--text-dark);
}

.layout { display: flex; min-height: 100vh; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 230px;
  background: var(--sidebar-bg);
  color: #e5e7eb;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 22px 20px;
  border-bottom: 1px solid #1f2937;
}
.brand-icon {
  background: var(--accent);
  color: #fff;
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
}
.brand-name { font-weight: 600; font-size: 15px; }

.sidebar nav { display: flex; flex-direction: column; padding: 14px 10px; gap: 2px; flex: 1; }
.sidebar nav a {
  color: #cbd5e1;
  text-decoration: none;
  padding: 11px 14px;
  border-radius: 8px;
  font-size: 14px;
  transition: background 0.15s;
}
.sidebar nav a:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar nav a.active { background: var(--accent); color: #fff; font-weight: 600; }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid #1f2937;
  font-size: 12px;
  color: #9ca3af;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.logout-link { color: #f87171; text-decoration: none; font-size: 12px; }
.logout-link:hover { text-decoration: underline; }

/* ---------- Main content ---------- */
.content { flex: 1; padding: 32px 40px; max-width: 1200px; }

h1.page-title { font-size: 22px; margin: 0 0 6px 0; }
p.page-subtitle { color: var(--text-muted); margin: 0 0 26px 0; font-size: 14px; }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 26px;
  margin-bottom: 24px;
}

.grid { display: grid; gap: 20px; }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 900px) { .grid-3, .grid-2 { grid-template-columns: 1fr; } }

.stat-card { display: flex; flex-direction: column; gap: 6px; }
.stat-value { font-size: 28px; font-weight: 700; color: var(--text-dark); }
.stat-label { font-size: 13px; color: var(--text-muted); }

/* ---------- Forms ---------- */
label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: #374151; }
.form-group { margin-bottom: 18px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], select, textarea {
  width: 100%;
  padding: 11px 13px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
  color: var(--text-dark);
}
textarea { resize: vertical; min-height: 110px; }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(16,185,129,0.15);
}
.hint { font-size: 12px; color: var(--text-muted); margin-top: 5px; }

.btn {
  display: inline-block;
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 11px 22px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}
.btn:hover { background: var(--accent-dark); }
.btn-secondary { background: #fff; color: var(--text-dark); border: 1px solid var(--border); }
.btn-secondary:hover { background: #f9fafb; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-row { display: flex; gap: 10px; align-items: center; }

/* ---------- Template gallery ---------- */
.template-card {
  border: 2px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: border-color 0.15s;
  background: #fff;
}
.template-card:hover { border-color: var(--accent); }
.template-card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(16,185,129,0.15); }
.template-card iframe { width: 100%; height: 260px; border: none; pointer-events: none; background: #fff; }
.template-card-title { padding: 12px 14px; font-size: 14px; font-weight: 600; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.template-card-desc { padding: 0 14px 14px 14px; font-size: 12px; color: var(--text-muted); }
.template-card-actions { padding: 0 14px 14px 14px; display: flex; gap: 14px; font-size: 12.5px; }
.template-card-actions a { color: var(--accent-dark); text-decoration: none; font-weight: 600; cursor: pointer; }
.template-card-actions a:hover { text-decoration: underline; }
.badge-builtin { background: #e0e7ff; color: #4338ca; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }
.badge-custom { background: #d1fae5; color: #047857; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 700; }

/* ---------- Template Designer tabs ---------- */
.tabs { display: flex; gap: 6px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab-btn {
  background: none;
  border: none;
  padding: 10px 18px;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab-btn.active { color: var(--accent-dark); border-bottom-color: var(--accent); }
.tab-panel textarea#custom_html { white-space: pre; }

/* ---------- Tables ---------- */
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data-table th {
  text-align: left;
  padding: 10px 12px;
  background: #f9fafb;
  border-bottom: 1px solid var(--border);
  color: #374151;
  font-weight: 600;
}
table.data-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge-success { background: #d1fae5; color: #047857; }
.badge-error { background: #fee2e2; color: #b91c1c; }

/* ---------- Alerts ---------- */
.alert { padding: 13px 16px; border-radius: 8px; font-size: 14px; margin-bottom: 20px; }
.alert-success { background: #d1fae5; color: #047857; border: 1px solid #a7f3d0; }
.alert-error { background: #fee2e2; color: #b91c1c; border: 1px solid #fecaca; }

/* ---------- Compose page layout ---------- */
.compose-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  align-items: start;
  gap: 24px;
}
.live-preview-card { position: sticky; top: 20px; }

/* ---------- Rich text editor (Quill) ---------- */
#editorContainer {
  border-bottom-left-radius: 8px;
  border-bottom-right-radius: 8px;
  min-height: 160px;
  font-size: 14px;
}
.ql-toolbar.ql-snow {
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  border-color: var(--border) !important;
}
.ql-container.ql-snow { border-color: var(--border) !important; }

/* ---------- Saved contacts picker ---------- */
.contact-picker {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  max-height: 160px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fafafa;
}
.contact-checkbox {
  display: flex;
  align-items: center;
  gap: 6px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-dark);
}
.contact-checkbox input { width: auto; margin: 0; }
.contact-checkbox small { color: var(--text-muted); font-weight: 400; }

/* ---------- Attachments ---------- */
.attachment-list { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.attachment-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #f3f4f6;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 13px;
}
.attachment-remove {
  background: none;
  border: none;
  color: var(--danger);
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  padding: 0;
}

/* ---------- Mobile nav toggle ---------- */
.mobile-nav-toggle {
  display: none;
  position: fixed;
  top: 14px;
  left: 14px;
  z-index: 60;
  background: var(--sidebar-bg);
  color: #fff;
  border: none;
  width: 40px;
  height: 40px;
  border-radius: 8px;
  font-size: 18px;
  cursor: pointer;
}

/* ================= RESPONSIVE ================= */
@media (max-width: 1000px) {
  .compose-grid { grid-template-columns: 1fr; }
  .live-preview-card { position: static; }
}

@media (max-width: 860px) {
  .mobile-nav-toggle { display: block; }

  .layout { flex-direction: column; }

  .sidebar {
    position: fixed;
    top: 0;
    left: -260px;
    width: 240px;
    height: 100vh;
    z-index: 55;
    transition: left 0.2s ease;
    box-shadow: 4px 0 20px rgba(0,0,0,0.25);
  }
  .sidebar.open { left: 0; }

  .content { padding: 70px 16px 30px 16px; max-width: 100%; }

  .grid-3, .grid-2 { grid-template-columns: 1fr; }

  table.data-table { display: block; overflow-x: auto; white-space: nowrap; }

  .card { padding: 18px; }

  .btn-row { flex-wrap: wrap; }

  .template-card iframe { height: 110px; }
}

@media (max-width: 480px) {
  h1.page-title { font-size: 19px; }
  .login-card { padding: 30px 24px; }
  .stat-value { font-size: 22px; }
}

/* ---------- Login page ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #111827, #1f2937);
}
.login-card {
  background: #fff;
  border-radius: 14px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
}
.login-card h1 { font-size: 20px; margin: 0 0 4px 0; text-align: center; }
.login-card p.sub { text-align: center; color: var(--text-muted); font-size: 13px; margin: 0 0 24px 0; }
.login-card .btn { width: 100%; padding: 12px; margin-top: 6px; }
