@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600&display=swap');

:root {
  --bg: #111113;
  --bg2: #18181b;
  --bg3: #232327;
  --border: #2e2e34;
  --border-light: #3a3a42;
  --text: #f4f4f5;
  --text2: #a1a1aa;
  --text3: #71717a;
  --accent: #6366f1;
  --accent-hover: #4f52d9;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

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

body {
  font-family: 'Inter', -apple-system, sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 10px; }

/* ── AUTH SCREEN ─────────────────────────────────── */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.auth-card {
  width: 380px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px 36px;
  box-shadow: var(--shadow);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.auth-logo-icon {
  width: 34px; height: 34px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff;
}

.auth-logo-text {
  font-size: 18px; font-weight: 600;
  letter-spacing: -0.3px;
}

.auth-title { font-size: 22px; font-weight: 600; margin-bottom: 6px; }
.auth-sub { font-size: 13px; color: var(--text2); margin-bottom: 28px; }

.auth-error {
  background: rgba(239,68,68,0.1);
  border: 1px solid rgba(239,68,68,0.25);
  color: #fca5a5;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

/* ── FORM ELEMENTS ──────────────────────────────── */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.form-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

.form-input:focus { border-color: var(--accent); }
.form-input::placeholder { color: var(--text3); }

textarea.form-input {
  resize: vertical;
  min-height: 120px;
  line-height: 1.6;
}

select.form-input { cursor: pointer; }

/* ── BUTTONS ────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  font-family: inherit;
  cursor: pointer; border: none;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
  text-decoration: none;
}

.btn-primary {
  background: var(--accent); color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }

.btn-secondary {
  background: var(--bg3); color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-danger {
  background: rgba(239,68,68,0.12); color: #fca5a5;
  border: 1px solid rgba(239,68,68,0.2);
}
.btn-danger:hover { background: var(--danger); color: #fff; border-color: var(--danger); }

.btn-ghost {
  background: transparent; color: var(--text2);
  border: 1px solid transparent;
}
.btn-ghost:hover { background: var(--bg3); color: var(--text); border-color: var(--border); }

.btn:disabled { opacity: 0.45; pointer-events: none; }

.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }

/* ── APP LAYOUT ─────────────────────────────────── */
#app-screen { display: none; height: 100vh; overflow: hidden; }
#app-screen.active { display: flex; }

/* Sidebar */
.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

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

.sidebar-logo-icon {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; color: #fff;
}

.sidebar-logo-text { font-size: 15px; font-weight: 600; }

.sidebar-section-title {
  font-size: 11px; font-weight: 500;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  padding: 18px 16px 8px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 16px;
  color: var(--text2);
  cursor: pointer;
  border-radius: 0;
  transition: background 0.1s, color 0.1s;
  font-size: 13px; font-weight: 400;
  user-select: none;
  border-left: 2px solid transparent;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: var(--bg3); color: var(--text); border-left-color: var(--accent); }

.nav-item i { width: 16px; text-align: center; font-size: 13px; }

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

.sidebar-body { flex: 1; overflow-y: auto; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 6px;
}

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.user-chip-avatar {
  width: 28px; height: 28px;
  background: var(--accent);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 600; color: #fff;
  flex-shrink: 0;
}

.user-chip-info { flex: 1; min-width: 0; }
.user-chip-name { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-chip-role { font-size: 11px; color: var(--text3); }

/* ── MAIN PANEL ─────────────────────────────────── */
.main-panel {
  flex: 1;
  display: flex;
  overflow: hidden;
  height: 100vh;
}

/* Mail list column */
.mail-list-col {
  width: 320px;
  flex-shrink: 0;
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  height: 100vh;
  background: var(--bg);
}

.col-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.col-header h2 { font-size: 15px; font-weight: 600; }

.col-body { flex: 1; overflow-y: auto; }

/* Mail address bar */
.address-bar {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
  background: var(--bg2);
  flex-shrink: 0;
}

.address-text {
  flex: 1; font-size: 13px; color: var(--text2);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  user-select: all;
}

/* Mail item */
.mail-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
  position: relative;
}

.mail-item:hover { background: var(--bg2); }
.mail-item.active { background: var(--bg3); }
.mail-item.unread { background: rgba(99,102,241,0.04); }

.mail-item-row1 {
  display: flex; justify-content: space-between;
  margin-bottom: 4px;
}

.mail-sender { font-size: 13px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 180px; }
.mail-time { font-size: 11px; color: var(--text3); flex-shrink: 0; }
.mail-subject { font-size: 13px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-bottom: 2px; }
.mail-item.unread .mail-subject { color: var(--text); font-weight: 500; }
.mail-preview { font-size: 12px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.unread-dot {
  display: none;
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--accent);
  position: absolute; left: 5px; top: 50%; transform: translateY(-50%);
}
.mail-item.unread .unread-dot { display: block; }

.empty-list {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%;
  color: var(--text3); gap: 10px;
  padding: 40px 20px;
}

.empty-list i { font-size: 32px; }
.empty-list p { font-size: 13px; text-align: center; }

/* Mail view column */
.mail-view-col {
  flex: 1;
  display: flex; flex-direction: column;
  height: 100vh;
  background: var(--bg);
  overflow: hidden;
}

.mail-view-placeholder {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  height: 100%; color: var(--text3); gap: 12px;
}

.mail-view-placeholder i { font-size: 36px; }
.mail-view-placeholder p { font-size: 14px; }

/* Mail view content */
.mail-view-header {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.mail-view-subject { font-size: 20px; font-weight: 600; margin-bottom: 14px; line-height: 1.3; }

.mail-meta-row {
  display: flex; justify-content: space-between;
  align-items: flex-start; gap: 12px;
}

.sender-row { display: flex; align-items: center; gap: 10px; }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--bg3); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 14px; font-weight: 600; color: var(--accent);
  flex-shrink: 0;
}

.sender-name { font-size: 14px; font-weight: 500; }
.sender-email { font-size: 12px; color: var(--text3); margin-top: 1px; }

.mail-date { font-size: 12px; color: var(--text3); white-space: nowrap; }

.mail-actions { display: flex; gap: 6px; margin-top: 8px; justify-content: flex-end; }

/* Attachments */
.attachments-bar {
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  display: none; flex-wrap: wrap; gap: 8px;
}

.att-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 10px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 12px; color: var(--text);
  transition: border-color 0.15s;
}
.att-chip:hover { border-color: var(--accent); }
.att-chip i { font-size: 13px; color: var(--text2); }

/* Mail body iframe */
.mail-body-frame {
  flex: 1; width: 100%; border: none;
  background: #fff;
}

/* ── CONTENT PAGES (Aliases, Admin tabs etc) ─────── */
.content-col {
  flex: 1;
  display: flex; flex-direction: column;
  height: 100vh;
  overflow-y: auto;
  padding: 28px 32px;
  background: var(--bg);
}

.page-title { font-size: 20px; font-weight: 600; margin-bottom: 6px; }
.page-sub { font-size: 13px; color: var(--text2); margin-bottom: 24px; }

/* Cards */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 20px;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}

.card-header h3 { font-size: 14px; font-weight: 600; }
.card-body { padding: 20px; }

/* Inline form */
.inline-form {
  display: flex; gap: 8px; align-items: flex-end;
  flex-wrap: wrap;
}
.inline-form .form-group { margin-bottom: 0; flex: 1; min-width: 160px; }

/* Table */
.data-table { width: 100%; border-collapse: collapse; }
.data-table th {
  text-align: left; padding: 10px 16px;
  font-size: 11px; font-weight: 600;
  color: var(--text3); text-transform: uppercase; letter-spacing: 0.4px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
}
.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--bg2); }

/* Badges */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px; font-weight: 600;
}
.badge-admin { background: rgba(99,102,241,0.15); color: #a5b4fc; }
.badge-user { background: rgba(34,197,94,0.1); color: #86efac; }
.badge-in { background: rgba(34,197,94,0.1); color: #86efac; }
.badge-out { background: rgba(99,102,241,0.1); color: #a5b4fc; }
.badge-info { background: rgba(34,197,94,0.1); color: #86efac; }
.badge-error { background: rgba(239,68,68,0.1); color: #fca5a5; }

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px;
  display: flex; flex-direction: column; gap: 8px;
}

.stat-label { font-size: 12px; color: var(--text3); font-weight: 500; }
.stat-value { font-size: 28px; font-weight: 600; line-height: 1; }

/* ── MODALS ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  opacity: 0; pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open { opacity: 1; pointer-events: auto; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 100%; max-width: 560px;
  box-shadow: var(--shadow);
  transform: translateY(12px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal { transform: translateY(0); }

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

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 20px; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

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

.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  font-size: 13px;
  box-shadow: var(--shadow);
  min-width: 240px; max-width: 360px;
  animation: toastIn 0.2s ease;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@keyframes toastIn {
  from { transform: translateX(20px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ── BOOT LOADER ────────────────────────────────── */
#boot-loader {
  position: fixed; inset: 0; z-index: 9999;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(99,102,241,0.15), transparent),
              linear-gradient(180deg, #111113 0%, #0b0b0e 100%);
  display: flex; align-items: center; justify-content: center;
  transition: opacity 0.5s ease, visibility 0.5s;
}
#boot-loader.done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-inner {
  width: min(380px, 88vw); text-align: center;
  background: rgba(24,24,27,0.8);
  border: 1px solid var(--border);
  border-radius: 18px; padding: 40px 32px 32px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5);
  backdrop-filter: blur(8px);
  animation: bootUp 0.5s ease;
}
@keyframes bootUp { from { transform: translateY(14px); opacity: 0; } to { transform: none; opacity: 1; } }
.boot-logo { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 24px; }
.boot-logo-icon {
  width: 46px; height: 46px; border-radius: 12px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff;
  box-shadow: 0 0 24px rgba(99,102,241,0.55);
  animation: bootPulse 1.6s ease-in-out infinite;
}
@keyframes bootPulse { 0%,100% { box-shadow: 0 0 18px rgba(99,102,241,0.4); transform: scale(1); } 50% { box-shadow: 0 0 34px rgba(99,102,241,0.75); transform: scale(1.05); } }
.boot-logo-text { font-size: 24px; font-weight: 800; letter-spacing: 1px; }
.boot-logo-text span { color: var(--accent); }
.boot-spinner {
  width: 34px; height: 34px; margin: 0 auto 18px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: bootSpin 0.8s linear infinite;
}
@keyframes bootSpin { to { transform: rotate(360deg); } }
.boot-bar {
  height: 8px; background: var(--bg3);
  border: 1px solid var(--border); border-radius: 99px;
  overflow: hidden; margin-bottom: 10px;
}
.boot-bar-fill {
  height: 100%; width: 0%;
  background: linear-gradient(90deg, #6366f1, #8b5cf6, #6366f1);
  background-size: 200% 100%;
  border-radius: 99px;
  transition: width 0.25s ease;
  animation: bootShimmer 1.2s linear infinite;
}
@keyframes bootShimmer { to { background-position: -200% 0; } }
.boot-percent { font-size: 13px; font-weight: 700; color: var(--accent); margin-bottom: 10px; font-variant-numeric: tabular-nums; }
.boot-status { font-size: 13px; color: var(--text); min-height: 18px; margin-bottom: 4px; }
.boot-sub { font-size: 12px; color: var(--text3); }
.boot-footer {
  position: absolute; bottom: 22px; left: 0; right: 0;
  text-align: center; font-size: 11px; color: var(--text3);
  letter-spacing: 0.4px;
}

/* ── RESPONSIVE ─────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { width: 72px; }
  .sidebar-logo-text, .sidebar-section-title, .nav-item { font-size: 0; gap: 0; justify-content: center; }
  .nav-item i { font-size: 16px; }
  .nav-badge { display: none; }
  .user-chip-info, #logout-btn { display: none; }
  .mail-list-col { width: 100%; border-right: none; }
  .mail-view-col { display: none; }
  .content-col { padding: 20px 16px; }
  .auth-card { width: calc(100vw - 32px); padding: 32px 24px; }
}

/* ── UTILS ──────────────────────────────────────── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-2 { gap: 8px; }
.ml-auto { margin-left: auto; }
.text-muted { color: var(--text3); }
.text-sm { font-size: 12px; }
.mt-1 { margin-top: 4px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
