/* KMail — Gmail-inspired light theme */

:root {
  --bg-outer:    #F6F8FC;
  --bg-white:    #FFFFFF;
  --bg-row-read: #F2F6FC;
  --bg-row-hover:#E8F0FE;
  --bg-compose:  #C5221F;
  --bg-compose-h:#A50E0E;
  --border:      #E0E0E0;
  --border-light:#F1F3F4;
  --sidebar-w:   256px;
  --list-w:      340px;
  --topbar-h:    64px;

  --text:        #202124;
  --muted:       #5F6368;
  --muted2:      #80868B;
  --link:        #1A73E8;
  --unread-bg:   #FFFFFF;
  --read-bg:     #F2F6FC;
  --star-on:     #F4B400;
  --star-off:    #BDC1C6;

  --shadow-sm:   0 1px 3px rgba(60,64,67,.12), 0 1px 2px rgba(60,64,67,.08);
  --shadow-md:   0 2px 6px rgba(60,64,67,.15), 0 1px 4px rgba(60,64,67,.10);
  --radius:      8px;
  --radius-pill: 24px;
}

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

html, body {
  height: 100%;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  color: var(--text);
  background: var(--bg-outer);
  overflow: hidden;
}

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

/* ===================== TOP BAR ===================== */
.topbar {
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--topbar-h);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 0 16px;
  z-index: 100;
  gap: 8px;
}

.topbar__logo {
  display: flex;
  align-items: center;
  min-width: 212px;
  padding-left: 8px;
  text-decoration: none;
  color: var(--text);
}

.logo-img {
  height: 36px;
  width: auto;
  object-fit: contain;
}

.logo-badge {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg-compose);
  color: #fff;
  font-size: 18px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
  letter-spacing: -.5px;
  flex-shrink: 0;
}

.logo-text {
  font-size: 22px;
  font-weight: 400;
  color: #5F6368;
  letter-spacing: -.3px;
}

.logo-text span { color: var(--text); }

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

.topbar__search input {
  width: 100%;
  height: 46px;
  background: #EAF1FB;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  padding: 0 48px 0 52px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: background .15s, border-color .15s, box-shadow .15s;
}

.topbar__search input:focus {
  background: var(--bg-white);
  border-color: var(--border);
  box-shadow: var(--shadow-sm);
}

.topbar__search input::placeholder { color: var(--muted); }

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

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

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 18px;
  transition: background .15s;
}
.icon-btn:hover { background: var(--border-light); }

/* ── App launcher (9-dot grid) — all styling via inline HTML ── */

.avatar-wrap {
  position: relative;
  margin-left: 4px;
  flex-shrink: 0;
  /* Always-visible Google rainbow ring */
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: conic-gradient(#4285F4 0deg 90deg, #DB4437 90deg 180deg, #F4B400 180deg 270deg, #0F9D58 270deg 360deg);
  padding: 3px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.avatar-btn {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  overflow: hidden;
  border: 2px solid #fff;
  box-sizing: border-box;
  flex-shrink: 0;
}
.avatar-btn img { width: 100%; height: 100%; object-fit: cover; }

/* ===== ACCOUNT POPUP ===== */
.acct-popup {
  display: none;
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  width: 240px;
  background: #fff;
  border-radius: 16px;
  box-shadow: 0 4px 24px rgba(60,64,67,.22), 0 1px 6px rgba(60,64,67,.12);
  border: 1px solid var(--border);
  z-index: 9999;
  overflow: hidden;
  animation: popupIn .12s ease;
}
.acct-popup.open { display: block; }
@keyframes popupIn {
  from { opacity: 0; transform: translateY(-6px) scale(.97); }
  to   { opacity: 1; transform: translateY(0)   scale(1); }
}

.acct-popup-inner {
  padding: 20px 16px 20px;
  text-align: center;
}
.acct-email {
  font-size: 14px;
  color: var(--text);
  font-weight: 500;
  margin-bottom: 16px;
}
.acct-name-row {
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 4px;
}
.acct-avatar-ring {
  width: 108px;
  height: 108px;
  border-radius: 50%;
  background: conic-gradient(#4285F4 0deg 90deg, #DB4437 90deg 180deg, #F4B400 180deg 270deg, #0F9D58 270deg 360deg);
  padding: 4px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.acct-avatar-large {
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: var(--bg-compose);
  color: #fff;
  font-size: 36px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: 2px solid #fff;
  box-sizing: border-box;
}
.acct-avatar-large img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
  display: block;
}
.avatar-placeholder {
  width: 100%;
  height: 100%;
  background: var(--bg-compose);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===================== LAYOUT SHELL ===================== */
.kmail-shell {
  display: flex;
  height: 100vh;
  padding-top: var(--topbar-h);
}

/* ===================== SIDEBAR ===================== */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-outer);
  padding: 8px 0;
  overflow-y: auto;
  border-right: none;
}

.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.compose-btn {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 8px 16px 16px;
  padding: 16px 24px;
  background: var(--bg-white);
  border-radius: var(--radius-pill);
  box-shadow: var(--shadow-sm);
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  transition: box-shadow .15s, background .15s;
  cursor: pointer;
  border: none;
  width: calc(100% - 32px);
}
.compose-btn:hover {
  box-shadow: var(--shadow-md);
  background: #F8FBFF;
}
.compose-btn i { font-size: 20px; color: var(--text); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 4px 16px 4px 26px;
  height: 32px;
  border-radius: 0 var(--radius-pill) var(--radius-pill) 0;
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  cursor: pointer;
  transition: background .1s;
  position: relative;
  margin-right: 16px;
}

.nav-item i {
  font-size: 18px;
  width: 20px;
  text-align: center;
  color: var(--muted);
  flex-shrink: 0;
}

.nav-item:hover { background: var(--border-light); }

.nav-item.active {
  background: #D3E3FD;
  font-weight: 700;
}
.nav-item.active i { color: var(--text); }

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

.nav-separator {
  height: 1px;
  background: var(--border);
  margin: 8px 16px;
}

.nav-label {
  padding: 6px 16px 4px 26px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--muted);
}

/* ===================== EMAIL LIST ===================== */
.email-list-panel {
  width: var(--list-w);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--bg-white);
  overflow: hidden;
}

.list-toolbar {
  display: flex;
  align-items: center;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  gap: 4px;
  min-height: 48px;
}

.list-toolbar .icon-btn { font-size: 16px; }

.list-toolbar__label {
  font-size: 14px;
  font-weight: 500;
  color: var(--text);
  margin-left: 4px;
  flex: 1;
}

.list-toolbar__count {
  font-size: 12px;
  color: var(--muted);
  margin-left: auto;
}

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

.email-list::-webkit-scrollbar { width: 6px; }
.email-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.email-row {
  display: flex;
  align-items: center;
  padding: 8px 16px;
  cursor: pointer;
  border-bottom: 1px solid var(--border-light);
  transition: box-shadow .1s, background .1s;
  position: relative;
  gap: 10px;
  min-height: 56px;
}

.email-row.unread { background: var(--unread-bg); }
.email-row.read   { background: var(--read-bg); }
.email-row:hover  { background: var(--bg-row-hover); box-shadow: inset 3px 0 0 var(--link); }
.email-row.active { background: #D3E3FD; box-shadow: inset 3px 0 0 var(--link); }

.email-row__star {
  font-size: 16px;
  color: var(--star-off);
  flex-shrink: 0;
  width: 18px;
  transition: color .15s;
  cursor: default;
  pointer-events: none;
}
.email-row__star.starred { color: var(--star-on); }

.email-row__pin {
  font-size: 12px;
  color: var(--link);
  margin-left: 6px;
  transform: rotate(-45deg);
  display: inline-block;
}
.email-row.pinned {
  background: linear-gradient(90deg, #E8F0FE 0%, transparent 100%);
}
.email-row.pinned.unread {
  background: linear-gradient(90deg, #E8F0FE 0%, var(--unread-bg) 100%);
}

.email-row__avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #1A73E8;
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.email-row__body {
  flex: 1;
  min-width: 0;
}

.email-row__top {
  display: flex;
  align-items: baseline;
  gap: 6px;
  margin-bottom: 2px;
}

.email-row__sender {
  font-size: 14px;
  font-weight: 400;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}
.email-row.unread .email-row__sender { font-weight: 700; }

.email-row__date {
  font-size: 12px;
  color: var(--muted);
  flex-shrink: 0;
}
.email-row.unread .email-row__date { font-weight: 700; color: var(--text); }

.email-row__subject {
  font-size: 14px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}
.email-row.unread .email-row__subject { font-weight: 600; }

.email-row__preview {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Avatar color variety */
.avatar-color-0 { background: #1A73E8; }
.avatar-color-1 { background: #E52592; }
.avatar-color-2 { background: #1E8E3E; }
.avatar-color-3 { background: #F29900; }
.avatar-color-4 { background: #9334E6; }
.avatar-color-5 { background: #D93025; }

/* ===================== READING PANE ===================== */
.reading-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-white);
  overflow: hidden;
}

.reading-pane__empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  gap: 16px;
}

.reading-pane__empty i {
  font-size: 72px;
  color: var(--border);
}

.reading-pane__empty p {
  font-size: 15px;
}

.reading-pane__toolbar {
  display: flex;
  align-items: center;
  padding: 8px 24px;
  border-bottom: 1px solid var(--border-light);
  gap: 4px;
  min-height: 48px;
}

.reading-pane__content {
  flex: 1;
  overflow-y: auto;
  padding: 24px 32px;
}

.reading-pane__content::-webkit-scrollbar { width: 6px; }
.reading-pane__content::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

.msg-subject {
  font-size: 22px;
  font-weight: 400;
  color: var(--text);
  margin-bottom: 20px;
  line-height: 1.3;
}

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

.msg-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1A73E8;
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  text-transform: uppercase;
}

.msg-meta { flex: 1; min-width: 0; }

.msg-from {
  font-size: 15px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 2px;
}

.msg-from span {
  font-weight: 400;
  color: var(--muted);
  font-size: 13px;
}

.msg-date {
  font-size: 13px;
  color: var(--muted);
}

.msg-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}

.msg-body {
  font-size: 15px;
  line-height: 1.75;
  color: var(--text);
  word-wrap: break-word;
}
.msg-body p { margin: 0 0 10px 0; }
.msg-body img { max-width: 100%; height: auto; border-radius: 8px; margin: 8px 0; }
.msg-body ul, .msg-body ol { margin: 10px 0; padding-left: 24px; }
.msg-body li { margin-bottom: 4px; }
.msg-body a { color: var(--link); text-decoration: underline; }
.msg-body blockquote { border-left: 3px solid var(--border); margin: 10px 0; padding-left: 12px; color: var(--muted); }
.msg-body pre, .msg-body code { background: var(--bg-outer); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: 13px; }
.msg-body pre { padding: 12px; overflow-x: auto; }
.msg-body table { border-collapse: collapse; margin: 10px 0; }
.msg-body th, .msg-body td { border: 1px solid var(--border); padding: 8px 12px; }
.msg-body th { background: var(--bg-outer); }

/* ===================== COMPOSE MODAL ===================== */
.compose-modal {
  position: fixed;
  bottom: 0;
  right: 24px;
  width: 500px;
  max-height: 480px;
  background: var(--bg-white);
  border-radius: 8px 8px 0 0;
  box-shadow: 0 8px 40px rgba(60,64,67,.28);
  display: flex;
  flex-direction: column;
  z-index: 200;
  display: none;
}

.compose-modal.open { display: flex; }

.compose-header {
  background: #404040;
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px 8px 0 0;
  display: flex;
  align-items: center;
  font-size: 14px;
  font-weight: 500;
  cursor: default;
  gap: 8px;
}

.compose-header button {
  margin-left: auto;
  color: #ccc;
  font-size: 16px;
  padding: 2px 6px;
  border-radius: 4px;
  transition: background .15s;
}
.compose-header button:hover { background: rgba(255,255,255,.15); color: #fff; }

.compose-field {
  border-bottom: 1px solid var(--border-light);
  display: flex;
  align-items: center;
  padding: 6px 16px;
  gap: 8px;
}
.compose-field label {
  font-size: 13px;
  color: var(--muted);
  width: 40px;
  flex-shrink: 0;
}
.compose-field input {
  flex: 1;
  border: none;
  outline: none;
  font-size: 14px;
  font-family: inherit;
  color: var(--text);
  background: transparent;
}
.compose-field input::placeholder { color: var(--muted2); }

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

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

.send-btn {
  background: var(--link);
  color: #fff;
  border-radius: var(--radius-pill);
  padding: 8px 20px;
  font-size: 14px;
  font-weight: 500;
  transition: background .15s, box-shadow .15s;
}
.send-btn:hover { background: #1967D2; box-shadow: var(--shadow-sm); }

/* ===================== EMPTY STATE ===================== */
.empty-list {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  color: var(--muted);
  gap: 12px;
  text-align: center;
}
.empty-list i { font-size: 56px; color: var(--border); }
.empty-list p { font-size: 14px; }

/* ===================== TABS (List toolbar) ===================== */
.list-tabs {
  display: flex;
  border-bottom: 1px solid var(--border-light);
  background: var(--bg-white);
}

.list-tab {
  flex: 1;
  padding: 12px 4px;
  text-align: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}
.list-tab:hover { color: var(--text); background: var(--bg-row-hover); }
.list-tab.active { color: var(--link); border-bottom-color: var(--link); }
.list-tab i { font-size: 16px; }
.tab-badge {
  background: #D93025;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 10px;
  margin-left: 4px;
}

/* ===================== HAMBURGER / DRAWER ===================== */
.menu-btn {
  display: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 20px;
  flex-shrink: 0;
  transition: background .15s;
  cursor: pointer;
}
.menu-btn:hover { background: var(--border-light); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 89;
}
.sidebar-overlay.visible { display: block; }

/* ===================== MOBILE ===================== */
@media (max-width: 900px) {
  :root { --sidebar-w: 72px; --list-w: 100%; }

  .sidebar { width: var(--sidebar-w); }
  .nav-item span, .compose-btn span, .nav-badge, .nav-label { display: none; }
  .compose-btn { padding: 16px; justify-content: center; }
  .compose-btn i { margin: 0; }
  .nav-item { padding: 8px 0; justify-content: center; margin-right: 0; border-radius: 0; }
  .logo-img { height: 28px; }
  .topbar__logo { min-width: auto; }

  .email-list-panel { width: 100%; }
  .reading-pane {
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    z-index: 50;
    transform: translateX(100%);
    transition: transform .25s ease;
  }
  .reading-pane.open { transform: translateX(0); }
  .compose-modal { width: calc(100vw - 16px); right: 8px; }
}

/* ===================== PHONE ===================== */
@media (max-width: 600px) {
  :root { --sidebar-w: 280px; }

  /* Hamburger visible, search hidden */
  .menu-btn { display: flex; }
  .topbar__search { display: none; }
  .topbar__logo { padding-left: 0; }

  /* Sidebar becomes a full-height drawer */
  .sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0;
    bottom: 0;
    z-index: 90;
    background: var(--bg-white);
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 4px 0 20px rgba(60,64,67,.2);
    width: var(--sidebar-w) !important;
    padding: 8px 0;
  }
  .sidebar.open { transform: translateX(0); }

  /* Restore full labels inside drawer */
  .nav-item {
    padding: 4px 16px 4px 26px !important;
    justify-content: flex-start !important;
    margin-right: 16px !important;
    border-radius: 0 var(--radius-pill) var(--radius-pill) 0 !important;
    height: 40px !important;
    gap: 16px !important;
  }
  .nav-item span { display: inline !important; }
  .nav-badge   { display: inline !important; margin-left: auto !important; }
  .nav-label   { display: block  !important; }
  .nav-item i  { color: var(--muted) !important; }
  .nav-item.active i { color: var(--text) !important; }

  .compose-btn {
    padding: 16px 24px !important;
    justify-content: flex-start !important;
    width: calc(100% - 32px) !important;
  }
  .compose-btn span { display: inline !important; }

  /* Full-width compose modal */
  .compose-modal {
    width: 100vw !important;
    right: 0 !important;
    max-height: 75vh;
  }
}

/* ===================== UTILITY ===================== */
.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.spinner {
  width: 20px; height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--link);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: 40px auto;
}

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

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}
