/* ── Variables ───────────────────────────────────────────────────────────── */
:root {
  --navy:          #0D2E72;
  --primary:       #2D69E3;
  --primary-h:     #2558c5;
  --surface:       #F4F5F7;
  --border:        #e4e8ef;
  --text:          #1a202c;
  --muted:         #697EA8;
  --success:       #1BC267;
  --success-bg:    #e8faf1;
  --warning:       #F4B804;
  --warning-bg:    #fef9e7;
  --danger:        #E85531;
  --danger-bg:     #fdf2ef;
  --sidebar-w:     224px;
  --radius:        10px;
}

/* ── Reset ───────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
       font-size: 14px; color: var(--text); background: var(--surface); }
a { color: inherit; text-decoration: none; }
button { cursor: pointer; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
svg { display: block; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--navy);
  position: fixed; top: 0; left: 0; height: 100vh;
  display: flex; flex-direction: column;
  overflow-y: auto; z-index: 100;
  flex-shrink: 0;
}

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex; flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 56px; background: white;
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.topbar-title { font-size: 16px; font-weight: 600; color: var(--navy); }
.topbar-user  { font-size: 13px; color: var(--muted); }

.content { padding: 24px; flex: 1; }

/* ── Sidebar ─────────────────────────────────────────────────────────────── */
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px 12px;
  color: white; font-weight: 700; font-size: 16px;
}
.sidebar-nav { padding: 8px 10px; flex: 1; }
.nav-section {
  font-size: 10px; font-weight: 600;
  color: rgba(255,255,255,.35);
  letter-spacing: .08em; text-transform: uppercase;
  padding: 14px 10px 5px;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px; border-radius: 8px;
  color: rgba(255,255,255,.65);
  font-size: 13.5px; font-weight: 500;
  transition: background .13s, color .13s;
  margin-bottom: 1px;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: rgba(255,255,255,.1); color: white; }
.nav-item.active { background: rgba(255,255,255,.15); color: white; }
.sidebar-footer { padding: 12px 10px; border-top: 1px solid rgba(255,255,255,.1); }
.logout-btn {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 10px; border-radius: 8px;
  background: none; border: none;
  color: rgba(255,255,255,.55); font-size: 13px;
  transition: background .13s, color .13s;
}
.logout-btn:hover { background: rgba(255,255,255,.1); color: white; }

/* ── Page header ─────────────────────────────────────────────────────────── */
.page-header { margin-bottom: 24px; }
.page-header h1 { font-size: 20px; font-weight: 700; color: var(--navy); margin: 0 0 2px; }
.page-header p  { font-size: 13px; color: var(--muted); margin: 0; }
.page-header-row { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card { background: white; border-radius: var(--radius); border: 1px solid var(--border); }
.card-body { padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between;
               padding: 16px 20px; border-bottom: 1px solid var(--border); }
.card-title { font-size: 14px; font-weight: 600; color: var(--navy); margin: 0; }

/* ── KPI ─────────────────────────────────────────────────────────────────── */
.kpi-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; margin-bottom: 24px; }
.kpi-card { background: white; border-radius: var(--radius); border: 1px solid var(--border); padding: 20px; }
.kpi-label { font-size: 11.5px; font-weight: 600; color: var(--muted); text-transform: uppercase;
             letter-spacing: .05em; margin-bottom: 8px; }
.kpi-value { font-size: 30px; font-weight: 700; color: var(--navy); line-height: 1; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 8px; border: none;
  font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: background .13s, opacity .13s;
  white-space: nowrap; text-decoration: none;
}
.btn-sm  { padding: 5px 11px; font-size: 12.5px; }
.btn-xs  { padding: 3px 8px;  font-size: 12px; border-radius: 6px; }
.btn svg { width: 14px; height: 14px; }

.btn-primary         { background: var(--primary);  color: white; }
.btn-primary:hover   { background: var(--primary-h); }
.btn-secondary       { background: white; color: var(--navy); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--surface); }
.btn-danger          { background: var(--danger);  color: white; }
.btn-danger:hover    { background: #cc3e22; }
.btn-ghost           { background: transparent; color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover     { background: var(--surface); color: var(--navy); }
.btn:disabled        { opacity: .55; cursor: not-allowed; }
.w-full              { width: 100%; }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 99px;
  font-size: 11.5px; font-weight: 500; white-space: nowrap;
}
.badge-success { background: var(--success-bg); color: #0e8c47; }
.badge-warning { background: var(--warning-bg); color: #9a7400; }
.badge-danger  { background: var(--danger-bg);  color: #b83d1f; }
.badge-info    { background: #eff4ff; color: var(--primary); }
.badge-gray    { background: #f0f2f5; color: var(--muted); }
.badge-navy    { background: #e8eef9; color: var(--navy); }

/* ── Table ───────────────────────────────────────────────────────────────── */
.table-wrap { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: white; }
table       { width: 100%; border-collapse: collapse; }
thead tr    { background: var(--surface); border-bottom: 1px solid var(--border); }
th          { padding: 10px 14px; font-size: 11.5px; font-weight: 600; color: var(--muted);
              text-align: left; text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
td          { padding: 11px 14px; font-size: 13.5px; color: var(--text); border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.td-mono    { font-family: 'Menlo','Monaco','Cascadia Code',monospace; font-size: 12px; }

/* ── Forms ───────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 500; color: var(--navy); margin-bottom: 5px; }
.form-input {
  width: 100%; padding: 9px 12px;
  border: 1px solid var(--border); border-radius: 8px;
  font-size: 13.5px; color: var(--text); background: white;
  outline: none; transition: border-color .13s, box-shadow .13s;
}
.form-input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,105,227,.12); }
.form-select { appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23697EA8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }
textarea.form-input { resize: vertical; min-height: 90px; }
.form-error { font-size: 12px; color: var(--danger); margin-top: 4px; }
.form-hint  { font-size: 12px; color: var(--muted); margin-top: 4px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

/* ── Filter bar ──────────────────────────────────────────────────────────── */
.filter-bar { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; align-items: center; }
.filter-bar .form-input { height: 36px; padding-top: 0; padding-bottom: 0; width: auto; }
.filter-bar .form-select { height: 36px; padding-top: 0; padding-bottom: 0; }
.search-wrap { position: relative; }
.search-wrap .form-input { padding-left: 32px; }
.search-icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; width: 14px; height: 14px; }

/* ── Pagination ──────────────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; justify-content: space-between;
              padding: 10px 14px; border-top: 1px solid var(--border); background: white; }
.pagination-info { font-size: 13px; color: var(--muted); }
.pagination-btns { display: flex; gap: 6px; }

/* ── Alerts ──────────────────────────────────────────────────────────────── */
.alert { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.alert-error   { background: var(--danger-bg);  color: var(--danger); border: 1px solid rgba(232,85,49,.2); }
.alert-success { background: var(--success-bg); color: #0e8c47; border: 1px solid rgba(27,194,103,.2); }
.alert-info    { background: #eff4ff; color: var(--primary); border: 1px solid rgba(45,105,227,.2); }
.alert-warning { background: var(--warning-bg); color: #9a7400; border: 1px solid rgba(244,184,4,.2); }

/* ── Modals (native <dialog>) ────────────────────────────────────────────── */
dialog {
  border: none; border-radius: 16px; padding: 0;
  width: 100%; max-width: 540px;
  box-shadow: 0 8px 40px rgba(0,0,0,.18);
  overflow: hidden;
}
dialog::backdrop { background: rgba(0,0,0,.45); }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; color: var(--navy); margin: 0; }
.modal-close { background: none; border: none; padding: 4px; border-radius: 6px;
               color: var(--muted); display: flex; align-items: center; }
.modal-close:hover { background: var(--surface); color: var(--navy); }
.modal-body { padding: 20px 24px; }
.modal-footer { padding: 16px 24px 20px; border-top: 1px solid var(--border);
                display: flex; justify-content: flex-end; gap: 10px; }

/* ── Dropdown ────────────────────────────────────────────────────────────── */
.dropdown { position: relative; display: inline-block; }
.dropdown-menu {
  display: none; position: absolute; right: 0; top: calc(100% + 4px);
  background: white; border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 4px 20px rgba(0,0,0,.1); min-width: 180px; z-index: 40; padding: 4px;
}
.dropdown.open .dropdown-menu { display: block; }
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border-radius: 7px;
  font-size: 13.5px; color: var(--text);
  cursor: pointer; background: none; border: none; width: 100%;
}
.dropdown-item:hover { background: var(--surface); }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: var(--danger-bg); }
.dropdown-item svg { width: 14px; height: 14px; flex-shrink: 0; }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Empty state ─────────────────────────────────────────────────────────── */
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center;
         padding: 60px 24px; color: var(--muted); text-align: center; }
.empty svg { opacity: .2; margin-bottom: 12px; width: 48px; height: 48px; }
.empty p { margin: 0; font-size: 14px; }

/* ── Skeleton ────────────────────────────────────────────────────────────── */
.skeleton { background: linear-gradient(90deg,#f0f0f0 25%,#e8e8e8 50%,#f0f0f0 75%);
            background-size: 200% 100%; animation: ske 1.4s infinite; border-radius: 6px; }
@keyframes ske { 0%{background-position:200% 0} 100%{background-position:-200% 0} }

/* ── Avatar ──────────────────────────────────────────────────────────────── */
.avatar { display: inline-flex; align-items: center; justify-content: center;
          width: 30px; height: 30px; border-radius: 50%;
          font-size: 11px; font-weight: 600; flex-shrink: 0; }
.avatar-navy { background: #e8eef9; color: var(--navy); }

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-body { display: flex; align-items: center; justify-content: center;
              min-height: 100vh; padding: 16px; background: var(--surface); }
.login-card { background: white; border-radius: 16px; border: 1px solid var(--border);
              width: 100%; max-width: 360px; padding: 32px 28px; }
.login-logo { display: flex; justify-content: center; margin-bottom: 12px; }
.login-title    { font-size: 20px; font-weight: 700; color: var(--navy); text-align: center; margin: 0 0 4px; }
.login-subtitle { font-size: 13px; color: var(--muted); text-align: center; margin: 0 0 24px; }

/* ── Activity / SSE ──────────────────────────────────────────────────────── */
.event-list { display: flex; flex-direction: column; gap: 6px; }
.event-item { display: flex; align-items: flex-start; gap: 12px; padding: 10px 14px;
              background: white; border-radius: var(--radius); border: 1px solid var(--border); }
.event-dot { width: 8px; height: 8px; border-radius: 50%; margin-top: 5px; flex-shrink: 0; }
.event-dot-info    { background: var(--primary); }
.event-dot-error   { background: var(--danger); }
.event-dot-success { background: var(--success); }
.event-dot-warning { background: var(--warning); }
.event-time { font-size: 11.5px; color: var(--muted); white-space: nowrap; margin-top: 1px; }
.event-msg  { font-size: 13px; color: var(--navy); flex: 1; }

/* ── Email ───────────────────────────────────────────────────────────────── */
.email-layout { display: flex; height: calc(100vh - 56px); overflow: hidden; }
.email-sidebar { width: 300px; flex-shrink: 0; border-right: 1px solid var(--border);
                 background: white; display: flex; flex-direction: column; overflow: hidden; }
.email-list { flex: 1; overflow-y: auto; }
.thread-item { display: flex; align-items: flex-start; gap: 10px; padding: 12px 14px;
               border-bottom: 1px solid var(--border); cursor: pointer;
               transition: background .12s; text-decoration: none; color: inherit; }
.thread-item:hover { background: var(--surface); }
.thread-item.active { background: #eff4ff; border-left: 2px solid var(--primary); padding-left: 12px; }
.thread-item.unread .thread-from { font-weight: 600; color: var(--navy); }
.thread-item.unread .thread-subject { font-weight: 500; color: var(--text); }
.thread-from    { font-size: 12.5px; color: var(--muted); }
.thread-subject { font-size: 13px; color: var(--text); truncate: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.thread-meta    { font-size: 11px; color: var(--muted); white-space: nowrap; }
.email-main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.email-toolbar { display: flex; align-items: center; gap: 10px; padding: 14px 20px;
                 border-bottom: 1px solid var(--border); background: white; flex-shrink: 0; }
.messages { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 12px; }
.msg-card { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: white; }
.msg-header { display: flex; align-items: center; gap: 10px; padding: 12px 16px;
              cursor: pointer; user-select: none; }
.msg-header:hover { background: var(--surface); }
.msg-from { font-size: 13px; font-weight: 500; color: var(--navy); flex: 1; }
.msg-date { font-size: 11.5px; color: var(--muted); }
.msg-body { padding: 16px; border-top: 1px solid var(--border); }
.msg-body pre { margin: 0; white-space: pre-wrap; font-family: inherit; font-size: 13.5px; line-height: 1.6; }
.msg-body iframe { width: 100%; border: none; min-height: 80px; }
.reply-box { flex-shrink: 0; border-top: 1px solid var(--border); background: white; padding: 12px 20px 16px; }
.reply-box textarea.form-input { min-height: 80px; }

/* ── Utilities ───────────────────────────────────────────────────────────── */
.flex            { display: flex; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.ml-auto { margin-left: auto; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-4 { margin-bottom: 16px; }
.mb-6 { margin-bottom: 24px; }
.text-xs   { font-size: 11.5px; }
.text-sm   { font-size: 13px; }
.text-muted { color: var(--muted); }
.text-navy  { color: var(--navy); }
.text-danger { color: var(--danger); }
.font-mono  { font-family: 'Menlo','Monaco','Cascadia Code',monospace; }
.font-semibold { font-weight: 600; }
.truncate { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hidden { display: none !important; }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main    { margin-left: 0; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .grid-2   { grid-template-columns: 1fr; }
}

/* ── Scrollbar ───────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(0,0,0,.15); border-radius: 3px; }
