/* ==========================================================================
   Sail - Premium Email Client Stylesheet
   ========================================================================== */

:root {
  /* Color Palette (HSL Tailored Modern Dark Theme) */
  --bg-main: #090d16;
  --bg-sidebar: #05080e;
  --bg-panel: #101625;
  --bg-panel-hover: #162035;
  --bg-panel-active: #1d2b48;
  
  --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #8b5cf6 100%);
  --primary-color: #3b82f6;
  --primary-hover: #2563eb;
  --accent-color: #a78bfa;
  
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  
  --border-color: rgba(148, 163, 184, 0.08);
  --border-focus: rgba(59, 130, 246, 0.4);
  
  --star-color: #f59e0b;
  --danger-color: #ef4444;
  --success-color: #10b981;
  
  /* Layout Constants */
  --sidebar-width: 260px;
  --list-pane-width: 380px;
  --header-height: 70px;
  
  /* Shadows & Glassmorphism */
  --glass-bg: rgba(16, 22, 37, 0.7);
  --glass-blur: blur(16px);
  --shadow-lg: 0 10px 25px -5px rgba(0, 0, 0, 0.3), 0 8px 10px -6px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px -1px rgba(0, 0, 0, 0.1);
  --transition-smooth: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  
  --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, sans-serif;
}

/* ================= Reset & Scrollbars ================= */
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-main);
  color: var(--text-primary);
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(148, 163, 184, 0.15);
  border-radius: 99px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(148, 163, 184, 0.3);
}

/* ================= Screen States ================= */
.screen {
  display: none;
  height: 100vh;
  width: 100vw;
}

.screen.active {
  display: flex;
}

/* ================= Buttons & Icons ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  border: none;
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  font-family: var(--font-sans);
  transition: var(--transition-smooth);
}

.btn-primary {
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.3);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.4);
}

.btn-secondary {
  background: rgba(148, 163, 184, 0.1);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(148, 163, 184, 0.18);
}

.btn-block {
  width: 100%;
}

.icon-btn-secondary {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border-color);
  background: rgba(16, 22, 37, 0.4);
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.icon-btn-secondary:hover {
  background: var(--bg-panel-hover);
  color: var(--text-primary);
  border-color: rgba(148, 163, 184, 0.2);
}

.text-danger {
  color: var(--danger-color) !important;
}
.text-danger:hover {
  background: rgba(239, 68, 68, 0.1) !important;
  border-color: rgba(239, 68, 68, 0.2) !important;
}

/* ================= Login Screen ================= */
#login-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, rgba(139, 92, 246, 0.15), transparent 40%),
              radial-gradient(circle at bottom left, rgba(59, 130, 246, 0.12), transparent 45%),
              var(--bg-main);
}

.login-card {
  width: 100%;
  max-width: 420px;
  padding: 40px;
  border-radius: 24px;
  background: var(--glass-bg);
  backdrop-filter: var(--glass-blur);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.5s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 30px;
}

.logo-icon {
  width: 64px;
  height: 64px;
  border-radius: 18px;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 20px;
  box-shadow: 0 8px 24px rgba(139, 92, 246, 0.3);
}

.logo-icon i {
  width: 32px;
  height: 32px;
  color: #fff;
}

.login-header h1 {
  font-size: 26px;
  font-weight: 700;
  margin-bottom: 8px;
  background: linear-gradient(to right, #fff, #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.login-header p {
  color: var(--text-secondary);
  font-size: 14px;
}

.input-group {
  margin-bottom: 24px;
}

.input-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.password-input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.password-input-wrapper input {
  width: 100%;
  padding: 12px 48px 12px 16px;
  background: rgba(5, 8, 14, 0.6);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: #fff;
  font-size: 15px;
  font-family: monospace;
  transition: var(--transition-smooth);
}

.password-input-wrapper input:focus {
  outline: none;
  border-color: var(--primary-color);
  box-shadow: 0 0 0 3px var(--border-focus);
}

.password-input-wrapper button {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.password-input-wrapper button:hover {
  color: var(--text-primary);
}

.error-msg {
  color: var(--danger-color);
  font-size: 13px;
  text-align: center;
  margin-top: 16px;
  min-height: 18px;
}

/* ================= Main App Screen ================= */
#app-screen {
  display: none;
}

#app-screen.active {
  display: flex;
}

/* Left Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background-color: var(--bg-sidebar);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
}

.logo i {
  width: 28px;
  height: 28px;
  color: var(--primary-color);
}

.logo span {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: 0.5px;
  background: linear-gradient(135deg, #ffffff 0%, #cbd5e1 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-compose {
  padding: 24px 20px 16px;
}

.btn-compose {
  width: 100%;
  padding: 12px;
  font-size: 15px;
}

.sidebar-nav {
  flex: 1;
  padding: 0 12px;
}

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

.nav-item {
  margin-bottom: 4px;
}

.nav-item a {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-radius: 12px;
  color: var(--text-secondary);
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  gap: 12px;
  transition: var(--transition-smooth);
  position: relative;
}

.nav-item a i {
  width: 18px;
  height: 18px;
}

.nav-item:hover a {
  background: rgba(148, 163, 184, 0.05);
  color: var(--text-primary);
}

.nav-item.active a {
  background: rgba(59, 130, 246, 0.1);
  color: var(--primary-color);
  font-weight: 600;
}

.nav-item .badge {
  position: absolute;
  right: 16px;
  background: var(--primary-color);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  box-shadow: 0 2px 8px rgba(59, 130, 246, 0.3);
  display: none;
}

.nav-item .badge.show {
  display: inline-block;
}

.sidebar-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border-color);
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-muted);
}

.status-indicator .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: var(--success-color);
  box-shadow: 0 0 8px var(--success-color);
}

/* Middle Pane: Thread List */
.thread-pane {
  width: var(--list-pane-width);
  background-color: rgba(9, 13, 22, 0.3);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.thread-pane .pane-header {
  height: var(--header-height);
  padding: 0 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--border-color);
}

.search-wrapper {
  position: relative;
  flex: 1;
  display: flex;
  align-items: center;
}

.search-wrapper i {
  position: absolute;
  left: 12px;
  width: 16px;
  height: 16px;
  color: var(--text-muted);
}

.search-wrapper input {
  width: 100%;
  padding: 10px 36px 10px 38px;
  background: rgba(16, 22, 37, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: var(--text-primary);
  font-size: 14px;
  transition: var(--transition-smooth);
}

.search-wrapper input:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(16, 22, 37, 0.8);
}

.search-wrapper .clear-btn {
  position: absolute;
  right: 12px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
}

.search-wrapper .clear-btn.show {
  display: flex;
}

.search-wrapper .clear-btn:hover {
  color: var(--text-primary);
}

.thread-list-container {
  flex: 1;
  overflow-y: auto;
}

/* Thread Item Card */
.thread-item {
  padding: 18px 20px;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition-smooth);
  position: relative;
}

.thread-item::after {
  content: '';
  position: absolute;
  left: 0;
  top: 0;
  height: 100%;
  width: 3px;
  background: transparent;
  transition: var(--transition-smooth);
}

.thread-item:hover {
  background: rgba(148, 163, 184, 0.02);
}

.thread-item.active {
  background: rgba(59, 130, 246, 0.04);
}

.thread-item.active::after {
  background: var(--primary-color);
}

.thread-item.unread {
  font-weight: 500;
}

.thread-item-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.thread-sender {
  font-size: 14px;
  color: var(--text-primary);
  max-width: 70%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-item.unread .thread-sender {
  font-weight: 600;
}

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

.thread-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.thread-unread-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background-color: var(--primary-color);
  box-shadow: 0 0 6px var(--primary-color);
  flex-shrink: 0;
}

.thread-subject {
  font-size: 13.5px;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.thread-item.unread .thread-subject {
  font-weight: 600;
}

.thread-snippet-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
}

.thread-snippet {
  font-size: 12.5px;
  color: var(--text-secondary);
  line-height: 1.4;
  height: 1.4em;
  max-width: 85%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-icons {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
}

.thread-icons i {
  width: 13px;
  height: 13px;
}

.thread-item-star {
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
}

.thread-item-star:hover {
  color: var(--star-color);
  transform: scale(1.1);
}

.thread-item-star.active {
  color: var(--star-color);
}

.thread-count-badge {
  background: rgba(148, 163, 184, 0.12);
  color: var(--text-secondary);
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 6px;
  font-weight: 600;
}

/* Right Pane: Reading Pane */
.reading-pane {
  flex: 1;
  background-color: var(--bg-main);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.thread-detail-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.thread-detail-footer {
  padding: 20px 30px;
  border-top: 1px solid var(--border-color);
  background: var(--bg-panel);
  display: flex;
  justify-content: flex-start;
  flex-shrink: 0;
}

.thread-detail-header {
  height: var(--header-height);
  padding: 0 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.thread-detail-header h2 {
  font-size: 18px;
  font-weight: 600;
  max-width: 80%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.thread-messages-list {
  flex: 1;
  overflow-y: auto;
  padding: 30px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* Email Card in Thread Detail */
.email-card {
  border-radius: 16px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: var(--transition-smooth);
}

.email-card:hover {
  border-color: rgba(148, 163, 184, 0.15);
  box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.email-card.collapsed .email-card-header {
  border-bottom: none;
  background: transparent;
  padding: 12px 20px;
}

.email-card.collapsed .email-recipients {
  display: none;
}

.email-card.collapsed .email-avatar {
  width: 32px;
  height: 32px;
  font-size: 13px;
}

.email-card-header {
  padding: 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-color);
  cursor: pointer;
  background: rgba(148, 163, 184, 0.01);
}

.email-sender-info {
  display: flex;
  align-items: center;
  gap: 12px;
}

.email-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 600;
  color: #fff;
  background-color: var(--primary-color);
}

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

.email-sender-name {
  font-size: 14px;
  font-weight: 600;
}

.email-recipients {
  font-size: 12px;
  color: var(--text-secondary);
}

.email-header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.email-time {
  font-size: 12px;
  color: var(--text-muted);
}

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

.email-star-btn,
.email-expand-btn {
  background: transparent;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  transition: var(--transition-smooth);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.email-star-btn:hover {
  color: var(--star-color);
}

.email-expand-btn:hover {
  color: var(--primary-color);
}

.email-star-btn.active {
  color: var(--star-color);
}

.email-card-body {
  padding: 24px 20px;
  overflow: hidden;
}

.email-body-iframe {
  width: 100%;
  min-height: 120px;
  border: none;
  background: transparent;
  overflow: hidden;
}

/* Attachments */
.email-attachments {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px dashed var(--border-color);
}

.attachments-title {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.attachments-title i {
  width: 14px;
  height: 14px;
}

.attachments-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.attachment-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(148, 163, 184, 0.05);
  border: 1px solid var(--border-color);
  padding: 8px 12px;
  border-radius: 10px;
  color: var(--text-primary);
  text-decoration: none;
  font-size: 13px;
  transition: var(--transition-smooth);
}

.attachment-chip:hover {
  background: var(--bg-panel-hover);
  border-color: rgba(148, 163, 184, 0.2);
}

.attachment-chip i {
  width: 15px;
  height: 15px;
  color: var(--text-secondary);
}

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

/* Quick Reply Box */
.quick-reply-container {
  padding: 20px 30px 30px;
  border-top: 1px solid var(--border-color);
  background: rgba(16, 22, 37, 0.2);
  flex-shrink: 0;
}

.quick-reply-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.reply-recipient-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.reply-recipient-label strong {
  color: var(--text-primary);
}

.quick-reply-container textarea {
  width: 100%;
  height: 90px;
  background: rgba(5, 8, 14, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  padding: 12px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  resize: vertical;
  transition: var(--transition-smooth);
  margin-bottom: 12px;
}

.quick-reply-container textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(5, 8, 14, 0.8);
}

.quick-reply-actions {
  display: flex;
  justify-content: flex-end;
}

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: var(--text-muted);
  text-align: center;
  padding: 40px;
  animation: fadeIn 0.4s ease-out;
}

.empty-state i {
  width: 48px;
  height: 48px;
  color: var(--text-muted);
  margin-bottom: 16px;
}

.empty-state .spinner {
  animation: spin 1.5s linear infinite;
  color: var(--primary-color);
}

.empty-state h3 {
  color: var(--text-secondary);
  font-size: 18px;
  margin-bottom: 8px;
}

.empty-state p {
  font-size: 14px;
  max-width: 280px;
}

/* ================= Modals ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(5, 8, 14, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s ease;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-card {
  width: 100%;
  max-width: 650px;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform 0.3s ease;
  overflow: hidden;
}

.modal-overlay.active .modal-card {
  transform: translateY(0);
}

.modal-card.modal-large {
  max-width: 850px;
  width: 95%;
}

.preview-modal-body {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 24px;
}

.preview-sender-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 12px;
  font-size: 14px;
}

.preview-content-container {
  flex: 1;
  min-height: 480px;
  border: 1px solid var(--border-color);
  border-radius: 12px;
  overflow: hidden;
  background: #0f172a;
}

#preview-modal-iframe {
  width: 100%;
  height: 480px;
  border: none;
  background: transparent;
}

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

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

#compose-form {
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group.inline-fields {
  flex-direction: row;
  gap: 16px;
}

.field-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.form-group input,
.form-group textarea {
  background: rgba(5, 8, 14, 0.5);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 10px 14px;
  color: var(--text-primary);
  font-family: var(--font-sans);
  font-size: 14px;
  transition: var(--transition-smooth);
}

.form-group input:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary-color);
  background: rgba(5, 8, 14, 0.8);
}

.form-body-group {
  flex: 1;
}

.form-body-group textarea {
  height: 220px;
  resize: vertical;
}

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

/* ================= Toasts ================= */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1100;
}

.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-left: 4px solid var(--primary-color);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: 10px;
  box-shadow: var(--shadow-lg);
  font-size: 13.5px;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 250px;
  animation: slideIn 0.3s ease-out;
}

.toast.toast-error {
  border-left-color: var(--danger-color);
}

.toast.toast-success {
  border-left-color: var(--success-color);
}

/* ================= Keyframes ================= */
@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideIn {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

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