/* ===========================================================
   ConnectPortal — app styling layered on the MailSafe design system.
   Design tokens (colors, fonts, buttons, cards, forms) come from mailsafe.css.
   =========================================================== */

body { background: var(--bg-soft); }

/* ---------- app top bar ---------- */
.app-header {
  position: sticky; top: 0; z-index: 60;
  background: var(--grad-deep); color: #fff;
  box-shadow: 0 6px 24px rgba(13,35,64,.18);
}
.app-header .nav { display: flex; align-items: center; justify-content: space-between; height: 66px; gap: 24px; }
.app-header .brand img { height: 34px; width: auto; }
.app-header .nav-links { display: flex; align-items: center; gap: 4px; list-style: none; margin: 0; padding: 0; }
.app-header .nav-links a {
  font-family: var(--font-head); font-weight: 600; font-size: .95rem;
  color: rgba(255,255,255,.82); padding: .5em .95em; border-radius: var(--r-pill);
  transition: background .2s, color .2s;
}
.app-header .nav-links a:hover { background: rgba(255,255,255,.12); color: #fff; }
.app-header .nav-links a.active { background: rgba(255,255,255,.16); color: #fff; }
.app-user { display: flex; align-items: center; gap: 14px; }
.app-user .who { font-family: var(--font-head); font-weight: 600; font-size: .92rem; color: #fff; }
.app-user .who small { display: block; font-weight: 500; font-size: .76rem; color: rgba(255,255,255,.62); max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.btn-logout {
  background: rgba(255,255,255,.14); color: #fff; border: 1px solid rgba(255,255,255,.3);
  font-family: var(--font-head); font-weight: 700; font-size: .9rem;
  padding: .5em 1.1em; border-radius: var(--r-pill); cursor: pointer; transition: background .2s;
}
.btn-logout:hover { background: rgba(255,255,255,.26); }

/* ---------- profile dropdown ---------- */
.profile { position: relative; }
.profile-btn {
  display: flex; align-items: center; gap: 10px; color: #fff;
  background: rgba(255,255,255,.10); border: 1px solid rgba(255,255,255,.24);
  border-radius: var(--r-pill); padding: .38em .8em .38em .95em; cursor: pointer;
  transition: background .2s;
}
.profile-btn:hover { background: rgba(255,255,255,.2); }
.profile-caret { opacity: .85; transition: transform .2s; }
.profile.open .profile-caret { transform: rotate(180deg); }
.profile-menu {
  position: absolute; right: 0; top: calc(100% + 10px); min-width: 216px;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r-sm);
  box-shadow: 0 14px 34px rgba(13,35,64,.18); padding: 6px; z-index: 80;
  opacity: 0; visibility: hidden; transform: translateY(-6px);
  transition: opacity .16s ease, transform .16s ease, visibility .16s;
}
.profile.open .profile-menu { opacity: 1; visibility: visible; transform: translateY(0); }
.profile-menu form { margin: 0; }
.profile-item {
  display: block; width: 100%; box-sizing: border-box; text-align: left;
  font-family: var(--font-head); font-weight: 600; font-size: .9rem; color: var(--navy);
  background: none; border: none; cursor: pointer; text-decoration: none;
  padding: .62em .85em; border-radius: 9px;
}
.profile-item:hover { background: var(--bg-soft); }
.profile-signout { color: var(--red); }
.profile-divider { height: 1px; background: var(--line); margin: 6px; }
.profile-head { padding: 4px 10px 10px; }
.profile-head-name { font-family: var(--font-head); font-weight: 700; color: var(--navy); font-size: .95rem; }
.profile-head-email { color: var(--muted); font-size: .82rem; margin-top: 2px; word-break: break-all; }
.profile-head-role { color: var(--muted-2); font-size: .78rem; margin-top: 4px; }

/* ---------- modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(13,35,64,.55);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  opacity: 0; visibility: hidden; transition: opacity .18s ease, visibility .18s; z-index: 200;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal-box {
  background: #fff; border-radius: var(--r); box-shadow: 0 24px 60px rgba(13,35,64,.32);
  width: 100%; max-width: 430px; padding: 26px 28px;
  transform: translateY(-12px) scale(.98); transition: transform .18s ease;
}
.modal-overlay.open .modal-box { transform: translateY(0) scale(1); }
.modal-title { font-family: var(--font-head); font-weight: 800; color: var(--navy); font-size: 1.18rem; margin: 0 0 8px; }
.modal-text { color: var(--muted); margin: 0; font-size: .95rem; line-height: 1.5; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.modal-actions form { margin: 0; }

/* ---------- app content ---------- */
.app-main { max-width: var(--maxw); margin: 0 auto; padding: 34px 24px; }
.page-title { font-family: var(--font-head); color: var(--navy); font-weight: 800; margin: 0 0 4px; }
.page-sub { color: var(--muted); margin: 0 0 26px; }

/* panel = card surface for app sections */
.panel {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--sh-sm); padding: 26px;
}

/* ---------- auth (login) screen ---------- */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background:
    radial-gradient(1100px 540px at 78% -8%, rgba(91,192,235,.20), transparent 60%),
    radial-gradient(900px 600px at 6% 12%, rgba(47,128,214,.12), transparent 55%),
    linear-gradient(180deg,#f7fbff 0%,#eef4fb 100%);
}
.auth-card {
  width: 100%; max-width: 410px; background: #fff;
  border: 1px solid var(--line); border-radius: var(--r-lg);
  box-shadow: var(--sh-lg); padding: 38px 34px;
}
.auth-card .auth-logo { display: grid; place-items: center; margin-bottom: 6px; }
.auth-card .auth-logo img { height: 46px; width: auto; }
.auth-title { text-align: center; font-family: var(--font-head); color: var(--navy); font-weight: 800; font-size: 1.4rem; margin: 14px 0 2px; }
.auth-sub { text-align: center; color: var(--muted); font-size: .94rem; margin: 0 0 24px; }
.auth-foot { text-align: center; color: var(--muted-2); font-size: .8rem; margin-top: 22px; }

/* ---------- forms in app ---------- */
.form-stack { display: grid; gap: 16px; }
.form-stack .field { display: flex; flex-direction: column; gap: 7px; }
.form-stack label { font-family: var(--font-head); font-weight: 600; font-size: .88rem; color: var(--navy); }
.form-stack input, .form-stack select {
  font-family: var(--font); font-size: 1rem; color: var(--ink);
  padding: .72em 1em; border: 1px solid var(--line-2); border-radius: var(--r-sm);
  background: var(--bg-soft); transition: border-color .2s, box-shadow .2s, background .2s;
}
.form-stack input:focus, .form-stack select:focus {
  outline: none; border-color: var(--blue); background: #fff;
  box-shadow: 0 0 0 4px rgba(47,128,214,.12);
}
.field-error { color: var(--red); font-size: .84rem; }
.alert { border-radius: var(--r-sm); padding: .8em 1em; font-size: .92rem; margin-bottom: 16px; }
.alert-error { background: #fde9ea; color: #a31218; border: 1px solid #f5c2c5; }
.alert-success { background: #e6f6ee; color: #14653b; border: 1px solid #bce4cd; }

/* ---------- data table ---------- */
.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; }
table.data thead th {
  font-family: var(--font-head); font-weight: 700; font-size: .78rem; letter-spacing: .04em;
  text-transform: uppercase; color: var(--muted-2); text-align: left;
  padding: 12px 14px; border-bottom: 1px solid var(--line);
}
table.data tbody td { padding: 14px; border-bottom: 1px solid var(--line); color: var(--ink); font-size: .96rem; }
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: var(--bg-soft); }

.badge { display: inline-flex; align-items: center; gap: .4em; font-family: var(--font-head); font-weight: 700; font-size: .76rem; padding: .35em .8em; border-radius: var(--r-pill); }
.badge-active { background: #e6f6ee; color: #14653b; }
.badge-inactive { background: #eef1f5; color: var(--muted); }
.role-chip { font-family: var(--font-head); font-weight: 600; font-size: .82rem; color: var(--blue-700); background: var(--bg-soft-2); border: 1px solid var(--line-2); padding: .3em .75em; border-radius: var(--r-pill); }

.btn-sm { padding: .45em 1em; font-size: .85rem; }
.btn-danger { background: #fff; color: var(--red); border: 1px solid #f3c4c7; }
.btn-danger:hover { background: #fde9ea; color: var(--red); transform: translateY(-1px); }
.btn-success { background: #fff; color: #14653b; border: 1px solid #bce4cd; }
.btn-success:hover { background: #e6f6ee; color: #14653b; transform: translateY(-1px); }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; }

/* ---------- dashboard KPI stat cards ---------- */
.section-head { font-family: var(--font-head); color: var(--navy); font-weight: 700; font-size: 1.05rem; margin: 6px 0 12px; }
.stat-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 16px; max-width: 860px; margin-bottom: 22px;
}
.stat-card {
  display: block; text-decoration: none;
  background: #fff; border: 1px solid var(--line); border-radius: var(--r);
  box-shadow: var(--sh-sm); padding: 20px 22px;
  border-left: 4px solid var(--blue);
  transition: transform .15s, box-shadow .15s;
}
a.stat-card:hover { transform: translateY(-2px); box-shadow: var(--sh-lg); }
.stat-card.overdue { border-left-color: var(--red); }
.stat-card.warn { border-left-color: #e8a317; }
.stat-card.muted { border-left-color: var(--line-2); }
.stat-num { font-family: var(--font-head); font-weight: 800; font-size: 1.3rem; line-height: 1.1; color: var(--navy); overflow-wrap: anywhere; }
.stat-card.overdue .stat-num { color: var(--red); }
.stat-label { color: var(--muted); font-size: .84rem; margin-top: 8px; }

/* ---------- renewal chart (dashboard) ---------- */
.chart {
  display: flex; align-items: flex-end; gap: 14px;
  height: 220px; padding: 8px 4px 0;
}
.chart-col { flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 8px; min-width: 0; text-decoration: none; cursor: pointer; }
.chart-col:hover .chart-bar { filter: brightness(1.08); transform: scaleY(1.02); transform-origin: bottom; }
.chart-col:hover .chart-count { color: var(--blue); }
.chart-count { font-family: var(--font-head); font-weight: 700; font-size: .9rem; color: var(--navy); }
.chart-bar {
  width: 100%; max-width: 46px; border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, var(--blue) 0%, var(--blue-700) 100%);
  transition: height .3s ease;
}
.chart-bar.overdue { background: linear-gradient(180deg, #f0606a 0%, var(--red) 100%); }
.chart-label {
  font-family: var(--font-head); font-weight: 600; font-size: .76rem; color: var(--muted);
  text-align: center; white-space: nowrap;
}

/* ---------- expiring drill-down list ---------- */
.expiry-list { display: grid; gap: 16px; max-width: 920px; }
.expiry-card { padding: 22px 24px; }
.expiry-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; }
.expiry-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px 28px; }
.expiry-grid .k { color: var(--muted); font-size: .78rem; margin-bottom: 2px; }
@media (max-width: 720px) { .expiry-grid { grid-template-columns: 1fr 1fr; } }
