/* Webmail — Gmail-inspired stylesheet */

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

:root {
  --blue:      #1a73e8;
  --blue-dark: #1557b0;
  --bg:        #f6f8fc;
  --surface:   #ffffff;
  --border:    #e0e0e0;
  --text:      #202124;
  --text2:     #5f6368;
  --text3:     #80868b;
  --unread-bg: #ffffff;
  --read-bg:   #f2f6fc;
  --hover-bg:  #f2f6fc;
  --sel-bg:    #e8f0fe;
  --err:       #d93025;
  --ok:        #188038;
  --warn:      #e37400;
  --shadow:    0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --radius:    8px;
}

html, body { height: 100%; font-family: 'Google Sans', Roboto, Arial, sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }

/* ── Top bar ─────────────────────────────────────────────────────────────── */

.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: 64px; background: var(--surface);
  display: flex; align-items: center; padding: 0 8px;
  border-bottom: 1px solid var(--border);
}

.topbar-left  { display: flex; align-items: center; width: 256px; min-width: 0; }
.topbar-right { display: flex; align-items: center; margin-left: auto; }

.menu-btn {
  width: 40px; height: 40px; border: none; background: none; cursor: pointer;
  display: flex; flex-direction: column; justify-content: center; align-items: center; gap: 5px;
  border-radius: 50%;
}
.menu-btn:hover { background: var(--hover-bg); }
.menu-btn span  { display: block; width: 20px; height: 2px; background: var(--text2); border-radius: 1px; }

.app-logo { display: flex; align-items: center; gap: 6px; padding-left: 4px; font-size: 20px; color: var(--text2); font-weight: 400; }
.app-logo svg { flex-shrink: 0; }

.topbar-search { flex: 1; max-width: 720px; padding: 0 16px; }
.search-wrap {
  display: flex; align-items: center; gap: 8px;
  background: #eaf1fb; border-radius: 24px; padding: 0 16px; height: 46px;
  transition: background .15s;
}
.search-wrap:focus-within { background: var(--surface); box-shadow: var(--shadow); }
.search-icon { flex-shrink: 0; }
.search-wrap input { flex: 1; border: none; outline: none; background: none; font-size: 16px; color: var(--text); }

.user-menu { position: relative; cursor: pointer; padding: 4px 8px; border-radius: 4px; }
.user-menu:hover .user-dropdown { display: block; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; background: var(--blue);
  color: #fff; font-size: 15px; font-weight: 500;
  display: flex; align-items: center; justify-content: center;
}
.user-dropdown {
  display: none; position: absolute; right: 0; top: 100%; min-width: 240px;
  background: var(--surface); border-radius: var(--radius); box-shadow: 0 4px 16px rgba(0,0,0,.18);
  overflow: hidden; z-index: 200;
}
.user-info { padding: 16px; border-bottom: 1px solid var(--border); }
.user-name  { font-weight: 500; font-size: 15px; }
.user-email { color: var(--text2); font-size: 13px; margin-top: 2px; }
.dropdown-item { display: block; padding: 12px 16px; color: var(--text); text-decoration: none; }
.dropdown-item:hover { background: var(--hover-bg); }
.dropdown-button { width: 100%; text-align: left; border: 0; background: var(--surface); font: inherit; cursor: pointer; }

.password-modal {
  width: 400px; max-width: calc(100vw - 32px); margin: 10vh auto 0;
  background: var(--surface); border-radius: var(--radius); box-shadow: 0 8px 32px rgba(0,0,0,.28);
  overflow: hidden;
}
.password-form { padding: 24px; }
.password-status { min-height: 20px; margin-bottom: 12px; color: var(--text2); }
.password-status.error { color: var(--err); }
.password-status.success { color: var(--ok); }

/* ── Layout ──────────────────────────────────────────────────────────────── */

.app-layout {
  display: flex; padding-top: 64px; height: 100vh;
}

.sidebar {
  width: 256px; min-width: 256px; height: calc(100vh - 64px);
  overflow-y: auto; overflow-x: hidden; padding: 8px 0;
  background: var(--bg); flex-shrink: 0;
  transition: width .2s, min-width .2s;
}
.sidebar.collapsed { width: 72px; min-width: 72px; }

.content {
  flex: 1; overflow: hidden; height: calc(100vh - 64px);
  background: var(--surface); border-radius: 16px 0 0 0;
  position: relative;
}

/* ── Compose button ──────────────────────────────────────────────────────── */

.compose-btn {
  display: flex; align-items: center; gap: 12px;
  margin: 8px 8px 8px 16px; padding: 18px 24px;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; cursor: pointer; font-size: 14px; font-weight: 500;
  color: var(--text); box-shadow: var(--shadow);
  transition: box-shadow .15s;
}
.compose-btn:hover { box-shadow: 0 2px 6px rgba(0,0,0,.18); }

/* ── Folder list ─────────────────────────────────────────────────────────── */

.folder-list { list-style: none; padding: 4px 0; }
.folder-list li a {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px 8px 26px; border-radius: 0 20px 20px 0; margin-right: 8px;
  text-decoration: none; color: var(--text); font-size: 14px; font-weight: 400;
  transition: background .1s;
}
.folder-list li a:hover    { background: var(--hover-bg); }
.folder-list li a.active   { background: var(--sel-bg); font-weight: 700; }
.folder-icon { width: 20px; height: 20px; flex-shrink: 0; color: var(--text2); }
.folder-name { flex: 1; }
.folder-badge {
  font-size: 12px; font-weight: 700; color: var(--text);
  min-width: 18px; text-align: right;
}

/* ── List view ───────────────────────────────────────────────────────────── */

.list-view, .read-view { position: absolute; inset: 0; overflow-y: auto; }
.list-view { display: none; }
.list-view.active, .read-view.active { display: block; }

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

.check-all { display: flex; align-items: center; padding: 4px 8px; }
.check-all input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--blue); }

.tb-btn {
  display: flex; align-items: center; gap: 4px; border: none;
  background: none; cursor: pointer; padding: 6px 8px; border-radius: 4px;
  color: var(--text2); font-size: 13px;
}
.tb-btn:hover:not(:disabled) { background: var(--hover-bg); }
.tb-btn:disabled { opacity: .4; cursor: default; }
.back-btn { font-size: 14px; color: var(--text); }

.list-status { color: var(--text2); font-size: 13px; margin-left: 4px; }
.list-pager  { margin-left: auto; display: flex; align-items: center; gap: 4px; }
#pagerInfo   { font-size: 13px; color: var(--text2); min-width: 80px; text-align: center; }

/* ── Message row ─────────────────────────────────────────────────────────── */

.msg-row {
  display: flex; align-items: center; gap: 4px;
  padding: 0 16px; border-bottom: 1px solid var(--border);
  height: 52px; cursor: pointer; transition: background .1s;
  background: var(--unread-bg);
}
.msg-row.read   { background: var(--read-bg); }
.msg-row:hover  { box-shadow: inset 1px 0 0 var(--border), inset -1px 0 0 var(--border), 0 2px 4px rgba(0,0,0,.1); z-index: 1; position: relative; }
.msg-row.selected { background: var(--sel-bg); }

.msg-check  { padding: 4px 8px; flex-shrink: 0; }
.msg-check input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--blue); }

.msg-star {
  padding: 4px 4px; flex-shrink: 0; color: var(--border); cursor: pointer; font-size: 16px;
  background: none; border: none;
}
.msg-star.starred { color: #f5a623; }
.msg-star:hover   { color: #f5a623; }

.msg-from    { width: 200px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex-shrink: 0; }
.msg-row.read .msg-from { font-weight: 400; }
.msg-middle  { flex: 1; overflow: hidden; display: flex; align-items: center; gap: 8px; min-width: 0; }
.msg-subject { font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; max-width: 300px; }
.msg-row.read .msg-subject { font-weight: 400; }
.msg-snippet { color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; flex: 1; min-width: 0; }
.msg-snippet::before { content: ' — '; }
.msg-date    { width: 80px; text-align: right; font-size: 12px; color: var(--text2); flex-shrink: 0; }
.msg-row:not(.read) .msg-date { font-weight: 700; color: var(--text); }

/* empty state */
.empty-state { padding: 64px 32px; text-align: center; color: var(--text2); }
.empty-state svg { opacity: .3; margin-bottom: 16px; }

/* loading spinner */
.loading { padding: 32px; text-align: center; color: var(--text2); }
.loading::after { content: ''; display: inline-block; width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .6s linear infinite; vertical-align: middle; margin-left: 8px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Read view ───────────────────────────────────────────────────────────── */

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

#messageContent { padding: 32px 48px; max-width: 900px; }

.msg-header { margin-bottom: 24px; }
.msg-subject-big { font-size: 22px; font-weight: 400; color: var(--text); margin-bottom: 16px; word-break: break-word; }
.msg-meta { display: flex; align-items: flex-start; gap: 12px; }
.msg-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--blue); color: #fff; font-size: 17px; font-weight: 500; display: flex; align-items: center; justify-content: center; flex-shrink: 0; }
.msg-meta-details { flex: 1; }
.msg-from-full { font-weight: 500; }
.msg-to-line   { font-size: 13px; color: var(--text2); margin-top: 2px; }
.msg-date-full { font-size: 12px; color: var(--text2); margin-top: 2px; }

.msg-body { margin-top: 24px; line-height: 1.6; word-wrap: break-word; }
.msg-body iframe { width: 100%; border: none; }
.msg-body a { color: var(--blue); }
.msg-body pre { white-space: pre-wrap; font-family: monospace; }

.attachments { margin-top: 16px; padding-top: 16px; border-top: 1px solid var(--border); }
.attachments h4 { font-size: 13px; color: var(--text2); margin-bottom: 8px; }
.attachment-chip { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--border); border-radius: 4px; padding: 6px 12px; font-size: 13px; color: var(--text); }

/* ── Compose modal ───────────────────────────────────────────────────────── */

.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 300;
  pointer-events: none;
}
.modal-overlay.open { display: block; pointer-events: auto; }

.compose-modal {
  position: absolute; bottom: 0; right: 24px;
  width: 560px; max-width: calc(100vw - 32px);
  background: var(--surface); border-radius: 8px 8px 0 0;
  box-shadow: 0 8px 32px rgba(0,0,0,.28);
  display: flex; flex-direction: column; max-height: 80vh;
}

.compose-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px; background: #404040; border-radius: 8px 8px 0 0; color: #fff;
  font-size: 14px; font-weight: 500;
}
.modal-close { background: none; border: none; color: #fff; font-size: 20px; cursor: pointer; line-height: 1; }
.modal-close:hover { opacity: .75; }

.compose-fields { border-bottom: 1px solid var(--border); }
.compose-field  { display: flex; align-items: center; border-bottom: 1px solid var(--border); padding: 4px 16px; }
.compose-field label { width: 52px; flex-shrink: 0; color: var(--text2); font-size: 13px; }
.compose-field input { flex: 1; border: none; outline: none; font-size: 14px; padding: 6px 0; }
.compose-field--between { align-items: stretch; }
.compose-subject-wrap   { display: flex; align-items: center; flex: 1; gap: 8px; }
.compose-subject-wrap label { width: 52px; flex-shrink: 0; color: var(--text2); font-size: 13px; }
.compose-subject-wrap input { flex: 1; border: none; outline: none; font-size: 14px; padding: 6px 0; }
.compose-cc-links { display: flex; align-items: center; gap: 4px; padding-right: 4px; }

#composeBody {
  flex: 1; border: none; outline: none; resize: none; padding: 12px 16px;
  font-size: 14px; font-family: inherit; min-height: 200px; line-height: 1.5;
}

.compose-footer {
  display: flex; align-items: center; gap: 8px; padding: 12px 16px;
  border-top: 1px solid var(--border);
}
.compose-status  { font-size: 13px; color: var(--text2); flex: 1; }
.compose-discard { margin-left: auto; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */

.btn-primary {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 24px; background: var(--blue); color: #fff;
  border: none; border-radius: 4px; font-size: 14px; font-weight: 500;
  cursor: pointer; transition: background .15s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-block { width: 100%; justify-content: center; }

.btn-ghost {
  display: inline-flex; align-items: center;
  padding: 8px 12px; background: none; border: none; border-radius: 4px;
  color: var(--text2); font-size: 14px; cursor: pointer;
}
.btn-ghost:hover { background: var(--hover-bg); }

.link-btn { background: none; border: none; color: var(--text2); font-size: 13px; cursor: pointer; text-decoration: underline; }

/* ── Login page ──────────────────────────────────────────────────────────── */

.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--bg); }
.login-card {
  width: 400px; max-width: calc(100vw - 32px);
  background: var(--surface); border-radius: 8px;
  padding: 48px 40px 36px; box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; gap: 10px; margin-bottom: 32px; font-size: 22px; font-weight: 400; }
.login-error { background: #fce8e6; color: var(--err); border-radius: 4px; padding: 10px 14px; margin-bottom: 16px; font-size: 14px; }
.form-group { margin-bottom: 20px; }
.form-group label { display: block; font-size: 13px; color: var(--text2); margin-bottom: 6px; }
.form-group input {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border);
  border-radius: 4px; font-size: 15px; outline: none;
  transition: border-color .15s;
}
.form-group input:focus { border-color: var(--blue); }
