/* ── Variables ────────────────────────────────────────────────────────────── */
:root {
  --sidebar-w: 240px;
  --sidebar-bg: #0f172a;
  --sidebar-text: #94a3b8;
  --sidebar-active: #2563eb;
  --sidebar-hover: #1e293b;
  --topbar-h: 54px;
  --content-bg: #f1f5f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text-main: #0f172a;
  --text-muted: #64748b;
}

/* ── Base ─────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

body {
  background: var(--content-bg);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 0.9rem;
  color: var(--text-main);
  margin: 0;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  z-index: 1000;
  transition: width .25s ease;
  overflow: hidden;
}

.sidebar-header {
  padding: 18px 16px;
  border-bottom: 1px solid #1e293b;
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  text-decoration: none;
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  white-space: nowrap;
}

.sidebar-brand i {
  font-size: 1.3rem;
  color: #60a5fa;
  flex-shrink: 0;
}

.sidebar-nav {
  list-style: none;
  padding: 10px 0;
  margin: 0;
  flex: 1;
  overflow-y: auto;
}

.sidebar-nav li { width: 100%; }

.sidebar-nav .nav-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  margin: 2px 8px;
  border-radius: 8px;
  color: var(--sidebar-text);
  text-decoration: none;
  transition: background .15s, color .15s;
  white-space: nowrap;
  font-size: .875rem;
}

.sidebar-nav .nav-link i {
  font-size: 1rem;
  width: 20px;
  text-align: center;
  flex-shrink: 0;
}

.sidebar-nav .nav-link:hover { background: var(--sidebar-hover); color: #fff; }
.sidebar-nav .nav-link.active { background: var(--sidebar-active); color: #fff; }
.sidebar-nav .logout-link:hover { color: #f87171; background: rgba(248,113,113,.1); }

.nav-section {
  padding: 14px 16px 4px;
  font-size: .7rem;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: #475569;
  white-space: nowrap;
}

.nav-divider {
  height: 1px;
  background: #1e293b;
  margin: 8px 16px;
}

/* Collapsed sidebar */
.sidebar.collapsed { width: 56px; }
.sidebar.collapsed .sidebar-brand span,
.sidebar.collapsed .nav-link span,
.sidebar.collapsed .nav-section { display: none; }
.sidebar.collapsed .nav-link { justify-content: center; padding: 9px 0; margin: 2px 8px; }

/* ── Main content ─────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  width: calc(100% - var(--sidebar-w));
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  transition: margin-left .25s, width .25s;
}

.main-content.expanded {
  margin-left: 56px;
  width: calc(100% - 56px);
}

/* ── Top bar ──────────────────────────────────────────────────────────────── */
.top-bar {
  height: var(--topbar-h);
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 3px rgba(0,0,0,.05);
}

.btn-toggle {
  background: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 9px;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  transition: background .15s;
}
.btn-toggle:hover { background: var(--content-bg); }

.breadcrumb { font-size: .83rem; }
.breadcrumb-item + .breadcrumb-item::before { color: #cbd5e1; }

/* ── Content wrapper ──────────────────────────────────────────────────────── */
.content-wrapper { padding: 24px; flex: 1; }

/* ── Page header ──────────────────────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 22px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text-main);
}

/* ── Stat cards ───────────────────────────────────────────────────────────── */
.stat-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 22px 24px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  display: flex;
  align-items: center;
  gap: 18px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-body .stat-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  line-height: 1;
}

.stat-body .stat-label {
  font-size: .8rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Table card ───────────────────────────────────────────────────────────── */
.table-card {
  background: var(--card-bg);
  border-radius: 12px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
  overflow: hidden;
}

.table-card-header {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}

.table-card-header h5 {
  margin: 0;
  font-size: 1rem;
  font-weight: 700;
}

.table-card .table {
  margin: 0;
  font-size: .875rem;
}

.table-card .table thead th {
  background: #f8fafc;
  font-size: .73rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  padding: 11px 16px;
  white-space: nowrap;
}

.table-card .table tbody td {
  padding: 13px 16px;
  vertical-align: middle;
  border-bottom: 1px solid #f1f5f9;
}

.table-card .table tbody tr:last-child td { border-bottom: none; }
.table-card .table tbody tr:hover { background: #f8fafc; }

/* Row urgency */
.row-critical { background: #fff5f5 !important; }
.row-warning  { background: #fffbeb !important; }

/* ── Days badge ───────────────────────────────────────────────────────────── */
.days-badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .78rem;
  font-weight: 700;
}
.days-badge.expired { background:#f1f5f9; color:#64748b; }
.days-badge.danger  { background:#fef2f2; color:#dc2626; }
.days-badge.warning { background:#fffbeb; color:#d97706; }
.days-badge.success { background:#f0fdf4; color:#16a34a; }

/* ── Form card ────────────────────────────────────────────────────────────── */
.form-card {
  background: var(--card-bg);
  border-radius: 12px;
  padding: 30px 32px;
  border: 1px solid var(--border);
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}

.form-label { font-weight: 500; font-size: .85rem; color: var(--text-main); }
.form-control, .form-select {
  font-size: .875rem;
  border-color: var(--border);
  border-radius: 7px;
}
.form-control:focus, .form-select:focus {
  border-color: var(--sidebar-active);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

/* ── Login page ───────────────────────────────────────────────────────────── */
.login-wrapper {
  min-height: 100vh;
  background: linear-gradient(135deg, #0f172a 0%, #1e3a5f 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 60px rgba(0,0,0,.35);
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}

.login-logo i {
  font-size: 2.5rem;
  color: var(--sidebar-active);
}

.login-logo h3 {
  margin: 8px 0 0;
  font-size: 1.2rem;
  font-weight: 700;
}

/* ── Empty state ──────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 60px 24px;
  color: #94a3b8;
}
.empty-state i { font-size: 3rem; margin-bottom: 14px; display: block; }
.empty-state p { margin: 0; font-size: .9rem; }

/* ── Options checkboxes ───────────────────────────────────────────────────── */
.option-item {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.option-item:hover { background: #f8fafc; }
.option-item input[type=checkbox]:checked ~ * { color: var(--sidebar-active); }
.option-item.selected { border-color: var(--sidebar-active); background: #eff6ff; }

/* ── Email preview panel ──────────────────────────────────────────────────── */
.preview-panel {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: #e8edf2;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: calc(var(--topbar-h) + 16px);
  max-height: calc(100vh - var(--topbar-h) - 32px);
}

.preview-panel-header {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 10px;
}

.preview-live-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #22c55e;
  animation: pulse-dot 2s ease-in-out infinite;
  flex-shrink: 0;
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

.preview-badge {
  font-size: .68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--text-muted);
}

.preview-subject-wrap {
  flex: 1;
  min-width: 0;
}

.preview-subject-label {
  font-size: .7rem;
  color: var(--text-muted);
  line-height: 1;
  margin-bottom: 2px;
}

.preview-subject-value {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.preview-iframe-wrap {
  flex: 1;
  overflow: hidden;
}

#emailPreview {
  width: 100%;
  height: 100%;
  min-height: 520px;
  border: none;
  display: block;
  background: #f1f5f9;
}

/* ── Quill WYSIWYG ────────────────────────────────────────────────────────── */
.ql-toolbar.ql-snow {
  border-radius: 7px 7px 0 0;
  border-color: var(--border);
  background: #f8fafc;
  padding: 6px 8px;
}
.ql-container.ql-snow {
  border-radius: 0 0 7px 7px;
  border-color: var(--border);
  font-family: inherit;
  font-size: .875rem;
}
.ql-container.ql-snow:focus-within {
  border-color: var(--sidebar-active);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.ql-editor {
  min-height: 300px;
  line-height: 1.8;
  color: var(--text-main);
}
.ql-editor p { margin-bottom: .5em; }
.ql-toolbar .ql-formats { margin-right: 8px; }
.ql-snow .ql-picker { font-size: .8rem; }
.ql-snow .ql-stroke { stroke: var(--text-muted); }
.ql-snow .ql-fill  { fill:   var(--text-muted); }
.ql-snow .ql-picker-label { color: var(--text-muted); }
.ql-snow .ql-active .ql-stroke,
.ql-snow button:hover .ql-stroke { stroke: var(--sidebar-active); }
.ql-snow .ql-active .ql-fill,
.ql-snow button:hover .ql-fill   { fill:   var(--sidebar-active); }
.ql-snow.ql-toolbar button:hover,
.ql-snow .ql-toolbar button:hover,
.ql-snow.ql-toolbar .ql-picker-label:hover {
  color: var(--sidebar-active);
}
/* WYSIWYG / HTML mode toggle bar */
.editor-mode-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 6px;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 56px; }
  .sidebar .sidebar-brand span,
  .sidebar .nav-link span,
  .sidebar .nav-section { display: none; }
  .sidebar .nav-link { justify-content: center; padding: 9px 0; }
  .main-content { margin-left: 56px; width: calc(100% - 56px); }
  .content-wrapper { padding: 16px; }
}
