:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1a202c;
  --muted: #718096;
  --primary: #2b6cb0;
  --primary-dark: #2c5282;
  --danger: #e53e3e;
  --success-bg: #c6f6d5;
  --success-text: #22543d;
  --error-bg: #fed7d7;
  --error-text: #742a2a;
}

* { box-sizing: border-box; }

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

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Topbar */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--card); border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px; position: sticky; top: 0; z-index: 10;
}
.brand a { font-weight: 700; font-size: 18px; color: var(--text); }
.nav { display: flex; gap: 18px; flex: 1; }
.nav a { color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); text-decoration: none; }
.user { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 14px; }

.container { max-width: 960px; margin: 24px auto; padding: 0 24px; }

/* Generic */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 28px 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }

.card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: 10px; padding: 20px; margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-block; background: #edf2f7; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 14px; font-size: 14px; cursor: pointer; font-weight: 500;
}
.btn:hover { background: #e2e8f0; text-decoration: none; }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-dark); }
.btn.danger { background: #fff; color: var(--danger); border-color: #feb2b2; }
.btn.danger:hover { background: #fff5f5; }
.btn.small { padding: 4px 10px; font-size: 13px; }
.link-btn { background: none; border: none; color: var(--muted); cursor: pointer; font-size: 14px; padding: 0; }
.link-btn:hover { color: var(--text); text-decoration: underline; }
.inline { display: inline; }

/* Forms */
label { display: block; margin-bottom: 12px; font-size: 14px; font-weight: 500; }
input, select, textarea {
  width: 100%; padding: 9px 11px; margin-top: 4px;
  border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
  font-family: inherit; background: #fff;
}
textarea { resize: vertical; }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; margin: 0; }
.row { display: flex; gap: 16px; flex-wrap: wrap; }
.row > label { flex: 1; min-width: 140px; }
.form-actions { display: flex; gap: 12px; margin-top: 8px; }
fieldset.schedule { border: 1px solid var(--border); border-radius: 8px; padding: 12px 16px; margin: 8px 0 16px; }
legend { font-weight: 600; font-size: 13px; padding: 0 6px; }
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar select { width: auto; min-width: 200px; }
.toolbar input[type=text] { flex: 1; min-width: 180px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 16px; font-size: 14px; }
.alert.success { background: var(--success-bg); color: var(--success-text); }
.alert.error { background: var(--error-bg); color: var(--error-text); }

/* Login */
.centered { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { width: 340px; }
.login-card h1 { font-size: 20px; margin-bottom: 4px; }

/* Message list */
.msg-list { list-style: none; padding: 0; margin: 0; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; background: var(--card); }
.msg-row { border-bottom: 1px solid var(--border); }
.msg-row:last-child { border-bottom: none; }
.msg-row a { display: grid; grid-template-columns: 180px 1fr auto; gap: 4px 16px; padding: 12px 16px; color: var(--text); align-items: baseline; }
.msg-row a:hover { background: #f7fafc; text-decoration: none; }
.msg-row.unread { background: #ebf8ff33; }
.msg-row.unread .msg-from, .msg-row.unread .msg-subject { font-weight: 700; }
.msg-from { color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-subject { font-weight: 500; }
.msg-snippet { grid-column: 2; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-meta { grid-column: 3; grid-row: 1 / span 2; text-align: right; display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.msg-date { color: var(--muted); font-size: 12px; }
.badge { background: #edf2f7; color: var(--muted); border-radius: 6px; padding: 1px 7px; font-size: 11px; }
.paperclip { font-size: 12px; }

/* Message view */
.message-subject { font-size: 20px; margin-bottom: 12px; }
.message-meta { font-size: 14px; color: var(--text); display: grid; gap: 2px; }
.message-meta strong { color: var(--muted); font-weight: 600; }
.message-body { margin-top: 12px; }
.html-body { width: 100%; min-height: 400px; border: none; }
.text-body { white-space: pre-wrap; word-wrap: break-word; font-family: inherit; font-size: 14px; }

/* Tables */
.table { width: 100%; border-collapse: collapse; background: var(--card); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.table th, .table td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); font-size: 14px; vertical-align: top; }
.table th { background: #f7fafc; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; }
.table tr:last-child td { border-bottom: none; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }

.status { font-size: 12px; padding: 2px 8px; border-radius: 6px; text-transform: capitalize; }
.status-pending { background: #feebc8; color: #7b341e; }
.status-sent { background: var(--success-bg); color: var(--success-text); }
.status-failed { background: var(--error-bg); color: var(--error-text); }
.status-canceled { background: #e2e8f0; color: var(--muted); }

/* Read vs unread rows */
.msg-row.read a { color: var(--muted); }
.msg-row.read .msg-from, .msg-row.read .msg-subject { color: var(--muted); font-weight: 400; }
.msg-row.read { background: #fbfcfd; }

/* Label chips */
.label-chip {
  display: inline-block; color: #fff; font-size: 11px; font-weight: 600;
  padding: 1px 8px; border-radius: 10px; margin-left: 4px; vertical-align: middle;
  text-shadow: 0 0 1px rgba(0,0,0,0.25);
}
.message-labels { margin: 12px 0; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.label-assign { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.label-check { display: inline-flex; align-items: center; gap: 4px; margin: 0; padding: 2px 6px; border: 1px solid var(--border); border-left-width: 3px; border-radius: 6px; font-weight: 400; cursor: pointer; }
.label-check input { width: auto; margin: 0; }
.label-edit { display: flex; align-items: center; gap: 6px; }
.label-edit .label-name-input { width: 160px; }
.label-edit input[type=color] { width: 36px; height: 32px; padding: 0; }

/* Pagination */
.pagination { display: flex; align-items: center; gap: 14px; justify-content: center; margin: 18px 0; }

/* Clickable table rows */
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #f7fafc; }

/* Rich text editor */
.editor { border: 1px solid var(--border); border-radius: 8px; margin-bottom: 12px; overflow: hidden; background: #fff; }
.editor-toolbar { display: flex; flex-wrap: wrap; align-items: center; gap: 2px; padding: 6px 8px; background: #f7fafc; border-bottom: 1px solid var(--border); }
.editor-toolbar button { background: #fff; border: 1px solid var(--border); border-radius: 6px; padding: 4px 9px; font-size: 13px; cursor: pointer; line-height: 1.2; color: var(--text); }
.editor-toolbar button:hover { background: #edf2f7; }
.editor-toolbar .sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }
.editor-toolbar .color-pick { display: inline-flex; align-items: center; gap: 3px; margin: 0; font-weight: 700; font-size: 13px; padding: 2px 6px; border: 1px solid var(--border); border-radius: 6px; background: #fff; cursor: pointer; }
.editor-toolbar .color-pick.hl { color: #b7791f; }
.editor-toolbar .color-pick input[type=color] { width: 22px; height: 20px; padding: 0; border: none; background: none; cursor: pointer; }
.editor-area { min-height: 240px; max-height: 480px; overflow-y: auto; padding: 12px 14px; font-size: 14px; line-height: 1.6; outline: none; }
.editor-area:focus { background: #fff; }
.editor-area a { color: var(--primary); }
.editor-area blockquote.reply-quote, .editor-area blockquote {
  margin: 8px 0 8px 2px; padding-left: 12px; border-left: 3px solid var(--border); color: #555;
}

.inline-details { display: inline-block; }
.inline-details summary { list-style: none; }
.pw-form { display: flex; gap: 6px; margin-top: 6px; }
.pw-form input { width: 160px; }

/* Dashboard */
.dash-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-top: 16px; }
.dash-card { display: flex; flex-direction: column; gap: 4px; background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 18px; color: var(--text); }
.dash-card:hover { border-color: var(--primary); text-decoration: none; box-shadow: 0 4px 14px rgba(0,0,0,0.05); }
.dash-ico { font-size: 26px; }
.module-form { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.module-form .check { margin: 0; font-weight: 400; }

/* Campaign UI */
.stats-row { display: flex; flex-wrap: wrap; gap: 24px; align-items: baseline; }
.stat { font-size: 14px; color: var(--muted); }
.stat-num { font-size: 22px; font-weight: 700; color: var(--text); margin-right: 4px; }
.content-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.content-item:last-child { border-bottom: none; }
.content-preview { max-height: 60px; overflow: hidden; max-width: 600px; }
.danger-zone { border-color: #feb2b2; }

/* Form section heading */
h3.form-section { font-size: 14px; margin: 20px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--border); color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }

/* ---------- Mobile responsiveness ---------- */
@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap; height: auto; padding: 8px 14px; gap: 10px 16px;
  }
  .brand { width: 100%; }
  .nav { width: 100%; gap: 14px; overflow-x: auto; white-space: nowrap; -webkit-overflow-scrolling: touch; padding-bottom: 4px; }
  .user { width: 100%; justify-content: space-between; }

  .container { padding: 0 14px; margin: 16px auto; }
  .page-head { flex-wrap: wrap; }
  h1 { font-size: 19px; }

  /* Filters / toolbars stack full width */
  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar select, .toolbar input[type=text], .toolbar .btn { width: 100%; min-width: 0; }

  /* Form rows stack */
  .row { flex-direction: column; gap: 0; }
  .row > label { min-width: 0; }
  .form-actions { flex-wrap: wrap; }
  .form-actions .btn { flex: 1; text-align: center; }

  /* Message list collapses to a stacked card */
  .msg-row a { grid-template-columns: 1fr; gap: 2px; padding: 12px 14px; }
  .msg-from { white-space: normal; }
  .msg-snippet { grid-column: 1; white-space: normal; }
  .msg-meta { grid-column: 1; grid-row: auto; text-align: left; flex-direction: row; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }

  /* Tables scroll horizontally instead of overflowing */
  .table { display: block; overflow-x: auto; white-space: nowrap; }

  /* Editor + message view */
  .editor-area { min-height: 180px; }
  .html-body { min-height: 300px; }
  .message-subject { font-size: 18px; }
  .pagination { gap: 10px; }
}
