*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --bg: #0f1117; --surface: #1a1d27; --border: #2a2d3a;
  --primary: #6366f1; --primary-h: #4f46e5; --danger: #ef4444;
  --text: #e2e8f0; --muted: #94a3b8; --green: #22c55e;
  --radius: 8px; --sidebar-w: 200px; --topnav-h: 52px;
}
body { background: var(--bg); color: var(--text); font-family: system-ui, sans-serif; font-size: 14px; height: 100vh; overflow: hidden; }
#app { display: flex; flex-direction: column; height: 100vh; }

/* ── Top nav ──────────────────────────────────────────────────────────── */
#topnav { height: var(--topnav-h); background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; padding: 0 1.25rem; gap: 1.5rem; flex-shrink: 0; }
.logo { font-size: 1.2rem; font-weight: 700; white-space: nowrap; } .logo span { color: var(--primary); }
.topnav-tabs { display: flex; gap: 4px; flex: 1; }
.topnav-tab { display: block; padding: 0.4rem 0.9rem; border-radius: var(--radius); color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500; transition: all 0.15s; }
.topnav-tab:hover { background: var(--border); color: var(--text); }
.topnav-tab.active { background: var(--primary); color: #fff; }
.topnav-tab.hidden { display: none; }
.topnav-right { display: flex; align-items: center; gap: 0.5rem; margin-left: auto; }

/* ── Top-nav Administration dropdown ──────────────────────────────────── */
.topnav-dropdown { position: relative; display: inline-flex; }
.topnav-dropdown.hidden { display: none !important; }
.topnav-dropdown-btn { cursor: pointer; background: none; border: none; }
.topnav-dropdown-menu { display: none; position: absolute; top: 100%; left: 0; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,0.25); min-width: 160px; padding: 0.25rem 0; padding-top: 8px; z-index: 300; }
.topnav-dropdown:hover .topnav-dropdown-menu,
.topnav-dropdown-menu:hover { display: block; }
.topnav-dropdown-item { display: block; padding: 0.45rem 1rem; color: var(--muted); text-decoration: none; font-size: 13px; font-weight: 500; white-space: nowrap; }
.topnav-dropdown-item:hover { background: var(--border); color: var(--text); }
#current-user { font-size: 12px; color: var(--muted); white-space: nowrap; }

/* ── Sections ─────────────────────────────────────────────────────────── */
.cp-section { display: none; flex: 1; overflow: hidden; }
.cp-section.active { display: flex; }

/* ── Home section ─────────────────────────────────────────────────────── */
#section-home { flex-direction: row; }
#section-apps { overflow-y: auto; }

/* Sidebar */
#home-sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; flex-shrink: 0; overflow: hidden; }
.home-sidebar-top { display: flex; align-items: center; padding: 0.9rem 1rem 0.6rem; gap: 0.5rem; flex-shrink: 0; }
.home-sidebar-title { font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; flex: 1; }
#home-app-list { flex: 1; overflow-y: auto; padding: 0.25rem 0; }
.home-sidebar-footer { padding: 0.5rem; border-top: 1px solid var(--border); flex-shrink: 0; }

/* App list items */
.home-cat-label { display: flex; align-items: center; gap: 0.4rem; padding: 0.3rem 0.75rem; font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); cursor: pointer; user-select: none; }
.home-cat-label:hover { color: var(--text); }
.home-cat-toggle { font-size: 9px; flex-shrink: 0; }
.home-app-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.75rem 0.45rem 1.5rem; border-radius: 0; color: var(--muted); font-size: 13px; cursor: pointer; transition: background 0.1s, color 0.1s; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.home-app-item:hover { background: var(--border); color: var(--text); }
.home-app-item.active { background: var(--primary); color: #fff; }
.home-app-item.no-access { opacity: 0.45; cursor: not-allowed; }
.home-app-item-icon { font-size: 14px; flex-shrink: 0; }
.home-cat-apps.collapsed { display: none; }
.home-cat-drop-hint { font-size: 12px; color: var(--muted); padding: 0.3rem 0.75rem 0.3rem 1.5rem; font-style: italic; }
.home-app-item[draggable="true"] { cursor: grab; }
.home-app-item.dragging { opacity: 0.4; }
.home-cat-section.drop-target { background: rgba(99,102,241,0.1); outline: 1px dashed var(--primary); border-radius: var(--radius); }
.home-register-item { display: flex; align-items: center; gap: 0.5rem; padding: 0.45rem 0.75rem 0.45rem 1.5rem; color: var(--muted); font-size: 13px; cursor: pointer; font-style: italic; }
.home-register-item:hover { color: var(--primary); }

/* Frame area */
#home-frame-area { flex: 1; display: flex; flex-direction: column; overflow: hidden; background: var(--bg); }
#home-welcome { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1rem; text-align: center; padding: 2rem; }
.home-welcome-icon { font-size: 3rem; }
#home-welcome h2 { font-size: 1.4rem; font-weight: 600; }
#home-iframe-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
#home-app-bar { display: flex; align-items: center; padding: 0.4rem 0.75rem; background: var(--surface); border-bottom: 1px solid var(--border); gap: 0.75rem; flex-shrink: 0; }
#home-app-bar-title { flex: 1; font-size: 13px; font-weight: 500; color: var(--text); }
#app-frame { flex: 1; border: none; width: 100%; height: 100%; background: #fff; color-scheme: light; }

/* ── Category panes ───────────────────────────────────────────────────── */
#home-panes { display: flex; flex-direction: column; gap: 1.25rem; }
.cat-pane { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cat-pane-header { display: flex; align-items: center; gap: 0.6rem; padding: 0.65rem 1rem; background: var(--surface); cursor: pointer; user-select: none; }
.cat-pane-header:hover { background: #1e2130; }
.cat-pane-header.drag-over { outline: 2px solid var(--primary); outline-offset: -2px; }
.cat-pane-toggle { font-size: 10px; color: var(--muted); width: 12px; flex-shrink: 0; }
.cat-pane-name { font-weight: 600; font-size: 14px; flex: 1; }
.cat-pane-count { font-size: 11px; color: var(--muted); background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 1px 7px; }
.cat-pane-actions { display: flex; gap: 0.4rem; margin-left: 0.5rem; }
.cat-pane-grid { padding: 1rem; background: var(--bg); display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; }
.cat-pane-grid.drag-over { outline: 2px dashed var(--primary); outline-offset: -4px; }
.cat-pane.collapsed .cat-pane-grid { display: none; }

/* ── App tile grid ────────────────────────────────────────────────────── */
.app-tile-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 2.5rem; }
.app-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; display: flex; flex-direction: column; gap: 0.75rem; transition: border-color 0.15s, box-shadow 0.15s; }
.app-tile:hover { border-color: var(--primary); box-shadow: 0 0 0 1px rgba(99,102,241,0.2); }
.app-tile[draggable="true"] { cursor: grab; }
.app-tile.dragging { opacity: 0.4; }
.app-tile.no-access { opacity: 0.5; filter: grayscale(40%); }
.app-tile.no-access:hover { border-color: var(--border); box-shadow: none; }
.no-access-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); cursor: not-allowed; font-size: 12px; padding: 0.25rem 0.6rem; border-radius: var(--radius); }
.app-tile-icon { font-size: 2rem; line-height: 1; }
.app-tile-name { font-weight: 600; font-size: 15px; }
.app-tile-desc { font-size: 12px; color: var(--muted); line-height: 1.45; flex: 1; }
.app-tile-footer { display: flex; justify-content: flex-end; }
.app-tile-register { background: var(--surface); border: 2px dashed var(--border); border-radius: var(--radius); padding: 1.25rem; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0.5rem; cursor: pointer; transition: border-color 0.15s; min-height: 140px; text-align: center; }
.app-tile-register:hover { border-color: var(--primary); }
.app-tile-register-icon { font-size: 1.5rem; color: var(--muted); }
.app-tile-register-label { font-size: 13px; color: var(--muted); font-weight: 500; }

/* ── App Manager: action-needed row highlight ─────────────────────────── */
tr.tr-action-needed { border-left: 3px solid #fbbf24; }
tr.tr-action-needed td:first-child { padding-left: calc(0.75rem - 3px); }

/* ── App Manager: actions dropdown ───────────────────────────────────── */
.btn-app-actions { font-size: 2rem; line-height: 1; padding: 0.1rem 0.4rem; background: none; border: none; cursor: pointer; color: var(--muted); }
.btn-app-actions:hover { color: var(--text); }
.actions-menu { position: fixed; z-index: 200; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: 0 4px 12px rgba(0,0,0,0.2); min-width: 150px; padding: 0.25rem 0; }
.actions-menu.hidden { display: none; }
.actions-menu-item { display: block; width: 100%; text-align: left; padding: 0.45rem 1rem; background: none; border: none; color: var(--text); font-size: 13px; cursor: pointer; }
.actions-menu-item:hover { background: var(--border); }
.actions-menu-item-danger { color: #ef4444; }
.actions-menu-divider { border: none; border-top: 1px solid var(--border); margin: 0.25rem 0; }

/* ── Auth section: sidebar + content ─────────────────────────────────── */
#section-auth { flex-direction: row; }
#sidebar { width: var(--sidebar-w); background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 1.25rem 1rem; gap: 0.5rem; flex-shrink: 0; }
#nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav-item { display: block; padding: 0.5rem 0.75rem; border-radius: var(--radius); color: var(--muted); text-decoration: none; transition: all 0.15s; }
.nav-item:hover { background: var(--border); color: var(--text); }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-section { font-size: 10px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); padding: 0.75rem 0.75rem 0.25rem; margin-top: 0.25rem; }
.nav-child { padding-left: 1.25rem !important; }
#auth-content { flex: 1; overflow-y: auto; padding: 2rem; }
.view { display: none; } .view.active { display: block; }

/* ── Common components ────────────────────────────────────────────────── */
h1 { font-size: 1.4rem; font-weight: 600; margin-bottom: 1.25rem; display: flex; align-items: center; gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem; }
.tabs { display: flex; gap: 4px; margin-bottom: 1.25rem; border-bottom: 1px solid var(--border); padding-bottom: 0.5rem; }
.tab { background: none; border: none; color: var(--muted); padding: 0.4rem 0.75rem; border-radius: var(--radius); cursor: pointer; font-size: 13px; }
.tab:hover { color: var(--text); background: var(--border); } .tab.active { color: var(--primary); font-weight: 600; }
.tab-content { display: none; } .tab-content.active { display: flex; flex-direction: column; gap: 0.75rem; }
label { display: flex; flex-direction: column; gap: 4px; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }
input, select, textarea { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 0.5rem 0.75rem; font-size: 14px; outline: none; transition: border-color 0.15s; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); }
.input-row { display: flex; gap: 0.5rem; } .input-row input { flex: 1; }
.btn { border: none; border-radius: var(--radius); padding: 0.5rem 1rem; font-size: 13px; font-weight: 500; cursor: pointer; transition: all 0.15s; }
.btn-primary { background: var(--primary); color: #fff; } .btn-primary:hover { background: var(--primary-h); }
.btn-secondary { background: var(--border); color: var(--text); } .btn-secondary:hover { background: #3a3d4a; }
.btn-ghost { background: none; color: var(--muted); } .btn-ghost:hover { color: var(--text); background: var(--border); }
.btn-danger { background: none; border: 1px solid var(--danger); color: var(--danger); padding: 0.25rem 0.6rem; font-size: 12px; }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-sm { padding: 0.35rem 0.75rem; font-size: 12px; }
.btn-success { background: var(--green); color: #fff; } .btn-success:hover { opacity: 0.85; }
.data-table { width: 100%; border-collapse: collapse; }
.data-table th { text-align: left; padding: 0.5rem 0.75rem; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; border-bottom: 1px solid var(--border); }
.data-table td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--border); }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: rgba(255,255,255,0.02); }
.pagination-bar { display: flex; align-items: center; gap: 0.75rem; padding: 0.75rem 0 0; font-size: 13px; color: var(--muted); }
.pagination-bar button { padding: 0.3rem 0.7rem; font-size: 12px; }
.pagination-bar.hidden { display: none !important; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 500; }
.badge-active   { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-revoked  { background: rgba(239,68,68,0.15);  color: var(--danger); }
.badge-user     { background: rgba(99,102,241,0.15); color: var(--primary); }
.badge-sa       { background: rgba(251,191,36,0.15); color: #fbbf24; }
.badge-suspended{ background: rgba(251,191,36,0.15); color: #fbbf24; }
.badge-pending  { background: rgba(251,191,36,0.15); color: #fbbf24; }
.badge-approved { background: rgba(34,197,94,0.15);  color: var(--green); }
.badge-rejected { background: rgba(239,68,68,0.15);  color: var(--danger); }
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-box { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.5rem; min-width: 380px; display: flex; flex-direction: column; gap: 1rem; max-height: 90vh; overflow-y: auto; }
.modal-box h2 { font-size: 1rem; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; padding-top: 0.5rem; }
.kv-table { width: 100%; border-collapse: collapse; }
.kv-table td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); }
.kv-table td:first-child { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; width: 160px; }
.kv-table tr:last-child td { border-bottom: none; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.5; }
.error { color: var(--danger); font-size: 13px; margin-top: 0.5rem; }
.hidden { display: none !important; }
code { font-family: monospace; background: var(--bg); padding: 2px 6px; border-radius: 4px; font-size: 12px; }
.raw-key { display: block; padding: 1rem; background: var(--bg); border-radius: var(--radius); font-size: 13px; word-break: break-all; border: 1px solid var(--primary); color: var(--green); }
.toast { position: fixed; bottom: 1.5rem; right: 1.5rem; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 0.75rem 1.25rem; font-size: 13px; z-index: 200; }
.toast.success { border-color: var(--green); color: var(--green); }
.toast.error   { border-color: var(--danger); color: var(--danger); }
.login-logo { font-size: 1.6rem; font-weight: 700; text-align: center; margin-bottom: 0.5rem; } .login-logo span { color: var(--primary); }
.login-divider { display: flex; align-items: center; gap: 0.75rem; color: var(--muted); font-size: 12px; margin: 0.25rem 0; } .login-divider::before, .login-divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.btn.active { outline: 2px solid var(--primary); }
.search-results { margin-top: 4px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.search-result-item { padding: 0.5rem 0.75rem; cursor: pointer; font-size: 13px; display: flex; gap: 0.75rem; align-items: center; }
.search-result-item:hover { background: var(--border); }
.search-result-item .sr-name { flex: 1; }
.search-result-item .sr-type { font-size: 11px; color: var(--muted); }
.info-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 1rem; }
.info-label { font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; color: var(--muted); margin-bottom: 0.4rem; }
.info-value { font-size: 14px; color: var(--text); word-break: break-all; }

/* ── Searchable select ────────────────────────────────────────────────────── */
.ss-wrap { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.ss-input { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); color: var(--text); padding: 0.4rem 0.6rem; font-size: 13px; outline: none; transition: border-color 0.15s; width: 100%; }
.ss-input:focus { border-color: var(--primary); }
.ss-list { list-style: none; background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); max-height: 130px; overflow-y: auto; margin: 0; padding: 2px 0; }
.ss-item { padding: 0.35rem 0.6rem; cursor: pointer; font-size: 13px; border-radius: 4px; margin: 0 2px; }
.ss-item:hover { background: var(--border); }
.ss-item.ss-selected { background: var(--primary); color: #fff; }
.ss-item.ss-item-hidden { display: none; }
.ss-empty { padding: 0.35rem 0.6rem; font-size: 13px; color: var(--muted); font-style: italic; }
