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

:root {
  --bg: #f5f6fa;
  --sidebar-bg: #1e1e2e;
  --sidebar-hover: #2a2a3e;
  --accent: #6366f1;
  --accent-light: #eef2ff;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --card-shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --radius: 10px;
  --radius-sm: 6px;
}

body { font-family: 'Inter', 'Segoe UI', system-ui, sans-serif; background: var(--bg); color: var(--text); font-size: 14.5px; line-height: 1.55; }

/* ── Layout ───────────────────────────────────────────────── */
.app { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: 246px; flex-shrink: 0;
  background: var(--sidebar-bg);
  display: flex; flex-direction: column;
  overflow-y: auto;
}

.sidebar-logo {
  padding: 22px 20px 18px;
  font-size: 16px; font-weight: 700; color: #fff;
  letter-spacing: .3px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  display: flex; align-items: center; gap: 8px;
}

.sidebar-section { padding: 13px 12px 5px; font-size: 10.5px; font-weight: 700; color: rgba(255,255,255,.34); letter-spacing: 1.1px; text-transform: uppercase; }

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 15px; margin: 2px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer; font-size: 14.5px; color: rgba(255,255,255,.68);
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--accent); color: #fff; }
.nav-item .icon { font-size: 16px; width: 22px; text-align: center; }
.nav-item .icon svg,
.sidebar-logo .icon-mark svg {
  width: 18px;
  height: 18px;
  display: block;
  stroke: currentColor;
}
.sidebar-logo .icon-mark {
  width: 22px;
  height: 22px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 10px; padding: 1px 6px; font-size: 10px; font-weight: 700; }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  background: #fff; border-bottom: 1px solid var(--border);
  padding: 0 24px; height: 56px;
  display: flex; align-items: center; justify-content: space-between;
  flex-shrink: 0;
}
.topbar-title { font-size: 17px; font-weight: 700; color: var(--text); }
.topbar-actions { display: flex; gap: 8px; align-items: center; }

.content { flex: 1; padding: 24px; overflow-y: auto; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: #fff; border-radius: var(--radius);
  box-shadow: var(--card-shadow); border: 1px solid var(--border);
  margin-bottom: 20px;
}
.card-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.card-title { font-size: 14px; font-weight: 600; color: var(--text); }
.card-body { padding: 20px; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 14px; border: none; border-radius: var(--radius-sm);
  cursor: pointer; font-size: 13px; font-weight: 500;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
.btn:hover { opacity: .88; }
.btn:active { transform: scale(.97); }
.btn-primary { background: var(--accent); color: #fff; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-ghost   { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--bg); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-icon { padding: 6px; border-radius: var(--radius-sm); background: transparent; border: 1px solid var(--border); cursor: pointer; color: var(--text-muted); }
.btn-icon:hover { background: var(--bg); color: var(--text); }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 14px; text-align: left; font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; background: #fafafa; border-bottom: 1px solid var(--border); }
td { padding: 11px 14px; border-bottom: 1px solid #f1f5f9; color: var(--text); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #f8faff; }

/* ── Badges / Tags ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-gray      { background: #f1f5f9; color: #64748b; }
.badge-blue      { background: #dbeafe; color: #1d4ed8; }
.badge-yellow    { background: #fef9c3; color: #854d0e; }
.badge-green     { background: #dcfce7; color: #166534; }
.badge-red       { background: #fee2e2; color: #991b1b; }
.badge-orange    { background: #ffedd5; color: #9a3412; }
.badge-purple    { background: #ede9fe; color: #5b21b6; }
.badge-orange    { background: #ffedd5; color: #9a3412; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 5px; text-transform: uppercase; letter-spacing: .4px; }
.form-control {
  width: 100%; padding: 8px 11px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text); background: #fff;
  transition: border-color .15s, box-shadow .15s;
  outline: none;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,.12); }
textarea.form-control { height: 100px; resize: vertical; }
.form-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ── Modal ────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(15,23,42,.5); backdrop-filter: blur(2px);
  z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
  background: #fff; border-radius: 14px;
  width: 520px; max-width: 95vw; max-height: 90vh;
  overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.2);
  animation: modalIn .18s ease;
}
@keyframes modalIn { from { opacity:0; transform:scale(.96) translateY(8px); } to { opacity:1; transform:none; } }
.modal-header { padding: 20px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-size: 15px; font-weight: 700; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); font-size: 18px; padding: 4px; border-radius: 4px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-body { padding: 20px 24px 24px; }

/* ── Pagination ───────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 6px; margin-top: 16px; font-size: 13px; color: var(--text-muted); }
.pagination button { padding: 5px 12px; border: 1px solid var(--border); background: #fff; border-radius: var(--radius-sm); cursor: pointer; font-size: 12px; }
.pagination button:hover:not(:disabled) { background: var(--accent-light); border-color: var(--accent); color: var(--accent); }
.pagination button:disabled { opacity: .4; cursor: default; }

/* ── Stats Grid ───────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; text-align: center; }
.stat-card .num { font-size: 26px; font-weight: 700; color: var(--accent); }
.stat-card .lbl { font-size: 11px; color: var(--text-muted); margin-top: 4px; font-weight: 500; }

/* ── Mail Two-Panel ───────────────────────────────────────── */
.mail-layout { display: flex; height: calc(100vh - 104px); gap: 0; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--border); background: #fff; }
.mail-sidebar { width: 270px; flex-shrink: 0; border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; }
.mail-sidebar-header { padding: 14px 16px; font-size: 12px; font-weight: 600; color: var(--text-muted); border-bottom: 1px solid var(--border); text-transform: uppercase; letter-spacing: .5px; display: flex; justify-content: space-between; align-items: center; }
.mail-contact-item { padding: 12px 16px; cursor: pointer; border-bottom: 1px solid #f8fafc; transition: background .12s; }
.mail-contact-item:hover { background: #f8faff; }
.mail-contact-item.active { background: var(--accent-light); border-left: 3px solid var(--accent); }
.mail-contact-item .name { font-size: 13px; font-weight: 600; color: var(--text); }
.mail-contact-item .meta { font-size: 11px; color: var(--text-muted); margin-top: 3px; display: flex; justify-content: space-between; align-items: center; }
.unread-dot { width: 7px; height: 7px; background: var(--accent); border-radius: 50%; display: inline-block; margin-right: 4px; }
.mail-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.mail-main-header { padding: 12px 18px; border-bottom: 1px solid var(--border); font-size: 13px; font-weight: 600; color: var(--text); display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.mail-list { flex: 1; overflow-y: auto; }
.mail-item { padding: 13px 18px; border-bottom: 1px solid #f1f5f9; cursor: pointer; transition: background .12s; position: relative; }
.mail-item:hover { background: #f8faff; }
.mail-item.unread { background: #fefce8; }
.mail-item .subject { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 3px; }
.mail-item.unread .subject::before { content: ''; display: inline-block; width: 6px; height: 6px; background: var(--accent); border-radius: 50%; margin-right: 6px; vertical-align: middle; }
.mail-item .preview { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90%; }
.mail-item .time { position: absolute; top: 13px; right: 18px; font-size: 11px; color: #94a3b8; }
.mail-item-actions { position: absolute; top: 10px; right: 18px; display: none; gap: 6px; }
.mail-item:hover .mail-item-actions { display: inline-flex; }
.mail-item:hover .time { display: none; }
.sent-mail-preview { display: flex; flex-direction: column; gap: 14px; }
.sent-mail-meta { display: grid; gap: 6px; padding: 12px; background: #f8fafc; border: 1px solid var(--border); border-radius: var(--radius-sm); }
.sent-mail-frame { min-height: 420px; }
.sent-mail-frame iframe { min-height: 420px; background: #fff; }

/* ── Toolbar strip ────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar-sep { width: 1px; height: 20px; background: var(--border); margin: 0 4px; }

/* ── Alert ────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: var(--radius-sm); font-size: 13px; margin-bottom: 12px; }
.alert-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-info { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ── Toast ────────────────────────────────────────────────── */
#toast {
  position: fixed; bottom: 28px; right: 28px;
  padding: 11px 18px; border-radius: 10px;
  font-size: 13px; font-weight: 500; color: #fff;
  display: none; z-index: 9999;
  box-shadow: 0 8px 24px rgba(0,0,0,.18);
  animation: toastIn .2s ease;
}
@keyframes toastIn { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:none; } }

/* ── Template Editor Overlay ──────────────────────────────── */
#tpl-editor-overlay { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 300; flex-direction: column; }
#tpl-editor-overlay.show { display: flex; }
.tpl-topbar { background: var(--sidebar-bg); color: #fff; padding: 10px 20px; display: flex; align-items: center; gap: 12px; flex-shrink: 0; min-height: 64px; }
.tpl-topbar input { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.2); color: #fff; padding: 7px 11px; border-radius: var(--radius-sm); font-size: 13px; outline: none; }
.tpl-topbar input:focus { border-color: var(--accent); background: rgba(255,255,255,.15); }
.tpl-topbar input::placeholder { color: rgba(255,255,255,.4); }
.tpl-body { flex: 1; display: flex; overflow: hidden; }
.tpl-editor-pane { flex: 1; display: flex; flex-direction: column; padding: 12px; overflow: hidden; gap: 0; }
.tpl-preview-pane { width: 380px; background: #fff; border-left: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px; overflow-y: auto; gap: 0; }
.tpl-preview-pane h4 { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 8px; }
#quill-editor { flex: 1; overflow-y: auto; background: #fff; border-radius: 0 0 var(--radius-sm) var(--radius-sm); min-height: 300px; }
.ql-toolbar.ql-snow { border-radius: var(--radius-sm) var(--radius-sm) 0 0 !important; border-color: var(--border) !important; background: #fafafa; }
.ql-container.ql-snow { border-color: var(--border) !important; }
.preview-frame { flex: 1; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; min-height: 280px; }
.preview-frame iframe { width: 100%; height: 100%; border: none; min-height: 280px; }

/* ── Contact Avatar ───────────────────────────────────────── */
.avatar { width: 32px; height: 32px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; color: #fff; flex-shrink: 0; }

/* ── Empty State ──────────────────────────────────────────── */
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .icon { font-size: 40px; margin-bottom: 12px; }
.empty-state p { font-size: 13px; }

/* ── Scrollbar ────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .nav-item span { display: none; }
  .sidebar-logo span { display: none; }
  .sidebar-section { display: none; }
}

/* Login */
.login-page {
  min-height: 100vh;
  position: relative;
  display: grid;
  grid-template-columns: 1fr .92fr;
  background:
    radial-gradient(circle at top left, rgba(99,102,241,.16), transparent 34%),
    radial-gradient(circle at bottom right, rgba(16,185,129,.14), transparent 32%),
    linear-gradient(135deg, #f8fafc 0%, #eef2ff 52%, #f8fafc 100%);
}
.login-particles {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  opacity: .9;
}
.login-hero {
  padding: 64px 70px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
  z-index: 1;
}
.login-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.72);
  border: 1px solid rgba(99,102,241,.18);
  color: #4338ca;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .6px;
  text-transform: uppercase;
}
.login-title {
  margin-top: 22px;
  font-size: 48px;
  line-height: 1.05;
  color: #0f172a;
  font-weight: 800;
  max-width: 620px;
}
.login-subtitle {
  margin-top: 18px;
  max-width: 560px;
  font-size: 17px;
  line-height: 1.9;
  color: #475569;
}
.timezone-grid {
  margin-top: 28px;
  max-width: 660px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}
.timezone-card {
  padding: 18px 18px 16px;
  border-radius: 18px;
  background: rgba(255,255,255,.78);
  border: 1px solid rgba(226,232,240,.92);
  box-shadow: 0 12px 30px rgba(15,23,42,.05);
  backdrop-filter: blur(8px);
}
.timezone-city {
  font-size: 14px;
  font-weight: 700;
  color: #0f172a;
}
.timezone-region {
  margin-top: 4px;
  font-size: 12px;
  color: #64748b;
  letter-spacing: .2px;
}
.timezone-time {
  margin-top: 12px;
  font-size: 34px;
  line-height: 1;
  font-weight: 800;
  color: #1e293b;
}
.timezone-date {
  margin-top: 8px;
  font-size: 12px;
  color: #475569;
}
.login-points {
  margin-top: 28px;
  display: grid;
  gap: 14px;
  max-width: 520px;
}
.login-point {
  padding: 16px 18px;
  border-radius: 16px;
  background: rgba(255,255,255,.74);
  border: 1px solid #e2e8f0;
  box-shadow: 0 10px 28px rgba(15,23,42,.04);
}
.login-point-title {
  font-size: 14px;
  font-weight: 700;
  color: #111827;
}
.login-point-text {
  margin-top: 4px;
  font-size: 13px;
  line-height: 1.7;
  color: #64748b;
}
.login-panel-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 32px;
  position: relative;
  z-index: 1;
}
.login-panel {
  width: 100%;
  max-width: 420px;
  padding: 36px 32px 30px;
  border-radius: 24px;
  background: rgba(255,255,255,.86);
  border: 1px solid rgba(226,232,240,.9);
  box-shadow: 0 26px 64px rgba(15,23,42,.12);
  backdrop-filter: blur(8px);
}
.login-panel h1 {
  font-size: 28px;
  line-height: 1.15;
  color: #0f172a;
  margin-bottom: 10px;
}
.login-panel p {
  color: #64748b;
  font-size: 14px;
  line-height: 1.8;
}
.login-error {
  display: none;
  margin-top: 14px;
  padding: 10px 12px;
  border-radius: 12px;
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  font-size: 13px;
}
.logout-btn {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
}
.logout-btn:hover {
  background: #f8fafc;
  color: var(--text);
}
@media (max-width: 980px) {
  .login-page { grid-template-columns: 1fr; }
  .login-hero { padding: 40px 28px 12px; }
  .login-title { font-size: 38px; max-width: none; }
  .timezone-grid { grid-template-columns: 1fr; max-width: none; }
  .login-panel-wrap { padding: 16px 20px 40px; }
}
