:root {
  color-scheme: light;
  font-family: "Inter", "Segoe UI", sans-serif;
  line-height: 1.5;
  --blue: #1b4ed8;
  --gray: #64748b;
  --border: #e2e8f0;
  --bg: #f8fafc;
}

body {
  margin: 0;
  background: var(--bg);
  color: #0f172a;
}

.site-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 32px;
  background: #fff;
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  font-size: 18px;
}

nav a {
  margin-right: 16px;
  color: var(--blue);
  text-decoration: none;
  font-weight: 600;
}

nav form.inline {
  display: inline;
}

nav button {
  border: 1px solid var(--border);
  background: #fff;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
}

.container {
  max-width: 1000px;
  margin: 32px auto;
  padding: 0 20px 40px;
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.card h2 {
  margin-top: 0;
}

.flash {
  background: #e2f2ff;
  border: 1px solid #93c5fd;
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 20px;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  text-align: left;
  font-size: 14px;
}

.table th {
  background: #f1f5f9;
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  color: var(--gray);
}

.pagination {
  display: flex;
  justify-content: space-between;
  margin-top: 16px;
}

form label {
  display: block;
  font-weight: 600;
  margin: 12px 0 6px;
}

form input[type="text"],
form input[type="email"],
form input[type="password"],
form select {
  width: 100%;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

form button {
  margin-top: 12px;
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  cursor: pointer;
}

.badge {
  display: inline-block;
  padding: 4px 8px;
  border-radius: 999px;
  background: #eef2ff;
  color: #4338ca;
  font-size: 12px;
  font-weight: 600;
}

/* Email detail view */
.email-meta {
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  margin: 16px 0;
  font-size: 14px;
}

.email-meta p {
  margin: 8px 0;
}

.email-meta strong {
  color: var(--gray);
  font-weight: 600;
  display: inline-block;
  min-width: 80px;
}

.email-meta code {
  font-size: 12px;
  background: #fff;
  padding: 2px 6px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
}

/* Attachments */
.attachments {
  margin: 20px 0;
  padding: 16px;
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: 8px;
}

.attachments h3 {
  margin-top: 0;
  color: #166534;
  font-size: 16px;
}

.attachment-list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
}

.attachment-list li {
  padding: 8px 0;
  border-bottom: 1px solid #dcfce7;
}

.attachment-list li:last-child {
  border-bottom: none;
}

.attachment-list a {
  color: #166534;
  text-decoration: none;
  font-weight: 600;
}

.attachment-list a:hover {
  text-decoration: underline;
}

.file-size {
  color: var(--gray);
  font-size: 12px;
  margin-left: 8px;
}

/* Email body */
.email-body {
  margin: 20px 0;
}

.email-body h3 {
  font-size: 16px;
  margin-bottom: 12px;
  color: var(--gray);
}

.email-body-text pre {
  background: var(--bg);
  padding: 16px;
  border-radius: 8px;
  border: 1px solid var(--border);
  overflow-x: auto;
  white-space: pre-wrap;
  word-wrap: break-word;
  font-family: 'Courier New', monospace;
  font-size: 13px;
  line-height: 1.6;
}

.email-body-html .html-content {
  background: #fff;
  padding: 20px;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-width: 100%;
  overflow-x: auto;
}

.email-body-html .html-content img {
  max-width: 100%;
  height: auto;
}

.email-body-html .html-content a {
  color: var(--blue);
  word-break: break-all;
}

/* Email actions */
.email-actions {
  margin-top: 24px;
  padding-top: 20px;
  border-top: 1px solid var(--border);
}

.email-actions .button,
.button {
  display: inline-block;
  background: var(--blue);
  color: #fff;
  text-decoration: none;
  padding: 10px 20px;
  border-radius: 8px;
  font-weight: 600;
  transition: background 0.2s;
}

.email-actions .button:hover,
.button:hover {
  background: #1e40af;
}

/* Make table links look good */
.table a {
  color: var(--blue);
  text-decoration: none;
  font-weight: 500;
}

.table a:hover {
  text-decoration: underline;
}

/* Filter form */
.filter-form {
  margin: 0;
}

.filter-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 16px;
}

.filter-col {
  display: flex;
  flex-direction: column;
}

.filter-col label {
  margin: 0 0 6px 0;
}

.filter-col input,
.filter-col select {
  flex: 1;
}

.filter-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.filter-actions button,
.filter-actions .btn-secondary {
  flex: 1;
  margin: 0;
}

.bulk-delete-form {
  margin: 0;
}

.bulk-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 12px;
}

.checkbox-col {
  width: 38px;
  text-align: center !important;
}

.checkbox-col input[type="checkbox"] {
  cursor: pointer;
}

.btn-danger {
  background: #dc2626;
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger:hover {
  background: #b91c1c;
}

.btn-danger:disabled {
  background: #94a3b8;
  cursor: not-allowed;
}

.btn-secondary, a.btn-secondary {
  display: inline-block;
  background: #fff;
  color: var(--gray);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
  text-align: center;
}

.btn-secondary:hover, a.btn-secondary:hover {
  background: var(--bg);
}

/* Upload options */
.upload-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
  margin-bottom: 16px;
}

.upload-options > div {
  display: flex;
  flex-direction: column;
}

.upload-options label {
  margin: 0 0 8px 0;
}

.upload-options small {
  color: var(--gray);
  font-size: 12px;
  margin-top: 4px;
}

.hidden {
  display: none !important;
}

.upload-progress {
  margin: 8px 0 12px;
}

.upload-progress-bar-wrap {
  width: 100%;
  height: 10px;
  background: #e2e8f0;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid #cbd5e1;
}

.upload-progress-bar {
  width: 0%;
  height: 100%;
  background: linear-gradient(90deg, #1d4ed8, #0ea5e9);
  transition: width 0.15s ease;
}

.upload-progress-text {
  margin-top: 6px;
  color: var(--gray);
  font-size: 13px;
}

/* Flash messages with HTML */
.flash {
  line-height: 1.6;
}

.flash br {
  display: block;
  content: "";
  margin-top: 4px;
}

/* User management */
.table td a {
  margin-right: 8px;
}

.table td a:last-child {
  margin-right: 0;
}

form .button,
form button[type="submit"] {
  margin-right: 8px;
}

/* Collapsible sections */
.collapsible-card {
  overflow: hidden;
}

.collapsible-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  padding: 0;
  margin: 0;
}

.collapsible-header:hover {
  opacity: 0.8;
}

.collapsible-header h2 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  color: var(--gray);
}

.collapse-icon {
  font-size: 14px;
  color: var(--gray);
  transition: transform 0.2s;
}

.collapsible-content {
  max-height: 1000px;
  overflow: hidden;
  transition: max-height 0.3s ease-out, opacity 0.3s ease-out, margin-top 0.3s ease-out;
  opacity: 1;
  margin-top: 16px;
}

.collapsible-content.collapsed {
  max-height: 0;
  opacity: 0;
  margin-top: 0;
}

/* Dropdown menu */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-toggle {
  background: var(--blue);
  color: #fff;
  border: none;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-weight: 600;
  font-size: 14px;
  transition: background 0.2s;
}

.dropdown-toggle:hover {
  background: #1e40af;
}

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  background: #fff;
  min-width: 200px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  border: 1px solid var(--border);
  border-radius: 8px;
  z-index: 1000;
  margin-top: 4px;
  padding: 8px 0;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-menu a {
  display: block;
  padding: 10px 16px;
  color: #0f172a;
  text-decoration: none;
  font-weight: 500;
  margin: 0;
  transition: background 0.2s;
}

.dropdown-menu a:hover {
  background: var(--bg);
}

.dropdown-menu form.inline {
  display: block;
  padding: 0;
  margin: 0;
}

.dropdown-menu form button {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 16px;
  color: #0f172a;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.dropdown-menu form button:hover {
  background: var(--bg);
}

/* Responsive adjustments */
@media (max-width: 768px) {
  .filter-row {
    grid-template-columns: 1fr;
  }

  .upload-options {
    grid-template-columns: 1fr;
  }

  .dropdown-menu {
    right: auto;
    left: 0;
  }
}
