/* NBD Forge Admin Console Styles */

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --secondary: #64748b;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --border: #475569;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}

.modal-content.wide {
    max-width: 900px;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    font-size: 1.25rem;
}

.close-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

.close-btn:hover {
    color: var(--text);
}

.modal-footer {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Login Box */
.login-box {
    text-align: center;
}

.login-box h1 {
    font-size: 2rem;
    margin-bottom: 0.5rem;
    background: linear-gradient(135deg, var(--primary), #a855f7);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-box h2 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 2rem;
}

.login-box p {
    margin-bottom: 1rem;
    color: var(--text-secondary);
}

.login-box input {
    width: 100%;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
}

.login-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.login-box button {
    width: 100%;
    margin-bottom: 0.5rem;
}

.error-msg {
    color: var(--danger);
    margin-top: 1rem;
    font-size: 0.875rem;
}

/* Buttons */
button {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

button:hover {
    background: var(--primary-dark);
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--secondary);
}

.btn-secondary:hover {
    background: #475569;
}

.btn-danger {
    background: var(--danger);
}

.btn-danger:hover {
    background: #dc2626;
}

.btn-warning {
    background: #f59e0b;
    color: white;
}

.btn-warning:hover {
    background: #d97706;
}

.btn-success {
    background: var(--success);
}

.btn-success:hover {
    background: #16a34a;
}

.btn-info {
    background: #3b82f6;
}

.btn-info:hover {
    background: #2563eb;
}

.btn-small {
    padding: 0.4rem 0.8rem;
    font-size: 0.75rem;
}

.btn-delete {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.btn-delete:hover {
    background: rgba(239, 68, 68, 0.3);
    color: #f87171;
}

/* Header */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
}

header h1 {
    font-size: 1.25rem;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.header-right span {
    color: var(--text-secondary);
}

.header-right button {
    padding: 0.5rem 1rem;
}

/* Styled Select (Language, Status Filter, etc.) */
.styled-select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    cursor: pointer;
    outline: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23999' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.5rem center;
    padding-right: 1.75rem;
}

.styled-select:hover,
.styled-select:focus {
    border-color: var(--primary);
}

.styled-select option {
    background: var(--bg-secondary);
    color: var(--text);
}

/* Header language selector specific */
.header-right .styled-select {
    background-color: #2d2d3a;
    color: #e0e0e0;
    border-color: #404050;
}

/* Navigation */
nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    position: fixed;
    top: 56px; /* header height */
    left: 0;
    right: 0;
    z-index: 999;
}

.nav-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
}

.nav-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text);
}

.nav-btn.active {
    background: var(--primary);
    color: white;
}

/* Main Content */
main {
    padding: 2rem;
    padding-top: 130px; /* header (56px) + nav (50px) + spacing (24px) */
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.section-header h2 {
    font-size: 1.5rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;
}

/* Search Box */
.search-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.search-box input {
    padding: 0.5rem 1rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-tertiary);
    color: var(--text);
    font-size: 0.875rem;
    width: 280px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

.search-box input::placeholder {
    color: var(--text-secondary);
}

.search-box button {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Template ID Style */
.template-id {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: var(--primary);
    font-weight: 600;
    letter-spacing: 0.05em;
}

/* Version History Table */
.version-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
    table-layout: auto;
}

.version-table th,
.version-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.version-table td:nth-child(2) {
    white-space: normal;
    min-width: 120px;
}

.version-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
}

.version-table tbody tr:hover {
    background: var(--bg-tertiary);
}

.no-versions {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.current-version-row {
    background: rgba(34, 197, 94, 0.1);
}

.current-version-row:hover {
    background: rgba(34, 197, 94, 0.15);
}

/* Tables */
table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-secondary);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

tbody tr:hover {
    background: var(--bg-tertiary);
}

/* User table time cells - compact */
.user-time-cell {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

#users-table th,
#users-table td {
    padding: 0.75rem 0.5rem;
}

#users-table th {
    font-size: 0.7rem;
}

/* Flow Progress Styles */
.flow-cell {
    min-width: 220px;
}

.flow-progress {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: wrap;
}

.flow-stage {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    position: relative;
    cursor: help;
    transition: transform 0.2s;
}

.flow-stage:hover {
    transform: scale(1.15);
}

.flow-stage-done {
    background: rgba(34, 197, 94, 0.2);
    border: 2px solid #22c55e;
}

.flow-stage-pending {
    background: var(--bg-tertiary);
    border: 2px dashed var(--border);
    opacity: 0.5;
}

.flow-stage-anomaly {
    background: rgba(239, 68, 68, 0.2);
    border: 2px solid #ef4444;
    animation: pulse-warning 1.5s infinite;
}

@keyframes pulse-warning {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4); }
    50% { box-shadow: 0 0 0 6px rgba(239, 68, 68, 0); }
}

.flow-icon {
    font-size: 0.9rem;
}

.flow-warning {
    position: absolute;
    top: -4px;
    right: -4px;
    font-size: 0.6rem;
}

.flow-arrow {
    color: var(--text-secondary);
    font-size: 0.7rem;
    opacity: 0.5;
}

.flow-anomaly-badge {
    background: rgba(239, 68, 68, 0.2);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 0.15rem 0.4rem;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.5rem;
}

.flow-timeout-badge {
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
    border: 1px solid rgba(251, 146, 60, 0.3);
    padding: 0.15rem 0.4rem;
    border-radius: 8px;
    font-size: 0.65rem;
    font-weight: 600;
    margin-left: 0.5rem;
    animation: pulse-warning 1.5s infinite;
}

/* User row warning styles */
.user-row-warning {
    background: rgba(239, 68, 68, 0.15) !important;
    border-left: 3px solid #ef4444;
    animation: row-pulse 2s ease-in-out infinite;
}

.user-row-warning:hover {
    background: rgba(239, 68, 68, 0.25) !important;
}

.user-row-warning td {
    position: relative;
}

@keyframes row-pulse {
    0%, 100% {
        background: rgba(239, 68, 68, 0.15);
    }
    50% {
        background: rgba(239, 68, 68, 0.08);
    }
}

.actions {
    display: flex;
    gap: 0.5rem;
}

/* Form Groups */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.875rem;
}

.form-group input:focus,
.form-group textarea:focus,
.form-group select:focus {
    outline: none;
    border-color: var(--primary);
}

.form-group textarea {
    font-family: 'Monaco', 'Menlo', monospace;
    resize: vertical;
}

.form-row {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.form-row .form-group {
    margin-bottom: 0;
}

.flex-1 {
    flex: 1;
}

.form-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin: 0.25rem 0 0.5rem 0;
    line-height: 1.4;
}

/* Assignment Container */
.assignment-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
}

.assignment-panel {
    background: var(--bg-secondary);
    padding: 1.5rem;
    border-radius: 8px;
}

.assignment-panel h3 {
    margin-bottom: 1rem;
    font-size: 1rem;
}

.assignment-panel h4 {
    margin: 1rem 0 0.5rem;
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.assignment-panel select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
}

.assignment-panel ul {
    list-style: none;
}

.assignment-panel li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

#available-prompts-list .prompt-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 4px;
}

.prompt-item .prompt-info {
    flex: 1;
}

.prompt-item .prompt-name {
    font-weight: 500;
}

.prompt-item .prompt-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

/* Status Badges */
.badge {
    display: inline-block;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 500;
    white-space: nowrap;
}

.badge-success {
    background: rgba(34, 197, 94, 0.2);
    color: var(--success);
}

.badge-warning {
    background: rgba(245, 158, 11, 0.2);
    color: var(--warning);
}

.badge-danger {
    background: rgba(239, 68, 68, 0.2);
    color: var(--danger);
}

.badge-info {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
}

/* Category Badges */
.badge-first-install {
    background: rgba(236, 72, 153, 0.2);
    color: #ec4899;
}

.badge-each-startup {
    background: rgba(168, 85, 247, 0.2);
    color: #a855f7;
}

.badge-each-query {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.badge-slash-command {
    background: rgba(249, 115, 22, 0.2);
    color: #f97316;
}

.badge-other {
    background: rgba(59, 130, 246, 0.2);
    color: #3b82f6;
}

/* Pre formatted text */
pre {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* ====== Resource Allocation (資源配置) ====== */

.resource-allocation-container {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    min-height: 600px;
}

/* Left Panel - Starter/User Resource Chart */
.user-resource-panel,
.starter-resource-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    min-height: 400px;
    position: relative;
    z-index: 1;
}

/* 確保左邊面板 hover 時 tooltip 能顯示在右邊面板上方 */
.starter-resource-panel:has(.assigned-template:hover) {
    z-index: 100;
}

.starter-resource-panel .panel-footer {
    padding: 1rem 0 0 0;
    margin-top: auto;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
    flex-shrink: 0;
}

.starter-resource-panel .org-chart {
    flex: 1 1 auto;
    min-height: 200px;
    overflow-y: auto;
}

.user-resource-panel .panel-header,
.starter-resource-panel .panel-header {
    margin-bottom: 1.5rem;
}

.user-resource-panel .panel-header h3,
.starter-resource-panel .panel-header h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    color: var(--text);
}

.user-resource-panel .panel-header select,
.starter-resource-panel .panel-header select {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 0.875rem;
}

.user-resource-panel .panel-header select:focus,
.starter-resource-panel .panel-header select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Org Chart Styles */
.org-chart {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
}

.org-placeholder {
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-align: center;
    padding: 2rem;
}

.org-tree {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

/* User Node */
.org-node.user-node {
    background: linear-gradient(135deg, var(--primary), #a855f7);
    border-radius: 12px;
    padding: 1rem 1.5rem;
    text-align: center;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.3);
}

.org-node.user-node .node-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.org-node.user-node .node-icon {
    font-size: 2rem;
}

.org-node.user-node .node-title {
    font-weight: 600;
    font-size: 1rem;
    color: white;
}

.org-node.user-node .node-subtitle {
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.8);
}

/* Connection Line */
.org-connector {
    width: 2px;
    height: 30px;
    background: var(--border);
    position: relative;
}

.org-connector::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: calc(100% + 300px);
    height: 2px;
    background: var(--border);
}

/* Category Nodes Container */
.category-nodes {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 1rem;
    width: 100%;
    margin-top: 30px;
    padding-top: 30px;
    position: relative;
}

/* 3-column variant for resource allocation (without first_install) */
.category-nodes.category-nodes-3 {
    grid-template-columns: repeat(3, 1fr);
}

/* 2-column variant for module config (only each_startup and each_query) */
.category-nodes.category-nodes-2 {
    grid-template-columns: repeat(2, 1fr);
}

.category-nodes::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 30px;
    background: linear-gradient(180deg, transparent 14px, var(--border) 14px, var(--border) 16px, transparent 16px);
}

/* Category Node */
.org-node.category-node {
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    position: relative;
}

.org-node.category-node::before {
    content: '';
    position: absolute;
    top: -30px;
    left: 50%;
    width: 2px;
    height: 30px;
    background: var(--border);
}

.node-header {
    padding: 0.75rem;
    text-align: center;
    font-weight: 600;
    font-size: 0.75rem;
}

.node-header.badge-first-install {
    background: rgba(236, 72, 153, 0.3);
    color: #ec4899;
}

.node-header.badge-each-startup {
    background: rgba(168, 85, 247, 0.3);
    color: #a855f7;
}

.node-header.badge-each-query {
    background: rgba(34, 197, 94, 0.3);
    color: #22c55e;
}

.node-header.badge-slash-command {
    background: rgba(249, 115, 22, 0.3);
    color: #f97316;
}

.node-header.badge-other {
    background: rgba(59, 130, 246, 0.3);
    color: #3b82f6;
}

/* Drop Zone */
.node-drop-zone {
    min-height: 100px;
    padding: 0.75rem;
    background: var(--bg);
    transition: background 0.2s, border-color 0.2s;
    border: 2px dashed transparent;
}

.node-drop-zone.drag-over {
    background: rgba(99, 102, 241, 0.1);
    border-color: var(--primary);
}

.node-drop-zone.drag-not-allowed {
    background: rgba(239, 68, 68, 0.1);
    border-color: var(--danger);
    cursor: not-allowed;
}

.node-drop-zone.drag-not-allowed .drop-hint {
    color: var(--danger);
}

.drop-hint {
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-align: center;
    padding: 1rem 0.5rem;
    opacity: 0.5;
}

/* Assigned Template in Org Chart */
.assigned-template {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-secondary);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.5rem;
    font-size: 0.75rem;
    border: 1px solid var(--border);
    transition: border-color 0.2s, background 0.2s;
}

.assigned-template:hover {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.assigned-template .template-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    overflow: hidden;
    min-width: 0;
}

.assigned-template .template-id-badge {
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.6rem;
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-weight: 600;
    letter-spacing: 0.03em;
    display: inline-block;
    width: fit-content;
}

.assigned-template .template-title {
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text);
}

.assigned-template .template-meta {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.6rem;
}

.assigned-template .template-version {
    color: var(--text-secondary);
    background: var(--bg-tertiary);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
}

.assigned-template .template-usage {
    color: #f472b6;
    background: rgba(236, 72, 153, 0.15);
    padding: 0.1rem 0.35rem;
    border-radius: 3px;
    font-weight: 500;
}

.assigned-template .remove-btn {
    background: transparent;
    border: none;
    color: var(--danger);
    font-size: 1rem;
    padding: 0 0.25rem;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

.assigned-template .remove-btn:hover {
    color: #dc2626;
    background: transparent;
}

/* Assigned Template Category Colors */
.assigned-template.template-each-startup {
    border-color: rgba(168, 85, 247, 0.5);
    background: rgba(168, 85, 247, 0.08);
}

.assigned-template.template-each-startup:hover {
    border-color: #a855f7;
    background: rgba(168, 85, 247, 0.15);
}

.assigned-template.template-each-startup .template-id-badge {
    background: rgba(168, 85, 247, 0.2);
    color: #c084fc;
}

.assigned-template.template-each-query {
    border-color: rgba(34, 197, 94, 0.5);
    background: rgba(34, 197, 94, 0.08);
}

.assigned-template.template-each-query:hover {
    border-color: #22c55e;
    background: rgba(34, 197, 94, 0.15);
}

.assigned-template.template-each-query .template-id-badge {
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
}

.assigned-template.template-slash-command {
    border-color: rgba(249, 115, 22, 0.5);
    background: rgba(249, 115, 22, 0.08);
}

.assigned-template.template-slash-command:hover {
    border-color: #f97316;
    background: rgba(249, 115, 22, 0.15);
}

.assigned-template.template-slash-command .template-id-badge {
    background: rgba(249, 115, 22, 0.2);
    color: #fb923c;
}

/* Slash Command Name Display */
.slash-command-name {
    display: inline-block;
    padding: 2px 8px;
    background: rgba(249, 115, 22, 0.3);
    color: #fdba74;
    border-radius: 4px;
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8rem;
    font-weight: 600;
    margin-right: 8px;
    white-space: nowrap;
}

.assigned-template.template-other {
    border-color: rgba(59, 130, 246, 0.5);
    background: rgba(59, 130, 246, 0.08);
}

.assigned-template.template-other:hover {
    border-color: #3b82f6;
    background: rgba(59, 130, 246, 0.15);
}

.assigned-template.template-other .template-id-badge {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

/* Right Panel - Templates Pool */
.templates-pool-panel {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    position: relative;
    z-index: 0;
}

.templates-pool-panel .panel-header {
    margin-bottom: 1.5rem;
}

.templates-pool-panel .panel-header h3 {
    font-size: 1.1rem;
    color: var(--text);
    font-weight: 600;
}

.templates-pool {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    overflow-y: auto;
}

/* Template Category in Pool */
.template-category {
    background: var(--bg-tertiary);
    border-radius: 8px;
    overflow: hidden;
}

.template-category .category-header {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border);
}

.template-category .category-badge {
    font-size: 0.875rem;
    font-weight: 600;
    padding: 0.35rem 0.6rem;
    border-radius: 4px;
}

.category-templates {
    padding: 0.75rem;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 40px;
}

/* Template Tags */
.template-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.85rem;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: grab;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    user-select: none;
}

.template-tag:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.template-tag.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.template-tag.assigned {
    opacity: 0.5;
    cursor: not-allowed;
}

.template-tag.assigned:hover {
    transform: none;
    box-shadow: none;
}

.template-tag .tag-title {
    font-weight: 500;
}

.template-tag .tag-version {
    font-size: 0.8rem;
    opacity: 0.85;
    color: #cbd5e1;
}

.template-tag .tag-assigned {
    font-size: 0.875rem;
    color: var(--success);
}

/* Template Tooltip */
.template-tag,
.assigned-template {
    position: relative;
}

.template-tooltip {
    display: none;
    position: fixed;
    width: 450px;
    max-width: 90vw;
    max-height: 70vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.4);
    z-index: 99999;
    padding: 0;
    overflow: hidden;
    pointer-events: auto;
    flex-direction: column;
}

.template-tooltip::after {
    display: none;
}

.template-tag:hover .template-tooltip,
.assigned-template:hover .template-tooltip,
.template-tooltip:hover {
    display: flex;
}

.template-tag:hover,
.assigned-template:hover {
    z-index: 9998;
}

.tooltip-header {
    background: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--primary);
    border-bottom: 1px solid var(--border);
}

.tooltip-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    font-size: 0.7rem;
}

.tooltip-meta span {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    color: var(--text-secondary);
}

.tooltip-content {
    padding: 0.75rem 1rem;
    font-size: 0.8rem;
    line-height: 1.6;
    color: var(--text);
    flex: 1;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

/* Adjust tooltip position when near edges */
.template-tag:first-child .template-tooltip,
.assigned-template:first-child .template-tooltip {
    left: 0;
    transform: translateX(0);
}

.template-tag:first-child .template-tooltip::after,
.assigned-template:first-child .template-tooltip::after {
    left: 30px;
}

/* Template tag colors */
.template-tag.badge-first-install {
    background: rgba(236, 72, 153, 0.3);
    color: #f472b6;
    border: 1px solid rgba(236, 72, 153, 0.5);
}

.template-tag.badge-each-startup {
    background: rgba(168, 85, 247, 0.3);
    color: #c084fc;
    border: 1px solid rgba(168, 85, 247, 0.5);
}

.template-tag.badge-each-query {
    background: rgba(34, 197, 94, 0.3);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.5);
}

.template-tag.badge-slash-command {
    background: rgba(249, 115, 22, 0.3);
    color: #fb923c;
    border: 1px solid rgba(249, 115, 22, 0.5);
}

.template-tag.badge-other {
    background: rgba(59, 130, 246, 0.3);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.5);
}

/* Responsive */
@media (max-width: 1200px) {
    .resource-allocation-container {
        grid-template-columns: 1fr;
    }

    .category-nodes {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    .assignment-container {
        grid-template-columns: 1fr;
    }

    nav {
        flex-wrap: wrap;
    }

    table {
        display: block;
        overflow-x: auto;
    }

    .category-nodes {
        grid-template-columns: 1fr;
    }

    .org-connector::after {
        display: none;
    }

    .org-node.category-node::before {
        display: none;
    }
}

/* Panel Footer with Compiled Button */
.panel-footer {
    padding: 1rem 0 0 0;
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: center;
}

.btn-compiled {
    background: linear-gradient(135deg, #3b82f6, #6366f1);
    color: white;
    border: none;
    padding: 0.75rem 1.5rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.3);
}

.btn-compiled:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.4);
}

.btn-compiled:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
    box-shadow: none;
}

/* Auth Message Button */
.btn-auth-message {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 0.4rem;
    box-shadow: 0 2px 6px rgba(245, 158, 11, 0.3);
}

.btn-auth-message:hover:not(:disabled) {
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(245, 158, 11, 0.4);
}

.btn-auth-message:disabled {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    cursor: not-allowed;
    box-shadow: none;
}

/* Panel Header Actions (for starter config panel) */
.panel-header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

/* Compiled Content Modal */
.compiled-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.compiled-info #compiled-user-info {
    color: var(--text);
    font-weight: 500;
}

.compiled-info #compiled-stats {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

/* Compiled Split View */
.compiled-split-view {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1.5rem;
    height: 55vh;
}

.compiled-panel {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

.compiled-panel .panel-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    font-weight: 600;
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
}

.compiled-panel .panel-icon {
    font-size: 1rem;
}

.compiled-panel.starter-panel {
    border-color: rgba(236, 72, 153, 0.3);
}

.compiled-panel.starter-panel .panel-title {
    background: rgba(236, 72, 153, 0.1);
    color: #ec4899;
}

.compiled-panel.templates-panel {
    border-color: rgba(99, 102, 241, 0.3);
}

.compiled-panel.templates-panel .panel-title {
    background: rgba(99, 102, 241, 0.1);
    color: #818cf8;
}

.compiled-panel pre {
    flex: 1;
    margin: 0;
    padding: 1rem;
    background: transparent;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: var(--text);
}

/* Extra wide modal for split view */
.modal-content.extra-wide {
    max-width: 1200px;
    width: 95%;
}

@media (max-width: 900px) {
    .compiled-split-view {
        grid-template-columns: 1fr;
        height: auto;
    }

    .compiled-panel {
        max-height: 40vh;
    }
}

/* Public badge indicator */
.badge-public {
    background: rgba(236, 72, 153, 0.15);
    color: #ec4899;
    font-size: 0.65rem;
    padding: 0.15rem 0.4rem;
    border-radius: 3px;
    margin-left: 0.5rem;
    border: 1px solid rgba(236, 72, 153, 0.3);
}

/* Starter Command Button */
.btn-starter {
    background: linear-gradient(135deg, #ec4899, #f472b6);
    color: white;
    border: none;
    padding: 0.4rem 0.6rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-starter:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(236, 72, 153, 0.4);
}

/* Starter Command Modal */
.starter-command-box {
    background: var(--bg);
    border: 2px solid rgba(236, 72, 153, 0.3);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.starter-command-box label {
    display: block;
    color: #ec4899;
    font-size: 0.75rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
    text-transform: uppercase;
}

.starter-command-text {
    display: block;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    color: var(--text);
    word-break: break-word;
    cursor: pointer;
    transition: border-color 0.2s;
    user-select: all;
}

.starter-command-text:hover {
    border-color: #ec4899;
}

.starter-url {
    color: #60a5fa;
    text-decoration: none;
}

.starter-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.starter-note {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.75rem;
    padding: 0.5rem;
    background: rgba(236, 72, 153, 0.1);
    border-radius: 4px;
    border-left: 3px solid #ec4899;
}

.starter-note strong {
    color: #ec4899;
}

/* ===== User Starter Config Modal ===== */
.user-starter-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
}

.starter-config-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border);
    transition: border-color 0.2s, background 0.2s;
}

.starter-config-item:hover {
    border-color: rgba(236, 72, 153, 0.5);
}

.starter-config-item.has-permission {
    border-color: rgba(34, 197, 94, 0.5);
    background: rgba(34, 197, 94, 0.05);
}

.starter-config-info,
.starter-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.starter-config-name,
.starter-title {
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

.starter-config-id,
.starter-template-id {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

.starter-toggle {
    flex-shrink: 0;
}

.starter-config-hint {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-bottom: 1rem;
    padding: 0.5rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    border-left: 3px solid #6366f1;
}

/* Toggle Switch */
.toggle-switch {
    position: relative;
    width: 50px;
    height: 26px;
    flex-shrink: 0;
}

.toggle-switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.toggle-slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--bg-secondary);
    border: 1px solid var(--border);
    transition: all 0.3s;
    border-radius: 26px;
}

.toggle-slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: var(--text-secondary);
    transition: all 0.3s;
    border-radius: 50%;
}

.toggle-switch input:checked + .toggle-slider {
    background: linear-gradient(135deg, #22c55e, #4ade80);
    border-color: #22c55e;
}

.toggle-switch input:checked + .toggle-slider:before {
    transform: translateX(24px);
    background-color: white;
}

.toggle-switch input:focus + .toggle-slider {
    box-shadow: 0 0 0 2px rgba(34, 197, 94, 0.3);
}

/* ===== Starter-Centric Resource Allocation ===== */
.section-desc {
    color: var(--text-secondary);
    font-size: 0.85rem;
    margin-top: 0.5rem;
}

/* Users Pool */
.users-pool {
    flex: 1;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-content: flex-start;
    overflow-y: auto;
    padding: 0.5rem;
    min-height: 200px;
}

.user-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    background: linear-gradient(135deg, rgba(99, 102, 241, 0.3), rgba(139, 92, 246, 0.3));
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.5);
    border-radius: 6px;
    font-size: 0.75rem;
    cursor: grab;
    transition: transform 0.2s, box-shadow 0.2s, opacity 0.2s;
    user-select: none;
}

.user-tag:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.3);
}

.user-tag.dragging {
    opacity: 0.5;
    cursor: grabbing;
}

.user-tag.assigned {
    opacity: 0.4;
    cursor: not-allowed;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-color: var(--border);
}

.user-tag.assigned:hover {
    transform: none;
    box-shadow: none;
}

.user-tag .tag-name {
    font-weight: 500;
}

.user-tag .tag-email {
    font-size: 0.625rem;
    opacity: 0.7;
}

.user-tag .tag-assigned-icon {
    font-size: 0.875rem;
    color: var(--success);
}

/* Starter Node in Org Chart */
.starter-node {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.2), rgba(244, 114, 182, 0.2));
    border: 2px solid rgba(236, 72, 153, 0.5);
    border-radius: 12px;
    padding: 1.5rem;
    text-align: center;
    position: relative;
}

.starter-node .node-icon {
    font-size: 2rem;
    margin-bottom: 0.5rem;
}

.starter-node .node-name {
    font-size: 1rem;
    font-weight: 600;
    color: #f472b6;
    margin-bottom: 0.25rem;
}

.starter-node .node-id {
    font-size: 0.7rem;
    color: var(--text-secondary);
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
}

/* Users Drop Zone */
.users-drop-zone {
    margin-top: 1.5rem;
    padding: 1rem;
    border: 2px dashed rgba(99, 102, 241, 0.3);
    border-radius: 8px;
    background: var(--bg-tertiary);
    min-height: 100px;
    transition: border-color 0.2s, background 0.2s;
}

.users-drop-zone.drag-over {
    border-color: #6366f1;
    background: rgba(99, 102, 241, 0.1);
}

.drop-zone-title {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 0.75rem;
}

.assigned-users-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
}

.assigned-user-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.5);
    border-radius: 6px;
    font-size: 0.7rem;
}

.assigned-user-tag .remove-btn {
    background: transparent;
    border: none;
    color: #f87171;
    font-size: 0.875rem;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    margin-left: 0.25rem;
}

.assigned-user-tag .remove-btn:hover {
    color: #ef4444;
}

/* No users message */
.no-users-msg {
    color: var(--text-secondary);
    font-size: 0.75rem;
    text-align: center;
    padding: 1rem;
    font-style: italic;
}

/* Org chart placeholder */
.org-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 200px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Assigned user in starter chart */
.node-users-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    justify-content: center;
    padding: 0.5rem;
    min-height: 40px;
}

.assigned-user {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.6rem;
    background: rgba(34, 197, 94, 0.2);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.5);
    border-radius: 6px;
    font-size: 0.75rem;
}

.assigned-user .user-name {
    font-weight: 500;
}

.assigned-user .remove-btn {
    background: transparent;
    border: none;
    color: #f87171;
    font-size: 1rem;
    padding: 0;
    cursor: pointer;
    line-height: 1;
    margin-left: 0.25rem;
}

.assigned-user .remove-btn:hover {
    color: #ef4444;
}

/* Loading and error states */
.loading, .error, .no-starters {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
}

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

/* ===== Template Management Sections ===== */
.template-section {
    margin-bottom: 1.5rem;
}

.starters-section {
    background: linear-gradient(135deg, rgba(236, 72, 153, 0.05), rgba(244, 114, 182, 0.05));
    border: 1px solid rgba(236, 72, 153, 0.2);
    border-radius: 12px;
    padding: 1.5rem;
}

.starters-section h2 {
    color: #ec4899;
}

.other-templates-section {
    background: var(--bg-secondary);
    border-radius: 12px;
    padding: 1.5rem;
}

.section-divider {
    height: 2px;
    background: linear-gradient(to right, transparent, var(--border), transparent);
    margin: 2rem 0;
}

/* Compact table for starters */
.compact-table {
    font-size: 0.875rem;
}

.compact-table th,
.compact-table td {
    padding: 0.6rem 0.75rem;
}

/* No data row */
.no-data {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem !important;
    font-style: italic;
}

/* ===== Starter Users Section (Left Panel) ===== */
.starter-users-section {
    margin-top: 1rem;
    border-top: 1px solid var(--border);
    padding-top: 1rem;
}

.users-section-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
    padding: 0 0.5rem;
}

.users-section-icon {
    font-size: 1rem;
}

.users-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text);
}

.users-count-badge {
    background: rgba(99, 102, 241, 0.2);
    color: var(--primary);
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    margin-left: auto;
}

.starter-users-list {
    max-height: 150px;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.starter-users-list::-webkit-scrollbar {
    width: 6px;
}

.starter-users-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.starter-users-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.starter-users-list::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

.starter-user-item {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    background: rgba(34, 197, 94, 0.15);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 6px;
    font-size: 0.7rem;
    white-space: nowrap;
}

.starter-user-item .user-icon {
    font-size: 0.75rem;
}

.starter-user-item .user-name {
    font-weight: 500;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
}

.starter-user-item .user-remove-btn {
    display: none;
    margin-left: 0.25rem;
    padding: 0;
    width: 16px;
    height: 16px;
    border: none;
    background: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    border-radius: 50%;
    font-size: 12px;
    line-height: 1;
    cursor: pointer;
    transition: all 0.15s ease;
}

.starter-user-item:hover .user-remove-btn {
    display: flex;
    align-items: center;
    justify-content: center;
}

.starter-user-item .user-remove-btn:hover {
    background: rgba(239, 68, 68, 0.6);
    color: #fff;
}

.starter-users-empty {
    width: 100%;
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.75rem;
    font-style: italic;
}

/* ===== Template Preview Modal (Long Press) ===== */
.template-preview-modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    justify-content: center;
    align-items: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.template-preview-modal.active {
    display: flex;
}

.template-preview-content {
    background: var(--bg-secondary);
    border-radius: 12px;
    max-width: 600px;
    width: 90%;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.5), 0 0 40px rgba(99, 102, 241, 0.2);
    border: 1px solid var(--border);
    animation: slideUp 0.25s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.template-preview-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.25rem;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border);
}

.template-preview-title {
    font-size: 1rem;
    font-weight: 600;
    color: var(--primary);
}

.template-preview-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    line-height: 1;
    transition: color 0.2s;
}

.template-preview-close:hover {
    color: var(--text);
    background: transparent;
}

.template-preview-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1.25rem;
    background: var(--bg);
    border-bottom: 1px solid var(--border);
}

.template-preview-meta span {
    font-size: 0.7rem;
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    color: var(--text-secondary);
}

.template-preview-body {
    padding: 1.25rem;
    max-height: 50vh;
    overflow-y: auto;
}

.template-preview-body pre {
    margin: 0;
    font-family: 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 0.8rem;
    line-height: 1.6;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text);
    background: transparent;
    padding: 0;
}

/* Long press indicator */
.template-tag.long-pressing {
    animation: longPressIndicator 2s linear forwards;
}

@keyframes longPressIndicator {
    0% {
        box-shadow: inset 0 0 0 0 rgba(99, 102, 241, 0.4);
    }
    100% {
        box-shadow: inset 0 0 0 30px rgba(99, 102, 241, 0.4);
    }
}

/* Disable hover tooltip for template tags (now using long press) */
.template-tag:hover .template-tooltip {
    display: none;
}

/* ===== Starter Permission Config Modal (New Style) ===== */
.starter-permission-list {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.add-user-section {
    display: flex;
    gap: 0.75rem;
    padding: 1rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.add-user-select {
    flex: 1;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
}

.add-user-select:focus {
    outline: none;
    border-color: var(--primary);
}

.btn-add-user {
    padding: 0.6rem 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.85rem;
    white-space: nowrap;
    transition: all 0.2s;
}

.btn-add-user:hover {
    background: var(--primary-hover);
    transform: translateY(-1px);
}

.all-users-assigned {
    padding: 1rem;
    text-align: center;
    color: var(--success);
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    border-radius: 8px;
    font-size: 0.85rem;
}

.assigned-users-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.section-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    padding-left: 0.25rem;
}

.assigned-users-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.assigned-users-list::-webkit-scrollbar {
    width: 6px;
}

.assigned-users-list::-webkit-scrollbar-track {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.assigned-users-list::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
}

.permission-user-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 6px;
    border: 1px solid var(--border);
    transition: all 0.15s;
}

.permission-user-item:hover {
    border-color: var(--primary);
    background: var(--bg-tertiary);
}

.permission-user-item .user-info {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex: 1;
    min-width: 0;
}

.permission-user-item .user-icon {
    font-size: 1rem;
}

.permission-user-item .user-display-name {
    font-weight: 500;
    color: var(--text);
    font-size: 0.85rem;
}

.permission-user-item .user-email {
    font-size: 0.75rem;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.btn-remove-user {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    font-size: 1rem;
    transition: all 0.15s;
    border-radius: 4px;
}

.btn-remove-user:hover {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

.no-users {
    padding: 2rem;
    text-align: center;
    color: var(--text-secondary);
    font-style: italic;
    font-size: 0.85rem;
}

/* Permission button style */
.btn-permission {
    background: linear-gradient(135deg, #8b5cf6 0%, #6366f1 100%) !important;
    color: white !important;
}

.btn-permission:hover {
    background: linear-gradient(135deg, #7c3aed 0%, #4f46e5 100%) !important;
}

/* === User Reply Records === */

.replies-table {
    width: 100%;
    border-collapse: collapse;
}

.replies-table th,
.replies-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.replies-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.replies-table td {
    font-size: 0.9rem;
}

.replies-table .no-data,
.replies-table .loading,
.replies-table .error {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
}

.reply-content-preview {
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Reply Detail Modal */
.reply-meta {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1.5rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.reply-meta-item {
    font-size: 0.9rem;
}

.reply-meta-item strong {
    color: var(--text-secondary);
    margin-right: 0.5rem;
}

.reply-meta-item code {
    background: var(--bg);
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    font-size: 0.85rem;
}

.reply-content-wrapper {
    margin-top: 1rem;
}

.reply-content-wrapper label {
    display: block;
    font-weight: 600;
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.reply-content {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    max-height: 500px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}

/* Data section with formatted text */
.reply-data-content {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 0.5rem;
    max-height: 300px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
    line-height: 1.6;
}

/* Reply Visual Content Styles */
.reply-visual-content {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.reply-section {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.5rem;
}

.reply-data-section {
    flex-direction: column;
    align-items: stretch;
}

.reply-data-section .reply-label {
    margin-bottom: 0.5rem;
}

.reply-label {
    font-weight: 600;
    color: var(--text-secondary);
    min-width: 100px;
    flex-shrink: 0;
}

.reply-code {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
}

.reply-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.reply-tag {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.reply-tag-info {
    background: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
    border: 1px solid rgba(59, 130, 246, 0.3);
}

.reply-tag-default {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px solid var(--border);
}

.reply-tag-device {
    background: rgba(139, 92, 246, 0.2);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.3);
}

.reply-tag-missing {
    background: rgba(107, 114, 128, 0.2);
    color: #9ca3af;
    border: 1px dashed rgba(107, 114, 128, 0.4);
    font-style: italic;
}

.reply-device-section {
    flex-direction: column;
    align-items: flex-start;
}

.reply-device-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.reply-device-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.reply-device-key {
    font-size: 0.8rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.reply-device-info {
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-device-cell {
    min-width: 180px;
}

.reply-device-tag {
    display: inline-block;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
    border: 1px solid rgba(139, 92, 246, 0.3);
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}

.reply-tasks-list {
    flex-direction: column;
    align-items: flex-start;
}

.reply-tasks {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.reply-task {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.85rem;
}

.reply-task-success {
    background: rgba(34, 197, 94, 0.1);
    border-left: 3px solid #22c55e;
}

.reply-task-fail {
    background: rgba(239, 68, 68, 0.1);
    border-left: 3px solid #ef4444;
}

.reply-task-icon {
    flex-shrink: 0;
}

.reply-task-name {
    font-weight: 500;
    color: var(--text);
}

.reply-task-msg {
    color: var(--text-secondary);
    font-size: 0.8rem;
    margin-left: auto;
    max-width: 300px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-summary {
    background: var(--bg-tertiary);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    color: var(--text);
    line-height: 1.5;
    flex: 1;
}

.reply-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    padding: 0.75rem 1rem;
    border-radius: 6px;
    color: #f87171;
    line-height: 1.5;
    flex: 1;
}

.reply-raw-toggle {
    flex-direction: column;
    align-items: flex-start;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.reply-raw-json {
    width: 100%;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 1rem;
    margin-top: 0.5rem;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.8rem;
    line-height: 1.4;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

.reply-raw-content pre {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 6px;
    white-space: pre-wrap;
    word-break: break-word;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 0.85rem;
}

/* === Toast Notification === */

#toast-container {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 100000;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    pointer-events: none;
}

.toast-message {
    background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
    color: white;
    padding: 12px 24px;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 500;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.3);
    opacity: 0;
    transform: translateY(-20px);
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: auto;
}

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


/* === Slide Confirm Modal === */

.slide-confirm-content {
    max-width: 400px;
}

.slide-confirm-warning {
    color: var(--warning);
    font-size: 1.1rem;
    font-weight: 600;
    text-align: center;
    margin-bottom: 0.5rem;
}

.slide-confirm-instruction {
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

.slide-confirm-container {
    padding: 0 1rem;
}

.slide-confirm-track {
    position: relative;
    width: 100%;
    height: 50px;
    background: linear-gradient(135deg, var(--bg) 0%, var(--bg-tertiary) 100%);
    border-radius: 25px;
    border: 2px solid var(--border);
    overflow: hidden;
    user-select: none;
}

.slide-confirm-handle {
    position: absolute;
    left: 0;
    top: 0;
    width: 50px;
    height: 46px;
    background: linear-gradient(135deg, var(--danger) 0%, #dc2626 100%);
    border-radius: 23px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
    z-index: 2;
    transition: background 0.3s ease;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.4);
}

.slide-confirm-handle:active,
.slide-confirm-handle.dragging {
    cursor: grabbing;
}

.slide-confirm-handle span {
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
    pointer-events: none;
}

.slide-confirm-handle.confirmed {
    background: linear-gradient(135deg, var(--success) 0%, #16a34a 100%);
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.4);
}

.slide-confirm-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 500;
    pointer-events: none;
    white-space: nowrap;
}

.slide-confirm-success {
    position: absolute;
    top: 50%;
    right: 15px;
    transform: translateY(-50%);
    color: var(--success);
    font-size: 0.9rem;
    font-weight: 600;
    opacity: 0;
    transition: opacity 0.2s ease;
    pointer-events: none;
}

.slide-confirm-success.show {
    opacity: 1;
}

/* ===== Tutorial Page Styles ===== */
.tutorial-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1rem;
}

.tutorial-section {
    background: var(--bg-secondary);
    border-radius: 16px;
    margin-bottom: 2rem;
    overflow: hidden;
    border: 1px solid var(--border);
}

.tutorial-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.5rem 2rem;
    background: linear-gradient(135deg, var(--bg-tertiary) 0%, var(--bg-secondary) 100%);
    border-bottom: 1px solid var(--border);
}

.tutorial-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text);
}

.tutorial-icon {
    font-size: 2rem;
}

.tutorial-content {
    padding: 2rem;
}

/* Tutorial Steps */
.tutorial-steps {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.tutorial-step {
    display: flex;
    gap: 1.5rem;
    padding: 1.5rem;
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    transition: transform 0.2s, box-shadow 0.2s;
}

.tutorial-step:hover {
    transform: translateX(8px);
    box-shadow: -4px 0 0 var(--primary);
}

.step-number {
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    font-size: 1.5rem;
    font-weight: 700;
    border-radius: 12px;
}

.step-content h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1.2rem;
    color: var(--text);
}

.step-content p {
    margin: 0 0 0.75rem 0;
    color: var(--text-secondary);
    line-height: 1.6;
}

.step-content ul {
    margin: 0;
    padding-left: 1.5rem;
    color: var(--text-secondary);
}

.step-content ul li {
    margin-bottom: 0.5rem;
    line-height: 1.6;
}

.step-content ul ul {
    margin-top: 0.5rem;
}

.step-content code {
    background: var(--bg-tertiary);
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.9rem;
    color: var(--primary);
}

.step-content .highlight {
    background: rgba(99, 102, 241, 0.2);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    color: #a5b4fc;
}

/* Tip Box */
.tip-box {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    margin-top: 1rem;
    padding: 1rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    border-left: 3px solid var(--primary);
}

.tip-box.warning {
    background: rgba(245, 158, 11, 0.1);
    border-left-color: var(--warning);
}

.tip-icon {
    font-size: 1.2rem;
}

.tip-box span:last-child {
    color: var(--text-secondary);
    font-size: 0.95rem;
    line-height: 1.5;
}

/* Flow Diagram */
.flow-diagram {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 2rem;
    padding: 2rem;
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow-x: auto;
}

.flow-column {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    min-width: 200px;
}

.column-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    padding: 0.75rem 1.5rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.flow-node {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    border-radius: 12px;
    min-width: 180px;
    text-align: center;
    transition: transform 0.2s;
}

.flow-node:hover {
    transform: scale(1.05);
}

.user-node {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
    color: white;
}

.server-node {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
    color: white;
}

.success-node {
    background: linear-gradient(135deg, #22c55e 0%, #15803d 100%);
    color: white;
}

.success-node.final {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.warning-node {
    background: linear-gradient(135deg, #ef4444 0%, #b91c1c 100%);
    color: white;
}

.node-icon {
    font-size: 1.5rem;
}

.node-text {
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.4;
}

.node-text code {
    display: block;
    margin-top: 0.5rem;
    font-size: 0.75rem;
    background: rgba(0, 0, 0, 0.2);
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
}

.node-text small {
    display: block;
    margin-top: 0.25rem;
    font-size: 0.75rem;
    opacity: 0.85;
}

/* Flow Arrows */
.flow-arrow {
    width: 2px;
    height: 30px;
    background: var(--border);
    position: relative;
}

.flow-arrow.down::after {
    content: '';
    position: absolute;
    bottom: -6px;
    left: -4px;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-top: 8px solid var(--border);
}

.flow-arrow.small {
    height: 20px;
}

/* Flow Connector */
.flow-connector {
    display: flex;
    align-items: center;
    padding-top: 80px;
}

.connector-line {
    width: 60px;
    height: 2px;
    background: var(--border);
}

.connector-arrow {
    width: 0;
    height: 0;
    border-top: 6px solid transparent;
    border-bottom: 6px solid transparent;
    border-left: 10px solid var(--border);
}

/* Flow Branch */
.flow-branch {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
    margin-top: 1rem;
}

.branch-condition {
    padding: 0.5rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 20px;
    font-weight: 600;
    color: var(--text);
    font-size: 0.9rem;
}

.flow-branch > div:last-child {
    display: flex;
    gap: 2rem;
}

.branch-path {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.75rem;
}

.branch-label {
    font-size: 0.85rem;
    font-weight: 600;
    padding: 0.4rem 0.8rem;
    border-radius: 6px;
}

.invalid-path .branch-label {
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
}

.valid-path .branch-label {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
}

/* Auth Flow Section */
.auth-flow-section {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.auth-flow-section h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.2rem;
    color: var(--text);
    text-align: center;
}

.auth-flow-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1rem;
    flex-wrap: wrap;
}

.auth-step {
    display: flex;
    gap: 1rem;
    padding: 1rem 1.5rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 1px solid var(--border);
    min-width: 220px;
}

.auth-step-num {
    flex-shrink: 0;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    font-weight: 700;
    border-radius: 50%;
}

.auth-step-content {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.auth-step-title {
    font-weight: 600;
    color: var(--text);
}

.auth-step-content code {
    font-size: 0.75rem;
    background: var(--bg-tertiary);
    padding: 0.3rem 0.5rem;
    border-radius: 4px;
    color: #a5b4fc;
}

.auth-step-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.auth-arrow {
    font-size: 1.5rem;
    color: var(--primary);
    font-weight: bold;
}

/* Data Structure Section */
.data-structure-section {
    margin-top: 2rem;
    padding: 1.5rem;
    background: var(--bg);
    border-radius: 12px;
    border: 1px solid var(--border);
}

.data-structure-section h3 {
    margin: 0 0 1.5rem 0;
    font-size: 1.2rem;
    color: var(--text);
    text-align: center;
}

.structure-diagram {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.structure-entity {
    min-width: 180px;
    background: var(--bg-secondary);
    border-radius: 12px;
    border: 2px solid var(--border);
    overflow: hidden;
}

.entity-header {
    padding: 0.75rem 1rem;
    font-weight: 600;
    text-align: center;
    color: white;
}

.starter-entity .entity-header {
    background: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
}

.template-entity .entity-header {
    background: linear-gradient(135deg, #8b5cf6 0%, #6d28d9 100%);
}

.user-entity .entity-header {
    background: linear-gradient(135deg, #3b82f6 0%, #1d4ed8 100%);
}

.entity-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.entity-field {
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border-radius: 6px;
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
}

.entity-field.category-once {
    border-left: 3px solid #f59e0b;
}

.entity-field.category-always {
    border-left: 3px solid #22c55e;
}

.entity-field.category-other {
    border-left: 3px solid #8b5cf6;
}

.structure-relation {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.25rem;
}

.relation-line {
    width: 60px;
    height: 2px;
    background: var(--border);
}

.relation-label {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--primary);
    background: var(--bg-tertiary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

.relation-desc {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: center;
    max-width: 120px;
}

/* Responsive */
@media (max-width: 768px) {
    .flow-diagram {
        flex-direction: column;
    }

    .flow-connector {
        padding-top: 0;
        transform: rotate(90deg);
    }

    .auth-flow-diagram {
        flex-direction: column;
    }

    .auth-arrow {
        transform: rotate(90deg);
    }

    .structure-diagram {
        flex-direction: column;
    }

    .structure-relation {
        transform: rotate(90deg);
        margin: 1rem 0;
    }
}

/* === File Download Logs Styles === */

/* Stats Card */
.stats-card {
    background: var(--bg-tertiary);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-item {
    background: var(--bg-secondary);
    padding: 1rem;
    border-radius: 8px;
    text-align: center;
}

.stat-label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.stat-value {
    display: block;
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stats-lists {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.stats-list h4 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.stats-list ul {
    list-style: none;
    padding: 0;
    margin: 0;
}

.stats-list li {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
    font-size: 0.9rem;
}

.stats-list li.empty {
    color: var(--text-secondary);
    font-style: italic;
}

.stats-list .file-name,
.stats-list .user-name {
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-right: 1rem;
}

.stats-list .file-count,
.stats-list .user-count {
    color: var(--success);
    font-weight: 500;
}

/* Filter Section */
.filter-section {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
}

.filter-section label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.filter-section select {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.9rem;
    min-width: 200px;
}

.filter-section select:focus {
    outline: none;
    border-color: var(--primary);
}

/* Downloads Table */
#downloads-table {
    width: 100%;
    border-collapse: collapse;
}

#downloads-table th,
#downloads-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

#downloads-table th {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 0.85rem;
    text-transform: uppercase;
}

#downloads-table td {
    font-size: 0.9rem;
}

#downloads-table tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

/* Badge for status */
.badge-danger {
    background: var(--danger);
    color: white;
}

/* ============================================
   File Management Styles
   ============================================ */

/* Files Table */
.files-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.files-table th,
.files-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.files-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.files-table td {
    font-size: 0.9rem;
}

.files-table tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.file-name-cell {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.file-name-cell .file-icon {
    font-size: 1.2rem;
}

.download-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2rem;
    padding: 0.25rem 0.5rem;
    background: rgba(99, 102, 241, 0.15);
    border-radius: 12px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--primary);
}

/* File Drop Zone */
.file-drop-zone {
    border: 2px dashed var(--border);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s ease;
    background: var(--bg);
    min-height: 150px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.file-drop-zone:hover,
.file-drop-zone.drag-over {
    border-color: var(--primary);
    background: rgba(99, 102, 241, 0.05);
}

.file-drop-zone.drag-over {
    transform: scale(1.02);
}

.drop-zone-content {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.drop-zone-icon {
    font-size: 3rem;
    opacity: 0.7;
}

.drop-zone-content p {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.drop-zone-content a {
    color: var(--primary);
    text-decoration: underline;
    cursor: pointer;
}

.drop-zone-content a:hover {
    color: var(--primary-dark);
}

/* Selected File Info */
.selected-file {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    background: rgba(99, 102, 241, 0.1);
    border-radius: 8px;
    border: 1px solid var(--primary);
}

.selected-file .file-icon {
    font-size: 1.5rem;
}

.selected-file .file-name {
    flex: 1;
    font-weight: 500;
    color: var(--text);
    word-break: break-all;
}

.selected-file .file-size {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.remove-file-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
    transition: color 0.2s;
}

.remove-file-btn:hover {
    color: var(--danger);
}

/* Upload Progress */
.upload-progress {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 1rem;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--success));
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    color: var(--text-secondary);
    font-size: 0.85rem;
    min-width: 100px;
    text-align: right;
}

/* Link Box */
.link-box {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    overflow: hidden;
}

.link-box code {
    flex: 1;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 0.85rem;
    color: var(--text);
    word-break: break-all;
    background: transparent;
    padding: 0;
}

.copy-btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.4rem 0.75rem;
    border-radius: 6px;
    font-size: 0.8rem;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.copy-btn:hover {
    background: var(--primary-dark);
}

.copy-btn.copied {
    background: var(--success);
}

/* File Info Text */
.file-info-text {
    color: var(--text);
    font-weight: 500;
    margin: 0;
}

/* Hint Text */
.hint-text {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
}

.hint-text.warning {
    color: var(--warning);
}

.hint-text code {
    background: rgba(99, 102, 241, 0.15);
    padding: 0.15rem 0.4rem;
    border-radius: 4px;
    font-size: 0.8rem;
    color: var(--primary);
}

/* Checkbox Group */
.checkbox-group {
    margin-top: 1rem;
}

.checkbox-group label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    color: var(--text);
}

.checkbox-group input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
}

/* Button Link Style */
.btn-small.btn-link {
    background: rgba(99, 102, 241, 0.15);
    color: var(--primary);
    font-size: 1rem;
    padding: 0.25rem 0.5rem;
}

.btn-small.btn-link:hover {
    background: rgba(99, 102, 241, 0.25);
}

/* Danger Button */
.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: #dc2626;
}

/* Small Modal */
.modal-content.small {
    max-width: 400px;
}

/* ============================================
   Sub-tab Navigation (for File Center)
   ============================================ */

.sub-tab-nav {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.sub-tab-btn {
    padding: 0.6rem 1.2rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.sub-tab-btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
    border-color: var(--primary);
}

.sub-tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.sub-tab-content {
    display: none;
}

.sub-tab-content.active {
    display: block;
}

/* === Permission Notice Banner === */
.permission-notice {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.5rem;
    background: linear-gradient(135deg, rgba(251, 191, 36, 0.15), rgba(245, 158, 11, 0.1));
    border: 1px solid rgba(251, 191, 36, 0.4);
    border-left: 4px solid #f59e0b;
    border-radius: 8px;
}

.permission-notice .notice-icon {
    font-size: 1.75rem;
    line-height: 1;
    flex-shrink: 0;
}

.permission-notice .notice-content {
    flex: 1;
}

.permission-notice .notice-content h3 {
    margin: 0 0 0.5rem 0;
    font-size: 1.1rem;
    font-weight: 600;
    color: #fbbf24;
}

.permission-notice .notice-content p {
    margin: 0 0 0.5rem 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

.permission-notice .notice-content p:last-child {
    margin-bottom: 0;
}

.permission-notice .notice-content strong {
    color: var(--text);
}

.permission-notice .highlight-warning {
    background: rgba(251, 191, 36, 0.25);
    padding: 2px 6px;
    border-radius: 4px;
}

.permission-notice .highlight-danger {
    background: rgba(239, 68, 68, 0.3);
    color: #fca5a5;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.permission-notice .highlight-danger strong {
    color: #fca5a5;
}

/* === Logs Filters === */
.logs-filters {
    background: var(--bg-tertiary);
    border-radius: 8px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
    border: 1px solid var(--border);
}

.logs-filters .filter-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    align-items: flex-end;
}

.logs-filters .filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 140px;
}

.logs-filters .filter-group label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.logs-filters .filter-group select,
.logs-filters .filter-group input {
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.875rem;
}

.logs-filters .filter-group select:focus,
.logs-filters .filter-group input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(99, 102, 241, 0.2);
}

.logs-filters .search-group {
    flex: 1;
    min-width: 200px;
}

.logs-filters .search-group input {
    width: 100%;
}

.logs-filters .btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* Sortable columns */
.sortable {
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}

.sortable:hover {
    color: var(--primary);
}

.sort-icon {
    margin-left: 0.25rem;
    font-size: 0.75rem;
    opacity: 0.7;
}

/* Logs table enhancements */
#logs-table .details-cell {
    max-width: 250px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#logs-table .ip-cell {
    font-family: 'Courier New', monospace;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

#logs-table .no-data {
    text-align: center;
    color: var(--text-secondary);
    padding: 2rem;
    font-style: italic;
}

/* Source badges */
.badge-admin {
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
    border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-api {
    background: rgba(34, 197, 94, 0.2);
    color: #86efac;
    border: 1px solid rgba(34, 197, 94, 0.3);
}

/* Code Level Badges */
.badge-code-level {
    font-weight: 600;
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    letter-spacing: 0.5px;
}

.badge-level-low {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2) 0%, rgba(34, 197, 94, 0.3) 100%);
    color: #4ade80;
    border: 1px solid rgba(34, 197, 94, 0.4);
    box-shadow: 0 0 8px rgba(34, 197, 94, 0.2);
}

.badge-level-mid {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2) 0%, rgba(245, 158, 11, 0.3) 100%);
    color: #fbbf24;
    border: 1px solid rgba(245, 158, 11, 0.4);
    box-shadow: 0 0 8px rgba(245, 158, 11, 0.2);
}

.badge-level-high {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2) 0%, rgba(168, 85, 247, 0.3) 100%);
    color: #f472b6;
    border: 1px solid rgba(168, 85, 247, 0.4);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.3);
}

/* Logs pagination */
.logs-pagination {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-tertiary);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.pagination-info {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.pagination-info span {
    color: var(--text);
    font-weight: 500;
}

.pagination-controls {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.pagination-controls button {
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
}

.pagination-controls button:hover:not(:disabled) {
    background: var(--primary);
    border-color: var(--primary);
}

.pagination-controls button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.pagination-controls span {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

/* ===== Permission Center Styles ===== */

/* Permission Form */
.permission-form {
    max-width: 800px;
    margin: 0 auto;
    padding: 1.5rem;
    background: var(--bg-tertiary);
    border-radius: 12px;
}

.permission-form .form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.permission-form .form-group {
    margin-bottom: 1rem;
}

.permission-form .form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--text);
}

.permission-form .form-group input[type="text"],
.permission-form .form-group input[type="email"],
.permission-form .form-group textarea,
.permission-form .form-group select {
    width: 100%;
    padding: 0.75rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
}

.permission-form .form-group input:focus,
.permission-form .form-group textarea:focus,
.permission-form .form-group select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.1);
}

.permission-form .form-group textarea {
    min-height: 100px;
    resize: vertical;
}

/* Field Hint - 欄位說明 */
.field-hint {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    line-height: 1.5;
    opacity: 0.8;
}

.field-hint strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* Validation Error State */
.permission-form .form-group.error .checkbox-group,
.permission-form .form-group.error select,
.permission-form .form-group.error textarea,
.permission-form .form-group.error input {
    border-color: #ef4444 !important;
}

.permission-form .form-group.error label {
    color: #ef4444;
}

.permission-form .error-message {
    color: #ef4444;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* Checkbox Group */
.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.checkbox-label:hover {
    border-color: var(--primary);
}

.checkbox-label input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--primary);
    cursor: pointer;
}

.checkbox-label.checked,
.checkbox-label:has(input:checked) {
    background: rgba(99, 102, 241, 0.15);
    border-color: var(--primary);
}

/* Unknown option styling */
.checkbox-label.unknown-option {
    border-color: #f59e0b;
}

.checkbox-label.unknown-option:has(input:checked) {
    background: rgba(245, 158, 11, 0.2);
    border-color: #f59e0b;
}

/* Disabled state for other options when Unknown is selected */
.checkbox-label.other-option.disabled {
    opacity: 0.4;
    pointer-events: none;
    cursor: not-allowed;
    background: var(--bg-secondary);
    border-color: var(--border);
}

.checkbox-label.other-option.disabled input[type="checkbox"] {
    cursor: not-allowed;
}

/* Form Actions */
.form-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

/* Permission Badges */
.badge-env {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
}

/* Environment-specific badge colors */
.badge-env-local {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
}

.badge-env-dev {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.badge-env-uat {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.badge-env-prod {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Legacy classes for backwards compatibility */
.badge-env.local {
    background: rgba(100, 116, 139, 0.2);
    color: #94a3b8;
}

.badge-env.dev {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.badge-env.uat {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.badge-env.production {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

.badge-ai-core,
.badge-ai-editor {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(99, 102, 241, 0.2);
    color: #a5b4fc;
}

.badge-category {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-radius: 4px;
    margin: 0.125rem;
    background: rgba(168, 85, 247, 0.2);
    color: #c4b5fd;
}

/* Permission Level Badges */
.badge-permission {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    border-radius: 4px;
}

.badge-permission.read-only {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.badge-permission.read-write {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

/* Request Status Badges */
.badge-request-status {
    display: inline-flex;
    align-items: center;
    padding: 0.25rem 0.75rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 9999px;
}

.badge-request-status.pending {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.badge-request-status.approved {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

.badge-request-status.rejected {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Permission Tables */
.permission-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.permission-table th,
.permission-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.permission-table th {
    background: var(--bg-tertiary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.875rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.permission-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.05);
}

.permission-table .badge-container {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

/* Project column with text truncation */
.permission-table .project-cell {
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.permission-table .project-cell[title] {
    cursor: help;
}

/* Expandable project cell on hover */
.permission-table .project-cell:hover {
    white-space: normal;
    word-break: break-word;
    max-width: none;
    background: var(--bg-tertiary);
    position: relative;
    z-index: 10;
}

/* Diff display styles */
.diff-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.125rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    cursor: pointer;
}

.diff-badge.has-diff {
    background: rgba(245, 158, 11, 0.2);
    color: #f59e0b;
}

.diff-badge.no-diff {
    background: rgba(34, 197, 94, 0.2);
    color: #22c55e;
}

/* Diff tooltip/popup */
.diff-popup {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.75rem;
    min-width: 300px;
    max-width: 400px;
    z-index: 100;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.diff-popup.show {
    display: block;
}

.diff-item {
    margin-bottom: 0.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.diff-item:last-child {
    margin-bottom: 0;
    padding-bottom: 0;
    border-bottom: none;
}

.diff-field {
    font-weight: 600;
    color: var(--text);
    font-size: 0.8rem;
    margin-bottom: 0.25rem;
}

.diff-from {
    color: #ef4444;
    font-size: 0.75rem;
    text-decoration: line-through;
}

.diff-to {
    color: #22c55e;
    font-size: 0.75rem;
}

.diff-arrow {
    color: var(--text-secondary);
    margin: 0 0.25rem;
}

/* Diff Modal Styles */
.diff-modal-content {
    max-width: 700px;
    width: 90%;
    margin: auto;
}

.diff-modal-content .modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.diff-modal-content .diff-summary,
.diff-modal-content .diff-comparison-table,
.diff-modal-content .diff-legend {
    width: 100%;
}

.diff-summary {
    margin-bottom: 1rem;
    padding: 0.75rem;
    background: rgba(245, 158, 11, 0.1);
    border-radius: 6px;
    border-left: 3px solid #f59e0b;
}

.diff-count {
    font-weight: 600;
    color: #f59e0b;
}

.diff-comparison-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.diff-comparison-table th,
.diff-comparison-table td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.diff-comparison-table th {
    background: var(--bg-secondary);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.85rem;
}

.diff-comparison-table th:nth-child(3) {
    text-align: center;
    width: 40px;
}

.diff-field-name {
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.diff-original-val {
    color: var(--text-secondary);
    max-width: 200px;
    word-wrap: break-word;
}

.diff-arrow-cell {
    text-align: center;
    color: var(--text-secondary);
    font-weight: bold;
}

.diff-current-val {
    max-width: 200px;
    word-wrap: break-word;
}

.diff-changed {
    background: rgba(245, 158, 11, 0.05);
}

.diff-changed .diff-original-val {
    color: #ef4444;
    text-decoration: line-through;
}

.diff-changed .diff-arrow-cell {
    color: #f59e0b;
}

.diff-highlight {
    color: #22c55e !important;
    font-weight: 600;
}

.diff-legend {
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border);
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.legend-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

.legend-changed {
    display: inline-block;
    width: 14px;
    height: 14px;
    background: rgba(245, 158, 11, 0.2);
    border: 1px solid #f59e0b;
    border-radius: 3px;
}

/* Admin user selector */
.user-selector {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.user-selector label {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.user-selector select {
    padding: 0.5rem 0.75rem;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.875rem;
    min-width: 200px;
}

.user-selector select:focus {
    outline: none;
    border-color: var(--primary);
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Revoked permission row */
.permission-table tr.revoked {
    opacity: 0.6;
    background: rgba(239, 68, 68, 0.05);
}

.permission-table tr.revoked td {
    text-decoration: line-through;
    text-decoration-color: var(--text-secondary);
}

.permission-table tr.revoked td:last-child {
    text-decoration: none;
}

.badge-revoked {
    background: rgba(239, 68, 68, 0.2);
    color: #ef4444;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--text-secondary);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text);
}

/* Review Modal */
.review-modal-content {
    max-width: 600px;
}

.review-detail {
    margin-bottom: 1.5rem;
}

.review-detail label {
    display: block;
    font-size: 0.875rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
}

.review-detail .value {
    font-size: 1rem;
    color: var(--text);
}

.review-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

.review-actions .btn-approve {
    background: var(--success);
}

.review-actions .btn-approve:hover {
    background: #16a34a;
}

.review-actions .btn-reject {
    background: var(--danger);
}

.review-actions .btn-reject:hover {
    background: #dc2626;
}

/* Pending Count Badge */
.pending-count {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    font-size: 0.75rem;
    font-weight: 600;
    background: var(--danger);
    color: white;
    border-radius: 9999px;
    margin-left: 0.5rem;
}

/* Permission Review Modal */
.review-info-section {
    background: var(--bg-tertiary);
    padding: 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
}

.review-info-section h3 {
    font-size: 0.9rem;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.review-info-row {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}

.review-info-row .label {
    color: var(--text-secondary);
    min-width: 80px;
}

.review-edit-section {
    margin-top: 1rem;
}

.review-edit-section h3 {
    font-size: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.review-edit-section .form-group {
    margin-bottom: 1rem;
}

.review-edit-section .form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1rem;
}

.btn-success {
    background: var(--success) !important;
    color: white;
}

.btn-success:hover {
    background: #16a34a !important;
}

/* Slash command input styling */
.input-with-prefix {
    display: flex;
    align-items: center;
}

.input-with-prefix .input-prefix {
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-right: none;
    padding: 0.75rem 0.75rem;
    border-radius: 6px 0 0 6px;
    color: #f97316;
    font-weight: 600;
    font-family: 'Monaco', 'Menlo', monospace;
}

.input-with-prefix input {
    border-radius: 0 6px 6px 0;
    flex: 1;
}

.slash-command-code {
    color: #f97316;
    background: rgba(249, 115, 22, 0.15);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 600;
}

.form-hint {
    color: var(--text-secondary);
    font-size: 0.75rem;
    margin-top: 0.25rem;
}

.required {
    color: #ef4444;
}

/* Drag handle for sortable templates */
.drag-handle {
    cursor: grab;
    color: var(--text-secondary);
    font-size: 0.9rem;
    padding: 0 0.4rem;
    margin-right: 0.25rem;
    opacity: 0.5;
    transition: opacity 0.2s, color 0.2s;
    user-select: none;
}

.assigned-template.sortable:hover .drag-handle {
    opacity: 1;
    color: var(--primary);
}

.assigned-template.sortable {
    cursor: grab;
}

.assigned-template.sortable:active {
    cursor: grabbing;
}

/* Custom drag sorting states */
.assigned-template.custom-dragging {
    opacity: 0.95;
    box-shadow: 0 8px 25px rgba(0, 0, 0, 0.3);
    border: 2px solid var(--primary) !important;
    background: var(--bg-elevated) !important;
    cursor: grabbing !important;
}

.sort-placeholder {
    border: 2px dashed var(--primary);
    border-radius: 8px;
    background: rgba(99, 102, 241, 0.1);
    margin-bottom: 0.5rem;
}

.assigned-template.sort-drop-target {
    border-style: dashed;
    border-color: var(--text-secondary);
    opacity: 0.7;
}

.assigned-template.sort-drag-over {
    background: rgba(99, 102, 241, 0.25) !important;
    border-color: var(--primary) !important;
    border-style: solid !important;
    opacity: 1 !important;
    transform: scale(1.02);
}

/* One-time category badge */
.badge-one-time {
    background: linear-gradient(135deg, #ec4899, #f472b6);
    color: white;
}

.template-one-time {
    border-color: rgba(236, 72, 153, 0.5);
    background: rgba(236, 72, 153, 0.08);
}

.template-one-time:hover {
    border-color: #ec4899;
    background: rgba(236, 72, 153, 0.15);
}

/* Pending Requests Table Styles */
#pending-requests-table {
    table-layout: fixed;
    width: 100%;
}

#pending-requests-table th,
#pending-requests-table td {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0.75rem 0.5rem;
}

/* Column widths for pending requests table */
#pending-requests-table th:nth-child(1),
#pending-requests-table td:nth-child(1) { width: 10%; } /* 申請人 */

#pending-requests-table th:nth-child(2),
#pending-requests-table td:nth-child(2) { width: 12%; } /* 專案 */

#pending-requests-table th:nth-child(3),
#pending-requests-table td:nth-child(3) { width: 10%; } /* 環境 */

#pending-requests-table th:nth-child(4),
#pending-requests-table td:nth-child(4) { width: 10%; } /* AI Core */

#pending-requests-table th:nth-child(5),
#pending-requests-table td:nth-child(5) { width: 10%; } /* AI Tools */

#pending-requests-table th:nth-child(6),
#pending-requests-table td:nth-child(6) { width: 6%; } /* 權限 */

#pending-requests-table th:nth-child(7),
#pending-requests-table td:nth-child(7) { width: 10%; } /* 類別 */

#pending-requests-table th:nth-child(8),
#pending-requests-table td:nth-child(8) { width: 12%; } /* 申請時間 */

#pending-requests-table th:nth-child(9),
#pending-requests-table td:nth-child(9) { width: 8%; } /* 狀態 */

#pending-requests-table th:nth-child(10),
#pending-requests-table td:nth-child(10) {
    width: 12%; /* 操作 */
    white-space: nowrap;
    overflow: visible;
}

#pending-requests-table .project-cell {
    max-width: 100%;
    cursor: help;
}

#pending-requests-table .project-cell:hover {
    white-space: normal;
    word-break: break-word;
    overflow: visible;
    background: var(--bg-tertiary);
    position: relative;
    z-index: 10;
}

#pending-requests-table .actions {
    display: flex;
    gap: 0.25rem;
    flex-wrap: nowrap;
}

/* Review modal project textarea */
#review-project {
    min-height: 120px;
    resize: vertical;
}

/* Button spinner for loading states */
.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    border-top-color: #fff;
    animation: btn-spin 0.8s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

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

/* Disabled button style during submission */
.permission-form .form-actions button:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}
