/* ProtonMail Early-2010s Webmail Aesthetic */
:root {
  --bg-dark-sidebar: #2d2d37;
  --bg-dark-hover: #3c3c4a;
  --primary-purple: #6a538d;
  --primary-purple-hover: #584377;
  --bg-light-gray: #f4f4f6;
  --border-color: #d1d1d8;
  --text-dark: #333333;
  --text-muted: #888888;
  --highlight-row: #fffde6;
  --composer-header-bg: #383842;
}

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

html,
body {
  height: 100%;
}

/* Accessibility: larger base font, good contrast, readable line-height */
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-dark);
  background-color: #e9e9ed;
  font-size: 16px;
  line-height: 1.5;
  /* dvh handles mobile browser chrome (URL bar) correctly; vh is the fallback */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  /* Flex column: banner + app share the viewport, no hardcoded calc() offsets */
  display: flex;
  flex-direction: column;
}

/* Top Warning Banner */
.top-warning-banner {
  background-color: #d9534f;
  color: #ffffff;
  text-align: center;
  padding: 10px 15px;
  font-weight: bold;
  font-size: 1rem;
  width: 100%;
  z-index: 1000;
  flex-shrink: 0;
}

/* App Container — flexes to fill the space left by the banner.
   position: relative makes this the containing block for the modal,
   so the modal can never overlap the banner above it. */
.webmail-app {
  display: flex;
  flex: 1;
  min-height: 0;
  width: 100%;
  position: relative;
}

/* 1. Left Sidebar */
.sidebar {
  width: 200px;
  background-color: var(--bg-dark-sidebar);
  color: #c9c9d4;
  display: flex;
  flex-direction: column;
  padding-top: 10px;
  font-size: 14px;
  flex-shrink: 0;
}

.brand {
  padding: 10px 15px 15px;
  color: #ffffff;
  font-weight: bold;
  font-size: 18px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo-img {
  width: 36px;
  height: 36px;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.brand-name {
  color: #ffffff;
  font-weight: bold;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

.compose-btn-wrapper {
  padding: 0 12px 15px;
}

.compose-btn {
  width: 100%;
  background-color: var(--primary-purple);
  color: white;
  border: none;
  padding: 10px 12px;
  border-radius: 3px;
  font-weight: 600;
  font-size: 14px;
  cursor: pointer;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 6px;
}

.compose-btn:hover {
  background-color: var(--primary-purple-hover);
}

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

.nav-list.secondary {
  margin-top: 15px;
}

.nav-item {
  padding: 10px 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.nav-item:hover, .nav-item.active {
  background-color: var(--bg-dark-hover);
  color: #ffffff;
}

.badge {
  background-color: #4a4a58;
  color: white;
  padding: 2px 8px;
  border-radius: 8px;
  font-size: 12px;
}

.badge.unread {
  background-color: #ffffff;
  color: var(--bg-dark-sidebar);
  font-weight: bold;
}

/* 2. Main Content Area */
.main-area {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: white;
  overflow: hidden;
}

.top-header {
  min-height: 45px;
  background-color: var(--bg-dark-sidebar);
  border-left: 1px solid #3c3c4a;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  color: white;
  font-size: 14px;
}

.search-bar input {
  background: #3c3c4a;
  border: 1px solid #4d4d5e;
  border-radius: 3px;
  padding: 6px 10px;
  color: white;
  width: 260px;
  font-size: 14px;
}

.user-meta {
  display: flex;
  gap: 15px;
  color: #aaaaaa;
}

.action-toolbar {
  min-height: 40px;
  background: var(--bg-light-gray);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 15px;
  font-size: 13px;
  color: #555;
}

.toolbar-group {
  display: flex;
  align-items: center;
  gap: 10px;
}

/* Email Table View */
.inbox-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.email-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.email-table td {
  padding: 12px 15px;
  border-bottom: 1px solid #eeeeee;
}

.email-table tr {
  cursor: pointer;
}

.email-table tr:hover {
  background-color: #f1f1f5;
}

.email-table tr.unread-row {
  background-color: var(--highlight-row);
  font-weight: bold;
}

.sender {
  width: 25%;
}

.checkbox-col {
  width: 30px;
  text-align: center;
}

/* 3. Composer / Reader Modal (desktop) */
.composer-modal {
  position: absolute;
  top: 50%;
  left: 55%;
  transform: translate(-50%, -50%);
  width: 800px;
  height: 650px;
  max-width: calc(100vw - 40px);
  max-height: calc(100% - 40px);
  background: white;
  border-radius: 5px;
  box-shadow: 0 15px 40px rgba(0, 0, 0, 0.35);
  border: 1px solid #999999;
  display: flex;
  flex-direction: column;
  z-index: 100;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.composer-modal.hidden {
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, -48%) scale(0.98);
}

.composer-titlebar {
  background-color: var(--composer-header-bg);
  color: white;
  padding: 12px 15px;
  border-radius: 4px 4px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 14px;
  /* Never let the title bar be squeezed out of the flex column */
  flex-shrink: 0;
  min-height: 44px;
}

.window-controls {
  display: flex;
  align-items: center;
  flex-shrink: 0;
}

.window-controls span {
  margin-left: 10px;
  cursor: pointer;
  opacity: 0.85;
  display: inline-block;
  min-width: 22px;
  text-align: center;
  line-height: 1;
}

.window-controls span:hover {
  opacity: 1;
}

.composer-fields {
  border-bottom: 1px solid var(--border-color);
  padding: 6px 15px;
  font-size: 14px;
  background: #fafafa;
  flex-shrink: 0;
}

.field-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
  padding: 6px 0;
}

.field-row:last-child {
  border-bottom: none;
}

.field-row label {
  width: 60px;
  color: var(--text-muted);
  font-weight: 500;
}

.field-row input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  color: #333;
  background: transparent;
  min-width: 0;
}

/* Fix rich toolbar item alignment */
.rich-toolbar {
  display: flex;
  align-items: center;
  gap: 15px;
  padding: 8px 12px;
  background: #f0f0f0;
  border-bottom: 1px solid #ddd;
  flex-shrink: 0;
  overflow-x: auto;
}

.rich-toolbar span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.rich-toolbar span b,
.rich-toolbar span i,
.rich-toolbar span u {
  display: inline-block;
  min-width: 14px;
  text-align: center;
  font-style: normal;
  font-size: 15px;
  line-height: 1;
}

.rich-toolbar span u {
  text-decoration: underline;
}

.rich-toolbar span i {
  font-style: italic;
}

/* Large Scrollable Content Body */
.composer-content {
  flex: 1;
  min-height: 0;
  padding: 25px 30px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  font-size: 15px;
  line-height: 1.7;
  color: #222;
}

.composer-content h1, .composer-content h2 {
  margin-bottom: 15px;
  color: #2d2d37;
  line-height: 1.3;
}

.composer-content p {
  margin-bottom: 15px;
}

.composer-footer {
  padding: 10px 15px;
  background-color: #f9f9f9;
  border-top: 1px solid #eeeeee;
  font-size: 13px;
  color: var(--text-muted);
  flex-shrink: 0;
}

/* ============================================
   MOBILE (max-width: 768px)
   ============================================ */
@media (max-width: 768px) {

  /* App becomes a vertical stack: sidebar bar on top, content below.
     No fixed heights — flexbox distributes the space. */
  .webmail-app {
    flex-direction: column;
  }

  /* Sidebar becomes a compact horizontal bar that scrolls sideways */
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 8px 10px;
    gap: 12px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    flex-shrink: 0;
  }

  /* Hide the horizontal scrollbar but keep scrolling */
  .sidebar::-webkit-scrollbar {
    display: none;
  }

  .sidebar .brand {
    padding: 0;
    flex-shrink: 0;
  }

  .sidebar .logo-img {
    width: 28px;
    height: 28px;
  }

  .brand-name {
    font-size: 0.95rem;
  }

  .sidebar .compose-btn-wrapper {
    padding: 0;
    margin: 0;
    flex-shrink: 0;
  }

  .compose-btn {
    padding: 8px 10px;
    font-size: 13px;
    white-space: nowrap;
  }

  .sidebar .nav-list {
    display: flex;
    flex-direction: row;
    gap: 4px;
    margin: 0;
    flex: 1;
    white-space: nowrap;
  }

  .sidebar .nav-list.secondary {
    margin-top: 0;
    flex: 0 0 auto;
  }

  .nav-item {
    padding: 6px 8px;
    font-size: 13px;
    flex-shrink: 0;
  }

  /* Content area fills the remaining space */
  .main-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
  }

  /* Header stacks vertically: search on its own line */
  .top-header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 10px;
  }

  .search-bar input {
    width: 100%;
    /* 16px prevents iOS Safari from zooming the page on focus */
    font-size: 16px;
  }

  .user-meta {
    justify-content: space-between;
    gap: 10px;
    font-size: 13px;
  }

  /* Toolbar wraps instead of overflowing */
  .action-toolbar {
    flex-wrap: wrap;
    padding: 8px 12px;
    gap: 6px;
    font-size: 13px;
  }

  .toolbar-group {
    flex-wrap: wrap;
    gap: 8px;
  }

  /* Table: truncate long senders/subjects instead of stretching the row */
  .email-table {
    table-layout: fixed;
  }

  .email-table td {
    padding: 10px 8px;
    font-size: 14px;
  }

  .checkbox-col {
    width: 34px;
  }

  .sender {
    width: 35%;
  }

  .sender,
  .subject-preview {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  /* ---- MODAL FIX ----
     Anchored to .webmail-app (position: relative), NOT the viewport.
     Because .webmail-app starts *below* the warning banner, the modal
     now fills exactly the area beneath it. No hardcoded offset needed,
     so it still works when the banner wraps to two lines on a phone.
     z-index stays below the banner's 1000 as a safety net. */
  .composer-modal {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 100%;
    max-width: none;
    max-height: none;
    transform: none;
    border-radius: 0;
    border: none;
    border-top: 1px solid #999;
    z-index: 300;
  }

  .composer-modal.hidden {
    transform: none;
    opacity: 0;
    pointer-events: none;
  }

  /* Title bar: guaranteed its own row, with finger-sized controls */
  .composer-titlebar {
    padding: 12px 15px;
    border-radius: 0;
    min-height: 54px;
  }

  .window-controls span {
    margin-left: 14px;
    font-size: 19px;
    padding: 8px 10px;
    min-width: 44px;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
  }

  .window-controls span:active {
    background-color: rgba(255, 255, 255, 0.15);
  }

  /* Shorter field rows on mobile to save vertical space */
  .composer-fields {
    padding: 4px 15px;
  }

  .field-row {
    padding: 4px 0;
  }

  .field-row label {
    font-size: 14px;
  }

  .field-row input {
    font-size: 16px;
    padding: 4px 0;
  }

  .rich-toolbar {
    padding: 6px 12px;
    gap: 12px;
    font-size: 15px;
  }

  .composer-content {
    padding: 16px;
  }
}
