:root{
  --navy: #0B3571;
  --navy-dark: #071F45;
  --navy-deeper: #051530;
  --gold: #C2903A;
  --gold-light: #E3B665;
  --cream: #F7F4EC;
  --paper: #FFFFFF;
  --ink: #16181C;
  --grey: #666B72;
  --grey-line: #E4E0D6;
  --danger: #B4432E;

  --font-display: 'Playfair Display', Georgia, serif;
  --font-body: 'Work Sans', -apple-system, BlinkMacSystemFont, sans-serif;
  --font-label: 'Space Grotesk', 'Work Sans', sans-serif;
}

*,*::before,*::after{ box-sizing:border-box; }
html,body{ height:100%; }
body{
  margin:0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  -webkit-font-smoothing: antialiased;
}
button{ font-family:inherit; }
.hidden{ display:none !important; }

/* ============ LOGIN ============ */
.login-view{
  min-height:100vh;
  min-height:100dvh;
  display:flex;
  align-items:center;
  justify-content:center;
  padding: 24px;
  background: linear-gradient(160deg, var(--navy) 0%, var(--navy-dark) 100%);
}
.login-card{
  width:100%;
  max-width: 360px;
  background: #fff;
  border-radius: 6px;
  padding: 40px 32px;
  display:flex;
  flex-direction:column;
  align-items:center;
  text-align:center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
}
.login-logo{ width: 88px; height:auto; margin-bottom: 18px; }
.login-card h1{ font-family: var(--font-display); font-size: 1.5rem; margin:0 0 6px; color: var(--navy); }
.login-sub{ color: var(--grey); font-size: 0.92rem; margin: 0 0 26px; }
.login-card label{
  align-self:flex-start;
  font-family: var(--font-label);
  font-size: 0.82rem;
  font-weight:600;
  margin-bottom: 8px;
}
.login-card input{
  width:100%;
  font-size: 1rem;
  padding: 13px 14px;
  border: 1.5px solid var(--grey-line);
  border-radius: 4px;
  margin-bottom: 20px;
}
.login-card input:focus{ outline:none; border-color: var(--navy); }
.login-card .btn{ width:100%; border:none; cursor:pointer; padding: 14px; font-weight:600; border-radius:4px; }
.login-error{
  color: var(--danger);
  font-size: 0.88rem;
  margin: 14px 0 0;
  min-height: 1.2em;
}
.btn-gold{ background: var(--gold); color: var(--navy-deeper); }
.btn-gold:hover{ background: var(--gold-light); }

/* ============ APP SHELL ============ */
.app-view{
  min-height:100vh;
  min-height:100dvh;
  display:flex;
  flex-direction:column;
}
.app-header{
  display:flex;
  align-items:center;
  justify-content:space-between;
  padding: 14px 18px;
  padding-top: max(14px, env(safe-area-inset-top));
  background: var(--navy-dark);
  color:#fff;
}
.app-header-brand{ display:flex; align-items:center; gap:10px; }
.app-header-brand img{ width: 30px; height:30px; object-fit:contain; border-radius:3px; }
.app-header-brand span{ font-family: var(--font-label); font-weight:600; font-size: 0.98rem; }
.app-header-actions{ display:flex; gap: 6px; }
.icon-btn{
  width: 38px; height:38px;
  border-radius: 50%;
  border:none;
  background: rgba(255,255,255,0.08);
  color:#fff;
  display:flex; align-items:center; justify-content:center;
  cursor:pointer;
  transition: background .15s ease;
}
.icon-btn:hover{ background: rgba(255,255,255,0.18); }

.toolbar{
  display:flex;
  align-items:center;
  padding: 12px 18px;
  background:#fff;
  border-bottom: 1px solid var(--grey-line);
}
.filter-tabs{ display:flex; gap: 6px; }
.filter-tab{
  border:none;
  background: transparent;
  padding: 8px 16px;
  border-radius: 999px;
  font-family: var(--font-label);
  font-size: 0.85rem;
  font-weight:600;
  color: var(--grey);
  cursor:pointer;
  display:flex;
  align-items:center;
  gap:6px;
}
.filter-tab.active{ background: var(--navy); color:#fff; }
.unread-count{
  background: var(--gold);
  color: var(--navy-deeper);
  border-radius: 999px;
  font-size: 0.72rem;
  padding: 1px 7px;
  min-width: 18px;
  text-align:center;
}
.filter-tab.active .unread-count{ background: var(--gold-light); }
.unread-count:empty{ display:none; }

.inbox-layout{
  flex:1;
  display:grid;
  grid-template-columns: 340px 1fr;
  min-height:0;
}

/* ---- message list ---- */
.message-list-pane{
  border-right: 1px solid var(--grey-line);
  overflow-y:auto;
  background:#fff;
}
.message-list{ list-style:none; margin:0; padding:0; }
.message-item{
  padding: 16px 18px;
  border-bottom: 1px solid var(--grey-line);
  cursor:pointer;
  display:flex;
  flex-direction:column;
  gap: 4px;
  position:relative;
}
.message-item:hover{ background: var(--cream); }
.message-item.selected{ background: var(--cream); box-shadow: inset 3px 0 0 var(--gold); }
.message-item.unread::before{
  content:"";
  position:absolute;
  left: 6px; top: 22px;
  width:8px; height:8px;
  border-radius:50%;
  background: var(--gold);
}
.message-item{ padding-left: 24px; }
.mi-top{ display:flex; justify-content:space-between; align-items:baseline; gap: 8px; }
.mi-name{ font-family: var(--font-label); font-weight:600; font-size: 0.95rem; color: var(--navy); }
.message-item.unread .mi-name{ color: var(--ink); font-weight:700; }
.mi-time{ font-size: 0.75rem; color: var(--grey); white-space:nowrap; }
.mi-meta{ font-size: 0.8rem; color: var(--grey); }
.mi-preview{ font-size: 0.85rem; color:#444; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }

.empty-state{ text-align:center; color: var(--grey); padding: 40px 20px; }

/* ---- detail pane ---- */
.message-detail-pane{ overflow-y:auto; background: var(--cream); }
.back-btn{
  display:none;
  border:none;
  background:none;
  color: var(--navy);
  font-family: var(--font-label);
  font-weight:600;
  font-size: 0.9rem;
  padding: 14px 18px 0;
  cursor:pointer;
}
.message-detail{ padding: 26px 28px 60px; max-width: 720px; }
.detail-placeholder{ color: var(--grey); text-align:center; margin-top: 60px; }
.detail-header{ margin-bottom: 22px; }
.detail-name{ font-family: var(--font-display); font-size: 1.6rem; color: var(--navy); margin: 0 0 6px; }
.detail-time{ color: var(--grey); font-size: 0.85rem; }
.detail-facts{
  display:grid;
  grid-template-columns: repeat(auto-fit, minmax(180px,1fr));
  gap: 14px;
  background:#fff;
  border: 1px solid var(--grey-line);
  border-radius: 6px;
  padding: 18px 20px;
  margin-bottom: 22px;
}
.df-label{ font-family: var(--font-label); font-size: 0.7rem; letter-spacing: 0.08em; text-transform:uppercase; color: var(--gold); font-weight:600; display:block; margin-bottom: 3px; }
.df-value{ font-size: 0.95rem; word-break: break-word; }
.df-value a{ color: var(--navy); }
.detail-message{
  background:#fff;
  border: 1px solid var(--grey-line);
  border-radius: 6px;
  padding: 20px 22px;
  white-space: pre-wrap;
  font-size: 0.98rem;
  line-height:1.7;
  margin-bottom: 22px;
}
.detail-actions{ display:flex; gap: 12px; flex-wrap:wrap; }
.detail-actions button{
  border: 1.5px solid var(--grey-line);
  background:#fff;
  padding: 10px 18px;
  border-radius: 4px;
  font-family: var(--font-label);
  font-size: 0.85rem;
  font-weight:600;
  cursor:pointer;
  color: var(--ink);
}
.detail-actions button:hover{ border-color: var(--navy); }
.detail-actions .danger{ color: var(--danger); border-color: rgba(180,67,46,0.4); }
.detail-actions .danger:hover{ border-color: var(--danger); background: rgba(180,67,46,0.06); }

/* ============ RESPONSIVE / MOBILE ============ */
@media (max-width: 820px){
  .inbox-layout{ grid-template-columns: 1fr; }
  .message-list-pane{ border-right:none; }
  .message-detail-pane{ display:none; }
  .inbox-layout.detail-open .message-list-pane{ display:none; }
  .inbox-layout.detail-open .message-detail-pane{ display:block; }
  .back-btn{ display:block; }
  .message-detail{ padding: 16px 18px 60px; }
}

@media (max-width: 480px){
  .login-card{ padding: 32px 22px; }
  .app-header-brand span{ display:none; }
  .toolbar{ padding: 10px 14px; }
}
