/* Lyahn Mail — refined product UI */

:root {
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --bg-grouped: #f2f2f7;
  --label: #1d1d1f;
  --label-secondary: #6e6e73;
  --label-tertiary: #8e8e93;
  --separator: rgba(60, 60, 67, 0.12);
  --separator-opaque: #c6c6c8;
  --fill: rgba(120, 120, 128, 0.14);
  --fill-secondary: rgba(120, 120, 128, 0.09);
  --blue: #0071e3;
  --blue-press: #0077ed;
  --blue-soft: rgba(0, 113, 227, 0.12);
  --green: #34c759;
  --red: #ff3b30;
  --orange: #ff9f0a;
  --radius-xl: 22px;
  --radius-lg: 16px;
  --radius-md: 12px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.03), 0 4px 14px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 8px 28px rgba(0, 0, 0, 0.08);
  --shadow-float: 0 10px 40px rgba(0, 0, 0, 0.16);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
    "Helvetica Neue", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei",
    system-ui, sans-serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --content: 1080px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --bg-elevated: #1c1c1e;
    --bg-grouped: #2c2c2e;
    --label: #f5f5f7;
    --label-secondary: #a1a1a6;
    --label-tertiary: #6e6e73;
    --separator: rgba(84, 84, 88, 0.55);
    --separator-opaque: #3a3a3c;
    --fill: rgba(120, 120, 128, 0.28);
    --fill-secondary: rgba(120, 120, 128, 0.18);
    --blue: #0a84ff;
    --blue-press: #409cff;
    --blue-soft: rgba(10, 132, 255, 0.2);
    --shadow-sm: 0 1px 0 rgba(255, 255, 255, 0.04) inset;
    --shadow-md: 0 12px 40px rgba(0, 0, 0, 0.5);
    --shadow-float: 0 16px 48px rgba(0, 0, 0, 0.55);
    color-scheme: dark;
  }
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: -0.015em;
  color: var(--label);
  background:
    radial-gradient(900px 420px at 10% -8%, rgba(0, 113, 227, 0.07), transparent 55%),
    radial-gradient(700px 360px at 100% 0%, rgba(88, 86, 214, 0.05), transparent 50%),
    var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

@media (prefers-color-scheme: dark) {
  body {
    background:
      radial-gradient(800px 360px at 15% -10%, rgba(10, 132, 255, 0.12), transparent 55%),
      var(--bg);
  }
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
  border: none;
  background: none;
  padding: 0;
}

button:disabled {
  opacity: 0.36;
  cursor: not-allowed;
  transform: none !important;
}

/* —— Shell —— */
.app {
  min-height: 100dvh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  padding-top: var(--safe-top);
  background: color-mix(in srgb, var(--bg) 68%, transparent);
  backdrop-filter: saturate(180%) blur(22px);
  -webkit-backdrop-filter: saturate(180%) blur(22px);
  border-bottom: 0.5px solid var(--separator);
}

.topbar-inner {
  max-width: var(--content);
  margin: 0 auto;
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.app-icon {
  width: 40px;
  height: 40px;
  border-radius: 11px;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(165deg, #64d2ff 0%, #0071e3 52%, #5856d6 120%);
  box-shadow: 0 6px 16px rgba(0, 113, 227, 0.28);
  flex-shrink: 0;
}

.app-title {
  margin: 0;
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -0.035em;
  line-height: 1.1;
}

.app-subtitle {
  margin: 3px 0 0;
  font-size: 12px;
  color: var(--label-secondary);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 11px;
  border-radius: 999px;
  background: var(--fill);
  color: var(--label-secondary);
  font-size: 12px;
  font-weight: 600;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: var(--label-secondary);
  background: var(--fill);
  transition: background 0.15s var(--ease), color 0.15s var(--ease),
    transform 0.12s var(--ease);
}

.icon-btn:hover {
  color: var(--label);
  background: var(--fill-secondary);
}

.icon-btn:active {
  transform: scale(0.93);
}

/* —— Layout —— */
.main {
  max-width: var(--content);
  margin: 0 auto;
  padding: 16px 16px calc(36px + var(--safe-bottom));
}

.layout {
  display: grid;
  grid-template-columns: minmax(300px, 380px) minmax(0, 1fr);
  gap: 20px;
  align-items: start;
}

@media (max-width: 860px) {
  .layout {
    grid-template-columns: 1fr;
    gap: 0;
  }
}

.col-side,
.col-main {
  min-width: 0;
}

.group {
  margin-bottom: 22px;
}

.group-label {
  margin: 0 0 8px 6px;
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--label-secondary);
  text-transform: uppercase;
  display: flex;
  align-items: center;
  gap: 8px;
}

.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
  padding: 0 4px;
}

.group-head .group-label {
  margin: 0;
  text-transform: uppercase;
}

.count-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 11px;
  font-weight: 700;
  text-transform: none;
  letter-spacing: 0;
}

.head-actions {
  display: flex;
  gap: 2px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.surface {
  background: var(--bg-elevated);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-sm);
  border: 0.5px solid var(--separator);
  overflow: hidden;
}

.pad {
  padding: 14px 16px;
}

.divider {
  height: 0.5px;
  background: var(--separator);
}

/* —— Segmented —— */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 2px;
  margin: 12px 12px 0;
  padding: 2px;
  background: var(--fill);
  border-radius: 10px;
}

.tab {
  height: 32px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-secondary);
  transition: all 0.18s var(--ease);
}

.tab.active {
  background: var(--bg-elevated);
  color: var(--label);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
  .tab.active {
    background: #636366;
    box-shadow: none;
    color: #fff;
  }
}

.panel.hidden {
  display: none !important;
}

/* —— Fields —— */
.field-label {
  display: block;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--label-secondary);
}

.field-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.field {
  height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 0.5px solid var(--separator-opaque);
  background: var(--bg-grouped);
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease),
    background 0.15s var(--ease);
}

.field:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3.5px var(--blue-soft);
  background: var(--bg-elevated);
}

.field.grow {
  flex: 1;
  min-width: 0;
}

.select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' fill='none'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' stroke='%238e8e93' stroke-width='1.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  min-width: 128px;
}

.custom-compose .select {
  flex: 0 1 150px;
  min-width: 110px;
}

.compose-at {
  color: var(--label-tertiary);
  font-weight: 600;
}

.foot-note {
  margin: 8px 0 0;
  font-size: 11.5px;
  color: var(--label-tertiary);
  line-height: 1.4;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  height: 40px;
  padding: 0 16px;
  border-radius: 980px;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: -0.02em;
  transition: transform 0.12s var(--ease), background 0.15s var(--ease),
    opacity 0.15s var(--ease);
  white-space: nowrap;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.15) inset;
}

.btn-primary:hover:not(:disabled) {
  background: var(--blue-press);
}

.btn-secondary {
  background: var(--fill);
  color: var(--blue);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--fill-secondary);
}

.btn.sm {
  height: 34px;
  padding: 0 13px;
  font-size: 13px;
}

.btn.grow {
  flex: 1;
}

.btn-ico {
  font-size: 13px;
  opacity: 0.9;
}

.text-btn {
  font-size: 13px;
  font-weight: 600;
  color: var(--blue);
  padding: 5px 8px;
  border-radius: 8px;
  transition: background 0.12s var(--ease);
}

.text-btn:hover {
  background: var(--blue-soft);
}

.text-btn.danger {
  color: var(--red);
}

.text-btn.danger:hover {
  background: rgba(255, 59, 48, 0.1);
}

/* —— Hero current mailbox —— */
.hero {
  padding: 16px;
}

.hero-inner {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}

.hero-avatar {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: #fff;
  background: linear-gradient(145deg, #5ac8fa, #0071e3 55%, #5856d6);
  box-shadow: 0 6px 14px rgba(0, 113, 227, 0.22);
  user-select: none;
}

.hero-avatar.empty {
  background: var(--fill);
  color: var(--label-tertiary);
  box-shadow: none;
}

.hero-body {
  flex: 1;
  min-width: 0;
}

.email-box {
  display: block;
  width: 100%;
  text-align: left;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--bg-grouped);
  border: 0.5px solid var(--separator);
  font-family: var(--mono);
  font-size: 13.5px;
  letter-spacing: -0.03em;
  color: var(--label-tertiary);
  word-break: break-all;
  line-height: 1.4;
  transition: border-color 0.15s var(--ease), background 0.15s var(--ease),
    color 0.15s var(--ease), transform 0.12s var(--ease);
}

.email-box:hover {
  border-color: color-mix(in srgb, var(--blue) 40%, var(--separator));
}

.email-box:active {
  transform: scale(0.995);
}

.email-box.active {
  color: var(--label);
  background: var(--blue-soft);
  border-color: color-mix(in srgb, var(--blue) 35%, transparent);
  font-weight: 600;
}

.meta {
  margin: 8px 2px 0;
  font-size: 12px;
  color: var(--label-secondary);
  line-height: 1.45;
  min-height: 1.2em;
}

.action-bar {
  display: flex;
  gap: 8px;
  margin-top: 14px;
  flex-wrap: wrap;
}

/* —— Search —— */
.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 10px 12px 6px;
  padding: 0 12px;
  height: 36px;
  border-radius: 10px;
  background: var(--fill);
}

.search-ico {
  color: var(--label-tertiary);
  flex-shrink: 0;
}

.search-input {
  flex: 1;
  min-width: 0;
  height: 100%;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: var(--label);
}

.search-input::placeholder {
  color: var(--label-tertiary);
}

/* —— Empty states —— */
.empty-block {
  padding: 36px 20px;
  text-align: center;
}

.empty-icon {
  font-size: 28px;
  line-height: 1;
  margin-bottom: 10px;
  filter: grayscale(0.15);
}

.empty-title {
  margin: 0;
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.02em;
  color: var(--label);
}

.empty-desc {
  margin: 6px 0 0;
  font-size: 13px;
  color: var(--label-tertiary);
  line-height: 1.4;
}

/* —— History list —— */
.hist-list {
  max-height: min(380px, 46vh);
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

.hist-list.empty,
.list.empty {
  /* empty-block inside */
}

.hist-item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 2px 10px;
  padding: 11px 14px;
  border-bottom: 0.5px solid var(--separator);
  align-items: center;
  transition: background 0.12s var(--ease);
  cursor: default;
}

.hist-item:last-child {
  border-bottom: none;
}

.hist-item:hover {
  background: var(--fill-secondary);
}

.hist-item.active {
  background: var(--blue-soft);
}

.hist-avatar {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.02em;
  user-select: none;
}

.hist-main {
  min-width: 0;
}

.hist-item .email {
  font-family: var(--mono);
  font-size: 12.5px;
  letter-spacing: -0.03em;
  color: var(--label);
  word-break: break-all;
  cursor: pointer;
  font-weight: 600;
  line-height: 1.35;
}

.hist-item .email:hover {
  color: var(--blue);
}

.hist-item .sub {
  margin-top: 3px;
  font-size: 11px;
  color: var(--label-tertiary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hist-item .btns {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 148px;
}

.hist-item .btns button {
  height: 28px;
  padding: 0 9px;
  border-radius: 980px;
  font-size: 11.5px;
  font-weight: 650;
  background: var(--fill);
  color: var(--blue);
  transition: background 0.12s var(--ease), transform 0.1s var(--ease);
}

.hist-item .btns button:hover {
  background: var(--fill-secondary);
}

.hist-item .btns button:active {
  transform: scale(0.96);
}

.hist-item .btns .danger-text {
  color: var(--red);
}

.badge-now {
  display: inline-flex;
  align-items: center;
  height: 17px;
  padding: 0 6px;
  border-radius: 999px;
  background: var(--blue);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
  margin-left: 6px;
  vertical-align: 1px;
  font-family: var(--font);
}

/* —— Inbox —— */
.status-cluster {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-text {
  font-size: 11px;
  color: var(--label-tertiary);
  font-variant-numeric: tabular-nums;
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.4);
  animation: live 2.2s ease-out infinite;
}

.live-dot.off {
  background: var(--label-tertiary);
  animation: none;
  box-shadow: none;
}

@keyframes live {
  0% {
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0.4);
  }
  70% {
    box-shadow: 0 0 0 8px rgba(52, 199, 89, 0);
  }
  100% {
    box-shadow: 0 0 0 0 rgba(52, 199, 89, 0);
  }
}

.inbox-surface {
  min-height: 220px;
}

.list {
  display: flex;
  flex-direction: column;
}

.item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 3px 12px;
  padding: 13px 16px;
  border-bottom: 0.5px solid var(--separator);
  cursor: pointer;
  transition: background 0.12s var(--ease);
}

.item:last-child {
  border-bottom: none;
}

.item:hover {
  background: var(--fill-secondary);
}

.item:active {
  background: var(--fill);
}

.item .from {
  font-size: 15px;
  font-weight: 650;
  letter-spacing: -0.025em;
  color: var(--label);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item .time {
  font-size: 12px;
  color: var(--label-tertiary);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
  padding-top: 2px;
}

.item .subj {
  grid-column: 1 / -1;
  font-size: 13px;
  color: var(--label-secondary);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item .att-badge {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 650;
  color: var(--blue);
}

/* —— Detail —— */
.d-meta {
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.d-row {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  padding: 7px 0;
  font-size: 13px;
}

.d-k {
  color: var(--label-tertiary);
  font-weight: 600;
}

.d-v {
  color: var(--label);
  word-break: break-word;
  font-weight: 500;
}

.atts {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 0.5px solid var(--separator);
}

.att-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  border-radius: 980px;
  background: var(--blue-soft);
  color: var(--blue);
  font-size: 12px;
  font-weight: 600;
  text-decoration: none;
  transition: background 0.12s var(--ease), transform 0.1s var(--ease);
}

.att-chip:hover {
  background: color-mix(in srgb, var(--blue) 22%, transparent);
}

.att-chip:active {
  transform: scale(0.97);
}

.d-body {
  margin: 12px;
  border-radius: var(--radius-md);
  background: #fff;
  color: #1d1d1f;
  padding: 16px;
  min-height: 140px;
  max-height: 55vh;
  overflow: auto;
  border: 0.5px solid var(--separator);
  -webkit-overflow-scrolling: touch;
}

.d-body.plain {
  background: var(--bg-grouped);
  color: var(--label);
  white-space: pre-wrap;
  font-family: var(--mono);
  font-size: 12.5px;
  line-height: 1.55;
}

@media (prefers-color-scheme: dark) {
  .d-body:not(.plain) {
    background: #2c2c2e;
    color: #f5f5f7;
  }
}

/* —— Global toast —— */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(28px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  z-index: 100;
  max-width: min(420px, calc(100vw - 32px));
  padding: 12px 18px;
  border-radius: 980px;
  background: rgba(28, 28, 30, 0.92);
  color: #f5f5f7;
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.02em;
  box-shadow: var(--shadow-float);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s var(--ease), transform 0.28s var(--ease);
  text-align: center;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.toast.err {
  background: rgba(255, 59, 48, 0.94);
}

.toast.warn {
  background: rgba(255, 149, 0, 0.94);
  color: #1d1d1f;
}

.hidden {
  display: none !important;
}

#toast.hidden {
  display: block !important; /* keep for opacity animation */
  opacity: 0;
  pointer-events: none;
}

#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}

.footer {
  text-align: center;
  padding: 12px 12px 8px;
}

.footer p {
  margin: 0;
  font-size: 11px;
  color: var(--label-tertiary);
}

/* Skeleton */
.skeleton-row {
  height: 64px;
  margin: 10px 14px;
  border-radius: 12px;
  background: linear-gradient(
    90deg,
    var(--fill-secondary) 25%,
    var(--fill) 50%,
    var(--fill-secondary) 75%
  );
  background-size: 200% 100%;
  animation: shimmer 1.2s ease infinite;
}

@keyframes shimmer {
  0% {
    background-position: 100% 0;
  }
  100% {
    background-position: -100% 0;
  }
}

/* Compact */
body.compact {
  --content: 1200px;
}

body.compact .layout {
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
}

body.compact .group {
  margin-bottom: 16px;
}

/* Mobile */
@media (max-width: 560px) {
  .topbar-inner {
    padding: 10px 14px;
  }

  .app-title {
    font-size: 18px;
  }

  .main {
    padding: 10px 12px calc(28px + var(--safe-bottom));
  }

  .custom-compose {
    flex-direction: column;
    align-items: stretch;
  }

  .compose-at {
    display: none;
  }

  .custom-compose .select,
  .select {
    width: 100%;
    min-width: 0;
  }

  .field-row .btn {
    flex: 1;
  }

  .hist-item {
    grid-template-columns: 36px 1fr;
  }

  .hist-item .btns {
    grid-column: 2;
    max-width: none;
    justify-content: flex-start;
    margin-top: 4px;
  }

  .hero-avatar {
    width: 42px;
    height: 42px;
    border-radius: 12px;
  }
}

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