:root {
  --bg: #f8f9fb;
  --surface: #ffffff;
  --border: #e8eaed;
  --border-light: #f3f4f6;
  --text: #1a1a2e;
  --text-sec: #6b7280;
  --text-ter: #9ca3af;
  --navy: #0f1f3d;
  --navy-soft: rgba(15,31,61,.06);
  --accent: #2563eb;
  --accent-soft: rgba(37,99,235,.07);
  --success: #059669;
  --success-soft: rgba(5,150,105,.08);
  --warning: #d97706;
  --warning-soft: rgba(217,119,6,.08);
  --danger: #dc2626;
  --danger-soft: rgba(220,38,38,.08);
  --topbar-h: 52px;
  --sidebar-w: 220px;
  --radius: 6px;
  --radius-lg: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04);
  --shadow-md: 0 2px 8px rgba(0,0,0,.06);
  --shadow-lg: 0 4px 16px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }
html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif; color: var(--text); background: var(--bg); font-size: 13.5px; -webkit-font-smoothing: antialiased; }
button, input, textarea, select { font: inherit; color: inherit; }
svg { flex-shrink: 0; }

/* ── Logo ── */
.logo-mark {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px;
  background: var(--navy); color: #fff;
  font-family: Georgia, serif; font-size: 16px; font-weight: 700; line-height: 1;
  box-shadow: 0 1px 4px rgba(15,31,61,.2);
}
.logo-sub { font-size: 6px; font-weight: 600; letter-spacing: .1em; opacity: .5; margin-top: 1px; font-family: system-ui, sans-serif; }

/* ── Auth ── */
.auth-overlay { display: flex; align-items: center; justify-content: center; position: fixed; inset: 0; z-index: 9999; background: #eef0f4; }
.auth-card { width: 360px; padding: 2.5rem 2rem; background: var(--surface); border-radius: var(--radius-lg); border: 1px solid var(--border); }
.auth-logo-block { display: flex; flex-direction: column; align-items: center; }
.auth-logo { width: 52px; height: 52px; border-radius: 13px; background: var(--navy); color: #fff; display: grid; place-items: center; font-family: Georgia, serif; font-size: 26px; font-weight: 700; box-shadow: 0 3px 12px rgba(15,31,61,.2); }
.auth-brand { font-family: Georgia, serif; font-size: 20px; font-weight: 700; color: var(--text); margin-top: 12px; letter-spacing: -.02em; }
.auth-org { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--text-ter); margin-top: 3px; }
.auth-divider { height: 1px; background: var(--border); margin: 22px 0; }
.auth-form { display: grid; gap: 12px; }
.auth-hint { color: var(--text-sec); font-size: 13px; line-height: 1.5; }
.auth-error { color: var(--danger); font-size: 12px; min-height: 1em; }
.auth-ok { color: var(--success); font-size: 12px; }
.field { display: grid; gap: 3px; }
.field-label { font-size: 11.5px; font-weight: 500; color: var(--text-sec); }
.auth-input { width: 100%; height: 38px; padding: 0 10px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); outline: none; font-size: 13.5px; transition: border-color .15s; }
.auth-input:focus { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(15,31,61,.06); }
.auth-btn { width: 100%; height: 38px; background: var(--navy); color: #fff; border: none; border-radius: var(--radius); font-weight: 500; font-size: 13.5px; cursor: pointer; transition: background .15s; }
.auth-btn:hover { background: #162d54; }
.auth-link { background: none; border: none; color: var(--text-ter); font-size: 11.5px; cursor: pointer; }
.auth-link:hover { color: var(--text-sec); text-decoration: underline; }
.auth-note { font-size: 11px; color: var(--text-ter); text-align: center; }

/* ── Inputs & Buttons ── */
.input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); outline: none; transition: border-color .15s; font-size: 13px; }
.input:focus { border-color: var(--navy); box-shadow: 0 0 0 2px rgba(15,31,61,.06); }
select.input { cursor: pointer; }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 7px 12px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); cursor: pointer; font-weight: 500; font-size: 12.5px; transition: all .12s; white-space: nowrap; }
.btn:hover { background: var(--bg); border-color: #d1d5db; }
.btn-primary { background: var(--navy); color: #fff; border-color: var(--navy); }
.btn-primary:hover { background: #162d54; }
.btn-ghost { border-color: transparent; background: transparent; color: var(--text-sec); }
.btn-ghost:hover { background: var(--navy-soft); color: var(--text); }
.btn-sm { padding: 5px 8px; font-size: 12px; }
.btn-full { width: 100%; }

.link { background: none; border: none; color: var(--accent); font-size: 12px; cursor: pointer; }
.link:hover { text-decoration: underline; }

/* ── Dropdowns ── */
.dropdown-wrap { position: relative; }
.dropdown { position: absolute; top: calc(100% + 4px); left: 0; min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); z-index: 500; padding: 4px; }
.dropdown-right { left: auto; right: 0; }
.dropdown-item { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 10px; border: none; background: none; border-radius: var(--radius); cursor: pointer; font-size: 12.5px; color: var(--text); text-align: left; transition: background .1s; }
.dropdown-item:hover { background: var(--bg); }
.dropdown-item-danger { color: var(--danger); }
.dropdown-item-danger:hover { background: var(--danger-soft); }
.dropdown-icon { width: 16px; height: 16px; display: flex; align-items: center; justify-content: center; color: var(--text-sec); }
.dropdown-sep { height: 1px; background: var(--border-light); margin: 3px 6px; }
.dropdown-user { padding: 10px 12px; }
.dropdown-user-name { font-weight: 600; font-size: 13px; }
.dropdown-user-email { font-size: 11.5px; color: var(--text-sec); margin-top: 1px; }
.dropdown-user-role { display: inline-block; margin-top: 5px; padding: 2px 7px; background: var(--navy-soft); color: var(--navy); border-radius: 999px; font-size: 10.5px; font-weight: 600; }

/* ── Badges ── */
.badge { display: inline-flex; padding: 2px 7px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge-active { background: var(--success-soft); color: var(--success); }
.badge-invited { background: var(--warning-soft); color: var(--warning); }
.badge-suspended { background: var(--danger-soft); color: var(--danger); }
.badge-app { background: var(--navy-soft); color: var(--navy); padding: 4px 10px; font-size: 12px; cursor: pointer; transition: all .12s; border: 1px solid transparent; border-radius: var(--radius); }
.badge-app.active { background: var(--navy); color: #fff; }
.badge-app:hover { border-color: var(--navy); }

/* ── Shell ── */
.shell { display: grid; grid-template-rows: var(--topbar-h) 1fr; height: 100vh; }

/* Topbar */
.topbar { display: flex; align-items: center; gap: 6px; padding: 0 14px; background: var(--surface); border-bottom: 1px solid var(--border); z-index: 100; }
.topbar-left { display: flex; align-items: center; gap: 8px; padding-right: 14px; margin-right: 2px; }
.topbar-apps { display: flex; align-items: stretch; gap: 0; flex: 1; min-width: 0; height: 100%; flex-wrap: wrap; }
.topbar-apps::-webkit-scrollbar { display: none; }
.app-tab { display: flex; align-items: center; gap: 6px; padding: 0 12px; font-size: 12.5px; font-weight: 500; color: var(--text-sec); cursor: pointer; border: none; background: none; transition: color .12s; white-space: nowrap; position: relative; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.app-tab:hover { color: var(--text); }
.app-tab.active { color: var(--navy); border-bottom-color: var(--navy); font-weight: 600; }
.app-tab svg { color: var(--text-ter); }
.app-tab.active svg { color: var(--navy); }
.app-tab-group-wrap { display: flex; align-items: stretch; height: 100%; }
.app-tab-group { display: flex; align-items: center; }
.app-tab-group-wrap > .dropdown { min-width: 200px; top: 100%; left: 0; }
.dropdown-item-active { background: var(--navy-soft); color: var(--navy); font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: 8px; margin-left: auto; padding-left: 10px; padding-right: 22px; flex-shrink: 0; }
.topbar-icon-btn { width: 34px; height: 34px; border: none; background: none; border-radius: var(--radius); cursor: pointer; display: grid; place-items: center; color: var(--text-ter); transition: all .12s; }
.topbar-icon-btn:hover { background: var(--navy-soft); color: var(--text); }

/* Notification Bell */
.notif-bell { position: relative; }
.notif-badge { position: absolute; top: 2px; right: 2px; min-width: 16px; height: 16px; background: #dc2626; color: #fff; font-size: 9px; font-weight: 700; border-radius: 8px; display: grid; place-items: center; padding: 0 4px; line-height: 1; pointer-events: none; }
.notif-bell.ringing .notif-badge { animation: bellPulse 1s infinite; }
.notif-bell.ringing svg { animation: bellShake .5s ease-in-out infinite; }
@keyframes bellPulse { 0%,100% { opacity: 1; } 50% { opacity: .5; } }
@keyframes bellShake { 0%,100% { transform: rotate(0); } 25% { transform: rotate(8deg); } 75% { transform: rotate(-8deg); } }
.notif-panel { position: fixed; top: calc(var(--topbar-h) + 4px); right: 80px; width: 360px; max-height: 420px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); z-index: 600; overflow: hidden; }
.notif-panel-header { padding: 12px 14px; font-weight: 700; font-size: 13px; border-bottom: 1px solid var(--border-light); }
.notif-panel-body { overflow-y: auto; max-height: 370px; }
.notif-item { display: flex; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border-light); cursor: pointer; font-size: 12px; transition: background .1s; }
.notif-item:hover { background: rgba(59,130,246,.04); }
.notif-item-icon { width: 28px; height: 28px; border-radius: 6px; display: grid; place-items: center; font-size: 14px; flex-shrink: 0; }
.notif-item-body { flex: 1; min-width: 0; }
.notif-item-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-desc { color: var(--text-sec); font-size: 11px; margin-top: 2px; }
.notif-item-time { font-size: 10px; color: var(--text-ter); margin-top: 2px; }
.notif-section-label { padding: 6px 14px; font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .05em; color: var(--text-ter); background: var(--bg); }

/* Avatar */
.avatar-btn { width: 38px; height: 38px; border: 2px solid var(--border); border-radius: 50%; background: var(--navy); color: #fff; font-size: 13px; font-weight: 700; cursor: pointer; display: grid; place-items: center; overflow: hidden; padding: 0; transition: border-color .12s, transform .12s; }
.avatar-btn:hover { border-color: var(--navy); transform: scale(1.05); }
.avatar-btn .avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
#avatar-initials { letter-spacing: .5px; line-height: 1; }
.dropdown-user { padding: 14px 12px; text-align: center; }
.dropdown-user-avatar { display: flex; justify-content: center; margin-bottom: 8px; }
.dropdown-user-avatar .avatar-img-lg { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; border: 2px solid var(--border); }
.dropdown-user-avatar .avatar-init-lg { width: 56px; height: 56px; border-radius: 50%; background: var(--navy); color: #fff; display: grid; place-items: center; font-size: 20px; font-weight: 700; }

/* Body */
.shell-body { display: grid; grid-template-columns: var(--sidebar-w) 1fr; overflow: hidden; }

/* Sidebar — light */
.sidebar { background: var(--surface); border-right: 1px solid var(--border); padding: 12px 0; overflow-y: auto; display: flex; flex-direction: column; }
.sidebar-section { padding: 0 8px; margin-bottom: 16px; }
.sidebar-label { display: block; padding: 0 10px; margin-bottom: 6px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-ter); }
.sidebar-item { display: flex; align-items: center; gap: 8px; padding: 7px 10px; border-radius: var(--radius); cursor: pointer; border: none; background: none; color: var(--text-sec); width: 100%; text-align: left; font-size: 12.5px; transition: all .1s; }
.sidebar-item:hover { background: var(--bg); color: var(--text); }
.sidebar-item.active { background: var(--navy-soft); color: var(--navy); font-weight: 600; }
.sidebar-item svg { color: var(--text-ter); }
.sidebar-item.active svg { color: var(--navy); }
.sidebar-highlight { color: var(--accent,#3b82f6); font-weight: 600; border-left: 3px solid var(--accent,#3b82f6); padding-left: 7px; }
.sidebar-highlight svg { color: var(--accent,#3b82f6); }
.sidebar-highlight.active { background: rgba(59,130,246,.1); color: var(--accent,#3b82f6); }
.sidebar-count { margin-left: auto; font-size: 10.5px; background: var(--bg); color: var(--text-sec); padding: 1px 6px; border-radius: 999px; }
.sidebar-footer { margin-top: auto; padding: 12px 18px; border-top: 1px solid var(--border-light); }
.sidebar-footer-text { font-size: 10.5px; color: var(--text-ter); }

/* Main */
.main { overflow-y: auto; padding: 20px 24px; background: var(--bg); }

/* ── Page ── */
.page-header { margin-bottom: 20px; }
.page-header-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 20px; }
.page-title { font-size: 18px; font-weight: 700; letter-spacing: -.02em; color: var(--text); }
.page-desc { color: var(--text-sec); font-size: 12px; margin-top: 2px; }

/* Stats */
.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 20px; }
.stat-card { padding: 14px 16px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); }
.stat-value { font-size: 24px; font-weight: 700; letter-spacing: -.03em; color: var(--text); }
.stat-label { font-size: 11px; color: var(--text-sec); margin-top: 2px; }

/* App cards grid — compact */
.apps-grid-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 16px; }
.app-card { padding: 16px 12px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); cursor: pointer; text-align: center; transition: all .12s; }
.app-card:hover { border-color: var(--navy); box-shadow: var(--shadow-md); }
.app-card-icon { height: 24px; display: flex; align-items: center; justify-content: center; margin-bottom: 8px; color: var(--text-sec); }
.app-card-name { font-weight: 600; font-size: 12px; color: var(--text); }
.app-card-desc { font-size: 10.5px; color: var(--text-ter); margin-top: 2px; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); overflow: hidden; }
.card + .card { margin-top: 10px; }
.card-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; border-bottom: 1px solid var(--border-light); }
.card-title { font-size: 13px; font-weight: 600; }
.card-body { padding: 16px; }
.card-body-flush { padding: 0; }

/* Table */
.table { width: 100%; border-collapse: collapse; }
.table th { text-align: left; padding: 8px 14px; font-size: 10.5px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-ter); background: var(--bg); border-bottom: 1px solid var(--border); }
.table td { padding: 10px 14px; border-bottom: 1px solid var(--border-light); font-size: 12.5px; vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--navy-soft); }

.user-cell { display: flex; align-items: center; gap: 8px; }
.user-avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--navy-soft); color: var(--navy); display: grid; place-items: center; font-size: 11px; font-weight: 700; flex-shrink: 0; overflow: hidden; }
.user-avatar .avatar-img { width: 100%; height: 100%; object-fit: cover; display: block; }
.avatar-with-dot { position: relative; overflow: visible; }
.presence-dot { position: absolute; bottom: -1px; right: -1px; width: 11px; height: 11px; border-radius: 50%; border: 2px solid #fff; box-sizing: border-box; }
.presence-dot.online { background: #16a34a; }
.presence-dot.offline { background: #9ca3af; }
.user-name { font-weight: 500; font-size: 12.5px; }
.user-email { font-size: 11px; color: var(--text-sec); }

/* Forms */
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 8px; margin-bottom: 10px; }
.form-group { display: grid; gap: 3px; }
.form-label { font-size: 11px; font-weight: 500; color: var(--text-sec); }

/* Apps grid (permissions) */
.apps-grid { display: flex; flex-wrap: wrap; gap: 5px; }

/* Audit */
.audit-item { display: grid; gap: 1px; padding: 10px 16px; border-bottom: 1px solid var(--border-light); }
.audit-item:last-child { border-bottom: none; }
.audit-msg { font-size: 12.5px; }
.audit-time { font-size: 10.5px; color: var(--text-ter); }

/* Placeholder */
.placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; min-height: 300px; text-align: center; color: var(--text-sec); }
.placeholder-icon { margin-bottom: 12px; color: var(--text-ter); opacity: .4; }
.placeholder-title { font-size: 16px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.placeholder-desc { font-size: 12.5px; max-width: 360px; line-height: 1.5; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.3); display: flex; align-items: center; justify-content: center; z-index: 1000; backdrop-filter: blur(1px); }
.modal { background: var(--surface); border-radius: var(--radius-lg); width: 440px; max-width: 95vw; max-height: 85vh; overflow-y: auto; box-shadow: var(--shadow-lg); border: 1px solid var(--border); }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 14px; font-weight: 600; }
.modal-body { padding: 20px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 6px; padding: 12px 20px; border-top: 1px solid var(--border); }

/* Contact list */
.contact-list { max-height: 180px; overflow-y: auto; margin: 6px 0; }
.contact-item { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: var(--radius); cursor: pointer; transition: background .1s; }
.contact-item:hover { background: var(--bg); }
.contact-item.selected { background: var(--navy-soft); }
.contact-name { font-weight: 500; font-size: 12.5px; }
.contact-detail { font-size: 11px; color: var(--text-sec); }

/* ── Animations ── */
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

@media (max-width: 900px) {
  .shell-body { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .topbar-apps { display: none; }
}
