/*
 * Apjakal Permission Manager — admin UI styles
 * Scope: .apm-shell[data-scope='permissions']
 */

.apm-shell {
	--apm-bg: #0E2E47;
	--apm-surface: #ffffff;
	--apm-surface-alt: #f4f7fb;
	--apm-border: #e2eaf2;
	--apm-border-strong: #cbd5e1;
	--apm-text: #0E2E47;
	--apm-text-muted: #4A5568;
	--apm-text-soft: #94a3b8;
	--apm-primary: #1F5E89;
	--apm-primary-hover: #174A6E;
	--apm-primary-soft: rgba(31, 94, 137, 0.12);
	--apm-accent: #3B82F6;
	--apm-danger: #dc2626;
	--apm-danger-soft: #fee2e2;
	--apm-warn: #f59e0b;
	--apm-warn-soft: #fef3c7;
	--apm-success: #16a34a;
	--apm-success-soft: #dcfce7;
	--apm-shadow: 0 1px 2px rgba(15, 23, 42, 0.04), 0 4px 12px rgba(15, 23, 42, 0.05);
	min-height: 100vh;
	background: var(--apm-surface-alt);
	color: var(--apm-text);
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.apm-shell *,
.apm-shell *::before,
.apm-shell *::after {
	box-sizing: border-box;
}

/* ==== Header ==== */
.apm-shell-header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 12px 24px;
	background: var(--apm-bg);
	color: #f1f5f9;
	box-shadow: var(--apm-shadow);
	position: sticky;
	top: 0;
	z-index: 20;
}

.apm-shell-brand {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	color: #f1f5f9;
	font-weight: 600;
	font-size: 15px;
	text-decoration: none;
}

.apm-shell-brand i {
	width: 22px;
	height: 22px;
	color: var(--apm-primary);
}

.apm-shell-brand-tag {
	font-size: 11px;
	font-weight: 600;
	padding: 2px 8px;
	border-radius: 999px;
	background: rgba(59, 130, 246, 0.18);
	color: #93C5FD;
	letter-spacing: 0.04em;
	text-transform: uppercase;
}

.apm-shell-tools {
	display: flex;
	align-items: center;
	gap: 10px;
}

.apm-icon-btn {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 36px;
	height: 36px;
	border-radius: 10px;
	color: #cbd5e1;
	background: rgba(255, 255, 255, 0.04);
	transition: background 0.15s ease, color 0.15s ease;
}

.apm-icon-btn:hover {
	background: rgba(255, 255, 255, 0.1);
	color: #fff;
	text-decoration: none;
}

.apm-icon-btn i {
	width: 18px;
	height: 18px;
}

.apm-profile {
	display: inline-flex;
	align-items: center;
	gap: 10px;
	padding: 4px 12px 4px 4px;
	border-radius: 999px;
	background: rgba(255, 255, 255, 0.06);
}

.apm-profile-img,
.apm-avatar {
	width: 30px;
	height: 30px;
	border-radius: 50%;
	object-fit: cover;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	background: var(--apm-primary);
	color: #fff;
	font-weight: 600;
	font-size: 12px;
}

.apm-profile-name {
	font-size: 13px;
	color: #e2e8f0;
}

/* ==== Main ==== */
.apm-shell-main {
	max-width: 1320px;
	margin: 0 auto;
	padding: 24px;
	display: flex;
	flex-direction: column;
	gap: 20px;
}

.apm-shell-embedded {
	background: transparent;
	min-height: auto;
}

.apm-shell-embedded .apm-shell-main {
	padding: 16px 20px;
}

.apm-perms-head {
	display: flex;
	align-items: flex-start;
	justify-content: space-between;
	gap: 16px;
}

.apm-perms-title {
	display: flex;
	gap: 14px;
	align-items: flex-start;
}

.apm-perms-icon {
	width: 44px;
	height: 44px;
	border-radius: 12px;
	background: var(--apm-primary-soft);
	color: var(--apm-primary-hover);
	display: inline-flex;
	align-items: center;
	justify-content: center;
}

.apm-perms-icon i {
	width: 22px;
	height: 22px;
}

.apm-perms-title h1 {
	margin: 0 0 4px;
	font-size: 22px;
	font-weight: 600;
}

.apm-perms-title p {
	margin: 0;
	font-size: 13px;
	color: var(--apm-text-muted);
	max-width: 720px;
}

/* ==== Tabs ==== */
.apm-perms-tabs {
	display: flex;
	gap: 6px;
	background: var(--apm-surface);
	border: 1px solid var(--apm-border);
	border-radius: 12px;
	padding: 4px;
	width: fit-content;
}

.apm-perms-tab {
	display: inline-flex;
	align-items: center;
	gap: 8px;
	padding: 8px 16px;
	font-size: 13px;
	font-weight: 500;
	color: var(--apm-text-muted);
	background: transparent;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	transition: background 0.15s ease, color 0.15s ease;
}

.apm-perms-tab i {
	width: 16px;
	height: 16px;
}

.apm-perms-tab:hover {
	color: var(--apm-text);
}

.apm-perms-tab.active {
	background: var(--apm-primary);
	color: #fff;
}

/* ==== Two-pane layout ==== */
.apm-perms-pane {
	display: grid;
	grid-template-columns: 320px 1fr;
	gap: 20px;
	min-height: 60vh;
}

@media (max-width: 900px) {
	.apm-perms-pane {
		grid-template-columns: 1fr;
	}
}

/* ==== List (left) ==== */
.apm-perms-list {
	background: var(--apm-surface);
	border: 1px solid var(--apm-border);
	border-radius: 14px;
	display: flex;
	flex-direction: column;
	max-height: 75vh;
	overflow: hidden;
}

.apm-perms-list-search {
	position: relative;
	padding: 12px;
	border-bottom: 1px solid var(--apm-border);
}

.apm-perms-list-search i {
	position: absolute;
	left: 22px;
	top: 50%;
	transform: translateY(-50%);
	width: 16px;
	height: 16px;
	color: var(--apm-text-soft);
	pointer-events: none;
}

.apm-perms-list-search input {
	width: 100%;
	padding: 8px 12px 8px 34px;
	border: 1px solid var(--apm-border);
	border-radius: 8px;
	font-size: 13px;
	background: var(--apm-surface-alt);
	color: var(--apm-text);
	outline: none;
	transition: border-color 0.15s ease, background 0.15s ease;
}

.apm-perms-list-search input:focus {
	border-color: var(--apm-primary);
	background: #fff;
}

.apm-perms-list-items {
	flex: 1;
	overflow-y: auto;
	padding: 6px;
}

.apm-perms-list-item {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 8px 10px;
	border-radius: 10px;
	color: var(--apm-text);
	text-decoration: none;
	transition: background 0.12s ease;
	margin-bottom: 2px;
}

.apm-perms-list-item:hover {
	background: var(--apm-surface-alt);
	text-decoration: none;
}

.apm-perms-list-item.active {
	background: var(--apm-primary-soft);
	color: var(--apm-primary-hover);
}

.apm-perms-list-avatar {
	width: 32px;
	height: 32px;
	border-radius: 50%;
	object-fit: cover;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	background: var(--apm-border);
	color: var(--apm-text);
	font-size: 11px;
	font-weight: 600;
}

.apm-perms-list-avatar-text {
	background: var(--apm-primary-soft);
	color: var(--apm-primary-hover);
}

.apm-perms-list-avatar-role {
	background: #ede9fe;
	color: #6d28d9;
}

.apm-perms-list-avatar-role i {
	width: 16px;
	height: 16px;
}

.apm-perms-list-meta {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.apm-perms-list-title {
	font-size: 13px;
	font-weight: 500;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.apm-perms-list-sub {
	font-size: 11px;
	color: var(--apm-text-muted);
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.apm-perms-list-item.active .apm-perms-list-sub {
	color: var(--apm-primary-hover);
	opacity: 0.85;
}

.apm-perms-loading,
.apm-perms-error,
.apm-perms-empty-list {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 16px;
	font-size: 13px;
	color: var(--apm-text-muted);
}

.apm-perms-loading i,
.apm-perms-error i {
	width: 16px;
	height: 16px;
}

.apm-perms-loading i {
	animation: apm-spin 1s linear infinite;
}

@keyframes apm-spin {
	to { transform: rotate(360deg); }
}

.apm-perms-error {
	color: var(--apm-danger);
}

/* ==== Detail (right) ==== */
.apm-perms-detail {
	background: var(--apm-surface);
	border: 1px solid var(--apm-border);
	border-radius: 14px;
	overflow: hidden;
	display: flex;
	flex-direction: column;
}

.apm-perms-empty {
	flex: 1;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	gap: 10px;
	padding: 48px;
	color: var(--apm-text-muted);
	text-align: center;
}

.apm-perms-empty i {
	width: 28px;
	height: 28px;
	color: var(--apm-text-soft);
}

.apm-perms-detail-head {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 16px;
	padding: 18px 22px;
	border-bottom: 1px solid var(--apm-border);
	background: var(--apm-surface-alt);
}

.apm-perms-detail-meta {
	display: flex;
	gap: 14px;
	align-items: center;
	min-width: 0;
}

.apm-perms-detail-avatar {
	width: 44px;
	height: 44px;
	border-radius: 50%;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	flex-shrink: 0;
	background: var(--apm-primary-soft);
	color: var(--apm-primary-hover);
	font-weight: 600;
	font-size: 14px;
	object-fit: cover;
}

.apm-perms-detail-meta h2 {
	margin: 0;
	font-size: 17px;
	font-weight: 600;
}

.apm-perms-detail-sub {
	margin: 2px 0 0;
	font-size: 12px;
	color: var(--apm-text-muted);
}

.apm-perms-detail-actions {
	display: flex;
	gap: 8px;
}

/* ==== Buttons ==== */
.apm-btn-sm {
	display: inline-flex;
	align-items: center;
	gap: 6px;
	padding: 6px 12px;
	font-size: 12px;
	font-weight: 500;
	border-radius: 8px;
	border: 1px solid transparent;
	cursor: pointer;
	transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
	text-decoration: none;
}

.apm-btn-sm i {
	width: 14px;
	height: 14px;
}

.apm-btn-ghost {
	background: var(--apm-surface);
	border-color: var(--apm-border);
	color: var(--apm-text);
}

.apm-btn-ghost:hover {
	background: var(--apm-surface-alt);
	border-color: var(--apm-border-strong);
	text-decoration: none;
	color: var(--apm-text);
}

.apm-btn-primary-sm {
	background: var(--apm-primary);
	color: #fff;
	border-color: var(--apm-primary);
}

.apm-btn-primary-sm:hover {
	background: var(--apm-primary-hover);
	border-color: var(--apm-primary-hover);
	color: #fff;
}

/* ==== Blocks ==== */
.apm-perms-block {
	padding: 18px 22px;
	border-bottom: 1px solid var(--apm-border);
}

.apm-perms-block:last-child {
	border-bottom: none;
}

.apm-perms-block-head {
	display: flex;
	align-items: center;
	gap: 10px;
	margin-bottom: 12px;
}

.apm-perms-block-head h3 {
	margin: 0;
	font-size: 14px;
	font-weight: 600;
}

.apm-perms-block-count {
	font-size: 11px;
	font-weight: 600;
	padding: 2px 8px;
	border-radius: 999px;
	background: var(--apm-surface-alt);
	color: var(--apm-text-muted);
	border: 1px solid var(--apm-border);
}

.apm-perms-block-hint {
	margin: 0 0 12px;
	font-size: 12px;
	color: var(--apm-text-muted);
}

.apm-perms-block-empty {
	font-size: 12px;
	color: var(--apm-text-muted);
	padding: 8px 0;
}

/* ==== Roles ==== */
.apm-perms-roles {
	display: flex;
	flex-wrap: wrap;
	gap: 6px;
	margin-bottom: 10px;
}

.apm-perms-role-chip {
	display: inline-flex;
	align-items: center;
	gap: 4px;
	padding: 4px 4px 4px 10px;
	border-radius: 999px;
	background: var(--apm-primary-soft);
	color: var(--apm-primary-hover);
	font-size: 12px;
	font-weight: 500;
}

.apm-perms-role-revoke {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 18px;
	height: 18px;
	border-radius: 50%;
	border: none;
	background: transparent;
	color: var(--apm-primary-hover);
	cursor: pointer;
	transition: background 0.12s ease;
}

.apm-perms-role-revoke:hover {
	background: rgba(31, 94, 137, 0.2);
}

.apm-perms-role-revoke i {
	width: 12px;
	height: 12px;
}

.apm-perms-role-add {
	display: flex;
	gap: 6px;
	margin-top: 8px;
}

.apm-perms-role-add input {
	flex: 1;
	padding: 6px 10px;
	border: 1px solid var(--apm-border);
	border-radius: 8px;
	font-size: 12px;
	outline: none;
	background: var(--apm-surface-alt);
}

.apm-perms-role-add input:focus {
	border-color: var(--apm-primary);
	background: #fff;
}

/* ==== Sections / toggles ==== */
.apm-perms-sections {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
	gap: 6px;
}

.apm-perms-toggle {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 8px 10px;
	border-radius: 8px;
	background: var(--apm-surface-alt);
	font-size: 12px;
	cursor: pointer;
	transition: background 0.12s ease;
}

.apm-perms-toggle:hover {
	background: #f1f5f9;
}

.apm-perms-toggle input {
	margin: 0;
	cursor: pointer;
}

/* ==== Workspaces ==== */
.apm-perms-ws-checks {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
	gap: 6px;
}

.apm-perms-ws-check {
	display: flex;
	align-items: center;
	gap: 10px;
	padding: 10px 12px;
	border-radius: 10px;
	background: var(--apm-surface-alt);
	border: 1px solid transparent;
	cursor: pointer;
	transition: background 0.12s ease, border-color 0.12s ease;
}

.apm-perms-ws-check:hover {
	background: #f1f5f9;
}

.apm-perms-ws-check input {
	margin: 0;
	cursor: pointer;
}

.apm-perms-ws-check.is-no-role {
	opacity: 0.6;
}

.apm-perms-ws-check.is-no-role input {
	cursor: not-allowed;
}

.apm-perms-ws-check.is-blocked {
	border-color: var(--apm-danger-soft);
}

.apm-perms-ws-check-meta {
	display: flex;
	flex-direction: column;
	min-width: 0;
}

.apm-perms-ws-check-name {
	font-size: 13px;
	font-weight: 500;
	white-space: nowrap;
	overflow: hidden;
	text-overflow: ellipsis;
}

.apm-perms-ws-check-sub {
	font-size: 11px;
	color: var(--apm-text-muted);
}

/* ==== Tags ==== */
.apm-perms-tag {
	display: inline-block;
	padding: 1px 8px;
	border-radius: 999px;
	background: var(--apm-primary-soft);
	color: var(--apm-primary-hover);
	font-size: 10px;
	font-weight: 600;
	letter-spacing: 0.03em;
	text-transform: uppercase;
}

.apm-perms-tag-muted {
	background: var(--apm-surface-alt);
	color: var(--apm-text-muted);
	border: 1px solid var(--apm-border);
}

.apm-perms-tag-danger {
	background: var(--apm-danger-soft);
	color: var(--apm-danger);
}

/* ==== Role detail: users grid ==== */
.apm-perms-users-grid {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 6px;
}

.apm-perms-user-chip {
	display: flex;
	align-items: center;
	gap: 8px;
	padding: 6px 10px;
	border-radius: 8px;
	background: var(--apm-surface-alt);
	font-size: 12px;
}

.apm-perms-user-chip .apm-perms-list-avatar {
	width: 26px;
	height: 26px;
	font-size: 10px;
}

.apm-perms-user-disabled {
	opacity: 0.55;
}

/* ==== Role detail: workspaces ==== */
.apm-perms-ws-list {
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.apm-perms-ws-row {
	display: flex;
	align-items: center;
	justify-content: space-between;
	padding: 8px 12px;
	border-radius: 8px;
	background: var(--apm-surface-alt);
	font-size: 12px;
}

.apm-perms-ws-name {
	font-weight: 500;
}

/* ==== DocPerm matrix ==== */
.apm-perms-docperm-table {
	border: 1px solid var(--apm-border);
	border-radius: 10px;
	overflow: hidden;
	overflow-x: auto;
}

.apm-perms-docperm-table table {
	width: 100%;
	border-collapse: collapse;
	font-size: 12px;
}

.apm-perms-docperm-table th,
.apm-perms-docperm-table td {
	padding: 6px 10px;
	border-bottom: 1px solid var(--apm-border);
	text-align: left;
}

.apm-perms-docperm-table th {
	background: var(--apm-surface-alt);
	font-weight: 600;
	color: var(--apm-text-muted);
	text-transform: uppercase;
	letter-spacing: 0.04em;
	font-size: 10px;
}

.apm-perms-docperm-table tr:last-child td {
	border-bottom: none;
}

.apm-perms-docperm-table td.flag-on {
	color: var(--apm-success);
	font-weight: 600;
}

.apm-perms-docperm-table td.flag-off {
	color: var(--apm-text-soft);
}

.apm-perms-note {
	margin-top: 8px;
	font-size: 11px;
	color: var(--apm-text-muted);
	font-style: italic;
}
