@import url('https://fonts.googleapis.com/css2?family=Lora:ital,wght@0,400;0,500;0,600;1,400&family=Nunito:wght@400;500;600;700&display=swap');

:root {
  --bg-app: #f4f2f5;
  --bg-sidebar: #fbfaf9;
  --bg-list: #ffffff;
  --bg-detail: #fcfcfc;
  --bg-active: #e7e2ef;
  --text-main: #3d3745;
  --text-muted: #958c9f;
  --primary: #463b5f;
  --primary-light: #7b6f95;
  --border: #f0ebf4;
  --font-serif: 'Lora', serif;
  --font-sans: 'Nunito', sans-serif;
  --shadow-sm: 0 2px 8px rgba(0,0,0,0.03);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: var(--font-sans);
  background-color: var(--bg-app);
  color: var(--text-main);
  height: 100vh;
  overflow: hidden;
  font-size: 14px;
}

/* Base Layout */
.app-layout {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: var(--bg-app);
  position: relative;
}

/* ==================== SIDEBAR ==================== */
.sidebar {
  width: 260px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 32px 0 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 20;
  transition: transform 0.3s ease;
}

.s-header {
  text-align: center;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border);
  margin: 0 24px 24px;
  position: relative;
}
.s-header::after {
  content: '✧';
  position: absolute;
  bottom: -10px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-sidebar);
  padding: 0 8px;
  color: var(--border);
  font-size: 14px;
}
.s-logo {
  font-size: 42px;
  color: var(--primary);
  margin-bottom: 8px;
  line-height: 1;
}
.s-title {
  font-family: var(--font-serif);
  font-size: 24px;
  color: var(--primary);
  font-weight: 500;
  display: block;
}
.s-subtitle {
  font-size: 10px;
  color: var(--text-muted);
  display: block;
  margin-top: 6px;
  line-height: 1.4;
  padding: 0 10px;
}

.sidebar-nav { flex-grow: 1; padding: 0 16px; position: relative; z-index: 2; }
.nav-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  color: var(--text-main);
  text-decoration: none;
  border-radius: 8px;
  margin-bottom: 6px;
  font-weight: 500;
  transition: all 0.2s;
  font-size: 14px;
}
.nav-item:hover { background: #f6f4f8; }
.nav-item.active { background: var(--bg-active); color: var(--primary); font-weight: 600; }
.nav-icon { margin-right: 12px; font-size: 18px; width: 24px; text-align: center; }
.nav-badge { margin-left: auto; font-size: 12px; font-weight: 600; color: var(--primary); }

.s-footer {
  padding: 16px 24px;
  position: relative;
  z-index: 2;
}

.flower-deco {
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 250px;
  background: url('../img/bg.png') no-repeat bottom left;
  background-size: cover;
  opacity: 0.15;
  pointer-events: none;
  z-index: 1;
  mask-image: linear-gradient(to top, rgba(0,0,0,1), rgba(0,0,0,0));
  -webkit-mask-image: linear-gradient(to top, rgba(0,0,0,1), rgba(0,0,0,0));
}

.btn-logout {
  display: flex;
  align-items: center;
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  padding: 8px 0;
  text-align: left;
}
.btn-logout .logout-icon { font-size: 24px; margin-right: 12px; color: var(--text-main); width: 24px; text-align: center;}
.btn-logout .logout-main { display: block; font-weight: 600; color: var(--text-main); font-size: 14px; }
.btn-logout .logout-sub { display: block; font-size: 11px; color: var(--text-muted); margin-top: 2px;}

/* ==================== MAIN CONTENT ==================== */
.main-content {
  flex-grow: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  position: relative;
}

.topbar { display: none; }

/* ==================== INBOX LAYOUT ==================== */
.inbox-layout {
  display: flex;
  height: 100%;
  width: 100%;
}

/* --- LIST COLUMN --- */
.inbox-col-list {
  width: 380px;
  background: var(--bg-list);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  z-index: 10;
  transition: transform 0.3s ease;
}
.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 24px 16px;
}
.list-header h2 { font-family: var(--font-serif); font-size: 24px; font-weight: 500; color: var(--primary); }
.btn-outline {
  border: 1px solid var(--primary-light);
  background: transparent;
  color: var(--primary);
  border-radius: 20px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.2s;
}
.btn-outline:hover { background: var(--bg-active); }

.list-filters {
  display: flex;
  gap: 16px;
  padding: 0 24px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
}
.filter-item { cursor: pointer; display: flex; align-items: center; gap: 4px; font-weight: 500;}

.email-list-scroll {
  flex-grow: 1;
  overflow-y: auto;
}
.email-item {
  display: flex;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.2s;
  gap: 16px;
}
.email-item:hover { background: #faf8fc; }
.email-item.active { background: var(--bg-active); }
.email-item .checkbox { 
  width: 16px; height: 16px; border: 1.5px solid #d1cdd8; border-radius: 4px; margin-top: 2px; flex-shrink: 0; 
  background: white;
}
.email-item-content { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px;}
.e-top { display: flex; justify-content: space-between; align-items: center;}
.e-sender { font-weight: 700; font-size: 14px; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.e-time { font-size: 11px; color: var(--text-muted); font-weight: 500; flex-shrink: 0; }
.e-subject { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--primary); }
.e-snippet-row { display: flex; justify-content: space-between; align-items: flex-end; }
.e-snippet { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 8px;}
.e-star { font-size: 18px; color: #d1cdd8; flex-shrink: 0; line-height: 1;}

.pagination {
  padding: 16px 24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--bg-list);
}
.page-btns { display: flex; gap: 8px; align-items: center;}
.page-btns button { border: none; background: transparent; padding: 4px 8px; cursor: pointer; color: var(--text-muted); border-radius: 4px; font-weight: 600;}
.page-btns button.active { background: var(--bg-active); color: var(--primary); }

/* --- DETAIL COLUMN --- */
.inbox-col-detail {
  flex-grow: 1;
  background: url('../img/bg.png') no-repeat right bottom;
  background-size: cover;
  display: flex;
  flex-direction: column;
  position: relative;
  background-color: var(--bg-detail);
}
/* Overlay for readability */
.inbox-col-detail::before {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: linear-gradient(to right, rgba(252,252,252,1) 0%, rgba(252,252,252,0.95) 45%, rgba(252,252,252,0) 100%);
  pointer-events: none;
}

.detail-toolbar {
  position: relative;
  z-index: 10;
  padding: 24px 40px;
  display: flex;
  gap: 24px;
  border-bottom: 1px solid var(--border);
}
.toolbar-btn {
  background: transparent; border: none; color: var(--text-main); font-weight: 600; font-size: 13px; cursor: pointer; display: flex; align-items: center; gap: 8px; font-family: var(--font-sans);
}
.toolbar-btn:hover { color: var(--primary); }
.toolbar-icon { font-size: 16px; color: var(--text-muted); }

.detail-content-wrap {
  position: relative;
  z-index: 10;
  flex-grow: 1;
  padding: 40px;
  overflow-y: auto;
  max-width: 800px;
}

.d-subject {
  font-family: var(--font-serif);
  font-size: 28px;
  color: var(--text-main);
  margin-bottom: 32px;
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 500;
}
.d-subject .star { font-size: 24px; color: #d1cdd8; cursor: pointer;}

.d-sender-box {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 40px;
}
.d-avatar {
  width: 50px; height: 50px; border-radius: 50%;
  background: #a99bb8;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: bold; color: white;
  box-shadow: var(--shadow-sm);
  background-size: cover;
  background-position: center;
}
.d-sender-info .name { font-weight: 700; font-size: 15px; margin-bottom: 4px; color: var(--text-main); }
.d-sender-info .to { font-size: 13px; color: var(--text-muted); margin-bottom: 2px;}
.d-sender-info .date { font-size: 12px; color: var(--text-muted); }

.d-body {
  font-size: 15px;
  line-height: 1.8;
  color: var(--text-main);
  font-family: var(--font-serif);
  padding-bottom: 32px;
  max-width: 600px; /* Keep line length readable */
}

.d-body iframe {
  width: 100%;
  border: none;
  min-height: 400px;
}

.d-attachments {
  margin-top: 40px;
  border-top: 1px solid var(--border);
  padding-top: 24px;
  max-width: 600px;
}
.d-attach-title { font-size: 13px; font-weight: 600; margin-bottom: 16px; display: flex; align-items: center; gap: 8px; color: var(--text-main); }
.d-attach-card {
  display: inline-flex; align-items: center; gap: 16px;
  background: white; border: 1px solid var(--border); border-radius: 8px; padding: 12px 20px;
  box-shadow: var(--shadow-sm); cursor: pointer;
  transition: all 0.2s;
}
.d-attach-card:hover { border-color: var(--primary-light); box-shadow: 0 4px 12px rgba(0,0,0,0.05);}
.d-attach-icon { font-size: 28px; color: #7b6f95; }
.d-attach-info .fname { font-size: 14px; font-weight: 600; color: var(--text-main); margin-bottom: 2px;}
.d-attach-info .fsize { font-size: 12px; color: var(--text-muted); }

/* ==================== MOBILE RESPONSIVENESS ==================== */
/* Tablet / Small Desktop */
@media (max-width: 1024px) {
  .inbox-col-detail::before {
    background: linear-gradient(to right, rgba(252,252,252,1) 0%, rgba(252,252,252,0.95) 60%, rgba(252,252,252,0.4) 100%);
  }
}

/* Mobile */
@media (max-width: 768px) {
  .topbar { 
    display: flex; 
    align-items: center; 
    padding: 16px 20px; 
    background: var(--bg-sidebar); 
    border-bottom: 1px solid var(--border); 
    z-index: 15;
  }
  .menu-btn { background: none; border: none; font-size: 24px; margin-right: 16px; cursor: pointer; color: var(--primary); }
  .topbar-title { font-family: var(--font-serif); font-size: 20px; color: var(--primary); font-weight: 500; }
  
  /* Sidebar Mobile Overlay */
  .sidebar { 
    position: fixed; 
    left: -260px; 
    top: 0; bottom: 0; 
    box-shadow: 4px 0 15px rgba(0,0,0,0.05); 
    z-index: 100;
  }
  .sidebar.open { left: 0; }
  
  .sidebar-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 90; opacity: 0; pointer-events: none; transition: 0.3s;
  }
  .sidebar-overlay.open { opacity: 1; pointer-events: all; }

  /* Mobile Inbox Layout: Stack list and detail, use JS to toggle */
  .inbox-layout { position: relative; overflow: hidden; }
  
  .inbox-col-list { width: 100%; height: 100%; border-right: none; position: absolute; top: 0; left: 0; z-index: 10; }
  .inbox-col-detail { width: 100%; height: 100%; position: absolute; top: 0; left: 100%; z-index: 20; transition: transform 0.3s ease; }
  
  /* When viewing an email on mobile */
  .inbox-layout.viewing-detail .inbox-col-list { transform: translateX(-30%); opacity: 0; pointer-events: none; }
  .inbox-layout.viewing-detail .inbox-col-detail { transform: translateX(-100%); }

  .mobile-back-btn { display: flex !important; }
  
  /* Adjust detail paddings for mobile */
  .detail-toolbar { padding: 16px 20px; overflow-x: auto; white-space: nowrap; }
  .detail-content-wrap { padding: 24px 20px; }
  .d-subject { font-size: 24px; margin-bottom: 24px; }
  .inbox-col-detail::before { background: rgba(255,255,255,0.85); } /* solid wash on mobile so it's readable over the image */
}

/* Hide back button on desktop */
.mobile-back-btn { display: none; margin-right: 16px; font-size: 20px; color: var(--primary); background: none; border: none; cursor: pointer; }

/* ==================== GENERIC UI (Admin/Auth) ==================== */
.page-container { padding: 32px; max-width: 1000px; margin: 0 auto; width: 100%; position: relative; z-index: 10; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; }
.page-header h2 { font-family: var(--font-serif); font-size: 24px; color: var(--primary); margin-bottom: 4px;}
.page-header p { color: var(--text-muted); font-size: 13px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; color: var(--text-main); }
.form-input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 6px; font-family: var(--font-sans); font-size: 14px; outline: none; transition: 0.2s;}
.form-input:focus { border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(123, 111, 149, 0.1);}
.input-with-domain { display: flex; gap: 8px; }

.btn { padding: 8px 16px; border-radius: 6px; border: none; cursor: pointer; font-weight: 600; font-family: var(--font-sans); font-size: 13px; transition: 0.2s; }
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: #322a44; }
.btn-secondary { background: #e6e2e8; color: var(--text-main); }
.btn-danger { background: #e06c75; color: white; }

.data-table-wrapper { background: white; border-radius: 8px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th, .data-table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border); font-size: 13px;}
.data-table th { background: var(--bg-sidebar); font-weight: 600; color: var(--text-muted); text-transform: uppercase; font-size: 11px; letter-spacing: 0.5px;}

.status-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.status-dot.active { background: #10b981; }
.status-dot.inactive { background: #ef4444; }
.role-badge { padding: 4px 8px; border-radius: 12px; font-size: 11px; font-weight: 700; text-transform: uppercase; }
.role-badge.admin { background: #fdf2f8; color: #be185d; }
.role-badge.user { background: #eef2ff; color: #4338ca; }
.table-actions button { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px; border-radius: 4px; transition: 0.2s; }
.table-actions button:hover { background: var(--bg-active); }

.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.3); backdrop-filter: blur(2px); display: flex; justify-content: center; align-items: center; z-index: 100; opacity: 0; transition: 0.2s; pointer-events: none;}
.modal-overlay.active { opacity: 1; pointer-events: all;}
.modal { background: white; padding: 24px; border-radius: 12px; width: 400px; max-width: 90%; box-shadow: 0 10px 25px rgba(0,0,0,0.1); transform: translateY(20px); transition: 0.3s; }
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.modal-header h3 { font-family: var(--font-serif); font-size: 20px; color: var(--primary); }
.modal-close { background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-footer { display: flex; justify-content: flex-end; gap: 8px; margin-top: 24px; }

.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; }
.toast { background: white; padding: 12px 20px; border-radius: 8px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); margin-top: 10px; border-left: 4px solid var(--primary); display: flex; align-items: center; gap: 8px; font-weight: 500; font-size: 13px;}

.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin 1s linear infinite; }
.loading-center { display: flex; justify-content: center; padding: 40px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Auth Layout */
.auth-container { 
  display: flex; 
  min-height: 100vh; 
  align-items: center; 
  justify-content: center; 
  background: url('../img/bg-login.png') no-repeat center center;
  background-size: cover;
  position: relative;
  padding: 24px;
}
.auth-box { 
  background: rgba(255, 255, 255, 0.95); 
  backdrop-filter: blur(10px);
  padding: 40px; 
  border-radius: 16px; 
  width: 100%; 
  max-width: 400px; 
  box-shadow: 0 16px 48px rgba(0,0,0,0.2); 
  position: relative; 
  z-index: 10; 
  border: 1px solid rgba(255, 255, 255, 0.3);
}
.auth-logo { text-align: center; margin-bottom: 32px; }
.auth-logo .icon { font-size: 48px; color: var(--primary); margin-bottom: 8px; display: block; line-height: 1; }
.auth-logo h1 { font-family: var(--font-serif); font-size: 28px; color: var(--primary); }
.auth-logo p { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* Global Mobile Fixes */
@media (max-width: 480px) {
  .auth-box { padding: 32px 24px; }
  .page-container { padding: 16px; }
}

/* ==================== DARK MODE (AUTO) ==================== */
@media (prefers-color-scheme: dark) {
  :root {
    --bg-app: #120e17;
    --bg-sidebar: #17131e;
    --bg-list: #1e1926;
    --bg-detail: #1a1622;
    --bg-active: #2a2238;
    --text-main: #e8e4ef;
    --text-muted: #8d859b;
    --primary: #b5a4d6;
    --primary-light: #52476b;
    --border: #2a2335;
    --shadow-sm: 0 2px 12px rgba(0,0,0,0.3);
  }

  .inbox-col-detail::before {
    background: linear-gradient(to right, rgba(26,22,34,1) 0%, rgba(26,22,34,0.95) 45%, rgba(26,22,34,0) 100%);
  }
  
  .auth-box {
    background: rgba(30, 25, 38, 0.85);
    border: 1px solid rgba(255, 255, 255, 0.08);
  }
  
  .auth-container::before {
    background: rgba(0, 0, 0, 0.65);
  }

  .data-table-wrapper, .modal, .toast {
    background: var(--bg-list);
  }

  .btn-secondary {
    background: #362d46;
    color: var(--text-main);
  }
  
  .d-attach-card {
    background: var(--bg-sidebar);
  }
  
  .nav-item:hover { background: #231c2d; }
  .email-item:hover { background: #231c2d; }
  
  .form-input {
    background: var(--bg-app);
    color: var(--text-main);
  }
}

@media (max-width: 1024px) and (prefers-color-scheme: dark) {
  .inbox-col-detail::before {
    background: linear-gradient(to right, rgba(26,22,34,1) 0%, rgba(26,22,34,0.95) 60%, rgba(26,22,34,0.5) 100%);
  }
}

@media (max-width: 768px) and (prefers-color-scheme: dark) {
  .inbox-col-detail::before { background: rgba(26,22,34,0.9); }
}
