:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --text: #1a2332;
  --text-muted: #5c6b7a;
  --border: #e2e8f0;
  --accent: #2d5a7b;
  --accent-hover: #234a66;
  --success: #0d7a4d;
  --warning: #b45309;
  --error: #b42318;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(26, 35, 50, 0.08);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
}

a {
  color: var(--accent);
}

.site-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: var(--shadow);
}

.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0.875rem 1.25rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  text-decoration: none;
  color: var(--text);
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  border-radius: 6px;
  font-size: 1.1rem;
}

.brand-mark.lg {
  width: 48px;
  height: 48px;
  font-size: 1.4rem;
}

.brand-text {
  font-weight: 600;
  font-size: 1rem;
}

.brand-sub {
  font-weight: 400;
  color: var(--text-muted);
}

.header-nav {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.user-email {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1.5rem 1.25rem 3rem;
}

.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: var(--shadow);
}

.section h2 {
  margin: 0 0 0.5rem;
  font-size: 1.125rem;
}

.section-desc,
.text-muted {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.section-header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.section-header h2 {
  margin: 0;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.stat-card {
  padding: 1rem;
  background: var(--bg);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}

.stat-card.stat-success .stat-value {
  color: var(--success);
}

.stat-card.stat-warning .stat-value {
  color: var(--warning);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
}

.form-stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

.form-group {
  flex: 1;
  min-width: 160px;
}

.form-group.flex-2 {
  flex: 2;
  min-width: 220px;
}

.form-group label {
  display: block;
  font-size: 0.875rem;
  font-weight: 500;
  margin-bottom: 0.35rem;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="file"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font: inherit;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.upload-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: center;
}

.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.5rem 1rem;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  border-radius: 6px;
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  min-height: 44px;
  transition: background 0.15s, border-color 0.15s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--bg);
  border-color: var(--border);
  color: var(--text);
}

.btn-secondary:hover:not(:disabled) {
  background: #eef1f5;
}

.btn-danger {
  background: #fef2f2;
  border-color: #fecaca;
  color: var(--error);
}

.btn-ghost {
  background: transparent;
  border-color: var(--border);
  color: var(--text-muted);
}

.btn-sm {
  min-height: 36px;
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.inline-form {
  display: inline;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 0.75rem;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.data-table th,
.data-table td {
  padding: 0.6rem 0.75rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--bg);
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
  text-transform: capitalize;
}

.badge-pending {
  background: #eef2ff;
  color: #3730a3;
}

.badge-sent {
  background: #ecfdf5;
  color: var(--success);
}

.badge-failed,
.badge-invalid {
  background: #fef2f2;
  color: var(--error);
}

.badge-running {
  background: #eff6ff;
  color: var(--accent);
}

.badge-paused,
.badge-draft,
.badge-stopped,
.badge-completed {
  background: var(--bg);
  color: var(--text-muted);
}

.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.alert-success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: var(--success);
}

.alert-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: var(--error);
}

.alert-info {
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: var(--accent);
}

.text-error {
  color: var(--error);
  font-size: 0.8rem;
}

.empty-state {
  color: var(--text-muted);
  text-align: center;
  padding: 1.5rem;
}

.progress-section {
  margin-top: 1.25rem;
}

.progress-section.hidden {
  display: none;
}

.progress-meta {
  display: flex;
  justify-content: space-between;
  font-size: 0.875rem;
  margin-bottom: 0.35rem;
}

.progress-bar {
  height: 8px;
  background: var(--border);
  border-radius: 999px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: var(--accent);
  transition: width 0.3s ease;
}

.filter-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}

.filter-form input,
.filter-form select {
  width: auto;
  min-width: 120px;
}

.pagination {
  display: flex;
  gap: 0.35rem;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.pagination a {
  padding: 0.35rem 0.65rem;
  border: 1px solid var(--border);
  border-radius: 4px;
  text-decoration: none;
  font-size: 0.875rem;
  color: var(--text);
}

.pagination a.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

#toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 360px;
}

.toast {
  padding: 0.75rem 1rem;
  background: var(--text);
  color: #fff;
  border-radius: var(--radius);
  font-size: 0.875rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.2s ease;
}

.toast.error {
  background: var(--error);
}

.toast.success {
  background: var(--success);
}

.toast.warning {
  background: #fff8e6;
  color: var(--warning);
  border: 1px solid #f5d78e;
}

@keyframes slideIn {
  from {
    transform: translateY(8px);
    opacity: 0;
  }
  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.25rem;
}

.attachment-status {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
}

.hidden {
  display: none !important;
}

.login-hint {
  font-size: 0.875rem;
  color: var(--text-muted);
  margin: 0 0 1rem;
  padding: 0.5rem 0.75rem;
  background: var(--bg);
  border-radius: 6px;
  border: 1px solid var(--border);
}

.password-field {
  position: relative;
  display: flex;
  align-items: stretch;
}

.password-field input {
  padding-right: 2.75rem;
}

.password-toggle {
  position: absolute;
  right: 4px;
  top: 50%;
  transform: translateY(-50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.password-toggle:hover {
  color: var(--text);
  background: var(--bg);
}

.password-toggle:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.password-toggle .icon-eye {
  display: block;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  box-shadow: var(--shadow);
}

.brand-center {
  text-align: center;
  margin-bottom: 1.5rem;
}

.brand-center h1 {
  font-size: 1.25rem;
  margin: 0.75rem 0 0.25rem;
}

.checkbox-group label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 400;
  cursor: pointer;
}

code {
  font-size: 0.85em;
  background: var(--bg);
  padding: 0.1em 0.35em;
  border-radius: 4px;
}

/* Rich text composer (Gmail-style toolbar) */
.rich-editor {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.rich-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.rich-toolbar-sep {
  width: 1px;
  height: 22px;
  margin: 0 4px;
  background: var(--border);
}

.rich-toolbar-btn {
  min-width: 32px;
  min-height: 32px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  line-height: 1;
}

.rich-toolbar-btn:hover {
  background: #fff;
  border-color: var(--border);
}

.rich-toolbar-btn:active {
  background: #e8ecf0;
}

.rich-btn-bold {
  font-weight: 700;
}

.rich-btn-italic {
  font-style: italic;
}

.rich-btn-underline {
  text-decoration: underline;
}

.rich-btn-strike {
  text-decoration: line-through;
}

.rich-editor-surface {
  min-height: 200px;
  max-height: 420px;
  overflow-y: auto;
  padding: 12px 14px;
  font: inherit;
  font-size: 0.95rem;
  line-height: 1.6;
  outline: none;
}

.rich-editor-compact .rich-editor-surface {
  min-height: 100px;
  max-height: 200px;
}

.rich-editor-surface:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.rich-editor-surface.is-empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
  white-space: pre-wrap;
}

.rich-editor-surface ul,
.rich-editor-surface ol {
  margin: 0.5em 0;
  padding-left: 1.5em;
}

.rich-editor-surface blockquote {
  margin: 0.5em 0;
  padding-left: 12px;
  border-left: 3px solid var(--accent);
  color: var(--text-muted);
}

.rich-editor-surface a {
  color: var(--accent);
  text-decoration: underline;
}

@media (max-width: 640px) {
  .header-inner {
    flex-direction: column;
    align-items: flex-start;
  }

  .form-actions .btn {
    flex: 1 1 100%;
  }
}

@media (prefers-reduced-motion: reduce) {
  .toast,
  .progress-fill {
    animation: none;
    transition: none;
  }
}
