/* ============================================ */
/* BASE STYLES */
/* ============================================ */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  line-height: 1.6;
  color: #1f2937;
  background: #f3f4f6;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

h1 {
  font-size: 1.875rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: #111827;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 1rem;
  color: #374151;
}

p {
  margin-bottom: 1rem;
}

small {
  color: #6b7280;
  font-size: 0.875rem;
}

code {
  background: #e5e7eb;
  padding: 2px 8px;
  border-radius: 4px;
  font-family: 'Courier New', monospace;
  font-size: 0.875rem;
  color: #1f2937;
}

/* ============================================ */
/* HEADER */
/* ============================================ */
.main-header {
  background: white;
  border-bottom: 1px solid #e5e7eb;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
}

.logo-link {
  text-decoration: none;
  color: inherit;
  transition: opacity 0.2s;
}

.logo-link:hover {
  opacity: 0.8;
}

.logo-link h1 {
  margin: 0;
  font-size: 1.5rem;
}

.admin-quick-nav {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.nav-link {
  padding: 0.5rem 1rem;
  background: #f3f4f6;
  color: #374151;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: all 0.2s;
}

.nav-link:hover {
  background: #667eea;
  color: white;
}

.nav-link:active {
  transform: scale(0.98);
}

/* Mobile Header */
@media (max-width: 768px) {
  .header-content {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }

  .logo-link h1 {
    font-size: 1.25rem;
  }

  .admin-quick-nav {
    width: 100%;
    justify-content: space-between;
  }

  .nav-link {
    flex: 1;
    text-align: center;
    padding: 0.6rem 0.5rem;
    font-size: 0.8rem;
  }
}

/* ============================================ */
/* MAIN CONTENT */
/* ============================================ */
.main-content {
  flex: 1;
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

@media (max-width: 768px) {
  .main-content {
    padding: 1rem;
  }
}

/* ============================================ */
/* FOOTER */
/* ============================================ */
.main-footer {
  background: white;
  border-top: 1px solid #e5e7eb;
  margin-top: auto;
}

.footer-user-info {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 2rem;
  border-bottom: 1px solid #f3f4f6;
}

.user-details {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-name {
  font-size: 0.875rem;
  color: #6b7280;
}

.user-name strong {
  color: #111827;
}

.user-role {
  font-size: 0.75rem;
  padding: 0.25rem 0.75rem;
  background: #f3f4f6;
  border-radius: 12px;
  cursor: help;
  transition: background 0.2s;
}

.user-role:hover {
  background: #e5e7eb;
}

.user-actions {
  display: flex;
  gap: 1rem;
}

.footer-link {
  color: #667eea;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  transition: all 0.2s;
}

.footer-link:hover {
  background: #f3f4f6;
}

.footer-link.logout {
  color: #dc3545;
}

.footer-copyright {
  max-width: 1100px;
  margin: 0 auto;
  padding: 1rem 1.5rem;
  text-align: center;
}

.footer-copyright p {
  color: #9ca3af;
  font-size: 0.75rem;
  margin: 0;
}

/* Mobile Footer */
@media (max-width: 768px) {
  .footer-user-info {
    flex-direction: column;
    gap: 1rem;
    padding: 1rem;
  }

  .user-details {
    flex-direction: column;
    gap: 0.5rem;
    text-align: center;
  }

  .user-actions {
    width: 100%;
    justify-content: center;
  }
}

/* ============================================ */
/* FORM ELEMENTS */
/* ============================================ */
label {
  display: block;
  margin: 0 0 0.5rem;
  font-weight: 500;
  font-size: 0.875rem;
  color: #374151;
}

input,
select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 1rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
  background: white;
  color: #1f2937;
  margin-bottom: 1rem;
}

input:focus,
select:focus {
  outline: none;
  border-color: #667eea;
  box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
}

input::placeholder {
  color: #9ca3af;
}

button {
  width: 100%;
  padding: 0.75rem 1rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 1rem;
  font-weight: 500;
  background: #667eea;
  color: white;
  transition: background-color 0.2s ease, transform 0.1s ease;
  margin-top: 0.5rem;
}

button:hover {
  background: #5568d3;
}

button:active {
  transform: scale(0.98);
}

form {
  display: flex;
  flex-direction: column;
}

@media (max-width: 640px) {
  input,
  select,
  button {
    font-size: 16px; /* Prevents zoom on iOS */
  }
}

/* ============================================ */
/* INDEX.PHP SPECIFIC (MAIL CARDS/TABLE) */
/* ============================================ */
.index-container {
  max-width: 1100px;
  width: 100%;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

@media (max-width: 768px) {
  .index-container {
    padding: 1rem;
  }
}

.card {
  background: white;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  padding: 1.5rem;
  margin: 1.5rem 0;
  box-shadow: 0 1px 3px 0 rgba(0, 0, 0, 0.1);
}

.page-header {
  background: white;
  padding: 1.5rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 2rem;
}

.header-left h1 {
  margin-bottom: 0.25rem;
}

.header-right {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
  flex-wrap: wrap;
}

.user-badge {
  background: #f3f4f6;
  padding: 0.5rem 1rem;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
}

.admin-badge {
  background: #667eea;
  color: white;
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  margin-left: 0.5rem;
  font-weight: 600;
}

.btn-header {
  padding: 0.5rem 1rem;
  background: #667eea;
  color: white;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 500;
  transition: background 0.2s;
  display: inline-block;
}

.btn-header:hover {
  background: #5568d3;
}

.btn-logout {
  background: #6b7280;
}

.btn-logout:hover {
  background: #4b5563;
}

.row {
  display: flex;
  gap: 1rem;
  margin-bottom: 1rem;
}

.row > div {
  flex: 1;
  min-width: 200px;
}

@media (max-width: 640px) {
  .row {
    flex-direction: column;
    gap: 0;
  }

  .row > div {
    min-width: 100%;
  }
}

.loading { 
  padding: 10px 0; 
  color: #6b7280;
  text-align: center;
}

.ok {
  background: #d1fae5;
  border: 1px solid #6ee7b7;
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  color: #065f46;
}

.err {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  padding: 1rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  color: #991b1b;
}

details {
  border: 1px solid #e5e7eb;
  padding: 1em;
  border-radius: 10px;
  margin: 1em 0;
  background: white;
}

summary {
  cursor: pointer;
  font-weight: 600;
  padding: 0.5rem;
}

/* Mail Table */
.mailtable {
  width: 100%;
  border-collapse: collapse;
}

.mailtable th {
  text-align: center;
  font-size: 0.9em;
  color: #6b7280;
  padding: 8px;
  background: #f9fafb;
}

.mailtable td {
  text-align: center;
  vertical-align: top;
  padding: 8px;
  border-bottom: 1px solid #f3f4f6;
}

.tablerow:hover {
  background: #f9fafb;
}

/* Responsive switch */
.desktop-only { 
  display: block; 
}

.mobile-only { 
  display: none; 
}

@media (max-width: 820px) {
  .desktop-only { 
    display: none; 
  }
  
  .mobile-only { 
    display: block; 
  }
}

/* Mobile Mail Cards */
.mailcard {
  border: 1px solid #e5e7eb;
  border-radius: 10px;
  padding: 1rem;
  margin: 1rem 0;
  background: white;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.cardhead {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding-bottom: 0.75rem;
  border-bottom: 1px solid #f3f4f6;
  margin-bottom: 0.75rem;
}

.who {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: baseline;
}

.who .at { 
  color: #9ca3af; 
  font-size: 0.95em; 
}

.cardrow {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 10px;
  padding: 6px 0;
}

.cardrow .label {
  color: #6b7280;
  font-size: 0.875rem;
  font-weight: 500;
}

.cardrow .value {
  min-width: 0;
  word-break: break-word;
}

@media (max-width: 420px) {
  .cardrow {
    grid-template-columns: 1fr;
  }
}

.cell-main {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.cell-sub {
  font-size: 0.85em;
  color: #9ca3af;
  margin-top: 2px;
}

.local {
  font-weight: 600;
}

.aliaslist {
  list-style: none;
  margin: 0;
  padding: 0;
}

.aliaslist li {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 2px 0;
}

.copybtn {
  border: 1px solid #e5e7eb;
  background: #5b54a0;
  padding: 4px;
  cursor: pointer;
  font-size: 0.75rem;
  opacity: 0.5;
  width: 1.5rem;
  height: 1.5rem;
  border-radius: 4px;
  transition: all 0.2s;
}

.copybtn:hover { 
  opacity: 1;
  background: #667eea;
  color: white;
}

.copybtn.copied {
  opacity: 1;
  background: #10b981;
  color: white;
  border-color: #10b981;
}

.muted { 
  color: #9ca3af; 
}

/* ============================================ */
/* ADMIN PAGES */
/* ============================================ */
.admin-container {
  max-width: 1100px;
  margin: 0 auto;
}

.admin-header {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 2rem;
}

.admin-header h1 {
  margin-bottom: 0.5rem;
}

.admin-breadcrumb {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  font-size: 0.875rem;
  color: #6b7280;
  margin-top: 0.5rem;
}

.admin-breadcrumb a {
  color: #667eea;
  text-decoration: none;
}

.admin-breadcrumb a:hover {
  text-decoration: underline;
}

.admin-nav {
  display: flex;
  gap: 1rem;
  margin-bottom: 2rem;
  flex-wrap: wrap;
}

.admin-nav a {
  color: #667eea;
  text-decoration: none;
  padding: 0.5rem 1rem;
  background: white;
  border-radius: 6px;
  font-weight: 500;
  transition: all 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.admin-nav a:hover {
  background: #667eea;
  color: white;
}

.admin-section {
  background: white;
  padding: 2rem;
  border-radius: 8px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  margin-bottom: 2rem;
}

.admin-section h2 {
  padding-bottom: 1rem;
  border-bottom: 2px solid #f3f4f6;
  margin-bottom: 1.5rem;
}

/* Alerts */
.alert {
  padding: 1rem 1.25rem;
  border-radius: 6px;
  margin-bottom: 1.5rem;
  font-size: 0.875rem;
}

.alert strong {
  font-weight: 600;
}

.alert-success {
  background: #d1fae5;
  border: 1px solid #6ee7b7;
  color: #065f46;
}

.alert-error {
  background: #fee2e2;
  border: 1px solid #fca5a5;
  color: #991b1b;
}

.alert-warning {
  background: #fef3c7;
  border: 1px solid #fcd34d;
  color: #92400e;
}

.alert-info {
  background: #dbeafe;
  border: 1px solid #93c5fd;
  color: #1e40af;
}

/* Admin Table */
.table-wrapper {
  overflow-x: auto;
  margin-top: 1rem;
  -webkit-overflow-scrolling: touch;
}

.admin-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 800px;
}

.admin-table th {
  background: #f9fafb;
  padding: 0.75rem 1rem;
  text-align: left;
  border-bottom: 2px solid #e5e7eb;
  font-weight: 600;
  font-size: 0.875rem;
  color: #374151;
}

.admin-table td {
  padding: 1rem;
  border-bottom: 1px solid #f3f4f6;
  font-size: 0.875rem;
}

.admin-table tr:hover {
  background: #f9fafb;
}

.admin-table tr.pending {
  background: #fef3c7;
}

.admin-table tr.pending:hover {
  background: #fde68a;
}

/* Badges */
.badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: 12px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success {
  background: #d1fae5;
  color: #065f46;
}

.badge-warning {
  background: #fef3c7;
  color: #92400e;
}

.badge-info {
  background: #dbeafe;
  color: #1e40af;
}

.badge-danger {
  background: #fee2e2;
  color: #991b1b;
}

/* Buttons */
.btn-tiny {
  padding: 0.375rem 0.75rem;
  font-size: 0.75rem;
  border: 1px solid #d1d5db;
  background: white;
  border-radius: 4px;
  cursor: pointer;
  text-decoration: none;
  color: #374151;
  font-weight: 500;
  transition: all 0.2s;
  display: inline-block;
  white-space: nowrap;
}

.btn-tiny:hover {
  background: #f3f4f6;
  border-color: #9ca3af;
}

.btn-tiny.btn-primary {
  background: #667eea;
  color: white;
  border-color: #667eea;
}

.btn-tiny.btn-primary:hover {
  background: #5568d3;
}

.btn-tiny.btn-success {
  background: #10b981;
  color: white;
  border-color: #10b981;
}

.btn-tiny.btn-success:hover {
  background: #059669;
}

.btn-tiny.btn-danger {
  background: #ef4444;
  color: white;
  border-color: #ef4444;
}

.btn-tiny.btn-danger:hover {
  background: #dc2626;
}

/* Domain Manager */
.domain-manager {
  background: #f9fafb;
}

.domain-manager-content {
  padding: 1.5rem;
}

.domain-manager-content h4 {
  margin-bottom: 1rem;
  color: #374151;
}

.assigned-domains ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}

.assigned-domains li {
  padding: 0.75rem;
  background: white;
  margin: 0.5rem 0;
  border-radius: 6px;
  border: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.add-domain {
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e5e7eb;
}

/* Mobile Admin Optimizations */
@media (max-width: 768px) {
  .admin-container {
    padding: 0;
  }

  .admin-header,
  .admin-section {
    padding: 1.25rem;
    margin-bottom: 1rem;
    border-radius: 0;
  }

  .admin-nav {
    gap: 0.5rem;
  }

  .admin-nav a {
    flex: 1;
    text-align: center;
    font-size: 0.875rem;
    padding: 0.75rem 0.5rem;
  }

  /* Responsive Table */
  .admin-table {
    font-size: 0.75rem;
  }

  .admin-table th,
  .admin-table td {
    padding: 0.5rem;
  }

  /* Stack buttons vertically on mobile */
  .admin-table td form {
    display: block;
    margin: 0.25rem 0;
  }

  .btn-tiny {
    font-size: 0.7rem;
    padding: 0.3rem 0.5rem;
  }

  /* Hide less important columns on mobile */
  /* Auf Tablets: Blende Global Admin, Domains und Details aus */
  .admin-table th:nth-child(5),
  .admin-table td:nth-child(5),
  .admin-table th:nth-child(6),
  .admin-table td:nth-child(6),
  .admin-table th:nth-child(7),
  .admin-table td:nth-child(7) {
    display: none;
  }
}

@media (max-width: 640px) {
  /* Auf Mobil: Nur Benutzername, Status und wesentliche Aktionen */
  .admin-table th:nth-child(2),
  .admin-table td:nth-child(2),
  .admin-table th:nth-child(4),
  .admin-table td:nth-child(4),
  .admin-table th:nth-child(5),
  .admin-table td:nth-child(5),
  .admin-table th:nth-child(6),
  .admin-table td:nth-child(6),
  .admin-table th:nth-child(7),
  .admin-table td:nth-child(7) {
    display: none;
  }

  /* Show action buttons as overlay */
  .admin-table tr {
    position: relative;
  }
}

@media (max-width: 640px) {
  .admin-header h1 {
    font-size: 1.5rem;
  }

  .admin-section h2 {
    font-size: 1.125rem;
  }
}

/* ============================================ */
/* SETTINGS PAGE */
/* ============================================ */
.settings-form {
  margin-top: 1.5rem;
}

.setting-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.5rem;
  background: #f9fafb;
  border-radius: 8px;
  margin-bottom: 1rem;
  border: 1px solid #e5e7eb;
}

.setting-info {
  flex: 1;
}

.setting-info strong {
  display: block;
  margin-bottom: 0.5rem;
  font-size: 1rem;
  color: #111827;
}

.setting-description {
  color: #6b7280;
  font-size: 0.875rem;
  margin: 0;
  line-height: 1.5;
}

.setting-control {
  margin-left: 2rem;
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 60px;
  height: 34px;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #d1d5db;
  transition: 0.3s;
  border-radius: 34px;
}

.toggle-slider:before {
  position: absolute;
  content: "";
  height: 26px;
  width: 26px;
  left: 4px;
  bottom: 4px;
  background-color: white;
  transition: 0.3s;
  border-radius: 50%;
  box-shadow: 0 2px 4px rgba(0,0,0,0.2);
}

input:checked + .toggle-slider {
  background-color: #10b981;
}

input:checked + .toggle-slider:before {
  transform: translateX(26px);
}

input:focus + .toggle-slider {
  box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.2);
}

/* Mobile Settings */
@media (max-width: 640px) {
  .setting-row {
    flex-direction: column;
    gap: 1rem;
    align-items: flex-start;
    padding: 1rem;
  }

  .setting-control {
    margin-left: 0;
    width: 100%;
    display: flex;
    justify-content: center;
  }
}
