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

:root {
  --blue: #1a73e8;
  --blue-light: #e8f0fe;
  --blue-mid: #d3e3fd;
  --red: #ea4335;
  --green: #34a853;
  --text: #202124;
  --text-muted: #5f6368;
  --border: #e0e0e0;
  --hover-bg: #f2f6fc;
  --sidebar-active: #d3e3fd;
  --unread-bg: #fff;
  --white: #fff;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.15), 0 2px 6px rgba(0,0,0,.1);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.22), 0 2px 8px rgba(0,0,0,.1);
}

body {
  font-family: 'Google Sans', Roboto, -apple-system, Arial, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: #f6f8fc;
  height: 100vh;
  overflow: hidden;
}

a { color: var(--blue); text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; }

/* ── App shell ── */
.app { display: flex; flex-direction: column; height: 100vh; }

/* ── Top bar ── */
.topbar {
  display: flex;
  align-items: center;
  height: 64px;
  padding: 0 16px;
  gap: 8px;
  background: #f6f8fc;
  flex-shrink: 0;
}

.topbar-logo {
  display: flex;
  align-items: center;
  gap: 4px;
  width: 220px;
  flex-shrink: 0;
}

.logo-icon {
  width: 40px;
  height: 40px;
  background: var(--red);
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 20px;
  font-weight: 800;
  font-style: italic;
  letter-spacing: -1px;
  flex-shrink: 0;
}

.logo-name {
  font-size: 22px;
  color: var(--text-muted);
  font-weight: 400;
  letter-spacing: -0.5px;
}

.search-wrap {
  flex: 1;
  max-width: 720px;
  position: relative;
}

.search-bar {
  width: 100%;
  height: 46px;
  background: #eaf1fb;
  border: 1px solid transparent;
  border-radius: 24px;
  padding: 0 48px 0 56px;
  font-size: 16px;
  font-family: inherit;
  color: var(--text);
  outline: none;
  transition: background 0.2s, border-color 0.2s, box-shadow 0.2s;
}

.search-bar:focus {
  background: var(--white);
  border-color: transparent;
  box-shadow: var(--shadow-md);
}

.search-icon {
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 18px;
  pointer-events: none;
}

.search-clear {
  position: absolute;
  right: 14px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 20px;
  padding: 4px;
  border-radius: 50%;
  display: none;
  line-height: 1;
}

.search-clear:hover { background: #e8e8e8; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 4px;
  margin-left: auto;
}

.avatar-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--blue);
  color: white;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Body ── */
.body {
  display: flex;
  flex: 1;
  overflow: hidden;
  padding: 0 8px 8px;
  gap: 0;
}

/* ── Sidebar ── */
.sidebar {
  width: 256px;
  flex-shrink: 0;
  padding-top: 8px;
  overflow-y: auto;
}

.compose-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0 8px 8px;
  padding: 18px 24px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: box-shadow 0.2s, background 0.2s;
  width: calc(100% - 16px);
}

.compose-btn:hover { box-shadow: var(--shadow-md); background: #f8fbff; }

.compose-btn svg { flex-shrink: 0; }

.folder-nav { padding: 4px 0; }

.folder-item {
  display: flex;
  align-items: center;
  gap: 12px;
  height: 36px;
  padding: 0 16px 0 12px;
  border-radius: 0 18px 18px 0;
  cursor: pointer;
  margin-right: 14px;
  color: var(--text);
  font-size: 14px;
  font-weight: 400;
  transition: background 0.15s;
  user-select: none;
}

.folder-item:hover { background: #e8eaed; }
.folder-item.active { background: var(--sidebar-active); font-weight: 700; }

.folder-item .folder-icon { font-size: 16px; width: 20px; text-align: center; flex-shrink: 0; }
.folder-item .folder-label { flex: 1; }

.folder-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  min-width: 18px;
  text-align: right;
}

/* ── Main content ── */
.main {
  flex: 1;
  background: var(--white);
  border-radius: 16px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-sm);
}

/* ── Toolbar above message list ── */
.list-toolbar {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
  flex-shrink: 0;
}

.toolbar-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 13px;
  color: var(--text-muted);
  transition: background 0.15s;
}

.toolbar-btn:hover { background: var(--hover-bg); color: var(--text); }

.toolbar-label {
  font-size: 13px;
  color: var(--text-muted);
  margin-left: auto;
}

.trash-banner {
  background: #fef7e0;
  border-bottom: 1px solid #f0e0a0;
  padding: 8px 16px;
  font-size: 13px;
  color: #7a6208;
}

/* ── Message list ── */
.msg-list { overflow-y: auto; flex: 1; }

.msg-row {
  display: flex;
  align-items: center;
  height: 52px;
  padding: 0 16px;
  border-bottom: 1px solid #f0f0f0;
  cursor: pointer;
  gap: 0;
  position: relative;
  transition: box-shadow 0.1s;
  background: var(--white);
}

.msg-row.unread { background: #f2f6fc; }

.msg-row:hover {
  box-shadow: 0 2px 8px rgba(0,0,0,.14);
  z-index: 2;
}

.msg-row:hover .msg-actions { opacity: 1; }
.msg-row:hover .msg-date { display: none; }

.msg-check {
  width: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.msg-check input[type=checkbox] {
  width: 16px;
  height: 16px;
  cursor: pointer;
  accent-color: var(--blue);
}

.msg-star {
  width: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  color: #c5c5c5;
  flex-shrink: 0;
  z-index: 3;
  transition: color 0.15s;
}

.msg-star:hover { color: #f4b400; }
.msg-star.starred { color: #f4b400; }

.msg-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
  margin-right: 12px;
  text-transform: uppercase;
}

.msg-from {
  width: 176px;
  flex-shrink: 0;
  font-size: 14px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  padding-right: 8px;
}

.msg-row.unread .msg-from { font-weight: 700; }

.msg-preview {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  font-size: 14px;
  color: var(--text);
  min-width: 0;
}

.msg-subject-text { }
.msg-row.unread .msg-subject-text { font-weight: 600; }

.msg-snippet-text { color: var(--text-muted); font-weight: 400; }
.msg-snippet-text::before { content: " — "; }

.msg-date {
  width: 68px;
  text-align: right;
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.msg-row.unread .msg-date { font-weight: 700; color: var(--text); }

.msg-actions {
  position: absolute;
  right: 16px;
  display: flex;
  align-items: center;
  gap: 2px;
  opacity: 0;
  background: var(--white);
}

.msg-row.unread .msg-actions { background: #f2f6fc; }
.msg-row:hover .msg-actions { background: transparent; }

.icon-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: 16px;
  transition: background 0.15s, color 0.15s;
}

.icon-btn:hover { background: #e0e0e0; color: var(--text); }
.icon-btn.danger:hover { background: #fce8e6; color: var(--red); }

/* ── Empty state ── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 320px;
  color: var(--text-muted);
  gap: 12px;
}

.empty-state .empty-icon { font-size: 64px; opacity: 0.3; }
.empty-state .empty-text { font-size: 16px; }

/* ── Message view ── */
.msg-view {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow-y: auto;
  padding: 0 24px 40px;
}

.msg-view-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 0;
  position: sticky;
  top: 0;
  background: var(--white);
  z-index: 5;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.back-btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 4px;
  font-size: 14px;
  color: var(--text-muted);
  margin-right: 4px;
}

.back-btn:hover { background: var(--hover-bg); color: var(--text); }

.msg-view-subject {
  font-size: 26px;
  font-weight: 400;
  margin-bottom: 20px;
  line-height: 1.3;
}

.msg-view-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 24px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.msg-view-header .msg-avatar {
  width: 40px;
  height: 40px;
  font-size: 16px;
  margin-right: 0;
  flex-shrink: 0;
}

.msg-view-meta { flex: 1; }

.msg-view-from {
  font-size: 14px;
  font-weight: 600;
}

.msg-view-addr { font-weight: 400; color: var(--text-muted); }

.msg-view-todate {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.msg-view-date-right {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.msg-view-body {
  font-size: 14px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text);
  max-width: 760px;
  margin-bottom: 32px;
}

.reply-bar {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.reply-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 14px;
  color: var(--text-muted);
  background: var(--white);
  transition: border-color 0.15s, background 0.15s;
}

.reply-btn:hover { border-color: #aaa; background: var(--hover-bg); color: var(--text); }

/* ── Compose overlay ── */
.compose-overlay {
  position: fixed;
  bottom: 0;
  right: 24px;
  width: 540px;
  height: 480px;
  background: var(--white);
  border-radius: 14px 14px 0 0;
  box-shadow: var(--shadow-lg);
  z-index: 500;
  display: flex;
  flex-direction: column;
  transition: height 0.2s;
}

.compose-overlay.minimized { height: 52px; }
.compose-overlay[hidden] { display: none; }

.compose-header {
  display: flex;
  align-items: center;
  background: #404040;
  color: white;
  padding: 0 16px;
  height: 52px;
  border-radius: 14px 14px 0 0;
  flex-shrink: 0;
  cursor: pointer;
  user-select: none;
  gap: 8px;
}

.compose-title { flex: 1; font-size: 14px; font-weight: 600; }

.compose-hbtn {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: white;
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
  flex-shrink: 0;
}

.compose-hbtn:hover { background: rgba(255,255,255,.15); }

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

.compose-field {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  gap: 8px;
  flex-shrink: 0;
}

.compose-field-label {
  font-size: 13px;
  color: var(--text-muted);
  width: 48px;
  flex-shrink: 0;
}

.compose-field input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
}

.compose-textarea {
  flex: 1;
  padding: 12px 16px;
  border: none;
  outline: none;
  resize: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  line-height: 1.7;
}

.compose-footer {
  display: flex;
  align-items: center;
  padding: 10px 16px;
  gap: 8px;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.send-btn {
  background: var(--blue);
  color: white;
  padding: 8px 20px;
  border-radius: 20px;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, box-shadow 0.15s;
}

.send-btn:hover { background: #1557b0; box-shadow: var(--shadow-sm); }

.draft-btn {
  color: var(--text-muted);
  padding: 8px 14px;
  border-radius: 20px;
  font-size: 13px;
  transition: background 0.15s;
}

.draft-btn:hover { background: var(--hover-bg); color: var(--text); }

.compose-del-btn {
  margin-left: auto;
  color: var(--text-muted);
}

/* ── Search results ── */
.search-header {
  padding: 12px 24px 8px;
  font-size: 13px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Toast ── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: #323232;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 1000;
  transition: transform 0.3s ease;
  pointer-events: none;
  white-space: nowrap;
}

.toast.show { transform: translateX(-50%) translateY(0); }

/* ── Draft indicator ── */
.draft-row .msg-from { color: var(--red); }

.mobile-menu-btn,
.mobile-compose-fab,
.sidebar-scrim {
  display: none;
}

/* ── Responsive tablet/mobile ── */
@media (max-width: 760px) {
  body {
    background: var(--white);
  }

  .app {
    min-width: 0;
  }

  .topbar {
    height: 96px;
    align-items: flex-start;
    gap: 0;
    padding: 10px 14px 8px;
    background: var(--white);
    position: relative;
    z-index: 120;
  }

  .mobile-menu-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    position: absolute;
    left: 26px;
    top: 18px;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    color: var(--text);
    font-size: 26px;
    line-height: 1;
    z-index: 2;
  }

  .mobile-menu-btn:hover {
    background: rgba(60,64,67,.08);
  }

  .topbar-logo {
    display: none;
  }

  .topbar-right {
    position: absolute;
    top: 18px;
    right: 26px;
    z-index: 2;
  }

  .avatar-btn {
    width: 32px;
    height: 32px;
    background: var(--white);
    color: transparent;
    border: 1px solid #dadce0;
    box-shadow: 0 1px 2px rgba(60,64,67,.15);
  }

  .search-wrap {
    flex: 1 1 auto;
    max-width: none;
    width: 100%;
  }

  .search-bar {
    height: 50px;
    padding: 0 54px;
    background: #eef3fb;
    border-radius: 25px;
    font-size: 16px;
    box-shadow: 0 1px 2px rgba(60,64,67,.08);
  }

  .search-bar::placeholder {
    color: #68717d;
  }

  .search-icon {
    display: none;
  }

  .search-clear {
    right: 54px;
  }

  .body {
    padding: 0;
    display: block;
    overflow: hidden;
  }

  .main {
    height: 100%;
    border-radius: 0;
    box-shadow: none;
    background: var(--white);
  }

  .sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    width: min(82vw, 320px);
    padding-top: 18px;
    background: var(--white);
    box-shadow: var(--shadow-lg);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    z-index: 300;
  }

  .sidebar-open .sidebar {
    transform: translateX(0);
  }

  .sidebar-scrim {
    position: fixed;
    inset: 0;
    background: rgba(32,33,36,.32);
    z-index: 250;
  }

  .sidebar-open .sidebar-scrim {
    display: block;
  }

  .compose-btn {
    margin: 0 14px 14px;
    width: calc(100% - 28px);
    border-radius: 18px;
  }

  .folder-item {
    height: 44px;
    font-size: 15px;
  }

  .list-toolbar {
    min-height: 38px;
    padding: 0 14px 8px;
    border-bottom: none;
    background: var(--white);
  }

  .list-toolbar > span:first-child {
    font-size: 14px !important;
    color: var(--text-muted) !important;
    font-weight: 500 !important;
  }

  .toolbar-label {
    display: none;
  }

  .trash-banner,
  .search-header {
    padding: 10px 14px;
  }

  .msg-list {
    padding-bottom: 96px;
  }

  .msg-row {
    display: grid;
    grid-template-columns: 46px minmax(0, 1fr) auto;
    grid-template-rows: auto auto;
    column-gap: 12px;
    row-gap: 2px;
    min-height: 100px;
    height: auto;
    padding: 14px 14px 12px;
    align-items: center;
    border-bottom: none;
    background: var(--white);
  }

  .msg-row.unread {
    background: var(--white);
  }

  .msg-row:hover {
    box-shadow: none;
  }

  .msg-check {
    display: none;
  }

  .msg-avatar {
    grid-column: 1;
    grid-row: 1 / span 2;
    width: 40px;
    height: 40px;
    margin-right: 0;
    align-self: start;
    font-size: 17px;
  }

  .msg-from {
    grid-column: 2;
    grid-row: 1;
    width: auto;
    padding-right: 0;
    font-size: 16px;
    font-weight: 600;
    line-height: 1.25;
  }

  .msg-preview {
    grid-column: 2 / 3;
    grid-row: 2;
    white-space: normal;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    font-size: 14px;
    line-height: 1.35;
    color: var(--text-muted);
  }

  .msg-subject-text {
    display: block;
    color: var(--text);
    font-weight: 600;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
  }

  .msg-snippet-text {
    display: block;
    color: var(--text-muted);
  }

  .msg-snippet-text::before {
    content: "";
  }

  .msg-date {
    grid-column: 3;
    grid-row: 1;
    width: auto;
    min-width: 48px;
    font-size: 12px;
    color: var(--text);
    align-self: start;
    padding-top: 2px;
  }

  .msg-star {
    grid-column: 3;
    grid-row: 2;
    width: 30px;
    justify-self: end;
    align-self: end;
    font-size: 25px;
    color: #747775;
  }

  .msg-row:hover .msg-date {
    display: block;
  }

  .msg-actions {
    display: none;
  }

  .mobile-compose-fab {
    display: flex;
    align-items: center;
    gap: 12px;
    position: fixed;
    right: 22px;
    bottom: 16px;
    height: 58px;
    padding: 0 22px;
    border-radius: 18px;
    background: var(--blue-mid);
    color: #183153;
    box-shadow: var(--shadow-md);
    font-size: 15px;
    font-weight: 500;
    z-index: 180;
  }

  .mobile-compose-fab svg {
    flex-shrink: 0;
  }

  .msg-view {
    padding: 0 18px 96px;
  }

  .msg-view-toolbar {
    margin-bottom: 14px;
  }

  .back-btn {
    padding: 8px;
    font-size: 0;
  }

  .back-btn svg {
    width: 22px;
    height: 22px;
  }

  .msg-view-subject {
    font-size: 22px;
    line-height: 1.3;
    margin-bottom: 18px;
  }

  .msg-view-header {
    gap: 10px;
    margin-bottom: 18px;
  }

  .msg-view-addr {
    display: none;
  }

  .msg-view-date-right {
    max-width: 88px;
    white-space: normal;
    text-align: right;
  }

  .reply-bar {
    flex-wrap: wrap;
  }

  .compose-overlay {
    inset: 0;
    width: auto;
    height: auto;
    right: 0;
    bottom: 0;
    border-radius: 0;
    z-index: 600;
  }

  .compose-overlay.minimized {
    height: 52px;
    top: auto;
  }

  .compose-header {
    border-radius: 0;
  }

  .compose-footer {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }

  .toast {
    left: 14px;
    right: 14px;
    bottom: 88px;
    transform: translateY(180px);
    text-align: center;
    white-space: normal;
  }

  .toast.show {
    transform: translateY(0);
  }
}

@media (max-width: 420px) {
  .topbar {
    height: 92px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .mobile-menu-btn {
    left: 20px;
  }

  .topbar-right {
    right: 20px;
  }

  .search-bar {
    padding-left: 52px;
    padding-right: 52px;
  }

  .msg-row {
    grid-template-columns: 46px minmax(0, 1fr) 44px;
    min-height: 98px;
  }

  .mobile-compose-fab {
    right: 18px;
    bottom: 12px;
  }
}
