@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 {
  color-scheme: light only;
  --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);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --motion-fast: 160ms var(--ease-out);
  --motion-normal: 240ms var(--ease-out);
}

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

@media (prefers-reduced-motion: no-preference) {
  .app-layout,
  .auth-container {
    animation: fade-in 180ms var(--ease-out) both;
  }

  .auth-box,
  .page-container,
  .detail-content-wrap {
    animation: lift-in 260ms var(--ease-out) both;
  }

  .sidebar {
    animation: sidebar-in 260ms var(--ease-out) both;
  }

  .inbox-col-list,
  .inbox-col-detail {
    animation: soft-in 220ms var(--ease-out) both;
  }
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes soft-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes lift-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes sidebar-in {
  from { opacity: 0; transform: translateX(-10px); }
  to { opacity: 1; transform: translateX(0); }
}

/* 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: 15px;
  color: var(--primary);
  font-weight: 600;
  display: block;
  word-break: break-all;
}
.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: background var(--motion-fast), color var(--motion-fast), transform var(--motion-fast); font-size: 14px;
}
.nav-item:hover { background: #f6f4f8; transform: translateX(2px); }
.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; }

.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-login.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;
  transition: color var(--motion-fast), transform var(--motion-fast);
}
.btn-logout:hover { transform: translateX(2px); }
.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%; overflow: hidden; }

.inbox-col-list {
  width: 360px; background: var(--bg-list); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0; z-index: 10;
}
.list-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 20px 16px; border-bottom: 1px solid var(--border);
}
.list-header h2 { font-family: var(--font-serif); font-size: 20px; font-weight: 500; color: var(--primary); }
.inbox-note {
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  line-height: 1.45;
  background: #fbfafc;
}
.btn-refresh {
  background: transparent; border: none; color: var(--text-muted); font-size: 13px;
  font-weight: 600; cursor: pointer; font-family: var(--font-sans);
  padding: 6px 12px; border-radius: 6px; transition: background var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}
.btn-refresh:hover { color: var(--primary); background: var(--bg-active); transform: translateY(-1px); }

.email-list-scroll { flex-grow: 1; overflow-y: auto; }

.email-item {
  display: flex; align-items: flex-start; padding: 16px 20px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background var(--motion-fast), transform var(--motion-fast); gap: 12px;
}
.email-item:hover { background: #faf8fc; transform: translateX(2px); }
.email-item.active { background: var(--bg-active); }
.email-item.unread .e-sender { font-weight: 800; }
.email-item.unread .e-subject { font-weight: 700; color: var(--text-main); }

.email-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 6px; flex-shrink: 0; background: transparent; }
.email-dot.show { background: var(--primary); animation: unread-pulse 2.4s ease-in-out infinite; }

.email-item-content { flex-grow: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.e-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.e-sender { font-weight: 600; 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: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-muted); }

.empty-state { padding: 60px 20px; text-align: center; }
.empty-state .empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-state h3 { font-family: var(--font-serif); color: var(--text-main); font-size: 16px; margin-bottom: 4px; }
.empty-state p { color: var(--text-muted); font-size: 13px; }

/* --- DETAIL COLUMN --- */
.inbox-col-detail {
  flex-grow: 1; background: url('../img/bg-login.png') no-repeat right bottom; background-size: cover;
  display: flex; flex-direction: column; position: relative; background-color: var(--bg-detail); overflow: hidden;
}
.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.96) 50%, rgba(252,252,252,0) 100%);
  pointer-events: none;
}

.detail-empty {
  display: flex; flex-direction: column; height: 100%; align-items: center; justify-content: center;
  color: var(--text-muted); position: relative; z-index: 10; font-family: var(--font-serif); font-size: 16px; gap: 8px;
}
.detail-empty-icon { font-size: 36px; opacity: 0.5; }

.detail-toolbar {
  position: relative; z-index: 10; padding: 12px 24px;
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 1px solid var(--border);
}
.detail-toolbar-right { display: flex; gap: 8px; }
.toolbar-btn {
  background: transparent; border: 1px solid var(--border); color: var(--text-main);
  font-weight: 600; font-size: 13px; cursor: pointer; padding: 6px 14px;
  border-radius: 6px; font-family: var(--font-sans); transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}
.toolbar-btn:hover { border-color: var(--primary-light); color: var(--primary); transform: translateY(-1px); }
.toolbar-btn.danger { color: #c0392b; border-color: #f0d5d5; }
.toolbar-btn.danger:hover { background: #fdf2f2; border-color: #e74c3c; }

.detail-content-wrap {
  position: relative; z-index: 10; flex-grow: 1; padding: 32px;
  overflow-y: auto; overflow-x: hidden; max-width: 700px; margin: 0 auto; width: 100%;
}

.d-subject {
  font-family: var(--font-serif); font-size: 22px; color: var(--text-main);
  margin-bottom: 24px; font-weight: 500; line-height: 1.4; word-break: break-word;
}

.d-sender-box { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.d-avatar {
  width: 40px; height: 40px; border-radius: 50%; background: #a99bb8;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; font-weight: bold; color: white; flex-shrink: 0;
}
.d-sender-info .name { font-weight: 700; font-size: 14px; color: var(--text-main); }
.d-sender-info .date { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.d-body {
  font-size: 15px; line-height: 1.8; color: var(--text-main);
  font-family: var(--font-serif); padding-bottom: 32px;
  max-width: 100%; overflow-x: hidden; word-break: break-word;
}
.d-body-text { white-space: pre-wrap; }
.d-body iframe { width: 100%; border: none; min-height: 300px; max-width: 100%; }

.header-actions { display: flex; gap: 8px; }
.hide-mobile {}

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

@media (max-width: 768px) {
  .topbar {
    display: flex; align-items: center; padding: 14px 16px;
    background: var(--bg-sidebar); border-bottom: 1px solid var(--border); z-index: 15;
  }
  .menu-btn { background: none; border: none; font-size: 24px; margin-right: 12px; cursor: pointer; color: var(--primary); }
  .topbar-title { font-family: var(--font-serif); font-size: 14px; color: var(--primary); font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: calc(100vw - 80px); }

  .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 */
  .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: 0; z-index: 20; transform: translateX(100%); transition: transform 0.3s ease; overflow-x: hidden; }

  .inbox-layout.viewing-detail .inbox-col-list { opacity: 0; pointer-events: none; }
  .inbox-layout.viewing-detail .inbox-col-detail { transform: translateX(0); }

  .mobile-back-btn { display: flex !important; }

  .detail-toolbar { padding: 10px 16px; }
  .detail-content-wrap { padding: 20px 16px; overflow-x: hidden; }
  .d-subject { font-size: 18px; margin-bottom: 16px; }
  .d-body { max-width: 100%; overflow-x: hidden; }
  .d-body iframe { max-width: 100%; }
  .inbox-col-detail::before { background: rgba(252,252,252,0.92); }

  /* Admin mobile adjustments */
  .page-container { padding: 16px; }
  .page-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .header-actions { width: 100%; }
  .pager { flex-direction: column; align-items: stretch; }
  .pager-actions { justify-content: center; flex-wrap: wrap; }
  .hide-mobile { display: none !important; }
  .data-table-wrapper { overflow-x: auto; }
}

/* Hide back button on desktop, style for mobile */
.mobile-back-btn {
  display: none; margin-right: 8px; font-size: 14px; color: var(--primary);
  background: none; border: 1px solid var(--border); cursor: pointer;
  padding: 8px 14px; border-radius: 6px; font-weight: 600;
  min-height: 40px; align-items: center; justify-content: center;
  font-family: var(--font-sans); transition: 0.2s;
}
.mobile-back-btn:active { background: var(--bg-active); }

/* ==================== GENERIC UI ==================== */
.page-container { padding: 32px; max-width: 1000px; margin: 0 auto; width: 100%; position: relative; z-index: 10; overflow-y: auto; height: 100%; }
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 8px; }
.page-header h2 { font-family: var(--font-serif); font-size: 22px; 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: border-color var(--motion-fast), box-shadow var(--motion-fast), transform var(--motion-fast); background: white; color: var(--text-main); }
.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: background var(--motion-fast), color var(--motion-fast), box-shadow var(--motion-fast), transform var(--motion-fast); }
.btn-sm { padding: 6px 12px; font-size: 12px; }
.btn-primary { background: var(--primary); color: white; }
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-sm); }
.btn:active { transform: translateY(0); box-shadow: none; }
.btn-primary:hover { background: #322a44; }
.btn-secondary { background: #e6e2e8; color: var(--text-main); }
.btn-danger { background: #e06c75; color: white; }

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  color: var(--text-muted);
  font-size: 12px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.85);
}
.pager:empty { display: none; }
.pager-actions { display: flex; align-items: center; gap: 4px; }
.pager-btn {
  min-width: 30px;
  height: 30px;
  border: 1px solid var(--border);
  background: white;
  color: var(--text-main);
  border-radius: 6px;
  cursor: pointer;
  font-family: var(--font-sans);
  font-size: 12px;
  font-weight: 700;
  transition: background var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}
.pager-btn:hover:not(:disabled) { background: var(--bg-active); border-color: #ded5e8; transform: translateY(-1px); }
.pager-btn.active { background: var(--primary); border-color: var(--primary); color: white; }
.pager-btn:disabled { cursor: not-allowed; opacity: 0.45; }

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
.stat-card { background: white; border: 1px solid var(--border); border-radius: 10px; padding: 20px; text-align: center; transition: border-color var(--motion-fast), box-shadow var(--motion-fast), transform var(--motion-fast); }
.stat-card:hover { border-color: #e3dce9; box-shadow: 0 10px 28px rgba(61,55,69,0.07); transform: translateY(-2px); }
.stat-icon { font-size: 28px; margin-bottom: 8px; }
.stat-value { font-family: var(--font-serif); font-size: 28px; font-weight: 600; color: var(--primary); }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-weight: 600; }

.data-table-wrapper { background: white; border-radius: 8px; box-shadow: var(--shadow-sm); border: 1px solid var(--border); overflow: hidden; animation: soft-in 220ms var(--ease-out) both; }
.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 { display: flex; gap: 4px; }
.table-actions button { background: none; border: none; cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 4px; transition: background var(--motion-fast), transform var(--motion-fast); }
.table-actions button:hover { background: var(--bg-active); transform: translateY(-1px); }
.table-actions button.danger:hover { background: #fef2f2; }

.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: opacity var(--motion-fast); pointer-events: none;}
.modal-overlay.active { opacity: 1; pointer-events: all;}
.modal { background: white; padding: 24px; border-radius: 12px; width: 420px; max-width: 90%; box-shadow: 0 10px 25px rgba(0,0,0,0.1); transform: translateY(20px) scale(0.98); transition: transform var(--motion-normal); }
.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: 18px; 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; animation: toast-in 220ms var(--ease-out) both;}

.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); } }

@keyframes unread-pulse {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.65; }
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* 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; }

@media (max-width: 480px) {
  .auth-box { padding: 32px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}

/* ==================== DARK MODE: DISABLED ==================== */
/* Tema Frieren selalu cerah — tidak mengikuti dark mode device */
