@import url('https://fonts.googleapis.com/css2?family=DM+Serif+Display&family=DM+Sans:ital,wght@0,300;0,400;0,500;0,600;1,400&display=swap');

:root {
  --bg:        #0c0c10;
  --surface:   #13131a;
  --surface2:  #1a1a24;
  --border:    #252530;
  --border2:   #2e2e3e;
  --text:      #e4e4f0;
  --muted:     #6a6a90;
  --muted2:    #9090b8;
  --danger:    #ff5e7d;
  --success:   #00d4aa;
  --radius:    12px;
  --sidebar-w: 240px;
  --accent:    #6c63ff;
  --accent-bg: rgba(108,99,255,0.13);
}

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

html, body { height: 100%; overflow: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: 'DM Sans', sans-serif;
  font-size: 14px;
  line-height: 1.5;
}

a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; }

/* ── SCROLLBAR ───────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 4px; }

/* ── PIN SCREEN ──────────────────────────── */
.pin-screen {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 40%, #1a1830 0%, var(--bg) 70%);
}

.pin-box {
  text-align: center;
  width: 340px;
}

.pin-logo {
  font-size: 52px;
  margin-bottom: 14px;
  filter: drop-shadow(0 0 24px rgba(108,99,255,0.5));
}

.pin-box h1 {
  font-family: 'DM Serif Display', serif;
  font-size: 30px;
  background: linear-gradient(135deg, #6c63ff, #00d4aa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  margin-bottom: 6px;
}

.pin-box p { color: var(--muted); font-size: 13px; margin-bottom: 30px; }

.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin-bottom: 28px;
}

.pin-dot {
  width: 15px; height: 15px;
  border-radius: 50%;
  border: 2px solid var(--border2);
  transition: all .2s;
}

.pin-dot.on {
  background: var(--accent);
  border-color: var(--accent);
  box-shadow: 0 0 10px rgba(108,99,255,.6);
}

.pin-error {
  color: var(--danger);
  font-size: 12px;
  margin-bottom: 14px;
  animation: shake .3s ease;
}

.numpad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  max-width: 260px;
  margin: 0 auto;
}

.num-btn {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: 20px;
  font-weight: 500;
  padding: 16px;
  border-radius: var(--radius);
  transition: all .14s;
  user-select: none;
}

.num-btn:hover  { background: var(--surface2); border-color: var(--accent); }
.num-btn:active { transform: scale(.93); background: var(--accent); border-color: var(--accent); }
.num-btn.del    { font-size: 16px; color: var(--muted); }
.num-btn.zero   { grid-column: 2; }

/* ── APP LAYOUT ──────────────────────────── */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── SIDEBAR ─────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-head {
  padding: 18px 16px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-logo { font-size: 22px; }

.sidebar-title {
  font-family: 'DM Serif Display', serif;
  font-size: 18px;
  background: linear-gradient(135deg, #6c63ff, #00d4aa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 10px 8px; }

.compose-btn {
  margin: 0 8px 12px;
  background: linear-gradient(135deg, #6c63ff, #00d4aa);
  border: none;
  color: #fff;
  font-weight: 600;
  font-size: 13px;
  padding: 10px 16px;
  border-radius: var(--radius);
  width: calc(100% - 16px);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: opacity .2s, transform .15s;
}

.compose-btn:hover { opacity: .9; transform: translateY(-1px); }

.sidebar-section {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--muted);
  padding: 10px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border-radius: 9px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted2);
  cursor: pointer;
  transition: all .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  position: relative;
}

.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: var(--accent-bg); color: var(--text); }
.nav-item.active .nav-icon { color: var(--accent); }

.nav-icon { font-size: 15px; width: 20px; text-align: center; }

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

/* Account nav items */
.acc-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 9px;
  font-size: 13px;
  cursor: pointer;
  transition: all .15s;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
  color: var(--muted2);
}

.acc-item:hover  { background: var(--surface2); }
.acc-item.active { color: var(--text); }

.acc-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.acc-label { flex: 1; font-size: 12px; }

.acc-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  color: #fff;
}

/* ── MAIN AREA ───────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

/* ── TOPBAR ──────────────────────────────── */
.topbar {
  height: 54px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  background: var(--surface);
  flex-shrink: 0;
}

.topbar-title {
  font-weight: 600;
  font-size: 15px;
  flex: 1;
}

.search-wrap {
  display: flex;
  align-items: center;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 9px;
  padding: 6px 12px;
  gap: 7px;
  width: 260px;
  transition: border-color .2s;
}

.search-wrap:focus-within { border-color: var(--accent); }

.search-wrap input {
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  width: 100%;
}

.search-wrap input::placeholder { color: var(--muted); }

.topbar-btn {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 6px 12px;
  border-radius: 9px;
  font-size: 12px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .15s;
}

.topbar-btn:hover { border-color: var(--accent); color: var(--text); }

/* ── TOOLBAR ─────────────────────────────── */
.toolbar {
  height: 42px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 14px;
  gap: 6px;
  background: var(--surface);
  flex-shrink: 0;
}

.tb-btn {
  background: none;
  border: 1px solid transparent;
  color: var(--muted2);
  padding: 5px 10px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 5px;
  transition: all .14s;
}

.tb-btn:hover { background: var(--surface2); border-color: var(--border); color: var(--text); }
.tb-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 2px; }

.tb-check {
  width: 16px; height: 16px;
  border: 2px solid var(--border2);
  border-radius: 4px;
  cursor: pointer;
  accent-color: var(--accent);
}

/* ── MAIL LIST ───────────────────────────── */
.mail-list-wrap {
  flex: 1;
  overflow-y: auto;
}

.mail-list { list-style: none; }

.mail-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background .12s;
  position: relative;
}

.mail-row:hover  { background: var(--surface); }
.mail-row.active { background: var(--surface2); }
.mail-row.unread { background: var(--surface); }

.mail-row.unread .mail-from,
.mail-row.unread .mail-subj { font-weight: 600; color: var(--text); }

.mail-row.unread::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}

.row-check {
  width: 16px; height: 16px;
  border: 2px solid var(--border2);
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  accent-color: var(--accent);
}

.acc-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 8px;
  white-space: nowrap;
  flex-shrink: 0;
}

.mail-from {
  width: 170px;
  min-width: 170px;
  font-size: 13px;
  font-weight: 500;
  color: var(--muted2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-middle { flex: 1; overflow: hidden; }

.mail-subj {
  font-size: 13px;
  color: var(--muted2);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mail-preview {
  font-size: 12px;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-top: 2px;
}

.mail-date {
  font-size: 11px;
  color: var(--muted);
  white-space: nowrap;
  flex-shrink: 0;
}

.mail-attach { color: var(--muted); font-size: 13px; }

/* Empty state */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  color: var(--muted);
  gap: 10px;
}

.empty-state .icon { font-size: 48px; opacity: .4; }
.empty-state p { font-size: 14px; }

/* Loading */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 200px;
  gap: 10px;
  color: var(--muted);
}

.spinner {
  width: 22px; height: 22px;
  border: 3px solid var(--border2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ── MAIL VIEW PANEL ─────────────────────── */
.view-panel {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: none;
}

.view-panel.open { display: block; }

.view-back {
  background: none;
  border: none;
  color: var(--muted2);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 20px;
  padding: 6px 10px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: all .15s;
}

.view-back:hover { color: var(--text); border-color: var(--accent); }

.view-subject {
  font-family: 'DM Serif Display', serif;
  font-size: 26px;
  line-height: 1.3;
  margin-bottom: 18px;
}

.view-meta-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  margin-bottom: 24px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.meta-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 13px;
}

.meta-lbl { color: var(--muted); min-width: 44px; }
.meta-val { color: var(--text); word-break: break-word; }
.meta-val.from { font-weight: 600; }

.view-body-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  font-size: 14px;
  line-height: 1.8;
  color: #d0d0e8;
  overflow-x: auto;
  margin-bottom: 24px;
}

.view-body-card img { max-width: 100%; border-radius: 8px; }
.view-body-card a   { color: var(--success); }
.view-body-card table { width: 100% !important; }

.view-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 40px;
}

/* ── COMPOSE ─────────────────────────────── */
.compose-panel {
  flex: 1;
  overflow-y: auto;
  padding: 28px 32px;
  display: none;
}

.compose-panel.open { display: block; }

.compose-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  max-width: 760px;
}

.compose-head {
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.compose-head h2 {
  font-family: 'DM Serif Display', serif;
  font-size: 20px;
}

.compose-body { padding: 20px 24px; }

.form-row {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  padding: 10px 0;
  gap: 10px;
}

.form-row:last-of-type { border-bottom: none; margin-bottom: 12px; }

.form-lbl {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .5px;
  min-width: 60px;
}

.form-row input,
.form-row select {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
}

.form-row select option { background: var(--surface2); }

.compose-textarea {
  width: 100%;
  min-height: 280px;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.7;
  resize: vertical;
  padding: 4px 0;
}

.compose-foot {
  padding: 14px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  gap: 10px;
}

/* ── BUTTONS ─────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 20px;
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  transition: all .18s;
}

.btn-primary {
  background: linear-gradient(135deg, #6c63ff, #8b84ff);
  color: #fff;
  box-shadow: 0 4px 16px rgba(108,99,255,.3);
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 22px rgba(108,99,255,.45); }

.btn-success {
  background: linear-gradient(135deg, #00d4aa, #00b894);
  color: #fff;
  box-shadow: 0 4px 16px rgba(0,212,170,.25);
}

.btn-success:hover { transform: translateY(-1px); }

.btn-ghost {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted2);
}

.btn-ghost:hover { border-color: var(--text); color: var(--text); }

.btn-danger {
  background: none;
  border: 1px solid var(--border);
  color: var(--danger);
}

.btn-danger:hover { background: rgba(255,94,125,.1); border-color: var(--danger); }

/* ── TOAST ───────────────────────────────── */
.toast-wrap {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface2);
  border: 1px solid var(--border2);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius);
  font-size: 13px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideIn .25s ease;
  max-width: 320px;
}

.toast.ok     { border-left: 3px solid var(--success); }
.toast.err    { border-left: 3px solid var(--danger); }
.toast.info   { border-left: 3px solid var(--accent); }

/* ── MODAL ───────────────────────────────── */
.overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  backdrop-filter: blur(5px);
  z-index: 500;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  width: 100%;
  max-width: 560px;
  box-shadow: 0 28px 70px rgba(0,0,0,.6);
  animation: fadeUp .25s ease;
}

.modal-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-head h3 { font-family: 'DM Serif Display', serif; font-size: 19px; }

.modal-close {
  background: none; border: none;
  color: var(--muted); font-size: 22px;
  line-height: 1; transition: color .15s;
}

.modal-close:hover { color: var(--text); }

.modal-body { padding: 20px 22px; }

.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin-bottom: 7px; }
.modal-field input,
.modal-field textarea,
.modal-field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 10px 14px;
  outline: none;
  transition: border-color .18s;
}

.modal-field input:focus,
.modal-field textarea:focus,
.modal-field select:focus { border-color: var(--accent); }
.modal-field textarea { min-height: 130px; resize: vertical; }
.modal-field select option { background: var(--surface2); }

.modal-foot {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── MOVE FOLDER MENU ────────────────────── */
.folder-menu {
  position: absolute;
  background: var(--surface2);
  border: 1px solid var(--border2);
  border-radius: 10px;
  padding: 6px;
  z-index: 200;
  box-shadow: 0 8px 28px rgba(0,0,0,.4);
  min-width: 160px;
  display: none;
}

.folder-menu.open { display: block; }

.folder-menu-item {
  padding: 8px 12px;
  border-radius: 7px;
  font-size: 13px;
  cursor: pointer;
  color: var(--muted2);
  transition: all .12s;
}

.folder-menu-item:hover { background: var(--border); color: var(--text); }

/* ── PAGINATION ──────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 14px;
  border-top: 1px solid var(--border);
}

.pg-btn {
  background: var(--surface2);
  border: 1px solid var(--border);
  color: var(--muted2);
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  transition: all .14s;
}

.pg-btn:hover   { border-color: var(--accent); color: var(--text); }
.pg-btn.current { background: var(--accent-bg); border-color: var(--accent); color: var(--text); }

/* ── ANIMATIONS ──────────────────────────── */
@keyframes spin    { to { transform: rotate(360deg); } }
@keyframes shake   { 0%,100% { transform:translateX(0); } 25% { transform:translateX(-8px); } 75% { transform:translateX(8px); } }
@keyframes fadeUp  { from { opacity:0; transform:translateY(16px); } to { opacity:1; transform:translateY(0); } }
@keyframes slideIn { from { opacity:0; transform:translateX(20px); } to { opacity:1; transform:translateX(0); } }

/* ── RESPONSIVE ──────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar-w: 200px; }
  .mail-from { width: 120px; min-width: 120px; }
  .search-wrap { width: 160px; }
  .view-panel, .compose-panel { padding: 16px; }
  .view-body-card { padding: 18px; }
}

@media (max-width: 560px) {
  .sidebar { display: none; }
  .mail-from { display: none; }
}