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

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

:root {
  --blue: #1a73e8;
  --blue-dark: #1557b0;
  --blue-light: #d2e3fc;
  --red: #ea4335;
  --green: #34a853;
  --yellow: #fbbc04;
  --bg: #f6f8fc;
  --white: #ffffff;
  --border: #e0e0e0;
  --text: #202124;
  --text2: #5f6368;
  --text3: #80868b;
  --hover: #f1f3f4;
  --selected: #d3e3fd;
  --active-nav: #d3e3fd;
  --shadow: 0 1px 2px rgba(60,64,67,.3),0 2px 6px 2px rgba(60,64,67,.15);
  --shadow-lg: 0 6px 30px rgba(0,0,0,.15);
  --r: 8px;
  --r-lg: 16px;
  --sidebar: 256px;
  --header-h: 64px;
  --font: 'Roboto', sans-serif;
  --font-g: 'Google Sans', sans-serif;
}

html { font-size: 14px; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

a { text-decoration: none; color: inherit; cursor: pointer; }
button { border: none; background: none; cursor: pointer; font-family: inherit; }
input { font-family: inherit; }
.hidden { display: none !important; }
.flex-spacer { flex: 1; }

/* SCROLLBAR */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #dadce0; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #bdc1c6; }

/* ===== AUTH OVERLAY ===== */
.auth-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-box {
  background: var(--white);
  border-radius: var(--r-lg);
  padding: 40px;
  width: 380px;
  text-align: center;
  box-shadow: var(--shadow-lg);
}

.rm-logo-sm {
  width: 48px; height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #ea4335, #fbbc04, #34a853, #4285f4);
  color: white;
  font-size: 24px;
  font-weight: 900;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 20px;
  font-family: var(--font-g);
}

.auth-box h2 { font-size: 22px; font-weight: 400; margin-bottom: 8px; }
.auth-box p { color: var(--text2); font-size: 14px; margin-bottom: 24px; }

.auth-box form { display: flex; flex-direction: column; gap: 12px; }
.auth-box input {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 12px 16px;
  font-size: 15px;
  outline: none;
  transition: border 0.2s;
}
.auth-box input:focus { border-color: var(--blue); }

.auth-box button[type="submit"] {
  background: var(--blue);
  color: white;
  border-radius: 24px;
  padding: 12px;
  font-size: 15px;
  font-weight: 500;
  transition: background 0.15s;
  margin-top: 4px;
}
.auth-box button[type="submit"]:hover { background: var(--blue-dark); }

.ql-error {
  color: var(--red);
  font-size: 13px;
  text-align: left;
  background: #fce8e6;
  padding: 8px 12px;
  border-radius: 6px;
}

.ql-link {
  display: block;
  margin-top: 16px;
  font-size: 13px;
  color: var(--blue);
}
.ql-link:hover { text-decoration: underline; }

/* ===== HEADER ===== */
.app-header {
  height: var(--header-h);
  background: var(--white);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 8px;
  border-bottom: 1px solid transparent;
  box-shadow: 0 1px 0 var(--border);
  z-index: 100;
  flex-shrink: 0;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: var(--sidebar);
}

.app-logo {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px 6px;
  border-radius: 6px;
  transition: background 0.15s;
}
.app-logo:hover { background: var(--hover); }

.logo-r {
  font-size: 26px;
  font-weight: 900;
  background: linear-gradient(135deg, #ea4335, #4285f4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-family: var(--font-g);
  line-height: 1;
}

.logo-text {
  font-size: 22px;
  color: var(--text2);
  font-family: var(--font-g);
  letter-spacing: -0.3px;
}

/* SEARCH */
.header-search {
  flex: 1;
  max-width: 720px;
  margin: 0 auto;
}

.search-wrap {
  display: flex;
  align-items: center;
  background: var(--bg);
  border-radius: 24px;
  padding: 6px 8px 6px 16px;
  gap: 4px;
  transition: all 0.2s;
}
.search-wrap:focus-within {
  background: var(--white);
  box-shadow: var(--shadow);
}

.search-wrap input {
  flex: 1;
  border: none;
  background: transparent;
  outline: none;
  font-size: 16px;
  color: var(--text);
}

.header-right {
  display: flex;
  align-items: center;
  gap: 4px;
  min-width: 180px;
  justify-content: flex-end;
  position: relative;
}

/* ICON BUTTON */
.icon-btn {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background 0.15s;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn .material-icons { font-size: 20px; }
.icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* USER BUTTON */
.user-btn-wrap { position: relative; }
.user-btn { background: none; border: none; cursor: pointer; }
.user-avatar {
  width: 36px; height: 36px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ea4335, #4285f4);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
  font-weight: 600;
  font-family: var(--font-g);
  transition: box-shadow 0.15s;
}
.user-avatar:hover { box-shadow: 0 0 0 3px var(--blue-light); }

/* USER MENU */
.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--white);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  min-width: 300px;
  z-index: 200;
  overflow: hidden;
  animation: menuDrop 0.15s ease;
}

@keyframes menuDrop {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.um-top { display: flex; align-items: center; gap: 12px; padding: 20px 16px; }
.um-avatar {
  width: 48px; height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ea4335, #4285f4);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  font-weight: 700;
  font-family: var(--font-g);
  flex-shrink: 0;
}
.um-name { font-size: 15px; font-weight: 500; }
.um-email { font-size: 13px; color: var(--text2); }
.um-hr { height: 1px; background: var(--border); }
.um-item {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px;
  width: 100%;
  font-size: 14px;
  color: var(--text);
  transition: background 0.15s;
}
.um-item:hover { background: var(--hover); }
.um-item .material-icons { font-size: 18px; color: var(--text2); }

/* ===== APP BODY ===== */
.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
}

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar);
  background: var(--white);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  padding: 8px 0 24px;
  flex-shrink: 0;
  transition: width 0.2s;
}

.sidebar.collapsed {
  width: 72px;
}
.sidebar.collapsed .compose-label,
.sidebar.collapsed .nav-item > span:nth-child(2),
.sidebar.collapsed .unread-badge,
.sidebar.collapsed .storage-info,
.sidebar.collapsed .nav-section-title { display: none; }
.sidebar.collapsed .compose-btn { width: 52px; height: 52px; border-radius: 50%; padding: 0; justify-content: center; margin: 8px auto; }
.sidebar.collapsed .nav-item { justify-content: center; border-radius: 50%; width: 52px; height: 52px; margin: 2px auto; padding: 0; }

/* COMPOSE BUTTON */
.compose-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  background: #c2e7ff;
  color: #001d35;
  border-radius: 16px;
  padding: 16px 24px;
  margin: 8px 8px 8px 16px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-g);
  transition: background 0.15s, box-shadow 0.15s;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.compose-btn:hover { background: #a8d8f8; box-shadow: var(--shadow); }
.compose-btn .material-icons { font-size: 20px; }

/* NAV */
.sidebar-nav, .sidebar-more { display: flex; flex-direction: column; gap: 1px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  border-radius: 0 24px 24px 0;
  font-size: 14px;
  color: var(--text);
  transition: background 0.15s;
  cursor: pointer;
  margin-right: 16px;
  user-select: none;
}
.nav-item:hover { background: var(--hover); }
.nav-item.active { background: var(--active-nav); font-weight: 700; }
.nav-item .material-icons { font-size: 20px; color: var(--text2); flex-shrink: 0; }
.nav-item.active .material-icons { color: var(--text); }

.unread-badge {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
}

.nav-section-title {
  font-size: 11px;
  color: var(--text2);
  padding: 8px 20px 4px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.storage-info {
  margin-top: auto;
  padding: 16px 20px;
}
.storage-bar { height: 4px; background: var(--border); border-radius: 2px; margin-bottom: 6px; }
.storage-fill { height: 100%; background: var(--blue); border-radius: 2px; }
.storage-info p { font-size: 11px; color: var(--text3); }

/* ===== EMAIL PANEL ===== */
.email-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--white);
  border-radius: 16px 0 0 0;
  margin: 8px 0 8px 8px;
  box-shadow: var(--shadow);
}

/* INBOX TABS */
.inbox-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
}

.tab {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 14px 20px 12px;
  font-size: 13px;
  color: var(--text2);
  border-bottom: 3px solid transparent;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
  white-space: nowrap;
}
.tab:hover { background: var(--hover); color: var(--text); }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); font-weight: 500; }
.tab .material-icons { font-size: 18px; }

/* LIST TOOLBAR */
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}
.lt-left { display: flex; align-items: center; gap: 4px; }
.lt-right { display: flex; align-items: center; gap: 4px; color: var(--text2); font-size: 13px; }

.select-all-wrap {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 4px;
  cursor: pointer;
}
.select-all-wrap input[type="checkbox"] {
  width: 16px; height: 16px; cursor: pointer;
}

.page-info { padding: 0 8px; }

/* EMAIL LIST */
.email-list { flex: 1; overflow-y: auto; }

.list-loading {
  display: flex; align-items: center; gap: 12px;
  padding: 32px 20px;
  color: var(--text2);
}

.load-spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* EMAIL ITEM */
.email-item {
  display: flex;
  align-items: center;
  padding: 6px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s, box-shadow 0.1s;
  gap: 6px;
  min-height: 50px;
  position: relative;
}
.email-item:hover { background: var(--hover); box-shadow: inset 3px 0 0 #c6c6c6; z-index: 1; }
.email-item.unread { background: var(--white); font-weight: 600; }
.email-item.read { background: #f6f8fc; }
.email-item.selected { background: var(--selected); }
.email-item:hover.selected { background: #c9d7f9; }

.ei-check {
  width: 18px; height: 18px;
  flex-shrink: 0;
  opacity: 0;
  cursor: pointer;
  transition: opacity 0.15s;
}
.email-item:hover .ei-check,
.email-item.selected .ei-check { opacity: 1; }

.ei-star {
  flex-shrink: 0;
  font-size: 18px !important;
  color: var(--text3);
  transition: color 0.15s;
  padding: 2px;
}
.ei-star:hover { color: var(--yellow); }
.email-item.starred .ei-star { color: var(--yellow); }

.ei-important {
  flex-shrink: 0;
  font-size: 16px !important;
  color: transparent;
  padding: 2px;
}
.email-item.important .ei-important { color: var(--yellow); }

.ei-from {
  width: 180px;
  flex-shrink: 0;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.ei-body {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 6px;
  overflow: hidden;
  min-width: 0;
}

.ei-subject {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
  max-width: 260px;
}

.ei-preview {
  font-size: 13px;
  color: var(--text2);
  font-weight: 400;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ei-preview::before { content: ' – '; }
.email-item.read .ei-subject { color: var(--text2); }

.ei-date {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  flex-shrink: 0;
  padding-left: 8px;
}
.email-item.unread .ei-date { color: var(--text); }

.ei-actions {
  display: none;
  align-items: center;
  gap: 2px;
  flex-shrink: 0;
}
.email-item:hover .ei-actions { display: flex; }
.email-item:hover .ei-date { display: none; }

.ei-action-btn {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background 0.15s;
}
.ei-action-btn:hover { background: rgba(0,0,0,0.08); }
.ei-action-btn .material-icons { font-size: 18px; }

/* EMPTY STATE */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 300px; gap: 12px;
  color: var(--text2);
}
.empty-state .material-icons { font-size: 72px; color: var(--border); }
.empty-state h3 { font-weight: 400; font-size: 20px; }
.empty-state p { font-size: 14px; }

/* ===== EMAIL VIEW ===== */
.email-view {
  position: absolute;
  top: var(--header-h);
  left: var(--sidebar);
  right: 0;
  bottom: 0;
  background: var(--white);
  z-index: 50;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slideIn 0.2s ease;
}
@keyframes slideIn {
  from { opacity: 0; transform: translateX(12px); }
  to { opacity: 1; transform: translateX(0); }
}

.view-toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 16px;
  border-bottom: 1px solid var(--border);
  min-height: 52px;
}

.view-body { flex: 1; overflow-y: auto; padding: 24px 56px; }

.vb-subject {
  font-size: 24px;
  font-weight: 400;
  font-family: var(--font-g);
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.vb-label {
  font-size: 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 8px;
  color: var(--text2);
}

.vb-msg {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  margin-bottom: 16px;
}

.vb-msg-header {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px 24px;
  cursor: pointer;
}
.vb-msg-header:hover { background: var(--bg); }

.vb-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.vb-from-info { flex: 1; }
.vb-from-name { font-weight: 600; font-size: 14px; }
.vb-from-addr { font-size: 12px; color: var(--text2); }
.vb-from-to { font-size: 12px; color: var(--text2); }

.vb-msg-actions {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-shrink: 0;
}

.vb-msg-date { font-size: 12px; color: var(--text2); padding: 4px 8px; }

.vb-body {
  padding: 16px 24px 24px 76px;
  font-size: 14px;
  line-height: 1.75;
  color: var(--text);
}
.vb-body img { max-width: 100%; }
.vb-body a { color: var(--blue); }

.vb-reply-area {
  margin-top: 24px;
  padding: 12px 20px;
  border: 1px solid var(--border);
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 12px;
  cursor: pointer;
  transition: box-shadow 0.15s;
  font-size: 14px;
  color: var(--text2);
}
.vb-reply-area:hover { box-shadow: var(--shadow); }
.vb-reply-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--border); flex-shrink: 0; }

/* ===== COMPOSE WINDOW ===== */
.compose-window {
  position: fixed;
  bottom: 0;
  right: 32px;
  width: 540px;
  background: var(--white);
  border-radius: 12px 12px 0 0;
  box-shadow: 0 8px 40px rgba(0,0,0,0.25);
  z-index: 300;
  display: flex;
  flex-direction: column;
  max-height: 80vh;
}

.cw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: #404040;
  color: white;
  border-radius: 12px 12px 0 0;
  cursor: pointer;
  font-size: 14px;
  font-weight: 500;
  user-select: none;
}

.cw-btns { display: flex; gap: 4px; }
.cw-btn {
  width: 28px; height: 28px;
  border-radius: 50%;
  color: #bbb;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s, color 0.15s;
}
.cw-btn:hover { background: rgba(255,255,255,0.15); color: white; }
.cw-btn .material-icons { font-size: 18px; }

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

.cw-field {
  display: flex;
  align-items: center;
  padding: 6px 16px;
}
.cw-field-border { border-top: 1px solid var(--border); }
.cw-field input {
  flex: 1; border: none; outline: none;
  font-size: 14px; padding: 6px 0;
  color: var(--text);
}

.cw-editor {
  flex: 1;
  padding: 12px 16px;
  min-height: 200px;
  max-height: 360px;
  overflow-y: auto;
  font-size: 14px;
  line-height: 1.65;
  outline: none;
  color: var(--text);
}
.cw-editor:empty::before { content: attr(placeholder); color: var(--text3); }

.cw-footer {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 12px;
  border-top: 1px solid var(--border);
}

.cw-send {
  background: var(--blue);
  color: white;
  border-radius: 24px;
  padding: 8px 18px;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-g);
  display: flex;
  align-items: center;
  transition: background 0.15s;
}
.cw-send:hover { background: var(--blue-dark); }

.cw-icon {
  width: 36px; height: 36px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text2);
  transition: background 0.15s;
}
.cw-icon:hover { background: var(--hover); color: var(--text); }
.cw-icon .material-icons { font-size: 20px; }
.cw-flex { flex: 1; }

/* ===== TOAST ===== */
.toast {
  position: fixed;
  bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #323232;
  color: white;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 500;
  animation: toastIn 0.25s ease;
  white-space: nowrap;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(-50%) translateY(8px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

/* ===== RESPONSIVE ===== */
@media (max-width: 900px) {
  :root { --sidebar: 72px; }
  .compose-label,
  .nav-item > span:nth-child(2),
  .storage-info { display: none !important; }
  .nav-item { justify-content: center; border-radius: 50%; width: 52px; height: 52px; margin: 2px auto; padding: 0; }
  .compose-btn { width: 52px; height: 52px; border-radius: 50%; padding: 0; justify-content: center; margin: 8px auto; }
  .ei-from { width: 120px; }
  .email-view { left: 72px; }
}

@media (max-width: 600px) {
  .sidebar { display: none; }
  .email-view { left: 0; }
  .compose-window { width: 100%; right: 0; border-radius: 12px 12px 0 0; }
  .header-search { display: none; }
  .inbox-tabs { display: none; }
}
