:root {
  --page: #121114;
  --bg: #161518;
  --surface: #1a191d;
  --surface-2: #222126;
  --surface-3: #2a292f;
  --line: rgba(255,255,255,0.07);
  --text: #ececef;
  --muted: #8b8b96;
  --accent: #4a7fd4;
  --accent-2: #5a8ee0;
  --danger: #c45a5a;
  --shadow: 0 16px 48px rgba(0,0,0,0.5);
  --sidebar: 260px;
  --list: 380px;
  --radius: 8px;
  --radius-sm: 6px;
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--page); color: var(--text); -webkit-font-smoothing: antialiased; }
body { overflow: hidden; }
.hidden { display: none !important; }
.screen { min-height: 100vh; min-height: 100dvh; }
.mobile-only { display: none; }

#app { position: relative; height: 100%; }

#login-screen {
  display: grid;
  place-items: center;
  padding: 32px;
  min-height: 100vh;
  min-height: 100dvh;
  background: var(--page);
}
.login-shell { width: min(400px, 100%); }
.login-card {
  padding: 28px;
  border-radius: var(--radius);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}
.brand { margin-bottom: 22px; }
.brand h2 { margin: 0; font-size: 24px; letter-spacing: -.02em; }
.brand p { margin: 8px 0 0; color: var(--muted); font-size: 14px; }
#login-form label { display: block; margin-bottom: 14px; }
#login-form label span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
#login-form input, #password-form input {
  width: 100%; height: 44px; padding: 0 12px; border-radius: var(--radius-sm); border: 1px solid var(--line); background: var(--bg); color: var(--text); outline: none;
}
#login-form input:focus, #password-form input:focus, #search-input:focus { border-color: rgba(74,127,212,0.6); box-shadow: 0 0 0 2px rgba(74,127,212,0.12); }
.btn-primary {
  display: inline-flex; align-items: center; justify-content: center; width: 100%; height: 44px; border: 0; border-radius: var(--radius-sm); background: var(--accent); color: #fff; font-weight: 600; cursor: pointer;
}
.btn-primary:hover { background: var(--accent-2); }
.btn-primary.slim { width: auto; min-width: 100px; }
.btn-ghost, .mini-action, .icon-btn {
  border: 0; background: transparent; color: var(--muted); cursor: pointer;
}
.btn-ghost { padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; }
.btn-ghost:hover, .mini-action:hover, .icon-btn:hover { background: rgba(255,255,255,0.05); color: var(--text); }
.login-footer { display: flex; justify-content: flex-end; margin-top: 12px; }
.error { color: #e08080; font-size: 13px; margin: 8px 0 0; }

#mail-screen {
  display: grid;
  grid-template-columns: var(--sidebar) minmax(0, 1fr);
  gap: 16px;
  padding: 20px;
  height: 100vh;
  height: 100dvh;
  background: var(--page);
}
.sidebar, .workspace-card {
  border: 1px solid var(--line);
  background: var(--surface);
  box-shadow: var(--shadow);
  min-height: 0;
}
.sidebar { border-radius: var(--radius); padding: 14px 12px; display: flex; flex-direction: column; }
.sidebar-head-row { display: flex; align-items: center; gap: 6px; padding: 2px 4px 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.mailbox-email {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--text); text-align: left; font-size: 13px; font-weight: 600; padding: 8px; border-radius: var(--radius-sm); cursor: pointer; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mailbox-email:hover { background: rgba(255,255,255,0.05); }
.folder-nav { flex: 1; }
.folder { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--muted); text-align: left; cursor: pointer; font-size: 14px; }
.folder.active { background: var(--surface-2); color: #fff; }
.folder-icon { flex-shrink: 0; opacity: .85; }
.badge { margin-left: auto; min-width: 20px; padding: 2px 7px; border-radius: var(--radius-sm); background: var(--accent); color: #fff; font-size: 11px; text-align: center; font-weight: 600; }
.sidebar-footer { margin-top: auto; padding-top: 12px; }
.mini-action { width: 100%; text-align: left; padding: 8px 10px; border-radius: var(--radius-sm); font-size: 13px; }

.workspace-card { border-radius: var(--radius); display: grid; grid-template-rows: 56px minmax(0, 1fr); min-width: 0; overflow: hidden; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); flex-shrink: 0; }
.search-wrap { flex: 1; display: flex; align-items: center; gap: 10px; height: 38px; padding: 0 12px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius-sm); min-width: 0; }
.search-icon { color: var(--muted); flex-shrink: 0; }
#search-input { width: 100%; border: 0; outline: none; background: transparent; color: var(--text); font-size: 14px; min-width: 0; }
.topbar-actions { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.icon-btn { width: 36px; height: 36px; border-radius: var(--radius-sm); display: grid; place-items: center; flex-shrink: 0; }
.icon-btn.spinning svg { animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.account-wrap { position: relative; }
.account-btn { display: flex; align-items: center; gap: 4px; padding: 6px 8px; border: 0; border-radius: var(--radius-sm); background: transparent; color: var(--text); cursor: pointer; }
.account-btn:hover { background: rgba(255,255,255,0.05); }
.chev { color: var(--muted); }
.account-menu { position: absolute; top: calc(100% + 6px); right: 0; min-width: 220px; max-width: min(320px, calc(100vw - 16px)); padding: 6px; border-radius: var(--radius); background: var(--surface-2); border: 1px solid var(--line); box-shadow: var(--shadow); z-index: 40; }
.account-menu-email {
  width: 100%; border: 0; background: transparent; text-align: left;
  padding: 10px 12px; font-size: 12px; color: var(--text); font-weight: 600;
  border-bottom: 1px solid var(--line); margin-bottom: 4px; word-break: break-all;
  cursor: pointer; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  display: flex; align-items: center; gap: 8px;
}
.account-menu-email:hover { background: rgba(255,255,255,0.05); }
.account-menu-email svg { flex-shrink: 0; color: var(--muted); }
.account-list { max-height: 160px; overflow: auto; margin-bottom: 4px; }
.account-item {
  width: 100%;
  border: 0;
  background: transparent;
  color: var(--muted);
  text-align: left;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 12px;
}
.account-item:hover { background: rgba(255,255,255,0.06); color: var(--text); }
.account-item.active { color: var(--text); background: rgba(255,255,255,0.05); }
.account-menu button { width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; padding: 10px 12px; border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; }
.account-menu button:hover { background: rgba(255,255,255,0.06); }

.content-shell { display: grid; grid-template-columns: var(--list) minmax(0, 1fr); min-height: 0; }
.list-panel { border-right: 1px solid var(--line); min-height: 0; overflow: auto; }
.message-list { padding: 6px 0; }
.msg-row { padding: 12px 16px; border-radius: 0; cursor: pointer; transition: background .12s ease; border-bottom: 1px solid var(--line); }
.msg-row:hover { background: rgba(255,255,255,0.03); }
.msg-row.active { background: var(--surface-2); }
.msg-top { display: flex; align-items: baseline; gap: 10px; margin-bottom: 4px; }
.msg-from { flex: 1; min-width: 0; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-date { font-size: 12px; color: var(--muted); white-space: nowrap; flex-shrink: 0; }
.msg-subject { font-size: 13px; font-weight: 500; color: #dddde2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px; }
.msg-snippet { font-size: 12px; color: var(--muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.empty, .loading, .read-empty { padding: 40px 20px; color: var(--muted); text-align: center; font-size: 14px; }

.read-panel { min-height: 0; overflow: hidden; display: flex; flex-direction: column; background: var(--bg); }
.read-empty { flex: 1; display: grid; place-items: center; }
.read-view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.read-header { flex-shrink: 0; padding: 20px 24px 16px; border-bottom: 1px solid var(--line); background: var(--surface); }
.read-from-line { display: flex; align-items: baseline; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
#read-from { font-size: 14px; font-weight: 600; color: var(--text); }
#read-date { font-size: 12px; color: var(--muted); }
#read-subject { margin: 0; font-size: clamp(18px, 2.2vw, 26px); line-height: 1.25; letter-spacing: -.02em; font-weight: 600; }
.read-body { flex: 1; min-height: 0; overflow: auto; -webkit-overflow-scrolling: touch; }
.read-body iframe { display: block; width: 100%; border: 0; background: #fff; min-height: 100%; }
.read-body .mail-text { margin: 0; padding: 20px 24px; font-family: inherit; font-size: 15px; line-height: 1.65; white-space: pre-wrap; word-break: break-word; color: #d4d4da; }

#password-dialog { width: min(400px, 92vw); border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--text); padding: 22px; }
#password-dialog::backdrop { background: rgba(0,0,0,0.65); }
#password-form h3 { margin: 0 0 16px; font-size: 20px; letter-spacing: -.02em; }
#password-form label { display: block; margin-bottom: 14px; }
#password-form label span { display: block; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(12px);
  padding: 10px 18px; border-radius: var(--radius-sm); background: var(--surface-2); border: 1px solid var(--line);
  color: var(--text); font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 100;
}
.toast.visible { opacity: 1; transform: translateX(-50%) translateY(0); }

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

@media (max-width: 920px) {
  body { overflow: hidden; }
  .mobile-only { display: grid; }
  .read-back { display: grid; }
  #mail-screen {
    grid-template-columns: 1fr;
    padding: 0;
    gap: 0;
  }
  .sidebar { display: none; }
  .workspace-card {
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    box-shadow: none;
  }
  .content-shell {
    grid-template-columns: 1fr;
    position: relative;
  }
  .list-panel {
    display: block;
    border-right: 0;
  }
  .read-panel {
    display: none;
    position: absolute;
    inset: 0;
    z-index: 5;
    background: var(--bg);
  }
  #mail-screen.show-read .list-panel { display: none; }
  #mail-screen.show-read .read-panel { display: flex; }
  #mail-screen.show-read .read-back { display: grid; }
  #mail-screen.show-read .search-wrap { display: none; }
  .read-header { padding: 16px 16px 14px; }
  .read-body .mail-text { padding: 16px; }
}

@media (min-width: 921px) {
  .read-back { display: none !important; }
}
