@import url('https://fonts.googleapis.com/css2?family=Clash+Display:wght@500;600;700&family=Satoshi:wght@400;500;700&display=swap');

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

:root {
  --sidebar-w: 248px;
  --list-w: 390px;
  --topbar-h: 58px;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-lg: 18px;
  --font-display: 'Clash Display', 'Satoshi', system-ui, sans-serif;
  --font: 'Satoshi', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

html[data-theme="light"] {
  --bg: #FAFAFB;
  --surface: #FFFFFF;
  --surface-2: #F4F3F6;
  --surface-3: #ECEAF1;
  --purple: #6D4AFF;
  --purple-strong: #5A37E6;
  --purple-faint: rgba(109,74,255,0.09);
  --text: #16151C;
  --text-muted: #6C6A78;
  --border: #E7E6EC;
  --shadow: 0 10px 34px rgba(20,17,40,0.14), 0 2px 8px rgba(20,17,40,0.06);
  --shadow-sm: 0 1px 3px rgba(20,17,40,0.07);
  --danger: #D6334A;
  --danger-bg: #FDECEF;
  --danger-border: #F4B9C3;
  --warn: #8A6500;
  --warn-bg: #FFF6D9;
  --warn-border: #F0DA91;
  --success: #2F9E5B;
  --success-bg: #E8F6EE;
  --scrim: rgba(22,21,28,0.42);
}

html[data-theme="dark"] {
  --bg: #17151F;
  --surface: #1D1B27;
  --surface-2: #262330;
  --surface-3: #2F2B3B;
  --purple: #8B72FF;
  --purple-strong: #7A5CFF;
  --purple-faint: rgba(139,114,255,0.16);
  --text: #F1F0F5;
  --text-muted: #9893A8;
  --border: rgba(255,255,255,0.09);
  --shadow: 0 12px 38px rgba(0,0,0,0.5), 0 2px 8px rgba(0,0,0,0.3);
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.28);
  --danger: #FC8181;
  --danger-bg: rgba(252,129,129,0.12);
  --danger-border: rgba(252,129,129,0.38);
  --warn: #ECC94B;
  --warn-bg: rgba(236,201,75,0.12);
  --warn-border: rgba(236,201,75,0.38);
  --success: #48BB78;
  --success-bg: rgba(72,187,120,0.13);
  --scrim: rgba(0,0,0,0.6);
}

html, body { height: 100%; }
body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  transition: background 0.2s ease, color 0.2s ease;
}

button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
a { color: var(--purple); text-decoration: none; }
.hidden { display: none !important; }
.spacer { flex: 1; }
.ic { width: 18px; height: 18px; flex-shrink: 0; stroke: currentColor; }
.only-mobile { display: none; }
small { color: var(--text-muted); font-size: 12.5px; }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; }

.screen { display: none; height: 100vh; height: 100dvh; position: relative; overflow-y: auto; overflow-x: hidden; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; align-items: center; justify-content: center; padding: 28px 16px; }
.screen.active { display: flex; }
#screen-loading { background: var(--bg); }
.loading-box { display: flex; flex-direction: column; align-items: center; gap: 22px; }
.loading-logo { width: 68px; animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.94); opacity: 0.8; } }
.spinner { width: 24px; height: 24px; border-radius: 50%; border: 3px solid var(--purple-faint); border-top-color: var(--purple); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.orbs { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.32; }
.o1 { width: 480px; height: 480px; background: radial-gradient(circle, #9B7FF6, #6B3FF0); top: -150px; left: -100px; }
.o2 { width: 400px; height: 400px; background: radial-gradient(circle, #C4B5FD, #7C3AED); bottom: -100px; right: -80px; }

.auth-card {
  position: relative; z-index: 1; width: 100%; max-width: 460px; margin: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 32px 30px 26px; box-shadow: var(--shadow); animation: rise 0.5s cubic-bezier(0.22,1,0.36,1) both;
}
.auth-card.narrow { max-width: 410px; }
@keyframes rise { from { opacity: 0; transform: translateY(18px); } to { opacity: 1; transform: translateY(0); } }
.auth-logo { width: 54px; display: block; margin: 0 auto 14px; }
.auth-card h1 { font-family: var(--font-display); font-size: 25px; text-align: center; margin-bottom: 6px; }
.auth-sub { color: var(--text-muted); text-align: center; font-size: 14px; margin-bottom: 22px; line-height: 1.55; word-break: break-word; }

.field-label { display: block; font-size: 13px; font-weight: 700; margin: 14px 0 6px; }
.input, .address-field, .password-field input {
  width: 100%; background: var(--surface-2); border: 1.5px solid transparent; border-radius: 10px;
  padding: 11px 13px; outline: none; transition: border-color 0.15s, background 0.15s;
}
.input:focus, .address-field:focus-within, .password-field input:focus { border-color: var(--purple); background: var(--surface); }
.address-field { display: flex; align-items: center; padding: 0; overflow: hidden; }
.address-field input { flex: 1; min-width: 0; background: transparent; border: none; outline: none; padding: 11px 4px 11px 13px; }
.address-suffix { padding: 0 13px 0 2px; color: var(--text-muted); font-weight: 700; white-space: nowrap; }
.password-field { position: relative; }
.password-field input { padding-right: 44px; }
.eye { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); width: 36px; height: 36px; display: grid; place-items: center; border-radius: 8px; color: var(--text-muted); }
.eye:hover { background: var(--surface-3); }
.hint { font-size: 12.5px; color: var(--text-muted); margin-top: 6px; min-height: 18px; }
.hint.ok { color: var(--success); }
.hint.bad { color: var(--danger); }
.strength { height: 4px; background: var(--surface-3); border-radius: 4px; margin-top: 8px; overflow: hidden; }
.strength span { display: block; height: 100%; width: 0; background: var(--danger); transition: width 0.2s, background 0.2s; }
.form-error { color: var(--danger); font-size: 13px; min-height: 20px; margin-top: 10px; font-weight: 500; }
.callout { display: flex; gap: 11px; padding: 12px 14px; margin-top: 16px; background: var(--purple-faint); border-radius: 10px; font-size: 13px; line-height: 1.5; color: var(--text); }
.callout .ic { color: var(--purple); margin-top: 2px; }
.check-row { display: flex; gap: 11px; align-items: flex-start; margin-top: 16px; cursor: pointer; }
.check-row input { margin-top: 4px; accent-color: var(--purple); width: 16px; height: 16px; }
.check-row span { display: flex; flex-direction: column; font-size: 14px; }
.auth-links { display: flex; justify-content: space-between; gap: 12px; margin-top: 14px; flex-wrap: wrap; }

.setup-photo { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 4px; }
.avatar-pick { position: relative; border-radius: 50%; }
.avatar-pick-badge { position: absolute; right: -2px; bottom: -2px; width: 28px; height: 28px; border-radius: 50%; background: var(--purple); color: #fff; display: grid; place-items: center; border: 3px solid var(--surface); }
.avatar-pick-badge .ic { width: 13px; height: 13px; }
.setup-photo-actions { display: flex; gap: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; font-weight: 700; font-size: 14px;
  padding: 11px 20px; border-radius: 10px; transition: transform 0.12s, background 0.15s, box-shadow 0.15s, opacity 0.15s; white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-primary { background: var(--purple); color: #fff; box-shadow: 0 4px 14px rgba(109,74,255,0.28); }
.btn-primary:hover:not(:disabled) { background: var(--purple-strong); }
.btn-ghost { background: var(--surface-2); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-outline-danger { border: 1.5px solid var(--danger-border); color: var(--danger); background: var(--danger-bg); }
.btn-outline-danger:hover { background: var(--danger); color: #fff; }
.btn-block { width: 100%; margin-top: 18px; }
.btn.sm { padding: 7px 12px; font-size: 13px; border-radius: 8px; }
.link-btn { color: var(--purple); font-weight: 700; font-size: 13.5px; padding: 4px 2px; }
.link-btn:hover { text-decoration: underline; }
.link-btn.danger { color: var(--danger); }
.link-btn.center { display: block; margin: 12px auto 0; color: var(--text-muted); font-weight: 500; }
.icon-btn { width: 38px; height: 38px; border-radius: 10px; display: inline-grid; place-items: center; color: var(--text-muted); transition: background 0.15s, color 0.15s; flex-shrink: 0; }
.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 8px; }
.icon-btn.active { color: #E5A400; }
.icon-btn.active .ic { fill: #E5A400; }

.avatar {
  display: inline-grid; place-items: center; border-radius: 50%; color: #fff; font-weight: 700; flex-shrink: 0; overflow: hidden;
  background: var(--purple); font-family: var(--font-display); user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-sm { width: 34px; height: 34px; font-size: 13px; }
.avatar-md { width: 42px; height: 42px; font-size: 15px; }
.avatar-lg { width: 52px; height: 52px; font-size: 18px; }
.avatar-xl { width: 92px; height: 92px; font-size: 32px; }
.avatar.system { background: linear-gradient(135deg, #8B72FF, #5A37E6); }
.avatar-btn { border-radius: 50%; padding: 2px; }
.avatar-btn:hover { background: var(--surface-3); }

.app { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.topbar {
  height: var(--topbar-h); flex-shrink: 0; display: flex; align-items: center; gap: 14px; padding: 0 16px;
  background: var(--surface); border-bottom: 1px solid var(--border); position: relative; z-index: 80;
}
.brand { display: flex; align-items: center; gap: 10px; width: calc(var(--sidebar-w) - 32px); font-family: var(--font-display); font-weight: 700; font-size: 20px; color: var(--text); }
.brand img { width: 34px; }
.search { flex: 1; max-width: 640px; position: relative; }
.search .ic { position: absolute; left: 13px; top: 50%; transform: translateY(-50%); color: var(--text-muted); width: 17px; height: 17px; }
.search input { width: 100%; background: var(--surface-2); border: 1.5px solid transparent; border-radius: 11px; padding: 10px 14px 10px 40px; outline: none; transition: all 0.15s; }
.search input:focus { background: var(--surface); border-color: var(--purple); }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 6px; }
.menu-wrap { position: relative; }

.popover {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 260px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow); padding: 8px; z-index: 60; animation: pop 0.14s ease-out;
}
@keyframes pop { from { opacity: 0; transform: translateY(-4px) scale(0.98); } to { opacity: 1; transform: none; } }
.popover-head { display: flex; gap: 12px; align-items: center; padding: 10px 10px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.popover-head div { display: flex; flex-direction: column; min-width: 0; }
.popover-head strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popover-head small { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.popover-item { display: flex; align-items: center; gap: 11px; width: 100%; padding: 10px 11px; border-radius: 9px; text-align: left; font-size: 14px; color: var(--text); }
.popover-item:hover { background: var(--surface-2); }
.popover-item .ic { color: var(--text-muted); }
.popover-item.danger { color: var(--danger); }
.popover-item.danger .ic { color: var(--danger); }

.alerts { flex-shrink: 0; display: flex; flex-direction: column; }
.alert-bar {
  display: flex; align-items: center; gap: 12px; padding: 10px 18px; background: var(--warn-bg); border-bottom: 1px solid var(--warn-border); color: var(--text); font-size: 14px; flex-wrap: wrap;
}
.alert-bar .ic { color: var(--warn); }
.alert-bar.danger { background: var(--danger-bg); border-color: var(--danger-border); }
.alert-bar.danger .ic { color: var(--danger); }
.alert-bar .alert-text { flex: 1; min-width: 220px; }
.alert-bar .alert-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.layout { flex: 1; display: flex; min-height: 0; position: relative; }
.sidebar { width: var(--sidebar-w); flex-shrink: 0; padding: 16px 12px; display: flex; flex-direction: column; gap: 14px; background: var(--bg); overflow-y: auto; }
.btn-compose { width: 100%; justify-content: flex-start; padding: 14px 18px; border-radius: 14px; font-size: 15px; }
.folders { display: flex; flex-direction: column; gap: 2px; }
.folder { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-radius: 10px; font-size: 14.5px; color: var(--text-muted); font-weight: 500; text-align: left; transition: background 0.15s, color 0.15s; }
.folder:hover { background: var(--surface-2); color: var(--text); }
.folder.active { background: var(--purple-faint); color: var(--purple); font-weight: 700; }
.folder span { flex: 1; }
.count { font-size: 12px; font-weight: 700; background: var(--purple); color: #fff; padding: 1px 8px; border-radius: 20px; min-width: 22px; text-align: center; }
.count.muted { background: var(--surface-3); color: var(--text-muted); }
.count:empty { display: none; }
.sidebar-foot { margin-top: auto; padding: 12px; border-radius: 12px; background: var(--surface); border: 1px solid var(--border); display: flex; flex-direction: column; gap: 4px; }
.e2e-badge { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 700; color: var(--success); }
.e2e-badge .ic { width: 15px; height: 15px; }
.sidebar-foot small { word-break: break-all; }

.list-pane { width: var(--list-w); flex-shrink: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: 16px 0 0 0; min-height: 0; margin-top: 4px; }
.list-head { display: flex; align-items: baseline; gap: 10px; padding: 16px 18px 10px; }
.list-head h2 { font-family: var(--font-display); font-size: 19px; }
.list-meta { color: var(--text-muted); font-size: 13px; }
.message-list { flex: 1; overflow-y: auto; padding-bottom: 20px; }
.list-empty { padding: 54px 24px; text-align: center; color: var(--text-muted); }
.list-empty .ic { width: 38px; height: 38px; opacity: 0.45; margin-bottom: 12px; }
.load-more { display: block; margin: 12px auto; }

.msg { position: relative; display: flex; gap: 12px; padding: 12px 16px 12px 14px; border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.12s; align-items: flex-start; }
.msg:hover { background: var(--surface-2); }
.msg.selected { background: var(--purple-faint); }
.msg.unread::before { content: ''; position: absolute; left: 4px; top: 50%; width: 6px; height: 6px; margin-top: -3px; border-radius: 50%; background: var(--purple); }
.msg-main { flex: 1; min-width: 0; }
.msg-row { display: flex; align-items: baseline; gap: 8px; }
.msg-from { flex: 1; min-width: 0; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg.unread .msg-from, .msg.unread .msg-subject { font-weight: 700; }
.msg-time { font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.msg-subject { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; }
.msg-snippet { font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 1px; min-height: 19px; }
.msg-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 20px; background: var(--purple-faint); color: var(--purple); }
.tag.danger { background: var(--danger-bg); color: var(--danger); }
.tag.warn { background: var(--warn-bg); color: var(--warn); }
.tag .ic { width: 11px; height: 11px; }
.msg-clip { color: var(--text-muted); width: 14px; height: 14px; }
.msg-star { width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center; color: var(--text-muted); opacity: 0.55; flex-shrink: 0; }
.msg-star:hover { opacity: 1; background: var(--surface-3); }
.msg-star.on { color: #E5A400; opacity: 1; }
.msg-star.on .ic { fill: #E5A400; }
.skeleton { display: inline-block; height: 12px; width: 70%; border-radius: 6px; background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.read-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-left: none; border-radius: 0 16px 0 0; margin: 4px 12px 0 0; min-height: 0; position: relative; }
.reader-empty { margin: auto; text-align: center; color: var(--text-muted); }
.reader-empty img { width: 64px; opacity: 0.25; margin-bottom: 14px; filter: grayscale(0.3); }
.reader { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.reader-toolbar { display: flex; align-items: center; gap: 6px; padding: 10px 14px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.reader-toolbar .sep { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }
.tool-btn { display: inline-flex; align-items: center; gap: 7px; padding: 7px 11px; border-radius: 9px; font-size: 13.5px; font-weight: 500; color: var(--text); background: transparent; }
.tool-btn:hover { background: var(--surface-3); }
.tool-btn .ic { width: 16px; height: 16px; color: var(--text-muted); }
.tool-btn.compact span { display: none; }
.tool-btn.report { color: var(--danger); background: var(--danger-bg); font-weight: 700; }
.tool-btn.report .ic { color: var(--danger); }
.tool-btn.report:hover { background: var(--danger); color: #fff; }
.tool-btn.report:hover .ic { color: #fff; }
.reader-scroll { flex: 1; overflow-y: auto; }
.banner { display: flex; gap: 14px; padding: 16px 20px; border-bottom: 1px solid var(--border); align-items: flex-start; }
.banner .ic { width: 24px; height: 24px; margin-top: 1px; }
.banner strong { display: block; font-size: 16px; margin-bottom: 3px; }
.banner p { font-size: 13.5px; line-height: 1.5; }
.banner ul { margin: 6px 0 0 18px; font-size: 13.5px; }
.banner.danger { background: var(--danger-bg); border-bottom-color: var(--danger-border); }
.banner.danger .ic, .banner.danger strong { color: var(--danger); }
.banner.warn { background: var(--warn-bg); border-bottom-color: var(--warn-border); }
.banner.warn .ic, .banner.warn strong { color: var(--warn); }
.banner.info { background: var(--surface-2); }
.banner.info .ic { color: var(--text-muted); }
.banner-body { flex: 1; min-width: 0; }
.banner-actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.reader-head { padding: 20px 22px 8px; }
.reader-subject { font-family: var(--font-display); font-size: 22px; line-height: 1.3; margin-bottom: 16px; word-break: break-word; }
.sender-row { display: flex; gap: 13px; align-items: center; }
.sender-info { flex: 1; min-width: 0; }
.sender-name { font-weight: 700; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sender-addr { font-size: 13px; color: var(--text-muted); word-break: break-all; }
.sender-addr.mismatch { color: var(--danger); font-weight: 700; }
.recipients-line { font-size: 13px; color: var(--text-muted); margin-top: 3px; word-break: break-all; }
.reader-date { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; align-self: flex-start; }
.badge-verified { display: inline-flex; align-items: center; gap: 4px; font-size: 11.5px; font-weight: 700; padding: 2px 8px; border-radius: 20px; background: var(--success-bg); color: var(--success); }
.badge-verified .ic { width: 12px; height: 12px; }
.frame-wrap { margin: 8px 22px 16px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.frame-wrap iframe { display: block; width: 100%; border: none; min-height: 120px; background: #fff; }
.attachments { margin: 0 22px 16px; display: flex; flex-wrap: wrap; gap: 10px; }
.attachment { display: flex; align-items: center; gap: 11px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); min-width: 220px; max-width: 100%; }
.attachment .file-ic { width: 36px; height: 36px; border-radius: 9px; background: var(--purple-faint); color: var(--purple); display: grid; place-items: center; flex-shrink: 0; }
.attachment.risky { border-color: var(--danger-border); background: var(--danger-bg); }
.attachment.risky .file-ic { background: var(--danger); color: #fff; }
.attachment-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.attachment-name { font-size: 13.5px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attachment-info small.risk { color: var(--danger); font-weight: 700; }
.reader-reply { padding: 4px 22px 28px; display: flex; gap: 10px; }

.composer {
  position: fixed; right: 24px; bottom: 0; width: 600px; max-width: calc(100vw - 24px); height: 640px; max-height: calc(100dvh - 24px);
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px 16px 0 0; box-shadow: var(--shadow); z-index: 70;
  display: flex; flex-direction: column; animation: rise 0.25s cubic-bezier(0.22,1,0.36,1) both;
}
.composer.minimized { height: auto; }
.composer.minimized .composer-body, .composer.minimized .composer-foot { display: none; }
.composer-head { display: flex; align-items: center; gap: 4px; padding: 10px 10px 10px 18px; background: var(--purple); color: #fff; border-radius: 15px 15px 0 0; font-weight: 700; cursor: pointer; }
.composer-head .icon-btn { color: rgba(255,255,255,0.85); }
.composer-head .icon-btn:hover { background: rgba(255,255,255,0.18); color: #fff; }
.draft-status { margin-left: auto; margin-right: 6px; font-size: 12px; font-weight: 500; opacity: 0.85; }
.composer-body { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow-y: auto; }
.field-row { display: flex; align-items: flex-start; gap: 10px; padding: 8px 16px; border-bottom: 1px solid var(--border); }
.field-row > label { width: 52px; padding-top: 8px; font-size: 13px; font-weight: 700; color: var(--text-muted); flex-shrink: 0; }
.field-row > input { flex: 1; border: none; outline: none; background: transparent; padding: 8px 0; min-width: 0; }
.chips { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; min-width: 0; padding: 3px 0; }
.chips input { flex: 1; min-width: 140px; border: none; outline: none; background: transparent; padding: 5px 0; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 4px 6px 4px 11px; border-radius: 20px; font-size: 13px; font-weight: 500; background: var(--purple-faint); color: var(--purple); border: 1.5px solid transparent; max-width: 100%; }
.chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chip button { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; opacity: 0.7; }
.chip button:hover { opacity: 1; background: rgba(0,0,0,0.12); }
.chip button .ic { width: 12px; height: 12px; }
.chip.pending { opacity: 0.7; }
.chip.warn { background: var(--warn-bg); color: var(--warn); border-color: var(--warn-border); }
.chip.danger { background: var(--danger-bg); color: var(--danger); border-color: var(--danger-border); font-weight: 700; }
.recipient-notices { display: flex; flex-direction: column; }
.notice { display: flex; gap: 10px; align-items: flex-start; padding: 8px 16px; font-size: 13px; line-height: 1.45; }
.notice .ic { width: 16px; height: 16px; margin-top: 2px; }
.notice.warn { background: var(--warn-bg); color: var(--warn); }
.notice.danger { background: var(--danger-bg); color: var(--danger); font-weight: 500; }
.editor-toolbar { display: flex; align-items: center; gap: 2px; padding: 6px 12px; border-bottom: 1px solid var(--border); }
.editor-toolbar button { width: 32px; height: 32px; border-radius: 8px; display: grid; place-items: center; color: var(--text-muted); }
.editor-toolbar button:hover { background: var(--surface-3); color: var(--text); }
.editor-toolbar .sep { width: 1px; height: 18px; background: var(--border); margin: 0 5px; }
.editor { flex: 1; min-height: 190px; padding: 14px 18px; outline: none; overflow-wrap: anywhere; line-height: 1.6; }
.editor:empty::before { content: 'Escribe tu mensaje…'; color: var(--text-muted); }
.editor blockquote { margin: 10px 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--text-muted); }
.editor a { text-decoration: underline; }
.editor ul, .editor ol { margin-left: 22px; }
.attach-list { display: flex; flex-wrap: wrap; gap: 8px; padding: 0 16px 12px; }
.attach-chip { display: inline-flex; align-items: center; gap: 8px; padding: 6px 8px 6px 11px; border: 1px solid var(--border); background: var(--surface-2); border-radius: 10px; font-size: 13px; max-width: 100%; }
.attach-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.attach-chip small { white-space: nowrap; }
.attach-chip button { width: 20px; height: 20px; border-radius: 50%; display: grid; place-items: center; color: var(--text-muted); }
.attach-chip button:hover { background: var(--surface-3); }
.composer-foot { display: flex; align-items: center; gap: 8px; padding: 10px 14px 12px; border-top: 1px solid var(--border); }
.attach-total { font-size: 12.5px; color: var(--text-muted); }
.composer.dragover .composer-body { outline: 2px dashed var(--purple); outline-offset: -8px; background: var(--purple-faint); }

#modal-host .backdrop { position: fixed; inset: 0; background: var(--scrim); z-index: 100; display: flex; align-items: center; justify-content: center; padding: 16px; animation: fade 0.15s ease-out; }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal { width: 100%; max-width: 460px; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow); padding: 24px; max-height: calc(100dvh - 32px); overflow-y: auto; animation: rise 0.2s ease-out both; border: 1px solid var(--border); }
.modal h3 { font-family: var(--font-display); font-size: 19px; margin-bottom: 8px; display: flex; gap: 10px; align-items: center; }
.modal p { color: var(--text-muted); font-size: 14px; line-height: 1.55; }
.modal .modal-body { margin-top: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.modal.danger h3 { color: var(--danger); }
.modal.warn h3 { color: var(--warn); }
.url-box { margin: 12px 0; padding: 12px 14px; border-radius: 10px; background: var(--surface-2); font-size: 14px; word-break: break-all; font-family: ui-monospace, 'JetBrains Mono', Menlo, monospace; line-height: 1.5; }
.url-box b { color: var(--purple); }
.url-box.danger b { color: var(--danger); }
.reason-list { margin: 10px 0 0 18px; font-size: 13.5px; color: var(--text); }
.reason-list li { margin-bottom: 4px; }
.modal .input { margin-top: 12px; }

.settings-sheet { max-width: 760px; padding: 0; display: flex; flex-direction: column; height: min(680px, calc(100dvh - 32px)); }
.settings-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 22px 12px; }
.settings-head h3 { margin: 0; font-size: 21px; }
.settings-tabs { display: flex; gap: 4px; padding: 0 16px; border-bottom: 1px solid var(--border); overflow-x: auto; flex-shrink: 0; }
.settings-tab { padding: 10px 14px; font-size: 14px; font-weight: 500; color: var(--text-muted); border-bottom: 2.5px solid transparent; white-space: nowrap; }
.settings-tab.active { color: var(--purple); border-bottom-color: var(--purple); font-weight: 700; }
.settings-body { flex: 1; overflow-y: auto; padding: 20px 22px 26px; }
.settings-section { margin-bottom: 26px; }
.settings-section h4 { font-size: 15px; margin-bottom: 4px; }
.settings-section > p { font-size: 13.5px; color: var(--text-muted); margin-bottom: 12px; line-height: 1.5; }
.profile-row { display: flex; gap: 18px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.profile-fields { flex: 1; min-width: 220px; }
.readonly-field { display: flex; align-items: center; gap: 8px; padding: 11px 13px; border-radius: 10px; background: var(--surface-2); font-size: 14px; word-break: break-all; }
.readonly-field span { flex: 1; }
.fingerprint { font-family: ui-monospace, 'JetBrains Mono', Menlo, monospace; font-size: 12.5px; letter-spacing: 0.04em; line-height: 1.7; word-break: break-word; }
.toggle-row { display: flex; align-items: center; gap: 14px; padding: 13px 0; border-bottom: 1px solid var(--border); }
.toggle-row:last-child { border-bottom: none; }
.toggle-row .toggle-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.toggle-row .toggle-text strong { font-size: 14.5px; }
.toggle-row .toggle-icon { width: 38px; height: 38px; border-radius: 10px; background: var(--purple-faint); color: var(--purple); display: grid; place-items: center; flex-shrink: 0; }
.toggle-row .toggle-icon img { width: 22px; height: 22px; object-fit: contain; }
.switch { position: relative; width: 44px; height: 26px; flex-shrink: 0; }
.switch input { opacity: 0; width: 100%; height: 100%; position: absolute; inset: 0; cursor: pointer; z-index: 1; margin: 0; }
.switch i { position: absolute; inset: 0; background: var(--surface-3); border-radius: 20px; transition: background 0.18s; }
.switch i::after { content: ''; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,0.3); transition: transform 0.18s; }
.switch input:checked + i { background: var(--purple); }
.switch input:checked + i::after { transform: translateX(18px); }
.switch input:disabled { cursor: not-allowed; }
.switch input:disabled + i { opacity: 0.55; }
.segmented { display: inline-flex; background: var(--surface-2); border-radius: 10px; padding: 3px; gap: 2px; }
.segmented button { padding: 7px 14px; border-radius: 8px; font-size: 13.5px; font-weight: 500; color: var(--text-muted); }
.segmented button.active { background: var(--surface); color: var(--purple); font-weight: 700; box-shadow: var(--shadow-sm); }
.device { display: flex; align-items: center; gap: 14px; padding: 14px; border: 1px solid var(--border); border-radius: 14px; margin-bottom: 10px; background: var(--surface); }
.device.current { border-color: var(--purple); background: var(--purple-faint); }
.device-ic { width: 42px; height: 42px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; color: var(--text-muted); flex-shrink: 0; }
.device.current .device-ic { background: var(--purple); color: #fff; }
.device-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.device-info strong { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: 14.5px; }
.device-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 14px; }
.trusted-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 6px 5px 11px; background: var(--surface-2); border-radius: 20px; font-size: 13px; margin: 0 6px 6px 0; }
.trusted-chip button { width: 18px; height: 18px; border-radius: 50%; display: grid; place-items: center; color: var(--text-muted); }
.trusted-chip button:hover { background: var(--surface-3); }
.pw-grid { display: grid; gap: 10px; max-width: 360px; }

.link-status {
  position: fixed; left: 0; bottom: 0; max-width: min(720px, 100vw); padding: 7px 14px; background: var(--surface); border: 1px solid var(--border); border-left: none; border-bottom: none;
  border-radius: 0 10px 0 0; font-size: 13px; z-index: 90; box-shadow: var(--shadow); word-break: break-all; display: flex; gap: 8px; align-items: center;
  font-family: ui-monospace, 'JetBrains Mono', Menlo, monospace;
}
.link-status b { color: var(--purple); }
.link-status.danger { background: var(--danger-bg); border-color: var(--danger-border); color: var(--danger); }
.link-status.danger b { color: var(--danger); }
.link-status .ic { width: 14px; height: 14px; }

.snackbar {
  position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 110; display: flex; align-items: center; gap: 14px; padding: 12px 14px 12px 18px;
  background: #1E1B2B; color: #fff; border-radius: 14px; box-shadow: var(--shadow); font-size: 14px; min-width: 300px; max-width: calc(100vw - 24px); overflow: hidden; animation: rise 0.2s ease-out both;
}
html[data-theme="dark"] .snackbar { background: #34304A; }
.snackbar span { flex: 1; }
.snackbar button { font-weight: 700; color: #C4B5FD; padding: 6px 10px; border-radius: 8px; }
.snackbar button:hover { background: rgba(255,255,255,0.1); }
.snackbar .bar { position: absolute; left: 0; bottom: 0; height: 3px; background: #8B72FF; width: 100%; transform-origin: left; }

.toast {
  position: fixed; left: 50%; bottom: 26px; transform: translate(-50%, 20px); background: var(--text); color: var(--surface); padding: 11px 18px; border-radius: 12px;
  font-size: 14px; font-weight: 500; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s; z-index: 120; max-width: calc(100vw - 24px); text-align: center; box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.scrim { position: fixed; inset: 0; background: var(--scrim); z-index: 40; }

@media (max-width: 1100px) {
  :root { --list-w: 340px; }
}

@media (max-width: 900px) {
  .only-mobile { display: inline-grid; }
  .brand { width: auto; }
  .topbar { gap: 8px; padding: 0 10px; z-index: 30; }
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; width: min(290px, 86vw); z-index: 50; transform: translateX(-102%); transition: transform 0.25s cubic-bezier(0.22,1,0.36,1); background: var(--surface); padding-top: 20px; box-shadow: var(--shadow); }
  .sidebar.open { transform: none; }
  .list-pane { width: 100%; border-radius: 0; border-left: none; border-right: none; margin-top: 0; }
  .read-pane { position: fixed; inset: 0; z-index: 45; margin: 0; border-radius: 0; border: none; transform: translateX(100%); transition: transform 0.25s cubic-bezier(0.22,1,0.36,1); }
  .read-pane.open { transform: none; }
  .reader-empty { display: none; }
  .search input { padding-top: 9px; padding-bottom: 9px; }
  .topbar-actions .menu-wrap { margin-left: 2px; }
  .composer { right: 0; left: 0; bottom: 0; top: 0; width: 100%; max-width: 100%; height: 100%; max-height: 100%; border-radius: 0; }
  .composer-head { border-radius: 0; padding-top: calc(10px + env(safe-area-inset-top, 0px)); }
  .composer.minimized { top: auto; height: auto; }
  .tool-btn span { display: none; }
  .tool-btn.report span { display: inline; }
  .reader-toolbar .back { display: inline-grid; }
  .snackbar { bottom: calc(16px + env(safe-area-inset-bottom, 0px)); }
}

@media (min-width: 901px) {
  .reader-toolbar .back { display: none; }
}

@media (max-width: 520px) {
  .auth-card { padding: 26px 20px 22px; }
  .tool-btn.report span { display: none; }
  .tool-btn.report { padding: 8px 10px; }
  .reader-head { padding: 16px 16px 6px; }
  .sender-row { flex-wrap: wrap; }
  .reader-date { order: 3; width: 100%; padding-left: 65px; margin-top: -4px; }
  .reader-toolbar { gap: 2px; padding: 8px 8px; }
  .frame-wrap, .attachments { margin-left: 14px; margin-right: 14px; }
  .reader-reply { padding-left: 16px; padding-right: 16px; }
  .banner { padding: 14px 16px; }
  .settings-body { padding: 16px; }
  .device { flex-wrap: wrap; }
  .snackbar { min-width: 0; width: calc(100vw - 24px); }
}

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