/* =========================================================
   SHAM MAIL – Global Stylesheet
   Dark-mode Gmail-inspired design
   ========================================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ── CSS Variables ── */
:root {
  --bg-base:       #1a1a2e;
  --bg-surface:    #16213e;
  --bg-card:       #0f3460;
  --bg-hover:      #1e3a5f;
  --bg-active:     #e94560;
  --accent:        #e94560;
  --accent-soft:   rgba(233,69,96,0.15);
  --accent-glow:   rgba(233,69,96,0.35);
  --text-primary:  #e0e6f0;
  --text-secondary:#8fa3b8;
  --text-muted:    #4a6080;
  --border:        rgba(255,255,255,0.07);
  --border-light:  rgba(255,255,255,0.12);
  --shadow-sm:     0 2px 8px rgba(0,0,0,0.4);
  --shadow-md:     0 4px 24px rgba(0,0,0,0.5);
  --shadow-lg:     0 8px 48px rgba(0,0,0,0.6);
  --radius-sm:     8px;
  --radius-md:     12px;
  --radius-lg:     20px;
  --sidebar-w:     260px;
  --topbar-h:      64px;
  --font:          'Inter', system-ui, sans-serif;
  --transition:    150ms cubic-bezier(.4,0,.2,1);
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: var(--font); border: none; outline: none; }
input, textarea { font-family: var(--font); }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--text-muted); border-radius: 99px; }

/* ============================================================
   AUTH PAGE  (index.html)
   ============================================================ */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 30% 50%, #0f3460 0%, #1a1a2e 60%);
  padding: 24px;
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  padding: 48px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .4s ease;
}

@keyframes slideUp {
  from { opacity:0; transform:translateY(20px); }
  to   { opacity:1; transform:translateY(0); }
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}
.auth-logo .logo-icon {
  width: 42px; height: 42px;
  background: var(--accent);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  box-shadow: 0 0 20px var(--accent-glow);
}
.auth-logo .logo-text { font-size: 22px; font-weight: 700; letter-spacing: -0.5px; }
.auth-logo .logo-text span { color: var(--accent); }

.auth-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 28px;
}
.auth-tab {
  flex: 1;
  padding: 10px;
  border-radius: 6px;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all var(--transition);
}
.auth-tab.active {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 0 12px var(--accent-glow);
}

.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
  margin-bottom: 6px;
}
.form-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.form-input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.form-input::placeholder { color: var(--text-muted); }

.form-hint {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
}

.btn-primary {
  width: 100%;
  padding: 13px;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  border-radius: var(--radius-sm);
  margin-top: 8px;
  transition: opacity var(--transition), transform var(--transition), box-shadow var(--transition);
  box-shadow: 0 4px 16px var(--accent-glow);
}
.btn-primary:hover  { opacity: .88; transform: translateY(-1px); }
.btn-primary:active { opacity: 1; transform: translateY(0); }
.btn-primary:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.auth-error {
  background: rgba(239,68,68,.15);
  border: 1px solid rgba(239,68,68,.4);
  color: #fca5a5;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}
.auth-error.show { display: block; }

/* ============================================================
   APP SHELL  (app.html)
   ============================================================ */
.app {
  display: grid;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-columns: var(--sidebar-w) 1fr;
  height: 100vh;
  overflow: hidden;
}

/* ── Top Bar ── */
.topbar {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  z-index: 10;
}
.topbar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 140px;
}
.menu-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 24px;
  padding: 8px;
  cursor: pointer;
  margin-right: 8px;
}
.topbar-logo .logo-icon {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  box-shadow: 0 0 14px var(--accent-glow);
}
.topbar-logo .logo-text { font-size: 18px; font-weight: 700; }
.topbar-logo .logo-text span { color: var(--accent); }

.search-bar {
  flex: 1;
  max-width: 560px;
  position: relative;
}
.search-bar input {
  width: 100%;
  padding: 10px 16px 10px 42px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 99px;
  color: var(--text-primary);
  font-size: 14px;
  transition: border-color var(--transition), box-shadow var(--transition);
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.search-bar .search-icon {
  position: absolute;
  left: 14px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 15px;
  pointer-events: none;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 12px;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--bg-base);
  border-radius: 99px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 500;
}
.user-avatar {
  width: 26px; height: 26px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
}
#user-email-display { color: var(--text-secondary); }

.btn-logout {
  padding: 8px 14px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: all var(--transition);
}
.btn-logout:hover { border-color: var(--accent); color: var(--accent); }

/* ── Sidebar ── */
.sidebar {
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 16px 12px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.compose-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 18px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 8px;
  box-shadow: 0 4px 16px var(--accent-glow);
  transition: opacity var(--transition), transform var(--transition);
}
.compose-btn:hover { opacity: .88; transform: translateY(-1px); }
.compose-btn .compose-plus { font-size: 20px; line-height: 1; }

.sidebar-label {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-muted);
  padding: 12px 8px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  user-select: none;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}
.nav-item .nav-icon { font-size: 17px; width: 20px; text-align: center; }
.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
}

/* ── Main Panel ── */
.main-panel {
  display: grid;
  grid-template-columns: 360px 1fr;
  overflow: hidden;
}

/* ── Message List ── */
.msg-list-pane {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.pane-header {
  padding: 20px 20px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.pane-title {
  font-size: 18px;
  font-weight: 700;
}
.pane-count {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
}

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

.msg-item {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background var(--transition);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  position: relative;
}
.msg-item:hover { background: var(--bg-hover); }
.msg-item.active { background: var(--accent-soft); }
.msg-item.unread .msg-sender { font-weight: 700; color: var(--text-primary); }
.msg-item.unread::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 4px; height: 40%;
  background: var(--accent);
  border-radius: 0 4px 4px 0;
}
.msg-sender {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  grid-row: 1;
  grid-column: 2;
}
.msg-subject {
  font-size: 14px;
  font-weight: 500;
  color: var(--text-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 1 / -1;
}
.msg-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  grid-column: 1 / -1;
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text-muted);
  padding: 40px;
}
.empty-state .empty-icon { font-size: 48px; }
.empty-state p { font-size: 14px; text-align: center; }

/* ── Message Detail ── */
.msg-detail-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.detail-placeholder {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
}
.detail-placeholder .ph-icon { font-size: 64px; opacity: .3; }
.detail-placeholder p { font-size: 15px; opacity: .5; }

.detail-view {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}
.detail-header {
  padding: 24px 28px 16px;
  border-bottom: 1px solid var(--border);
}
.detail-subject {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 12px;
  line-height: 1.3;
}
.detail-meta {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}
.detail-avatar {
  width: 38px; height: 38px;
  background: var(--bg-card);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  border: 1px solid var(--border-light);
  flex-shrink: 0;
}
.detail-from { font-size: 13px; }
.detail-from strong { color: var(--text-primary); }
.detail-from span { color: var(--text-muted); }
.detail-date { margin-left: auto; font-size: 12px; color: var(--text-muted); }

.detail-actions {
  display: flex;
  gap: 8px;
  padding: 12px 28px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.btn-action {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  transition: all var(--transition);
}
.btn-action:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.btn-action.danger:hover { border-color: #ef4444; color: #ef4444; background: rgba(239,68,68,.1); }

.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  font-size: 15px;
  line-height: 1.75;
  color: var(--text-primary);
}
.detail-body p { margin-bottom: 12px; }
.detail-body a { color: var(--accent); }

/* ============================================================
   COMPOSE MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  justify-content: flex-end;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--transition);
}
.modal-overlay.open { opacity: 1; pointer-events: all; }

.compose-modal {
  width: 560px;
  max-height: 70vh;
  background: var(--bg-surface);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  display: flex;
  flex-direction: column;
  transform: translateY(20px);
  transition: transform .25s ease;
  overflow: hidden;
}
.modal-overlay.open .compose-modal { transform: translateY(0); }

.compose-header {
  display: flex;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: 15px;
}
.compose-close {
  margin-left: auto;
  background: none;
  color: var(--text-muted);
  font-size: 20px;
  line-height: 1;
  padding: 4px 8px;
  border-radius: 4px;
  transition: color var(--transition), background var(--transition);
}
.compose-close:hover { color: var(--text-primary); background: var(--bg-hover); }

.compose-field {
  display: flex;
  align-items: center;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
}
.compose-field label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  min-width: 52px;
}
.compose-field input {
  flex: 1;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 14px;
}
.compose-field input:focus { outline: none; }
.compose-field input::placeholder { color: var(--text-muted); }

.rich-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.toolbar-btn {
  padding: 5px 10px;
  background: none;
  color: var(--text-secondary);
  border-radius: 4px;
  font-size: 13px;
  font-weight: 700;
  transition: all var(--transition);
  border: 1px solid transparent;
}
.toolbar-btn:hover { background: var(--bg-hover); color: var(--text-primary); border-color: var(--border); }
.toolbar-btn.active { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }

.compose-body-editor {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  min-height: 160px;
  color: var(--text-primary);
  font-size: 14px;
  line-height: 1.7;
  outline: none;
}
.compose-body-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--text-muted);
  pointer-events: none;
}

.compose-footer {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 20px;
  border-top: 1px solid var(--border);
}
.btn-send {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 22px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  box-shadow: 0 4px 14px var(--accent-glow);
  transition: opacity var(--transition), transform var(--transition);
}
.btn-send:hover { opacity: .88; transform: translateY(-1px); }
.btn-send:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.btn-draft {
  padding: 10px 18px;
  background: var(--bg-base);
  border: 1px solid var(--border);
  color: var(--text-secondary);
  border-radius: var(--radius-sm);
  font-size: 13px;
  transition: all var(--transition);
}
.btn-draft:hover { border-color: var(--accent); color: var(--accent); }
.btn-discard {
  margin-left: auto;
  padding: 10px;
  background: none;
  color: var(--text-muted);
  font-size: 13px;
  transition: color var(--transition);
}
.btn-discard:hover { color: #ef4444; }

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
.toast-container {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  backdrop-filter: blur(10px);
  border: 1px solid;
  animation: toastIn .3s ease, toastOut .3s ease 2.7s forwards;
  white-space: nowrap;
}
.toast.success {
  background: rgba(34,197,94,.15);
  border-color: rgba(34,197,94,.4);
  color: #86efac;
}
.toast.error {
  background: rgba(239,68,68,.15);
  border-color: rgba(239,68,68,.4);
  color: #fca5a5;
}
.toast.info {
  background: rgba(99,102,241,.15);
  border-color: rgba(99,102,241,.4);
  color: #a5b4fc;
}
@keyframes toastIn {
  from { opacity:0; transform:translateY(10px) scale(.95); }
  to   { opacity:1; transform:translateY(0) scale(1); }
}
@keyframes toastOut {
  to { opacity:0; transform:translateY(-6px) scale(.95); }
}

/* ── Loading Spinner ── */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-state {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 60px;
}

/* ── Mobile Navigation Helpers ── */
.mobile-back-btn {
  display: none;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  padding: 8px 12px;
  cursor: pointer;
  margin-right: 8px;
}

/* ── Responsive ── */
@media (max-width: 900px) {
  :root { --sidebar-w: 280px; }
  
  .app {
    grid-template-columns: 1fr;
  }

  /* Sidebar as Drawer */
  .sidebar {
    position: fixed;
    left: calc(-1 * var(--sidebar-w));
    top: var(--topbar-h);
    bottom: 0;
    width: var(--sidebar-w);
    z-index: 100;
    transition: left 0.3s ease;
    box-shadow: 10px 0 30px rgba(0,0,0,0.5);
  }
  .sidebar.mobile-open {
    left: 0;
  }
  
  .menu-toggle {
    display: block;
  }

  .main-panel {
    grid-template-columns: 1fr;
    position: relative;
  }

  /* View Stacking */
  .msg-list-pane, .msg-detail-pane {
    grid-column: 1;
    grid-row: 1;
    height: 100%;
    width: 100%;
    background: var(--bg-base);
  }

  .msg-detail-pane {
    position: absolute;
    right: -100%;
    transition: right 0.3s ease;
    z-index: 5;
  }
  .msg-detail-pane.mobile-show {
    right: 0;
  }

  .mobile-back-btn {
    display: block;
  }

  .detail-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
  }

  .topbar-logo .logo-text { font-size: 16px; }
  .search-bar { display: none; } /* Hide search on small screens to save space */
  
  .user-chip { padding: 4px 8px; }
  .user-chip span { display: none; }
}

@media (max-width: 600px) {
  .compose-btn span { display: none; }
  .compose-btn { width: 50px; height: 50px; padding: 0; justify-content: center; }
  .compose-modal { width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
}
