:root {
  --navy: #0B1F3A;
  --navy-light: #132C54;
  --gold: #C89B3C;
  --gold-light: #E8B84B;
  --green: #1A7A4A;
  --green-light: #22A35F;
  --red: #C0392B;
  --bg: #F4F6FA;
  --card-bg: #FFFFFF;
  --text: #1A2332;
  --text-muted: #5A6B80;
  --border: #D8E0EB;
  --shadow: 0 2px 12px rgba(11,31,58,0.08);
  --shadow-hover: 0 8px 28px rgba(11,31,58,0.14);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  background-image: radial-gradient(circle at 50% -10%, rgba(11,31,58,0.05) 0%, transparent 45%);
  background-repeat: no-repeat;
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* ── LOGIN PAGE (split-screen) ── */
#login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 1fr;
}

.login-brand {
  background: linear-gradient(150deg, var(--navy) 0%, var(--navy-light) 55%, #1B3A6E 100%);
  color: white;
  display: flex; align-items: center;
  padding: 56px;
  position: relative; overflow: hidden;
}

.login-brand::before {
  content: ''; position: absolute; top: -120px; right: -120px;
  width: 440px; height: 440px;
  background: radial-gradient(circle, rgba(200,155,60,0.18) 0%, transparent 70%);
  border-radius: 50%;
}

.login-brand::after {
  content: ''; position: absolute; bottom: -100px; left: -100px;
  width: 340px; height: 340px;
  background: radial-gradient(circle, rgba(26,122,74,0.14) 0%, transparent 70%);
  border-radius: 50%;
}

.login-brand-inner { position: relative; z-index: 1; max-width: 440px; }

.login-logo { display: flex; align-items: center; gap: 12px; margin-bottom: 44px; }
.login-logo .logo-mark {
  width: 40px; height: 40px; background: var(--gold); border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--navy); font-size: 17px;
}
.login-logo span { font-size: 18px; font-weight: 600; letter-spacing: 0.3px; }

.login-brand h1 { font-size: 34px; font-weight: 800; line-height: 1.15; margin-bottom: 14px; letter-spacing: -0.5px; }
.login-brand p { color: rgba(255,255,255,0.72); font-size: 15px; line-height: 1.6; max-width: 380px; }

.login-panel {
  display: flex; align-items: center; justify-content: center;
  padding: 40px 24px; background: var(--bg);
}

.login-body { width: 100%; max-width: 420px; }

.login-card {
  background: var(--card-bg);
  border-radius: 16px;
  box-shadow: var(--shadow-hover);
  padding: 36px;
  width: 100%;
  max-width: 420px;
  border: 1px solid var(--border);
}

.login-card h2 {
  font-size: 20px; font-weight: 700; margin-bottom: 6px; color: var(--navy);
}

.login-card .sub { color: var(--text-muted); font-size: 14px; margin-bottom: 28px; }

.login-error {
  display: none;
  background: #FDEDEB; color: var(--red); border: 1px solid #F2C4BE;
  border-radius: 8px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px;
}

.login-error.show { display: block; }

.form-group { margin-bottom: 18px; }

.form-group label {
  display: block; font-size: 13px; font-weight: 600; color: var(--navy); margin-bottom: 6px;
}

.form-group input {
  width: 100%; padding: 11px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; color: var(--text);
  transition: border-color 0.2s;
  outline: none;
}

.form-group input:focus { border-color: var(--navy); }

.btn-primary {
  width: 100%; padding: 12px; background: var(--navy);
  color: white; border: none; border-radius: 8px;
  font-size: 15px; font-weight: 600; cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-primary:hover { background: var(--navy-light); }
.btn-primary:active { transform: scale(0.99); }
.btn-primary:disabled { opacity: 0.6; cursor: wait; }

.login-divider {
  text-align: center; color: var(--text-muted); font-size: 13px; margin: 20px 0;
  position: relative;
}

.login-divider::before, .login-divider::after {
  content: ''; position: absolute; top: 50%; width: 42%; height: 1px;
  background: var(--border);
}

.login-divider::before { left: 0; }
.login-divider::after { right: 0; }

.sso-btn {
  width: 100%; padding: 11px; background: white;
  border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 14px; font-weight: 500; cursor: pointer;
  display: flex; align-items: center; justify-content: center; gap: 10px;
  transition: border-color 0.2s, box-shadow 0.2s;
  color: var(--text);
}

.sso-btn:hover { border-color: var(--navy); box-shadow: 0 2px 8px rgba(0,0,0,0.06); }

.demo-section {
  background: #F0F4F9; border-radius: 12px; padding: 16px; margin-top: 24px;
  border: 1px dashed var(--border);
}

.demo-section p { font-size: 12px; color: var(--text-muted); margin-bottom: 10px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }

.demo-roles {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}

.demo-role-btn {
  padding: 8px 10px; border-radius: 7px; border: 1.5px solid var(--border);
  background: white; cursor: pointer; font-size: 12px; font-weight: 500;
  transition: all 0.15s; text-align: left; color: var(--text);
}

.demo-role-btn:hover { border-color: var(--navy); background: var(--navy); color: white; }

.demo-role-btn .role-title { font-weight: 600; display: block; }
.demo-role-btn .role-sub { color: var(--text-muted); font-size: 11px; }
.demo-role-btn:hover .role-sub { color: rgba(255,255,255,0.7); }

/* ── PORTAL ── */
#portal-page { display: none; min-height: 100vh; flex-direction: column; }

.portal-nav {
  background: var(--navy);
  padding: 0 32px;
  display: flex;
  align-items: center;
  gap: 20px;
  height: 60px;
  position: sticky; top: 0; z-index: 100;
}

.nav-logo {
  display: flex; align-items: center; gap: 10px; margin-right: auto;
}

.nav-logo .logo-mark {
  width: 32px; height: 32px; background: var(--gold); border-radius: 6px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: var(--navy); font-size: 14px; flex-shrink: 0;
}

.nav-logo span { color: white; font-size: 16px; font-weight: 600; }

.nav-badge {
  background: rgba(255,255,255,0.12); color: rgba(255,255,255,0.8);
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 500;
  border: 1px solid rgba(255,255,255,0.2);
}

.nav-user {
  display: flex; align-items: center; gap: 8px;
}

.nav-avatar {
  width: 32px; height: 32px; background: var(--gold); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; color: var(--navy); font-size: 13px;
}

.nav-user-info { text-align: right; }
.nav-user-info .name { color: white; font-size: 13px; font-weight: 600; }
.nav-user-info .role { color: rgba(255,255,255,0.55); font-size: 11px; }

.nav-logout {
  color: rgba(255,255,255,0.6); font-size: 13px; cursor: pointer;
  padding: 6px 12px; border-radius: 6px; transition: background 0.2s;
  background: none; border: none;
}

.nav-logout:hover { background: rgba(255,255,255,0.08); color: white; }

.nav-toggle {
  background: rgba(255,255,255,0.12); color: white; border: 1px solid rgba(255,255,255,0.25);
  font-size: 13px; font-weight: 600; cursor: pointer;
  padding: 6px 14px; border-radius: 6px; transition: background 0.2s;
}
.nav-toggle:hover { background: rgba(255,255,255,0.22); }

.portal-main { flex: 1; padding: 32px; max-width: 1200px; margin: 0 auto; width: 100%; }

.portal-welcome { margin-bottom: 28px; }

.portal-welcome h2 { font-size: 26px; font-weight: 800; color: var(--navy); margin-bottom: 4px; letter-spacing: -0.4px; }
.portal-welcome p { color: var(--text-muted); font-size: 14px; }

.access-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 12px; border-radius: 20px; font-size: 12px; font-weight: 600;
  margin-top: 10px;
}

.access-pill.full { background: #E8F5EE; color: var(--green); border: 1px solid #B5DFC8; }
.access-pill.limited { background: #FFF3E0; color: #B06000; border: 1px solid #FECB7A; }
.access-pill.custom { background: #E8EEF8; color: var(--navy); border: 1px solid #BDC9DF; }

.section-heading {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}

.section-heading h3 {
  display: flex; align-items: center; gap: 9px;
  font-size: 13px; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.6px; color: var(--navy);
}

/* ── Production / Development environment toggle ── */
.env-bar { display: flex; justify-content: flex-end; margin-bottom: 16px; }
.env-toggle {
  display: inline-flex; gap: 2px; padding: 3px;
  background: #EEF1F6; border: 1px solid #E0E5EC; border-radius: 9px;
}
.env-opt {
  border: 0; background: transparent; color: var(--text-muted);
  font: inherit; font-size: 12.5px; font-weight: 600;
  padding: 5px 14px; border-radius: 7px; cursor: pointer;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}
.env-opt:hover { color: var(--navy); }
.env-opt.active {
  background: #fff; color: var(--navy);
  box-shadow: 0 1px 3px rgba(11,31,58,0.12);
}

.section-heading h3::before {
  content: ''; width: 3px; height: 14px; border-radius: 2px;
  background: var(--gold);
}

/* ── APP GRID ── */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
  margin-bottom: 36px;
}

.app-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  cursor: pointer;
  transition: box-shadow 0.2s, transform 0.15s, border-color 0.2s;
  position: relative;
  text-decoration: none;
  color: inherit;
  display: block;
}

.app-card:hover {
  box-shadow: var(--shadow-hover);
  transform: translateY(-3px);
  border-color: var(--gold);
}

.app-icon {
  width: 50px; height: 50px; border-radius: 13px;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px; margin-bottom: 16px;
  box-shadow: inset 0 0 0 1px rgba(11,31,58,0.04);
  transition: transform 0.15s;
}

.app-card:hover .app-icon { transform: scale(1.05); }

.app-card-header {
  display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px;
}

.app-name { font-size: 15px; font-weight: 700; color: var(--navy); }
.app-name .env-tag { font-weight: 400; color: var(--text-muted); font-size: 12px; }
.app-desc { font-size: 13px; color: var(--text-muted); line-height: 1.5; margin-bottom: 14px; }

.app-badges { display: flex; gap: 6px; flex-wrap: wrap; }

.badge {
  padding: 3px 8px; border-radius: 5px; font-size: 11px; font-weight: 600;
}

.badge-prod { background: #E8F5EE; color: var(--green); }
.badge-dev { background: #E8EEF8; color: #3B5A9A; }
.badge-pending { background: #F0F2F5; color: #909AAA; }

/* ── Live status dot (set by GET /api/apps/status) ── */
.badge-status { display: inline-flex; align-items: center; gap: 5px; background: #F0F2F5; color: var(--text-muted); }
.badge-status .status-dot { width: 7px; height: 7px; border-radius: 50%; background: #C0C8D4; }
.badge-status.up { background: #E8F5EE; color: var(--green); }
.badge-status.up .status-dot { background: var(--green-light); }
.badge-status.down { background: #FDECEA; color: #C0392B; }
.badge-status.down .status-dot { background: #E74C3C; }
.badge-status.checking .status-dot { animation: status-pulse 1s ease-in-out infinite; }
@keyframes status-pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.app-card.no-url { cursor: default; opacity: 0.75; }
.app-card.no-url:hover { transform: none; box-shadow: none; border-color: var(--border); }

.app-launch-btn {
  position: absolute; bottom: 18px; right: 18px;
  width: 32px; height: 32px; background: var(--navy); border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  opacity: 0; transform: translateY(4px); transition: opacity 0.2s, transform 0.2s, background 0.2s;
  color: white; font-size: 14px;
}

.app-card:hover .app-launch-btn { opacity: 1; transform: translateY(0); }
.app-card:hover .app-launch-btn { background: var(--gold); color: var(--navy); }

/* ── Pin star ── */
.pin-btn {
  position: absolute; top: 14px; right: 14px;
  background: none; border: none; cursor: pointer;
  font-size: 16px; line-height: 1; padding: 2px;
  color: #C8D0DC; opacity: 0; transition: opacity 0.15s, transform 0.1s; z-index: 2;
}
.app-card:hover .pin-btn { opacity: 1; }
.pin-btn.pinned { opacity: 1; color: var(--gold); }
.pin-btn:hover { transform: scale(1.15); }


/* ── ADMIN PANEL ── */
.admin-panel { display: none; }

.admin-tabs {
  display: flex; gap: 0; border-bottom: 2px solid var(--border); margin-bottom: 24px;
}

.admin-tab {
  padding: 10px 20px; border: none; background: none; cursor: pointer;
  font-size: 14px; font-weight: 500; color: var(--text-muted);
  border-bottom: 2px solid transparent; margin-bottom: -2px;
  transition: color 0.15s;
}

.admin-tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 700; }

.admin-content { display: none; }
.admin-content.active { display: block; }

.user-table {
  width: 100%; border-collapse: collapse; background: white;
  border-radius: 12px; overflow: hidden;
  box-shadow: var(--shadow); border: 1px solid var(--border);
}

.user-table th {
  background: #F8FAFC; padding: 12px 16px; text-align: left;
  font-size: 12px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.user-table td {
  padding: 14px 16px; border-bottom: 1px solid #F0F2F5;
  font-size: 13px;
}

.user-table tr:last-child td { border-bottom: none; }
.user-table tr:hover td { background: #F8FAFC; }

.user-status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600;
}

.user-status.active { background: #E8F5EE; color: var(--green); }
.user-status.invited { background: #FEF9E0; color: #8A6500; }
.user-status.inactive { background: #F0F2F5; color: #909AAA; }

.user-avatar-sm {
  width: 28px; height: 28px; border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 11px; font-weight: 700; margin-right: 8px;
  vertical-align: middle;
  background: #E8EEF8; color: var(--navy);
}

.app-access-pills { display: flex; gap: 4px; flex-wrap: wrap; }

.ap-pill {
  padding: 2px 8px; border-radius: 4px; font-size: 11px;
  background: #E8EEF8; color: var(--navy-light); font-weight: 500;
}

.btn-sm {
  padding: 6px 14px; border-radius: 6px; font-size: 12px; font-weight: 600;
  cursor: pointer; border: none; transition: all 0.15s;
}

.btn-sm-outline {
  background: white; border: 1.5px solid var(--border); color: var(--text);
}

.btn-sm-outline:hover { border-color: var(--navy); color: var(--navy); }

.btn-sm-danger {
  background: white; border: 1.5px solid var(--border); color: var(--red);
}

.btn-sm-danger:hover { border-color: var(--red); }

.btn-sm-primary { background: var(--navy); color: white; }
.btn-sm-primary:hover { background: var(--navy-light); }

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

.toolbar-left { display: flex; gap: 8px; align-items: center; }

.search-input {
  padding: 8px 14px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; outline: none; width: 220px;
  transition: border-color 0.2s;
}

.search-input:focus { border-color: var(--navy); }

.role-filter {
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 8px;
  font-size: 13px; outline: none;
}

/* ── MODAL ── */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(11,31,58,0.5); z-index: 200;
  align-items: center; justify-content: center;
}

.modal-overlay.open { display: flex; }

.modal {
  background: white; border-radius: 16px; padding: 32px;
  width: 100%; max-width: 480px; box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}

.modal h3 { font-size: 18px; font-weight: 700; margin-bottom: 6px; }
.modal p { color: var(--text-muted); font-size: 14px; margin-bottom: 24px; }

.modal-form-group { margin-bottom: 16px; }
.modal-form-group label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.modal-form-group input, .modal-form-group select {
  width: 100%; padding: 10px 14px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 14px; outline: none;
}
.modal-form-group input:focus, .modal-form-group select:focus { border-color: var(--navy); }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 24px; }

.app-checkboxes {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px;
}

.app-checkbox-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1.5px solid var(--border); border-radius: 7px;
  cursor: pointer; font-size: 13px; transition: border-color 0.15s;
}

.app-checkbox-item:hover { border-color: var(--navy); }
.app-checkbox-item input { accent-color: var(--navy); }

/* ── STATS ── */
.stats-row { display: flex; gap: 16px; margin-bottom: 32px; }

.stat-card {
  background: var(--card-bg); border: 1px solid var(--border);
  border-radius: 14px; padding: 18px 22px; flex: 1;
  box-shadow: var(--shadow); position: relative; overflow: hidden;
  transition: transform 0.15s, box-shadow 0.2s;
}

.stat-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--gold), var(--gold-light));
  opacity: 0; transition: opacity 0.2s;
}

.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-hover); }
.stat-card:hover::before { opacity: 1; }

.stat-card .stat-label { font-size: 11px; color: var(--text-muted); font-weight: 700; text-transform: uppercase; letter-spacing: 0.6px; margin-bottom: 8px; }
.stat-card .stat-value { font-size: 30px; font-weight: 800; color: var(--navy); line-height: 1.1; letter-spacing: -0.5px; }
.stat-card .stat-sub { font-size: 12px; color: var(--green); margin-top: 4px; }

/* ── DASHBOARD LAYOUT ── */
.dash-search { position: relative; max-width: 380px; margin-bottom: 28px; }
.dash-search .search-icon {
  position: absolute; left: 14px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); opacity: 0.55; pointer-events: none;
}
.dash-search .search-input {
  width: 100%; padding: 10px 14px 10px 40px; font-size: 14px;
  border-radius: 10px; background: var(--card-bg);
  box-shadow: var(--shadow);
}
.dash-search .search-input:focus { box-shadow: 0 0 0 3px rgba(11,31,58,0.08); }

.welcome-date { color: var(--text-muted); font-size: 13px; margin-bottom: 2px; }

/* ── INVITE LINK ── */
.invite-link-box {
  display: flex; gap: 8px; margin-bottom: 8px;
}

.invite-link-box input {
  flex: 1; padding: 10px 12px; border: 1.5px solid var(--border);
  border-radius: 8px; font-size: 12px; color: var(--text-muted);
  font-family: monospace; outline: none; background: #F8FAFC;
}

.modal .login-error { margin-bottom: 16px; }

/* ── TOAST ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 300;
  background: var(--navy); color: white; padding: 12px 20px; border-radius: 10px;
  font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,0.2);
  transform: translateY(80px); opacity: 0;
  transition: transform 0.3s, opacity 0.3s;
}

.toast.show { transform: translateY(0); opacity: 1; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center; padding: 64px 32px;
  background: white; border-radius: 14px; border: 1px solid var(--border);
}

.empty-state .empty-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 16px; font-weight: 700; margin-bottom: 8px; }
.empty-state p { color: var(--text-muted); font-size: 14px; }

/* ── RESPONSIVE ── */
@media (max-width: 880px) {
  #login-page { grid-template-columns: 1fr; }
  .login-brand { padding: 40px 32px; }
  .login-brand h1 { font-size: 27px; }
  .login-logo { margin-bottom: 28px; }
}

@media (max-width: 600px) {
  .portal-nav { padding: 0 16px; }
  .portal-main { padding: 20px 16px; }
  .stats-row { flex-direction: column; }
  .app-grid { grid-template-columns: 1fr; }
  .nav-user-info { display: none; }
}
