/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:        #1a56db;
  --primary-dark:   #1342b0;
  --primary-light:  #e8f0fe;
  --success:        #0e9f6e;
  --success-light:  #d1fae5;
  --danger:         #e02424;
  --danger-light:   #fee2e2;
  --warning:        #d97706;
  --warning-light:  #fef3c7;
  --info:           #0891b2;
  --info-light:     #e0f2fe;
  --bg:             #f3f4f6;
  --surface:        #ffffff;
  --border:         #e5e7eb;
  --border-dark:    #d1d5db;
  --text:           #111827;
  --text-mid:       #374151;
  --text-light:     #6b7280;
  --sidebar-w:      240px;
  --header-h:       60px;
  --radius:         10px;
  --shadow:         0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.06);
}

html { font-size: 15px; }
body { font-family: 'Inter', Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); line-height: 1.6; }
a { color: var(--primary); }

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

.sidebar {
  width: var(--sidebar-w);
  background: #1e2433;
  color: #c9d1e0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
}
.sidebar-logo svg { color: var(--primary); flex-shrink: 0; }
.sidebar-logo-text { font-size: .95rem; font-weight: 700; color: #fff; line-height: 1.2; }
.sidebar-logo-sub  { font-size: .7rem; color: #8896b0; font-weight: 400; }

.sidebar-section { padding: 12px 0 4px; }
.sidebar-section-label {
  font-size: .68rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #5a6a85;
  padding: 0 16px 6px;
}

.sidebar-nav { list-style: none; }
.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: .88rem;
  color: #a8b4c8;
  text-decoration: none;
  border-radius: 6px;
  margin: 1px 8px;
  transition: background .15s, color .15s;
}
.sidebar-nav a:hover { background: rgba(255,255,255,.07); color: #fff; }
.sidebar-nav a.active { background: var(--primary); color: #fff; }
.sidebar-nav a svg { flex-shrink: 0; opacity: .8; }
.sidebar-nav a.active svg { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 12px 8px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: .85rem;
  color: #8896b0;
  text-decoration: none;
  border-radius: 6px;
  transition: background .15s, color .15s;
}
.sidebar-footer a:hover { background: rgba(255,255,255,.07); color: #fff; }

.main-wrap {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.topbar-user {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .85rem;
  color: var(--text-mid);
}
.topbar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: .8rem;
  flex-shrink: 0;
}

.impersonate-bar {
  background: #fbbf24;
  color: #78350f;
  font-size: .82rem;
  font-weight: 600;
  padding: 6px 28px;
  display: flex;
  align-items: center;
  gap: 12px;
}
.impersonate-bar a { color: #78350f; font-weight: 700; }

.page-content { padding: 28px; flex: 1; max-width: 1400px; width: 100%; }

/* ── Page header ──────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
  flex-wrap: wrap;
}
.page-header h1 { font-size: 1.45rem; font-weight: 700; color: var(--text); }
.page-header p  { font-size: .88rem; color: var(--text-light); margin-top: 2px; }

/* ── Cards ────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-header h2, .card-header h3 { font-size: 1rem; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }

/* ── Stats grid ───────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.stat-icon.blue   { background: var(--primary-light); color: var(--primary); }
.stat-icon.green  { background: var(--success-light); color: var(--success); }
.stat-icon.yellow { background: var(--warning-light); color: var(--warning); }
.stat-icon.red    { background: var(--danger-light);  color: var(--danger);  }
.stat-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-light); margin-top: 2px; }

/* ── Tables ───────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .875rem; }
thead tr { border-bottom: 2px solid var(--border); }
th { padding: 11px 16px; text-align: left; font-size: .75rem; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--text-light); white-space: nowrap; }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafafa; }

/* ── Badges ───────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: .73rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge-sent    { background: var(--success-light); color: var(--success); }
.badge-draft   { background: #f3f4f6; color: var(--text-light); }
.badge-admin   { background: var(--primary-light); color: var(--primary); }
.badge-user    { background: #f3f4f6; color: var(--text-light); }
.badge-trial   { background: var(--warning-light); color: var(--warning); }
.badge-starter { background: var(--info-light); color: var(--info); }
.badge-pro     { background: var(--primary-light); color: var(--primary); }
.badge-enterprise { background: #f3e8ff; color: #7c3aed; }

/* ── Buttons ──────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 7px;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1.5px solid transparent;
  text-decoration: none;
  transition: background .15s, border-color .15s, color .15s, opacity .15s;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary  { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success  { background: var(--success); color: #fff; border-color: var(--success); }
.btn-success:hover:not(:disabled) { background: #0b8060; }
.btn-danger   { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover:not(:disabled)  { background: #b91c1c; }
.btn-outline  { background: transparent; color: var(--text-mid); border-color: var(--border-dark); }
.btn-outline:hover:not(:disabled) { background: var(--bg); border-color: var(--text-light); }
.btn-sm  { padding: 5px 11px; font-size: .8rem; border-radius: 6px; }
.btn-lg  { padding: 11px 22px; font-size: .95rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── Forms ────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-label { display: block; font-size: .84rem; font-weight: 500; color: var(--text-mid); margin-bottom: 5px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border-dark);
  border-radius: 7px;
  font-size: .875rem;
  color: var(--text);
  background: var(--surface);
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,86,219,.12); }
textarea.form-control { resize: vertical; min-height: 80px; }
.form-hint { font-size: .78rem; color: var(--text-light); margin-top: 4px; }

.colour-row { display: flex; align-items: center; gap: 10px; }

/* ── Alerts ───────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: 8px;
  font-size: .875rem;
  margin-bottom: 16px;
  border: 1px solid transparent;
}
.alert-success { background: var(--success-light); color: #065f46; border-color: #a7f3d0; }
.alert-danger  { background: var(--danger-light);  color: #991b1b; border-color: #fca5a5; }
.alert-warning { background: var(--warning-light); color: #92400e; border-color: #fcd34d; }
.alert-info    { background: var(--info-light);    color: #0e4f6a; border-color: #7dd3fc; }

/* ── Modals ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  overflow-y: auto;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.22);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  animation: modal-in .18s ease;
}
@keyframes modal-in { from { opacity:0; transform:translateY(-12px); } to { opacity:1; transform:none; } }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.4rem; cursor: pointer; color: var(--text-light); line-height: 1; padding: 0 4px; }
.modal-body   { padding: 20px 22px; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Tabs ─────────────────────────────────────────────── */
.tabs { display: flex; gap: 4px; margin-bottom: 20px; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.tab-btn {
  background: none;
  border: none;
  padding: 8px 14px;
  font-size: .84rem;
  font-weight: 500;
  color: var(--text-light);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color .15s, border-color .15s;
}
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Compose layout ───────────────────────────────────── */
.compose-layout {
  display: grid;
  grid-template-columns: 380px 1fr;
  gap: 20px;
  align-items: start;
}
.compose-panel { position: sticky; top: calc(var(--header-h) + 20px); }

/* ── Preview frame ────────────────────────────────────── */
.preview-frame-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  gap: 8px;
}
.preview-toolbar h3 { font-size: .95rem; font-weight: 600; }
#preview-placeholder { display: none; }

/* ── AI Chat ──────────────────────────────────────────── */
.ai-chat {
  max-height: 220px;
  overflow-y: auto;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.ai-msg {
  padding: 9px 13px;
  border-radius: 8px;
  font-size: .84rem;
  max-width: 88%;
  line-height: 1.5;
}
.ai-msg.user   { background: var(--primary); color: #fff; align-self: flex-end; }
.ai-msg.ai     { background: var(--bg); color: var(--text-mid); align-self: flex-start; border: 1px solid var(--border); }
.ai-msg.system { background: var(--success-light); color: #065f46; align-self: center; font-size: .78rem; border-radius: 20px; padding: 5px 12px; }

/* ── Image upload ─────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border-dark);
  border-radius: 8px;
  padding: 24px;
  text-align: center;
  cursor: pointer;
  color: var(--text-light);
  transition: border-color .15s, background .15s;
  font-size: .84rem;
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--primary); background: var(--primary-light); }
.drop-zone svg { margin-bottom: 8px; opacity: .5; }
.image-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.image-thumb { position: relative; width: 72px; height: 72px; border-radius: 6px; overflow: hidden; border: 1px solid var(--border); }
.image-thumb img { width: 100%; height: 100%; object-fit: cover; }
.remove-img {
  position: absolute;
  top: 2px; right: 2px;
  background: rgba(0,0,0,.6);
  color: #fff;
  border: none;
  border-radius: 50%;
  width: 18px; height: 18px;
  font-size: .75rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

/* ── Login page ───────────────────────────────────────── */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #1e2433 0%, #1a56db 100%);
  padding: 24px;
}
.login-card {
  background: var(--surface);
  border-radius: 14px;
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo svg { color: var(--primary); margin-bottom: 10px; }
.login-logo h1  { font-size: 1.4rem; font-weight: 800; color: var(--text); }
.login-logo p   { font-size: .85rem; color: var(--text-light); margin-top: 4px; }

/* ── Spinner ──────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ───────────────────────────────────────── */
@media (max-width: 900px) {
  .compose-layout { grid-template-columns: 1fr; }
  .compose-panel  { position: static; }
  .form-row       { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: none; }
  .main-wrap { margin-left: 0; }
  .page-content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
