:root {
  --blue:    #2756A7;
  --blue-dk: #1D4387;
  --blue-lt: rgba(39,86,167,0.10);
  --orange:  #F15A26;
  --org-dk:  #C74618;
  --green:   #0d9e6e;
  --red:     #e03d3d;
  --bg:      #f0f4fa;
  --surface: #ffffff;
  --border:  #dde4f0;
  --border2: #c8d4e8;
  --text:    #0f1b30;
  --muted:   #6577a0;
  --muted2:  #94a3be;
  --font:    var(--wow1-font);
  --fontb:   var(--wow1-font);
  --shadow:  0 2px 14px rgba(39,86,167,0.10);
  --shadow2: 0 6px 28px rgba(39,86,167,0.14);
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { background: var(--bg); color: var(--text); font-family: var(--fontb); min-height: 100vh; }

/* HEADER */
.site-header {
  background: var(--surface);
  border-bottom: 3px solid var(--orange);
  box-shadow: 0 6px 20px rgba(29,67,135,0.08);
  position: relative; overflow: hidden;
}
.site-header::after {
  content: none;
}
.header-inner {
  min-height: 92px; padding: 16px 0;
  border: 0; background: transparent;
  display: flex; align-items: center; justify-content: flex-start;
  position: relative; z-index: 1; cursor: pointer;
}
.site-logo {
  display: block;
  width: 224px;
  max-width: 62vw;
  height: auto;
}
.header-domain {
  background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.22);
  border-radius: 20px; padding: 5px 14px;
  font-family: var(--font); font-size: 12px; color: rgba(255,255,255,0.75);
  white-space: nowrap; flex-shrink: 0;
}

/* PAGE */
.page { padding: 24px 0 48px; }

/* WELCOME */
#welcome-view { animation: fadeUp 0.4s ease both; }
.welcome-card { width: 100%; margin: 0 auto; background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow2); overflow: hidden; }
.welcome-top {
  padding: 2rem 2rem 1.5rem; text-align: center;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, #f5f8ff 0%, var(--surface) 100%);
}
.welcome-icon {
  width: 70px; height: 70px; border-radius: 50%; margin: 0 auto 1.25rem;
  background: linear-gradient(135deg, var(--blue-lt), rgba(241,91,38,0.1));
  border: 2px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
}
.welcome-icon svg { color: var(--blue); }
.welcome-title { font-family: var(--font); font-size: 30px; line-height: 1.2; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.welcome-sub { font-size: 16px; color: var(--wow1-muted); line-height: 1.65; max-width: 440px; margin: 0 auto; }
.welcome-form { width: 100%; max-width: var(--wow1-form-width); margin-inline: auto; padding: 1.5rem 2rem; }
.welcome-top,
.welcome-form { min-width: 0; }
.welcome-form .random-btn { min-height: 52px; }
.welcome-form .restore-btn { min-height: 48px; font-size: 15px; }
.welcome-form .divider span { font-size: 12px; }
.random-btn {
  width: 100%; padding: 14px; border: none; border-radius: 10px;
  background: linear-gradient(135deg, var(--orange), var(--org-dk));
  color: #fff; font-family: var(--font); font-size: 16px; font-weight: 700;
  letter-spacing: 0.5px; cursor: pointer; transition: all 0.15s;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  box-shadow: 0 4px 16px rgba(241,91,38,0.3); margin-bottom: 14px;
}
.random-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(241,91,38,0.38); }
.divider { display: flex; align-items: center; gap: 12px; margin-bottom: 14px; }
.divider::before, .divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }
.divider span { font-size: 11px; color: var(--muted2); white-space: nowrap; font-family: var(--font); }
.input-group {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--border2); border-radius: 10px;
  overflow: hidden; background: var(--bg); margin-bottom: 10px;
  transition: border-color 0.15s;
}
.input-group:focus-within { border-color: var(--blue); }
.input-prefix {
  padding: 0 14px; background: var(--blue-lt); border-right: 1.5px solid var(--border2);
  display: flex; align-items: center; flex-shrink: 0; color: var(--blue);
}
.username-input {
  flex: 1; min-width: 0; padding: 12px 14px; border: none; outline: none;
  background: transparent; font-family: var(--font); font-size: 16px;
  font-weight: 700; color: var(--text);
}
.username-input::placeholder { color: var(--muted2); font-weight: 400; }
.domain-select {
  padding: 0 12px; background: var(--bg); border: none; border-left: 1.5px solid var(--border2);
  flex-shrink: 0; font-family: var(--font); font-size: 16px; font-weight: 700;
  color: var(--blue); white-space: nowrap; outline: none; cursor: pointer; min-width: 142px;
}
.domain-select:focus { color: var(--blue-dk); }
.restore-btn {
  width: 100%; padding: 11px; border-radius: 10px;
  border: 1.5px solid var(--border2); background: var(--surface);
  color: var(--muted); font-family: var(--font); font-size: 14px; font-weight: 700;
  cursor: pointer; transition: all 0.15s; display: flex; align-items: center; justify-content: center; gap: 7px;
}
.restore-btn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-lt); }
.back-inbox-btn {
  border-color: var(--blue);
  background: #fff;
  color: var(--blue);
  box-shadow: 0 3px 12px rgba(14,82,184,0.10);
}
.back-inbox-btn:hover {
  border-color: var(--blue-dk);
  background: var(--blue-lt);
  color: var(--blue-dk);
}
.back-inbox-label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  flex-shrink: 0;
}
.back-email-hint {
  min-width: 0;
  color: var(--muted);
  font-size: 11px;
  margin-left: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* INBOX SCREEN */
#inbox-screen { display: none; animation: fadeUp 0.35s ease both; }
.ctrl-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow2); margin-bottom: 14px; overflow: hidden; }
.ctrl-top { padding: 16px 20px 14px; border-bottom: 1px solid var(--border); position: relative; }
.ctrl-top::before {
  content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: linear-gradient(180deg, var(--blue), var(--orange)); border-radius: 14px 0 0 0;
}
.section-lbl {
  font-family: var(--font); font-size: 9px; font-weight: 700;
  letter-spacing: 2.5px; text-transform: uppercase; color: var(--muted2); margin-bottom: 8px;
}
.email-row {
  display: flex; align-items: stretch;
  border: 1.5px solid var(--border2); border-radius: 10px; overflow: hidden; background: var(--bg);
}
.email-icon-slot {
  padding: 0 14px; background: var(--blue-lt); border-right: 1.5px solid var(--border2);
  display: flex; align-items: center; flex-shrink: 0; color: var(--blue);
}
.email-value {
  flex: 1; min-width: 0; padding: 12px 14px; font-family: var(--font);
  font-size: 16px; font-weight: 700; color: var(--text); line-height: 1.2;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.copy-btn {
  padding: 0 18px; background: var(--orange); border: none; cursor: pointer;
  display: flex; align-items: center; gap: 7px; flex-shrink: 0;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  color: #fff; letter-spacing: 0.5px; text-transform: uppercase; transition: background 0.15s;
}
.copy-btn:hover { background: var(--org-dk); }

/* CTRL BAR - desktop: 1 hàng, mobile: 2 hàng */
.ctrl-bar { padding: 10px 20px; background: #fafbfe; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.ctrl-status { display: flex; align-items: center; gap: 6px; flex: 1; min-width: 0; }
.ctrl-btns { display: flex; flex-wrap: wrap; gap: 7px; flex-shrink: 0; }

.dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; background: var(--green); box-shadow: 0 0 0 2px rgba(13,158,110,0.2); }
.dot.orange { background: var(--orange); box-shadow: 0 0 0 2px rgba(241,91,38,0.2); animation: dpulse 1.6s infinite; }
.dot.red    { background: var(--red); box-shadow: 0 0 0 2px rgba(224,61,61,0.2); }
@keyframes dpulse { 0%,100%{transform:scale(1);opacity:1} 50%{transform:scale(0.7);opacity:0.4} }
.status-txt { min-width: 0; font-family: var(--fontb); font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.ctxt { font-family: var(--font); font-size: 12px; color: var(--muted2); white-space: nowrap; }

.abtn {
  display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 7px 13px; border-radius: 8px;
  font-family: var(--font); font-size: 12px; font-weight: 700; letter-spacing: 0.3px; cursor: pointer;
  border: 1.5px solid var(--border2); background: var(--surface); color: var(--text);
  transition: all 0.15s; white-space: nowrap;
}
.abtn:hover { border-color: var(--blue); color: var(--blue); background: var(--blue-lt); }
.abtn.danger { color: var(--red); border-color: rgba(224,61,61,0.3); }
.abtn.danger:hover { border-color: var(--red); background: rgba(224,61,61,0.08); }
.abtn.renew { color: var(--green); border-color: rgba(13,158,110,0.35); }
.abtn.renew:hover { border-color: var(--green); background: rgba(13,158,110,0.08); color: var(--green); }

/* INBOX */
.inbox-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow); overflow: hidden; }
.inbox-head {
  padding: 11px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: flex-start; gap: 20px; background: #fafbfe;
}
.inbox-title {
  font-family: var(--font); font-size: 11px; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase; color: var(--muted);
  display: flex; align-items: center; gap: 8px;
}
.inbox-title::before { content: ''; width: 3px; height: 14px; background: linear-gradient(var(--blue), var(--orange)); border-radius: 2px; display: inline-block; }
.nbadge { background: var(--orange); color: #fff; border-radius: 20px; padding: 2px 9px; font-family: var(--font); font-size: 11px; font-weight: 700; }
.mail-item {
  padding: 13px 20px; border-bottom: 1px solid var(--border);
  cursor: pointer; display: flex; gap: 13px; align-items: center;
  transition: background 0.11s; position: relative;
}
.mail-item:last-child { border-bottom: none; }
.mail-item:hover { background: #f5f8ff; }
.mail-item.unread::after { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--orange); }
.avatar {
  width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
  background: var(--blue-lt); border: 1.5px solid var(--border2);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font); font-size: 15px; font-weight: 700; color: var(--blue);
}
.mail-meta { flex: 1; min-width: 0; }
.mail-from { font-family: var(--fontb); font-size: 12px; color: var(--muted2); margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-subj { font-family: var(--font); font-size: 15px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mail-item.unread .mail-subj { font-weight: 700; color: var(--text); }
.mail-time { font-family: var(--font); font-size: 11px; color: var(--muted2); flex-shrink: 0; }
.empty { padding: 3.5rem 1rem; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty-ico { width: 60px; height: 60px; border-radius: 50%; background: var(--blue-lt); display: flex; align-items: center; justify-content: center; }
.empty-ico svg { color: var(--blue); opacity: 0.45; }
.empty-ttl { font-family: var(--font); font-size: 16px; font-weight: 700; color: var(--muted); }
.empty-addr { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--font); font-size: 13px; color: var(--muted2); background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 5px 14px; }

/* DETAIL */
#detail-view { display: none; animation: fadeUp 0.25s ease both; }
.back-row { margin-bottom: 12px; }
.back-btn {
  display: inline-flex; align-items: center; gap: 7px; min-height: 44px; padding: 8px 16px; border-radius: 8px;
  font-family: var(--font); font-size: 13px; font-weight: 700; cursor: pointer;
  border: 1.5px solid var(--blue); background: var(--surface);
  color: var(--blue); box-shadow: 0 3px 12px rgba(14,82,184,0.10);
  transition: all 0.15s;
}
.back-btn:hover { border-color: var(--blue-dk); color: var(--blue-dk); background: var(--blue-lt); }
.detail-card { background: var(--surface); border-radius: 14px; box-shadow: var(--shadow2); overflow: hidden; }
.detail-info { padding: 18px 22px; border-bottom: 1px solid var(--border); background: #fafbfe; }
.detail-subj { overflow-wrap: anywhere; font-family: var(--font); font-size: 21px; font-weight: 700; color: var(--text); margin-bottom: 10px; line-height: 1.2; }
.detail-meta { display: flex; flex-wrap: wrap; gap: 14px; font-size: 13px; color: var(--muted2); }
.detail-meta > div { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
.meta-lbl { color: var(--muted); font-weight: 500; }
.detail-body { min-width: 0; padding: 22px; max-height: 520px; overflow: auto; overflow-wrap: anywhere; font-size: 14px; line-height: 1.75; color: var(--text); }
.detail-body:has(> .mail-frame) { padding: 0; max-height: none; }
.detail-body a { color: var(--blue); }
.detail-body pre { font-family: monospace; font-size: 13px; white-space: pre-wrap; word-break: break-word; }
.detail-body img { max-width: 100%; height: auto; }
.mail-frame {
  width: 100%;
  max-width: 100%;
  min-width: 0;
  height: 520px;
  border: 0;
  display: block;
  background: #fff;
}

@keyframes fadeUp { from{opacity:0;transform:translateY(14px)} to{opacity:1;transform:none} }
/* COUNTDOWN */
.countdown-box {
  background: #fff8f0; border: 1.5px solid #f15b26;
  border-radius: 12px; padding: 16px 22px;
  display: flex; align-items: center; justify-content: space-between; gap: 20px;
  margin-top: 14px; margin-bottom: 14px; gap: 16px;
}
.countdown-left { display: flex; flex-direction: column; gap: 5px; }
.countdown-label {
  font-family: var(--font); font-size: 10px; font-weight: 700;
  letter-spacing: 2px; text-transform: uppercase; color: var(--muted2);
}
.countdown-time {
  font-family: var(--font); font-size: 28px; font-weight: 700;
  color: var(--orange); line-height: 1;
  font-variant-numeric: tabular-nums;
}
.countdown-time.warn { color: var(--red); animation: timepulse 1s infinite; }
@keyframes timepulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
@keyframes toastIn { from{opacity:0;transform:translateX(-50%) translateY(8px)} to{opacity:1;transform:translateX(-50%) translateY(0)} }
.copy-toast {
  position: fixed; bottom: 24px; left: 50%;
  transform: translateX(-50%);
  background: #1a1d27; color: #fff;
  padding: 8px 18px; border-radius: 20px;
  font-family: var(--font); font-size: 13px; font-weight: 700;
  border-left: 3px solid var(--orange);
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  animation: toastIn 0.2s ease both;
  width: max-content; max-width: calc(100% - 2 * var(--wow1-page-gutter));
  z-index: 9999; overflow-wrap: anywhere;
  pointer-events: none;
}

@media(min-width:901px) {
  /* Only the welcome view takes the available vertical space. Inbox and reader
     remain at the top; auto margins collapse safely on shorter screens. */
  .page { display: flex; flex-direction: column; padding-bottom: 24px; }
  #welcome-view { margin-block: auto; }
  .welcome-card {
    display: grid;
    grid-template-columns: minmax(0, 42fr) minmax(0, 58fr);
    min-height: 360px;
  }
  .welcome-top {
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 40px 32px;
    text-align: left;
    border-bottom: 0;
    border-right: 1px solid var(--border);
  }
  .welcome-icon { width: 64px; height: 64px; margin: 0 0 20px; }
  .welcome-sub { max-width: none; margin: 0; }
  .welcome-form { align-self: center; padding: 40px 32px; }

  .ctrl-card {
    display: grid;
    grid-template-columns: minmax(0, 65fr) minmax(260px, 35fr);
    grid-template-areas:
      "email countdown"
      "bar bar";
  }
  .ctrl-top {
    grid-area: email;
    border-bottom: none;
    border-right: 1px solid var(--border);
  }
  .ctrl-bar {
    grid-area: bar;
    border-top: 1px solid var(--border);
  }
  .countdown-box {
    grid-area: countdown;
    margin: 16px 20px 14px;
    min-height: 74px;
  }
}

/* TABLET (601-900px) */
@media(min-width:601px) and (max-width:900px) {
  .ctrl-bar { padding: 10px 16px; flex-wrap: wrap; }
  .ctrl-status { flex-basis: 100%; }
  .ctrl-btns { width: 100%; justify-content: flex-end; }
  .abtn { padding: 7px 11px; font-size: 12px; }
  .copy-btn span { display: inline; }
  .countdown-box { margin: 14px; align-items: stretch; flex-direction: column; }
  .countdown-box .abtn { justify-content: center; }
}

/* MOBILE (tối đa 600px) */
@media(max-width:600px) {
  .abtn { min-height: 44px; }
  /* Header */
  .header-inner { min-height: 76px; padding: 12px 0; }
  .site-logo { width: 184px; max-width: 68vw; }
  .header-domain { font-size: 11px; padding: 4px 10px; }

  /* Welcome */
  .welcome-top { padding: 1.75rem 1.25rem 1.5rem; }
  .welcome-icon { width: 60px; height: 60px; margin-bottom: 1rem; }
  .welcome-title { font-size: 26px; }
  .welcome-form { padding: 1rem; }
  .back-inbox-btn { flex-direction: column; gap: 5px; }
  .back-email-hint {
    width: 100%;
    min-width: 0;
    margin-left: 0;
    font-size: 12px;
    line-height: 1.4;
    text-align: center;
  }

  /* Email row */
  .email-row { display: grid; grid-template-columns: auto minmax(0, 1fr); }
  .email-icon-slot { padding: 0 10px; }
  .email-value { font-size: 16px; padding: 12px 10px; }
  .copy-btn { grid-column: 1 / -1; justify-content: center; min-height: 44px; padding: 10px 14px; font-size: 12px; }
  .ctrl-top { padding: 14px; }
  .countdown-box { margin: 14px; align-items: stretch; flex-direction: column; }
  .countdown-box .abtn { justify-content: center; }

  /* Control buttons fit small screens in two columns. */
  .ctrl-bar {
    padding: 10px 14px;
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }
  .ctrl-status {
    width: 100%;
    padding: 2px 0;
  }
  .ctrl-btns {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    width: 100%;
    gap: 6px;
  }
  .ctrl-btns .abtn {
    min-height: 44px;
    min-width: 0;
    flex: 1;
    justify-content: center;
    padding: 9px 6px;
    font-size: 12px;
    white-space: normal;
  }

  /* Inbox */
  .mail-item { padding: 14px; gap: 12px; }
  .avatar { width: 36px; height: 36px; font-size: 13px; }
  .mail-subj { font-size: 14px; }
  .inbox-head { padding: 12px 14px; }

  /* Detail */
  .detail-info { padding: 16px; }
  .detail-body { padding: 16px; }
  .detail-subj { font-size: 18px; }

  /* Page padding */
  .page { padding: 16px 0 40px; }

  .input-group {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 8px;
    border: 0;
    overflow: visible;
    background: transparent;
  }
  .input-prefix { display: none; }
  .username-input,
  .domain-select {
    width: 100%;
    min-width: 0;
    min-height: 46px;
    padding: 0 12px;
    border: 1.5px solid var(--border2);
    border-radius: 10px;
    background: var(--bg);
    font-size: 16px;
  }
  .restore-btn { min-height: 44px; }
}
