* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --success: #10b981;
  --danger: #ef4444;
  --border: #334155;
  --shadow: rgba(0, 0, 0, 0.3);
}

[data-theme="light"] {
  --bg-primary: #ffffff;
  --bg-secondary: #f8fafc;
  --bg-tertiary: #e2e8f0;
  --text-primary: #0f172a;
  --text-secondary: #64748b;
  --border: #e2e8f0;
  --shadow: rgba(0, 0, 0, 0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  transition: background 0.3s, color 0.3s;
}

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px;
}

.header {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 4px 6px var(--shadow);
}

.header-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: linear-gradient(135deg, #3b82f6, #8b5cf6);
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.theme-toggle {
  background: var(--bg-tertiary);
  border: none;
  padding: 10px 16px;
  border-radius: 8px;
  color: var(--text-primary);
  cursor: pointer;
  font-size: 20px;
  transition: all 0.3s;
}

.theme-toggle:hover {
  transform: scale(1.05);
}

.email-controls {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.email-display {
  flex: 1;
  min-width: 300px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  color: var(--accent);
}

.btn {
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  color: var(--text-primary);
  padding: 12px 24px;
  border-radius: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  font-size: 14px;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 12px var(--shadow);
}

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

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

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

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

.btn-sm {
  padding: 8px 16px;
  font-size: 13px;
}

#statusMsg {
  margin-top: 12px;
  padding: 10px 16px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  display: none;
}

#statusMsg.success {
  background: rgba(16, 185, 129, 0.2);
  color: var(--success);
  display: block;
}

#statusMsg.error {
  background: rgba(239, 68, 68, 0.2);
  color: var(--danger);
  display: block;
}

.main-grid {
  display: grid;
  grid-template-columns: 400px 1fr;
  gap: 20px;
  margin-top: 20px;
}

.panel {
  background: var(--bg-secondary);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 4px 6px var(--shadow);
}

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

.panel-title {
  font-size: 18px;
  font-weight: 700;
}

.panel-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  margin-top: 4px;
}

.inbox-list {
  max-height: 600px;
  overflow-y: auto;
  padding: 12px;
}

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

.email-item {
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
  cursor: pointer;
  transition: all 0.3s;
}

.email-item:hover {
  transform: translateX(4px);
  border-color: var(--accent);
}

.email-item.active {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.email-subject {
  font-weight: 600;
  margin-bottom: 8px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.email-meta {
  font-size: 13px;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.email-item.active .email-meta {
  color: rgba(255,255,255,0.8);
}

.message-header {
  padding: 20px 24px;
  border-bottom: 2px solid var(--border);
}

.message-field {
  display: flex;
  gap: 12px;
  margin-bottom: 12px;
}

.message-label {
  min-width: 80px;
  font-weight: 600;
  color: var(--text-secondary);
}

.message-value {
  flex: 1;
  word-break: break-word;
}

.message-viewer {
  padding: 24px;
  min-height: 500px;
}

.message-frame {
  width: 100%;
  min-height: 500px;
  border: none;
  background: white;
  border-radius: 12px;
}

.message-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 500px;
  color: var(--text-secondary);
  font-size: 16px;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal.active {
  display: flex;
}

.modal-content {
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 32px;
  max-width: 500px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.modal-title {
  font-size: 24px;
  font-weight: 700;
  margin-bottom: 24px;
}

.modal-field {
  margin-bottom: 20px;
}

.modal-label {
  display: block;
  margin-bottom: 8px;
  font-weight: 600;
}

.modal-input, .modal-select {
  width: 100%;
  padding: 12px 16px;
  background: var(--bg-tertiary);
  border: 2px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 14px;
}

.modal-select option {
  background: var(--bg-secondary);
  color: var(--text-primary);
}

.modal-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
  margin-top: 24px;
}

@media (max-width: 1024px) {
  .main-grid {
    grid-template-columns: 1fr;
  }
  
  .inbox-list {
    max-height: 400px;
  }
}

@media (max-width: 640px) {
  .email-controls {
    flex-direction: column;
  }
  
  .email-display {
    min-width: 100%;
  }
  
  .btn {
    width: 100%;
  }
}

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

.loading {
  opacity: 0.6;
  pointer-events: none;
}

.loading::after {
  content: '';
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid currentColor;
  border-right-color: transparent;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin-left: 8px;
}

/* Footer */
.footer {
  background: var(--bg-secondary);
  border-top: 2px solid var(--border);
  padding: 40px 20px;
  margin-top: 60px;
  text-align: center;
}

.footer-content {
  max-width: 800px;
  margin: 0 auto;
}

.footer-content p {
  margin: 12px 0;
  color: var(--text-secondary);
  line-height: 1.8;
}

.footer-links {
  margin: 20px 0;
}

.footer-links a {
  color: var(--text-primary);
  text-decoration: none;
  margin: 0 8px;
  transition: color 0.3s;
}

.footer-links a:hover {
  color: var(--accent);
}

.footer-copy {
  font-size: 13px;
  opacity: 0.7;
  margin-top: 20px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  max-width: 400px;
  pointer-events: auto;
  animation: slideIn 0.3s ease;
  cursor: pointer;
}

.toast:hover {
  transform: translateX(-4px);
  transition: transform 0.2s;
}

.toast-icon {
  font-size: 24px;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.toast-message {
  font-size: 14px;
  opacity: 0.95;
}

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

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

.toast.removing {
  animation: slideOut 0.3s ease forwards;
}

@media (max-width: 640px) {
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }
  
  .toast {
    min-width: auto;
    max-width: 100%;
  }
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 10000;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.toast {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 300px;
  max-width: 400px;
  pointer-events: auto;
  animation: slideIn 0.3s ease;
  cursor: pointer;
}

.toast:hover {
  transform: translateX(-4px);
  transition: transform 0.2s;
}

.toast-icon {
  font-size: 24px;
}

.toast-content {
  flex: 1;
}

.toast-title {
  font-weight: 700;
  margin-bottom: 4px;
}

.toast-message {
  font-size: 14px;
  opacity: 0.95;
}

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

@keyframes slideOut {
  from {
    transform: translateX(0);
    opacity: 1;
  }
  to {
    transform: translateX(400px);
    opacity: 0;
  }
}

.toast.removing {
  animation: slideOut 0.3s ease forwards;
}

@media (max-width: 640px) {
  .toast-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }
  
  .toast {
    min-width: auto;
    max-width: 100%;
  }
}

/* Updated Logo */
.logo-icon {
  width: 40px;
  height: 40px;
  background: url('/static/images/logo.svg') center/contain no-repeat;
  border-radius: 0;
  border: none;
}

/* Better Mobile Experience */
@media (max-width: 768px) {
  .container {
    padding: 10px;
  }
  
  .header {
    padding: 16px;
  }
  
  .header-top {
    flex-direction: column;
    gap: 12px;
  }
  
  .email-controls {
    flex-direction: column;
  }
  
  .email-display {
    min-width: 100%;
    font-size: 14px;
  }
  
  .btn {
    width: 100%;
    padding: 12px;
  }
  
  .main-grid {
    grid-template-columns: 1fr;
    gap: 12px;
  }
  
  .panel {
    min-height: 400px;
  }
  
  .message-header {
    padding: 12px;
  }
  
  .message-field {
    flex-direction: column;
    gap: 4px;
  }
  
  .message-label {
    min-width: auto;
    font-size: 12px;
  }
}

/* Install PWA Banner */
.install-banner {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: white;
  padding: 16px 24px;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
  display: none;
  align-items: center;
  gap: 16px;
  z-index: 9999;
  animation: slideUp 0.3s ease;
}

@keyframes slideUp {
  from {
    transform: translateX(-50%) translateY(100px);
    opacity: 0;
  }
  to {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
  }
}

.install-banner.show {
  display: flex;
}

.install-banner button {
  background: white;
  color: var(--accent);
  border: none;
  padding: 8px 20px;
  border-radius: 8px;
  font-weight: 700;
  cursor: pointer;
}

/* ===== BEAUTIFUL NOTIFICATIONS ===== */
.notif-container {
  position: fixed;
  top: 30px;
  right: 30px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 12px;
  pointer-events: none;
}

.notif {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 20px;
  border-radius: 16px;
  background: rgba(15,23,42,0.95);
  backdrop-filter: blur(20px);
  border: 1px solid rgba(255,255,255,0.1);
  box-shadow: 0 8px 32px rgba(0,0,0,0.4), 0 0 0 1px rgba(255,255,255,0.05);
  pointer-events: all;
  cursor: pointer;
  min-width: 280px;
  max-width: 360px;
  animation: notifIn 0.4s cubic-bezier(0.34,1.56,0.64,1);
  transition: transform 0.2s, opacity 0.2s;
}

.notif:hover { transform: scale(1.02); }

.notif.removing {
  animation: notifOut 0.3s ease forwards;
}

.notif-icon {
  font-size: 28px;
  flex-shrink: 0;
  animation: iconPop 0.5s cubic-bezier(0.34,1.56,0.64,1);
}

.notif-body { flex: 1; }

.notif-title {
  font-size: 14px;
  font-weight: 700;
  color: #f1f5f9;
  margin-bottom: 2px;
}

.notif-msg {
  font-size: 12px;
  color: #94a3b8;
}

.notif-progress {
  position: absolute;
  bottom: 0;
  left: 0;
  height: 3px;
  border-radius: 0 0 16px 16px;
  animation: progress linear forwards;
}

.notif.success { border-color: rgba(16,185,129,0.4); }
.notif.success .notif-progress { background: #10b981; }
.notif.error { border-color: rgba(239,68,68,0.4); }
.notif.error .notif-progress { background: #ef4444; }
.notif.info { border-color: rgba(59,130,246,0.4); }
.notif.info .notif-progress { background: #3b82f6; }
.notif.warning { border-color: rgba(245,158,11,0.4); }
.notif.warning .notif-progress { background: #f59e0b; }

@keyframes notifIn {
  from { transform: translateX(120%) scale(0.8); opacity: 0; }
  to { transform: translateX(0) scale(1); opacity: 1; }
}
@keyframes notifOut {
  from { transform: translateX(0) scale(1); opacity: 1; }
  to { transform: translateX(120%) scale(0.8); opacity: 0; }
}
@keyframes iconPop {
  0% { transform: scale(0) rotate(-180deg); }
  100% { transform: scale(1) rotate(0deg); }
}
@keyframes progress {
  from { width: 100%; }
  to { width: 0%; }
}

/* ===== COUNTDOWN TIMER ===== */
.refresh-timer {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}

.refresh-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  animation: pulse 1s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(0.8); }
}

/* ===== NEW MESSAGE BADGE ===== */
.inbox-badge {
  background: #ef4444;
  color: white;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  animation: badgePop 0.3s cubic-bezier(0.34,1.56,0.64,1);
}

@keyframes badgePop {
  from { transform: scale(0); }
  to { transform: scale(1); }
}

/* ===== NEW EMAIL HIGHLIGHT ===== */
.email-item.new-msg {
  border-left: 3px solid #10b981;
  animation: newMsgGlow 2s ease;
}

@keyframes newMsgGlow {
  0% { background: rgba(16,185,129,0.2); box-shadow: 0 0 20px rgba(16,185,129,0.3); }
  100% { background: transparent; box-shadow: none; }
}

/* ===== MOBILE TABS ===== */
.mobile-tabs {
  display: none;
  background: var(--bg-secondary);
  border-radius: 16px;
  padding: 6px;
  margin-bottom: 12px;
  gap: 6px;
}

.mobile-tab {
  flex: 1;
  padding: 12px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.mobile-tab.active {
  background: var(--accent);
  color: white;
  box-shadow: 0 4px 12px rgba(59,130,246,0.4);
}

@media (max-width: 768px) {
  .mobile-tabs {
    display: flex;
  }

  .container {
    padding: 10px;
  }

  .header {
    padding: 14px;
    border-radius: 12px;
  }

  .header-top {
    flex-direction: row;
    margin-bottom: 12px;
  }

  .logo {
    font-size: 20px;
  }

  .logo-icon {
    width: 32px;
    height: 32px;
  }

  .email-controls {
    display: grid;
    grid-template-columns: 1fr auto auto auto;
    gap: 8px;
  }

  .email-display {
    min-width: unset;
    font-size: 13px;
    padding: 10px 12px;
    grid-column: 1 / -1;
  }

  .btn {
    width: auto;
    padding: 10px 14px;
    font-size: 13px;
  }

  .main-grid {
    grid-template-columns: 1fr;
    gap: 0;
  }

  .panel {
    border-radius: 12px;
  }

  /* hide inactive panel on mobile */
  .panel.hidden-mobile {
    display: none;
  }

  .inbox-list {
    max-height: calc(100vh - 280px);
  }

  .message-viewer {
    padding: 12px;
    min-height: 400px;
  }

  .message-frame {
    min-height: 400px;
  }

  .message-empty {
    min-height: 300px;
  }

  .notif-container {
    top: 10px;
    right: 10px;
    left: 10px;
  }

  .notif {
    min-width: unset;
    max-width: 100%;
  }
}

/* === LANGUAGE SUPPORT === */
[data-lang="ar"] {
  direction: rtl;
}

[data-lang="ar"] .logo {
  flex-direction: row-reverse;
}

[data-lang="ar"] .email-controls {
  direction: rtl;
}

[data-lang="ar"] .main-grid {
  direction: rtl;
}

[data-lang="ar"] .message-field {
  direction: rtl;
}

/* === STARRED & READ STATUS === */
.star-btn {
  background: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  transition: transform 0.2s;
  opacity: 0.3;
}

.star-btn:hover {
  transform: scale(1.2);
  opacity: 1;
}

.star-btn.starred {
  opacity: 1;
}

.inbox-item.unread {
  background: var(--bg-tertiary);
  border-left: 4px solid #3b82f6;
}

.inbox-item.unread:hover {
  background: var(--bg-hover);
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0;
  left: 0;
  width: 220px;
  height: 100vh;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  z-index: 1000;
  transition: left 0.3s ease;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  box-shadow: 4px 0 20px rgba(0,0,0,0.15);
}

.sidebar.open {
  left: 0;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 16px;
  font-weight: 700;
  font-size: 15px;
  border-bottom: 1px solid var(--border);
  color: var(--text-primary);
}

.sidebar-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  transition: background 0.2s;
}

.sidebar-close:hover {
  background: var(--bg-tertiary);
}

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 12px 8px;
  gap: 4px;
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--text-primary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
  width: 100%;
}

.sidebar-btn:hover {
  background: var(--bg-tertiary);
  transform: translateX(3px);
}

.sidebar-btn.locked {
  color: #ef4444;
}

.sidebar-icon {
  font-size: 18px;
  width: 24px;
  text-align: center;
}

.sidebar-divider {
  height: 1px;
  background: var(--border);
  margin: 6px 8px;
}

.sidebar-toggle {
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 18px;
  cursor: pointer;
  padding: 6px 10px;
  transition: all 0.2s;
  line-height: 1;
}

.sidebar-toggle:hover {
  background: var(--accent);
  color: white;
  border-color: var(--accent);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 999;
  backdrop-filter: blur(2px);
}

.sidebar-overlay.active {
  display: block;
}

/* ===== HIDE TOGGLE/CLOSE ON DESKTOP ===== */
@media (min-width: 901px) {
  .sidebar-toggle { display: none !important; }
  .sidebar-close { display: none !important; }
}
