/*
 * Webmail Client Styles
 * Modern, responsive design with CSS Grid/Flexbox
 */

/* CSS Variables - Minimalist Grey/Off-White Theme */
:root {
  --primary: #404040;
  --primary-dark: #262626;
  --primary-light: #525252;
  --secondary: #737373;
  --background: #fafafa;
  --surface: #ffffff;
  --surface-hover: #f5f5f5;
  --border: #e5e5e5;
  --border-light: #f5f5f5;
  --text-primary: #171717;
  --text-secondary: #737373;
  --text-muted: #a3a3a3;
  --error: #dc2626;
  --success: #16a34a;
  --warning: #d97706;
  
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);
  
  --header-height: 60px;
  --sidebar-width: 260px;
  
  --transition: all 0.2s ease;
}

/* Dark mode support - System preference - Minimalist Grey Theme */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --background: #171717;
    --surface: #262626;
    --surface-hover: #404040;
    --border: #404040;
    --border-light: #262626;
    --text-primary: #fafafa;
    --text-secondary: #a3a3a3;
    --text-muted: #737373;
  }
}

/* Manual dark mode */
[data-theme="dark"] {
  --background: #171717;
  --surface: #262626;
  --surface-hover: #404040;
  --border: #404040;
  --border-light: #262626;
  --text-primary: #fafafa;
  --text-secondary: #a3a3a3;
  --text-muted: #737373;
}

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

html {
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--background);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* Utility Classes */
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0; }

/* Auth Screen */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #e5e5e5 0%, #d4d4d4 100%);
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
}

.auth-card h1 {
  font-size: 28px;
  font-weight: 700;
  text-align: center;
  margin-bottom: 8px;
  color: var(--text-primary);
}

.auth-subtitle {
  text-align: center;
  color: var(--text-secondary);
  margin-bottom: 32px;
  font-size: 14px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 6px;
  color: var(--text-primary);
}

.form-group input {
  width: 100%;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: var(--surface);
  color: var(--text-primary);
  transition: var(--transition);
}

.form-group input:focus {
  outline: none;
  border-color: var(--text-secondary);
  box-shadow: 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.form-hint {
  display: block;
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.auth-error {
  color: var(--error);
  font-size: 14px;
  text-align: center;
  margin-top: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  border: none;
  background: transparent;
  color: var(--text-primary);
}

.btn:hover {
  background: var(--surface-hover);
}

.btn-primary {
  background: var(--primary);
  color: white;
}

.btn-primary:hover {
  background: var(--primary-dark);
}

.btn-secondary {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: var(--surface-hover);
}

.btn-danger {
  background: var(--surface);
  border: 1px solid var(--error);
  color: var(--error);
}

.btn-danger:hover {
  background: var(--error);
  color: white;
}

.btn-full {
  width: 100%;
}

.btn-icon {
  padding: 8px;
  border-radius: var(--radius-sm);
}

.btn-small {
  padding: 6px;
}

/* Main App */
.main-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Header */
.app-header {
  height: var(--header-height);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.menu-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-primary);
  padding: 4px;
}

.app-title {
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

.header-center {
  flex: 1;
  max-width: 400px;
  margin: 0 20px;
}

.search-container {
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
}

.search-input {
  width: 100%;
  padding: 10px 12px 10px 40px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: var(--background);
  color: var(--text-primary);
  transition: var(--transition);
}

.search-input:focus {
  outline: none;
  border-color: var(--text-secondary);
  background: var(--surface);
}

/* App Container */
.app-container {
  flex: 1;
  display: grid;
  grid-template-columns: var(--sidebar-width) 360px 1fr;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  padding: 20px 0;
}

.nav-section {
  margin-bottom: 24px;
}

.nav-title {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  padding: 0 20px;
  margin-bottom: 8px;
}

.nav-list {
  list-style: none;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  cursor: pointer;
  transition: var(--transition);
  font-size: 14px;
}

.nav-item:hover {
  background: var(--surface-hover);
}

.nav-item.active {
  background: var(--surface-hover);
  color: var(--text-primary);
  border-right: 3px solid var(--primary);
  font-weight: 500;
}

.nav-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.nav-label {
  flex: 1;
}

.nav-count {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--background);
  padding: 2px 8px;
  border-radius: 12px;
}

/* Alias Badge */
.alias-badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 500;
  text-transform: lowercase;
}

.alias-badge-blue { background: #f5f5f5; color: #525252; }
.alias-badge-green { background: #f0f0f0; color: #525252; }
.alias-badge-purple { background: #e5e5e5; color: #525252; }
.alias-badge-orange { background: #fafafa; color: #525252; }
.alias-badge-pink { background: #f5f5f5; color: #525252; }
.alias-badge-teal { background: #f0f0f0; color: #525252; }

/* Email List */
.email-list-container {
  background: var(--background);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.list-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}

.list-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.select-small {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  background: var(--surface);
  color: var(--text-primary);
}

.email-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px;
}

.email-item {
  padding: 16px;
  background: var(--surface);
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
}

.email-item:hover {
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.email-item.active {
  border-color: var(--border);
  background: var(--surface-hover);
}

.email-item.unread::before {
  content: '';
  position: absolute;
  left: 0;
  top: 20px;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--text-primary);
}

.email-item.unread .email-from {
  font-weight: 600;
}

.email-item.unread .email-subject {
  font-weight: 500;
  color: var(--text-primary);
}

.email-item {
  position: relative;
}

.email-item-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.email-from {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-date {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.email-subject {
  font-size: 13px;
  color: var(--text-secondary);
  margin-bottom: 8px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.email-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.email-alias {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  background: var(--surface-hover);
  color: var(--text-secondary);
}

.attachment-indicator {
  color: var(--text-muted);
  display: flex;
  align-items: center;
}

/* Loading States */
.list-loading {
  padding: 20px;
}

.skeleton-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.skeleton-item {
  height: 80px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-hover) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  border-radius: var(--radius-md);
  animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.list-empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.list-empty svg {
  margin-bottom: 16px;
  opacity: 0.5;
}

/* Email Reader */
.email-reader {
  background: var(--surface);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.reader-empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  padding: 40px;
}

.reader-empty svg {
  margin-bottom: 16px;
  opacity: 0.3;
}

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

.reader-header {
  padding: 20px;
  border-bottom: 1px solid var(--border);
}

.reader-actions {
  display: none;
  margin-bottom: 16px;
}

.reader-toolbar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.email-subject-container {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.email-subject {
  font-size: 20px;
  font-weight: 600;
  line-height: 1.3;
  flex: 1;
}

.email-alias-badge {
  font-size: 11px;
  padding: 4px 10px;
  border-radius: 12px;
  background: var(--surface-hover);
  color: var(--text-secondary);
  font-weight: 500;
  text-transform: lowercase;
  border: 1px solid var(--border);
}

.email-meta {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.meta-row {
  display: flex;
  align-items: baseline;
  font-size: 13px;
}

.meta-label {
  color: var(--text-muted);
  width: 50px;
  flex-shrink: 0;
}

.meta-value {
  color: var(--text-primary);
  flex: 1;
}

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

.reader-tabs {
  display: flex;
  gap: 4px;
  padding: 12px 20px 0;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 8px 16px;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: var(--transition);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--text-primary);
  border-bottom-color: var(--text-primary);
  font-weight: 500;
}

.reader-body-content {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  font-size: 14px;
  line-height: 1.6;
}

.reader-body-content.plain-text {
  font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
  white-space: pre-wrap;
  background: var(--background);
  border-radius: var(--radius-md);
  padding: 20px;
}

.reader-body-content img {
  max-width: 100%;
  height: auto;
}

.reader-body-content a {
  color: var(--text-secondary);
  text-decoration: underline;
}

.reader-body-content a:hover {
  text-decoration: underline;
}

.reader-attachments {
  padding: 20px;
  border-top: 1px solid var(--border);
  background: var(--background);
}

.reader-attachments h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text-secondary);
}

.attachments-list {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
}

.attachment-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition);
  min-width: 200px;
}

.attachment-item:hover {
  border-color: var(--text-secondary);
  box-shadow: var(--shadow-sm);
}

.attachment-icon {
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
}

.attachment-info {
  flex: 1;
  min-width: 0;
}

.attachment-name {
  font-size: 13px;
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.attachment-meta {
  font-size: 11px;
  color: var(--text-muted);
}

.reader-loading {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--text-secondary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Responsive Design */
@media (max-width: 1024px) {
  .app-container {
    grid-template-columns: 200px 320px 1fr;
  }
  
  :root {
    --sidebar-width: 200px;
  }
}

@media (max-width: 768px) {
  .app-container {
    grid-template-columns: 1fr;
  }
  
  .sidebar {
    position: fixed;
    left: -100%;
    top: var(--header-height);
    bottom: 0;
    width: 280px;
    z-index: 90;
    transition: left 0.3s ease;
  }
  
  .sidebar.open {
    left: 0;
  }
  
  .menu-toggle {
    display: block;
  }
  
  .email-list-container {
    border-right: none;
  }
  
  .email-reader {
    position: fixed;
    top: var(--header-height);
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 80;
    transform: translateX(100%);
    transition: transform 0.3s ease;
  }
  
  .email-reader.open {
    transform: translateX(0);
  }
  
  .reader-actions {
    display: block;
  }
  
  .header-center {
    display: none;
  }
  
  .app-title {
    display: none;
  }
}

@media (max-width: 480px) {
  .auth-card {
    padding: 30px 20px;
  }
  
  .email-subject {
    font-size: 16px;
  }
  
  .attachment-item {
    min-width: 100%;
  }
}

/* Modal / Compose Overlay */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.modal-content {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 700px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 {
  font-size: 18px;
  font-weight: 600;
}

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

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.form-row {
  margin-bottom: 16px;
}

.form-row label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 6px;
}

.form-row input,
.form-row textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 14px;
  background: var(--surface);
  color: var(--text-primary);
  font-family: inherit;
}

.form-row input:focus,
.form-row textarea:focus {
  outline: none;
  border-color: var(--text-secondary);
}

.form-row textarea {
  min-height: 200px;
  resize: vertical;
  line-height: 1.6;
}

.quote-preview {
  background: var(--background);
  border-left: 3px solid var(--border);
  padding: 12px 16px;
  margin-top: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}

.quote-preview strong {
  color: var(--text-primary);
}

/* Settings Panel */
.settings-panel {
  position: fixed;
  top: var(--header-height);
  right: -400px;
  width: 360px;
  bottom: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 200;
  transition: right 0.3s ease;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.settings-panel.open {
  right: 0;
}

.settings-header {
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.settings-header h3 {
  font-size: 16px;
  font-weight: 600;
}

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

.settings-section {
  margin-bottom: 24px;
}

.settings-section h4 {
  font-size: 13px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.settings-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border-light);
}

.settings-option:last-child {
  border-bottom: none;
}

.settings-option label {
  font-size: 14px;
}

.toggle-switch {
  position: relative;
  width: 44px;
  height: 24px;
  background: var(--border);
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-switch.active {
  background: var(--text-secondary);
}

.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px;
  left: 2px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle-switch.active::after {
  transform: translateX(20px);
}

.select-field {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 14px;
  background: var(--surface);
  color: var(--text-primary);
}

/* Density Modes */
.density-compact .email-item {
  padding: 12px;
}

.density-compact .email-item-header {
  margin-bottom: 4px;
}

.density-compact .email-subject {
  margin-bottom: 4px;
}

.density-compact .reader-header {
  padding: 12px 20px;
}

.density-compact .reader-body-content {
  padding: 12px 20px;
}

/* Print Styles */
@media print {
  .app-header,
  .sidebar,
  .email-list-container,
  .reader-actions {
    display: none !important;
  }
  
  .email-reader {
    position: static;
    transform: none;
  }
  
  .reader-content {
    display: flex !important;
  }
}
