/* CSS Variables */
:root {
    --primary-color: #0078d4;
    --primary-hover: #106ebe;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --warning-color: #ffc107;
    --danger-color: #dc3545;
    --info-color: #17a2b8;
    
    --bg-primary: #1e1e1e;
    --bg-secondary: #252526;
    --bg-tertiary: #2d2d30;
    --bg-hover: #3e3e42;
    --bg-active: #094771;
    
    --text-primary: #ffffff;
    --text-secondary: #cccccc;
    --text-muted: #858585;
    
    --border-color: #3e3e42;
    --border-radius: 6px;
    
    --sidebar-width: 320px;
    --header-height: 56px;
    --console-height: 200px;
    
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* Reset & Base */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
}

/* App Container */
.app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

/* Header */
.app-header {
    height: var(--header-height);
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    flex-shrink: 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    color: var(--primary-color);
}

.logo h1 {
    font-size: 18px;
    font-weight: 600;
    color: var(--text-primary);
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-secondary);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--secondary-color);
}

.status-indicator.connected {
    background-color: var(--success-color);
    box-shadow: 0 0 8px var(--success-color);
}

.status-indicator.disconnected {
    background-color: var(--danger-color);
}

.status-indicator.loading {
    background-color: var(--warning-color);
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* Main Content */
.main-content {
    display: flex;
    flex: 1;
    overflow: hidden;
}

/* Sidebar */
.sidebar {
    width: var(--sidebar-width);
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

.sidebar-header {
    padding: 16px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.sidebar-header h2 {
    font-size: 14px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}

.refresh-btn {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.refresh-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.refresh-btn.spinning svg {
    animation: spin 1s linear infinite;
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

.workspace-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Embed Settings Panel */
.embed-settings {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.2);
}

.settings-group {
    margin-bottom: 12px;
}

.settings-group:last-child {
    margin-bottom: 0;
}

.settings-group label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 6px;
}

.settings-group input[type="text"],
.settings-group input[type="password"] {
    width: 100%;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    color: var(--text-primary);
    font-size: 13px;
    font-family: 'Monaco', 'Menlo', monospace;
}

.settings-group input[type="text"]:focus,
.settings-group input[type="password"]:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 2px rgba(102, 178, 255, 0.2);
}

.roles-list {
    max-height: 120px;
    overflow-y: auto;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    padding: 8px;
}

.role-checkbox {
    display: flex;
    align-items: center;
    padding: 6px 8px;
    cursor: pointer;
    border-radius: 4px;
    transition: background var(--transition-fast);
}

.role-checkbox:hover {
    background: var(--bg-hover);
}

.role-checkbox input[type="checkbox"] {
    margin-right: 8px;
    cursor: pointer;
    accent-color: var(--primary-color);
}

.role-checkbox .role-name {
    font-size: 13px;
    color: var(--text-primary);
}

.role-count {
    font-size: 10px;
    font-weight: normal;
    color: var(--text-muted);
    margin-left: 4px;
}

.no-roles {
    padding: 12px;
    text-align: center;
    color: var(--text-muted);
    font-size: 12px;
}

.loading-placeholder.small {
    flex-direction: row;
    padding: 12px;
    gap: 8px;
}

.spinner.small {
    width: 16px;
    height: 16px;
    border-width: 2px;
    margin-bottom: 0;
}

/* Loading Placeholder */
.loading-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

/* Workspace Items */
.workspace-item {
    margin-bottom: 4px;
}

.workspace-header {
    display: flex;
    align-items: center;
    padding: 10px 12px;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: background var(--transition-fast);
    gap: 8px;
}

.workspace-header:hover {
    background: var(--bg-hover);
}

.workspace-header.expanded {
    background: var(--bg-tertiary);
}

.workspace-icon {
    color: var(--primary-color);
    flex-shrink: 0;
    transition: transform var(--transition-fast);
}

.workspace-header.expanded .workspace-icon {
    transform: rotate(90deg);
}

.workspace-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.report-count {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 8px;
    border-radius: 10px;
}

/* Report List */
.report-list {
    display: none;
    padding-left: 12px;
}

.report-list.expanded {
    display: block;
}

.report-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    cursor: pointer;
    border-radius: var(--border-radius);
    transition: all var(--transition-fast);
    gap: 8px;
    margin: 2px 0;
}

.report-item:hover {
    background: var(--bg-hover);
}

.report-item.active {
    background: var(--bg-active);
    border-left: 3px solid var(--primary-color);
}

.report-icon {
    color: var(--text-muted);
    flex-shrink: 0;
}

.report-item.active .report-icon {
    color: var(--primary-color);
}

.report-name {
    flex: 1;
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.report-type {
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

/* Report Area */
.report-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.report-container {
    flex: 1;
    position: relative;
    background: var(--bg-tertiary);
    overflow: hidden;
}

.empty-state {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
}

.empty-state svg {
    margin-bottom: 16px;
    opacity: 0.5;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-secondary);
}

.empty-state p {
    font-size: 14px;
}

.report-embed {
    width: 100%;
    height: 100%;
}

.report-embed iframe {
    width: 100%;
    height: 100%;
    border: none;
}

/* Console Panel */
.console-panel {
    background: var(--bg-secondary);
    border-top: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    transition: height var(--transition-normal);
    flex-shrink: 0;
    height: 33vh;
    min-height: 36px;
    max-height: 50vh;
}

.console-panel.collapsed {
    height: 36px !important;
    min-height: 36px;
}

.console-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0;
}

.console-header h3 {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}

.console-actions {
    display: flex;
    gap: 4px;
}

.console-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: 4px;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    justify-content: center;
}

.console-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.console-panel.collapsed #toggleConsoleBtn svg {
    transform: rotate(180deg);
}

.console-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px 16px;
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 12px;
    min-height: 0;
}

.console-panel.collapsed .console-content {
    display: none;
}

.console-entry {
    padding: 4px 0;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    gap: 12px;
    word-break: break-all;
}

.console-entry:last-child {
    border-bottom: none;
}

.console-entry .timestamp {
    color: var(--text-muted);
    flex-shrink: 0;
}

.console-entry .method {
    font-weight: 600;
    flex-shrink: 0;
    min-width: 50px;
}

.console-entry.request .method {
    color: var(--info-color);
}

.console-entry.response .method {
    color: var(--success-color);
}

.console-entry.error .method,
.console-entry.error .message {
    color: var(--danger-color);
}

.console-entry.info .message {
    color: var(--text-secondary);
    font-style: italic;
}

.console-entry .url {
    color: var(--primary-color);
    flex-shrink: 0;
    max-width: 400px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.console-entry .message {
    color: var(--text-secondary);
    flex: 1;
}

.console-entry .status {
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 11px;
    font-weight: 600;
}

.console-entry .status.success {
    background: rgba(40, 167, 69, 0.2);
    color: var(--success-color);
}

.console-entry .status.error {
    background: rgba(220, 53, 69, 0.2);
    color: var(--danger-color);
}

.console-entry .json-body {
    font-family: 'Consolas', 'Monaco', 'Courier New', monospace;
    font-size: 11px;
    background: var(--bg-tertiary);
    padding: 8px;
    border-radius: 4px;
    margin-top: 4px;
    white-space: pre-wrap;
    word-break: break-all;
    color: var(--text-secondary);
    max-height: 150px;
    overflow-y: auto;
    width: 100%;
}

.console-entry {
    flex-wrap: wrap;
}

/* Scrollbar Styling */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--bg-hover);
}

/* No Reports State */
.no-reports {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* Error State */
.error-state {
    padding: 20px;
    text-align: center;
    color: var(--danger-color);
}

.error-state svg {
    margin-bottom: 12px;
}

.error-state h4 {
    margin-bottom: 8px;
}

.error-state p {
    font-size: 13px;
    color: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        left: 0;
        top: var(--header-height);
        bottom: 0;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform var(--transition-normal);
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
}
