:root {
  --bg: #f4f7fb;
  --panel: #ffffff;
  --panel-2: #f8fbff;
  --text: #122033;
  --muted: #64748b;
  --border: #dbe5f1;
  --primary: #2563eb;
  --primary-soft: #eef5ff;
  --primary-border: #bfdbfe;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --danger-border: #fecaca;
  --shadow: 0 14px 34px rgba(15, 23, 42, 0.10);
}
* { box-sizing: border-box; }
html, body { min-height: 100%; }
body {
  margin: 0;
  background:
    radial-gradient(circle at top left, rgba(59, 130, 246, 0.10), transparent 34%),
    linear-gradient(180deg, #f8fbff 0%, var(--bg) 100%);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}
a { color: inherit; text-decoration: none; }
.mobile-only { display: none !important; }
.desktop-only-inline { display: block; }
.desktop-only { display: inline-flex; }
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap: 12px;
  padding:14px 18px;
  border-bottom:1px solid var(--border);
  background:rgba(255,255,255,.92);
  box-shadow: 0 8px 22px rgba(15,23,42,.06);
  backdrop-filter: blur(10px);
}
.topbar-left { display:flex; align-items:center; gap:12px; min-width: 0; }
.topbar-actions { display:flex; gap:10px; align-items:center; flex-wrap: wrap; justify-content: flex-end; }
.mailbox-pill {
  display:inline-flex;
  align-items:center;
  padding:8px 12px;
  border-radius:999px;
  border:1px solid var(--primary-border);
  color: #1d4ed8;
  background: var(--primary-soft);
  font-size:12px;
}
.layout {
  display:grid;
  grid-template-columns: 240px minmax(280px, 390px) minmax(320px, 1fr);
  min-height: calc(100vh - 66px);
}
.folders-panel, .messages-panel, .detail-panel {
  min-width: 0;
  border-right:1px solid var(--border);
  padding:16px 14px;
  background: rgba(255,255,255,.42);
}
.messages-panel { background: rgba(248,251,255,.72); }
.detail-panel { border-right:none; background: rgba(255,255,255,.72); }
.panel-head {
  display:flex;
  justify-content:space-between;
  align-items:center;
  gap:12px;
  margin-bottom:14px;
}
.sticky-head {
  position: sticky;
  top: 79px;
  z-index: 10;
  padding-bottom: 12px;
  background: linear-gradient(180deg, rgba(248,251,255,0.98), rgba(248,251,255,0.88));
  backdrop-filter: blur(8px);
}
.folder-list, .messages-list { display:flex; flex-direction:column; gap:10px; }
.folder-item, .message-item {
  border:1px solid var(--border);
  background: rgba(255,255,255,.92);
  color:var(--text);
  border-radius:16px;
  padding:14px 12px;
  text-align:left;
  cursor:pointer;
  box-shadow: 0 6px 16px rgba(15,23,42,.04);
  transition: border-color .18s ease, box-shadow .18s ease, background .18s ease, transform .18s ease;
}
.folder-item:hover, .message-item:hover {
  border-color: var(--primary-border);
  background: #ffffff;
  box-shadow: 0 10px 24px rgba(37,99,235,.08);
  transform: translateY(-1px);
}
.folder-item.active, .message-item.active {
  outline:2px solid #93c5fd;
  border-color: #93c5fd;
  background: var(--primary-soft);
}
.message-item.unseen .message-subject { font-weight:700; }
.message-item.unseen { border-left: 4px solid var(--primary); }
.message-item { width:100%; }
.message-line { display:flex; align-items:flex-start; justify-content:space-between; gap:12px; }
.message-subject { font-size: 15px; font-weight: 600; margin-bottom: 6px; line-height: 1.35; }
.message-from, .message-date, .muted, .small { color: var(--muted); font-size: 13px; }
.message-date { flex-shrink: 0; text-align: right; }
.empty, .detail-empty { color: var(--muted); padding: 10px; }
.mail-view h2 { margin: 0 0 8px; line-height: 1.3; }
.meta-row { margin-bottom: 8px; color: var(--muted); word-break: break-word; }
.meta-row strong { color: var(--text); }
.attachments-meta-row { display:grid; gap:8px; }
.received-attachments { display:grid; gap:8px; margin-top:2px; }
.received-attachment {
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:10px 12px;
  border:1px solid var(--border);
  border-radius:13px;
  background:#f8fbff;
}
.received-attachment-info { display:flex; align-items:center; gap:10px; min-width:0; }
.received-attachment-icon {
  width:38px;
  height:38px;
  display:grid;
  place-items:center;
  flex:0 0 auto;
  border:1px solid var(--primary-border);
  border-radius:11px;
  background:var(--primary-soft);
  font-size:19px;
}
.received-attachment-text { display:grid; gap:3px; min-width:0; }
.received-attachment-text strong { color:var(--text); overflow-wrap:anywhere; }
.received-attachment-text small { color:var(--muted); overflow-wrap:anywhere; }
.received-attachment-actions { display:flex; align-items:center; gap:8px; flex-wrap:wrap; flex:0 0 auto; }
.attachment-action-btn { min-height:34px; padding:7px 10px; font-size:12px; }
.mail-body {
  margin-top: 14px;
  padding: 16px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: #ffffff;
  min-height: 280px;
  overflow: auto;
  word-break: break-word;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.65), 0 8px 22px rgba(15,23,42,.04);
}
.mail-body img { max-width: 100%; height: auto; }
.mail-body pre { white-space: pre-wrap; word-break: break-word; }
.btn {
  border:1px solid var(--border);
  border-radius: 12px;
  background:#eef3fa;
  color:#1e293b;
  padding:10px 16px;
  cursor:pointer;
  min-height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: background .18s ease, border-color .18s ease, box-shadow .18s ease, transform .18s ease;
}
.btn:hover { background:#e6edf7; border-color:#cbd5e1; box-shadow:0 8px 18px rgba(15,23,42,.08); transform: translateY(-1px); }
.btn.primary { background: var(--primary); border-color: var(--primary); color:#fff; }
.btn.primary:hover { background:#1d4ed8; border-color:#1d4ed8; }
.btn.ghost { background: rgba(255,255,255,.78); border:1px solid var(--border); color:#334155; }
.btn.danger { background: var(--danger-soft); border-color: var(--danger-border); color:#991b1b; }
.btn.danger:hover { background:#fee2e2; }
.btn.icon-only { width:42px; padding:0; display:inline-flex; align-items:center; justify-content:center; }
.login-body { display:grid; place-items:center; min-height:100vh; padding: 20px; }
.login-card { width: min(420px, 100%); background: rgba(255,255,255,.94); border:1px solid var(--border); border-radius:20px; padding:26px; box-shadow: var(--shadow); }
.login-card h1 { margin-top:0; }
.login-form { display:flex; flex-direction:column; gap:10px; }
.login-form input, .login-form button, .modal-body input, .modal-body textarea, .modal-body select {
  width:100%;
  background:#ffffff;
  color:var(--text);
  border:1px solid var(--border);
  border-radius:12px;
  padding:12px;
  outline: none;
}
.login-form input:focus, .modal-body input:focus, .modal-body textarea:focus, .modal-body select:focus, .compose-editor:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(147,197,253,.35);
}
.login-form button {
  margin-top: 4px;
  background: var(--primary);
  color: #ffffff;
  border-color: var(--primary);
  cursor: pointer;
  font-weight: 700;
}
.login-form button:hover { background:#1d4ed8; }
.alert { margin: 10px 0 14px; padding: 12px; background: var(--danger-soft); border:1px solid var(--danger-border); border-radius:12px; color:#991b1b; }
.modal.hidden { display:none; }
.modal { position:fixed; inset:0; background: rgba(15,23,42,.28); display:grid; place-items:center; z-index: 90; backdrop-filter: blur(4px); }
.modal-card { width:min(820px, calc(100vw - 32px)); max-height: min(92vh, 980px); display:flex; flex-direction:column; background:var(--panel); border:1px solid var(--border); border-radius:18px; overflow:hidden; box-shadow: var(--shadow); }
.modal-header, .modal-footer { padding:14px 16px; border-bottom:1px solid var(--border); background:#ffffff; }
.modal-footer { border-top:1px solid var(--border); border-bottom:none; display:flex; justify-content:flex-end; gap:10px; flex-wrap: wrap; }
.modal-body { padding:16px; display:grid; gap:12px; overflow:auto; background: var(--panel-2); }
.icon-btn { background:none; border:none; color:#334155; font-size:28px; cursor:pointer; line-height: 1; }
.detail-header { display:flex; justify-content:space-between; align-items:flex-start; gap:12px; margin-bottom:12px; }
.detail-badges { display:flex; gap:8px; flex-wrap:wrap; }
.badge { display:inline-flex; align-items:center; padding:6px 10px; border-radius:999px; border:1px solid var(--primary-border); color:#1d4ed8; background:var(--primary-soft); font-size:12px; }
.detail-grid { display:grid; gap:8px; margin-bottom:10px; }
.detail-actions { display:flex; gap:8px; margin:12px 0; flex-wrap:wrap; }
.compose-grid-two { display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.compose-card label { display:block; margin:0 0 6px; color:var(--muted); font-size:13px; }
.editor-card, .attachment-card { border:1px solid var(--border); border-radius:14px; background:#ffffff; overflow:hidden; }
.editor-toolbar { display:flex; gap:8px; flex-wrap:wrap; padding:10px; border-bottom:1px solid var(--border); background:#f1f5fb; position: sticky; top: 0; z-index: 1; }
.toolbar-btn { border:1px solid var(--border); background:#ffffff; color:#334155; border-radius:10px; padding:8px 10px; cursor:pointer; font-size:13px; }
.toolbar-btn:hover { background:#eef5ff; border-color:var(--primary-border); }
.compose-editor { min-height:240px; padding:14px; outline:none; color:var(--text); line-height: 1.5; background:#ffffff; }
.compose-editor:empty:before { content: attr(data-placeholder); color: #94a3b8; }
.hidden-field { display:none; }
.attachment-card { padding:12px; display:grid; gap:8px; }
.attachment-row { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
.attachment-btn { display:inline-flex; width:auto; align-items:center; justify-content:center; }
.attachment-list { list-style:none; margin:0; padding:0; display:grid; gap:8px; }
.attachment-item { display:flex; align-items:center; justify-content:space-between; gap:10px; padding:10px 12px; border:1px solid var(--border); border-radius:12px; background:#f8fafc; }
.attachment-item small { color:var(--muted); }
.attachment-remove { border:none; background:var(--danger-soft); color:#991b1b; border-radius:10px; padding:8px 10px; cursor:pointer; }
.compose-header h3 { margin:0; }
.mobile-scrim {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.32);
  z-index: 59;
}
.mobile-scrim.hidden { display:none; }
@media (max-width: 1180px) {
  .layout { grid-template-columns: 220px minmax(280px, 340px) minmax(300px, 1fr); }
}
@media (max-width: 640px) {
  .received-attachment { align-items:flex-start; flex-direction:column; }
  .received-attachment-actions { width:100%; }
  .received-attachment-actions .attachment-action-btn { flex:1 1 auto; }
}
@media (max-width: 960px) {
  .mobile-only { display: inline-flex !important; }
  .desktop-only-inline, .desktop-only { display:none !important; }
  .topbar { padding: 12px 14px; }
  .topbar-actions { gap:8px; }
  .mailbox-pill { display:none; }
  .layout { display:block; min-height: calc(100vh - 62px); }
  .folders-panel, .messages-panel, .detail-panel {
    border-right:none;
    padding: 14px;
  }
  .folders-panel {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 84vw);
    background: #ffffff;
    z-index: 60;
    transform: translateX(-105%);
    transition: transform .24s ease;
    overflow: auto;
    box-shadow: var(--shadow);
  }
  body.show-folders .folders-panel { transform: translateX(0); }
  .messages-panel { display:block; }
  .detail-panel {
    position: fixed;
    inset: 62px 0 0 0;
    background: var(--bg);
    z-index: 50;
    overflow: auto;
    transform: translateX(100%);
    transition: transform .24s ease;
    padding-bottom: calc(24px + env(safe-area-inset-bottom));
  }
  body.show-detail .detail-panel { transform: translateX(0); }
  .sticky-head { top: 0; }
  .detail-topbar { margin: -14px -14px 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); }
  body.show-detail #messagesPanel { visibility:hidden; pointer-events:none; }
  .message-item { padding: 14px; }
  .message-line { flex-direction: column; gap: 4px; }
  .message-date { text-align:left; }
  .detail-actions .btn { flex: 1 1 calc(50% - 8px); }
  .modal { align-items: stretch; }
  .modal-card {
    width: 100vw;
    max-height: 100vh;
    min-height: 100vh;
    border-radius: 0;
    border-left: none;
    border-right: none;
  }
  .sticky-compose-head, .sticky-compose-footer {
    position: sticky;
    background: var(--panel);
    z-index: 2;
  }
  .sticky-compose-head { top: 0; }
  .sticky-compose-footer { bottom: 0; }
}
@media (max-width: 700px) {
  .compose-grid-two { grid-template-columns:1fr; }
  .topbar-actions .btn { padding: 10px 12px; }
  .detail-actions .btn { flex: 1 1 100%; }
  .toolbar-btn { font-size: 12px; padding: 8px 9px; }
  .modal-body { padding: 12px; }
}

.admin-card {
  width: min(1100px, 96vw);
}
.admin-body {
  display: flex;
  flex-direction: column;
  gap: 18px;
}
.admin-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}
.stat-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 8px 20px rgba(15,23,42,.04);
}
.stat-card span { color: var(--muted); font-size: 13px; }
.stat-card strong { font-size: 22px; }
.admin-grid {
  display: grid;
  grid-template-columns: 380px minmax(0, 1fr);
  gap: 16px;
}
.admin-section {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 16px;
  box-shadow: 0 8px 20px rgba(15,23,42,.04);
}
.admin-section-wide { min-width: 0; }
.compact-head { padding: 0 0 12px; }
.admin-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.admin-form-actions {
  display: flex;
  justify-content: flex-end;
}
.admin-accounts-list {
  display: grid;
  gap: 12px;
  max-height: 60vh;
  overflow: auto;
  padding-right: 4px;
}
.account-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  background: #ffffff;
}
.account-card-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}
.account-card-head h5 {
  margin: 0 0 4px;
  font-size: 16px;
}
.account-card-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.small-btn {
  padding: 8px 10px;
  font-size: 12px;
}
.badge-admin {
  background: var(--primary-soft);
  color: #1d4ed8;
}
.usage-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 12px 0 8px;
  color: var(--muted);
  font-size: 13px;
}
.usage-bar {
  width: 100%;
  height: 10px;
  border-radius: 999px;
  background: #e2e8f0;
  overflow: hidden;
}
.usage-bar span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb 0%, #38bdf8 100%);
}
.folder-chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}
.folder-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: #f1f5f9;
  border: 1px solid var(--border);
}

@media (max-width: 980px) {
  .admin-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .admin-grid {
    grid-template-columns: 1fr;
  }
  .admin-accounts-list {
    max-height: none;
  }
}

@media (max-width: 700px) {
  .admin-stats {
    grid-template-columns: 1fr;
  }
  .account-card-head,
  .usage-meta {
    flex-direction: column;
  }
  .admin-card {
    width: 100vw;
  }
}

.profile-trigger {
  display:flex;
  align-items:center;
  gap:12px;
  min-width: 0;
  background: transparent;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0;
}
.profile-meta {
  display:flex;
  flex-direction:column;
  min-width:0;
  text-align:left;
}
.profile-meta strong, .profile-meta span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-avatar, .account-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: #dbeafe;
}
.profile-avatar-fallback, .account-avatar-fallback {
  display:inline-flex;
  align-items:center;
  justify-content:center;
  font-weight:700;
  color:#1d4ed8;
}
.profile-card { width:min(560px, calc(100vw - 32px)); }
.profile-body { gap:16px; }
.profile-preview-wrap { display:flex; align-items:center; gap:16px; flex-wrap:wrap; }
.profile-preview-frame {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  overflow: hidden;
  border: 1px solid var(--border);
  display:flex;
  align-items:center;
  justify-content:center;
  background:#eff6ff;
}
.profile-preview-frame img { width:100%; height:100%; object-fit:cover; }
.profile-preview-fallback {
  width:100%; height:100%; display:flex; align-items:center; justify-content:center; font-size:34px; font-weight:700;
}
.profile-checkbox { display:flex; align-items:center; gap:10px; color:var(--muted); font-size:14px; }
.account-ident { display:flex; gap:12px; align-items:center; min-width:0; }
.account-ident h5 { margin:0 0 4px; }
.account-ident .muted { white-space: normal; word-break: break-word; }
.account-avatar { width:48px; height:48px; }

@media (max-width: 700px) { .profile-meta .small { max-width: 170px; } .profile-trigger { gap:10px; } .profile-avatar { width:36px; height:36px; } }

.password-settings-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  background: #ffffff;
}

.profile-form label {
  display: block;
  margin: 0 0 6px;
  color: var(--muted);
  font-size: 13px;
}

.profile-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
}

.profile-checkbox input {
  width: auto;
}
