/* Style System Variables */
:root {
    --bg-main: #0b0f19;
    --bg-sidebar: #0f172a;
    --bg-card: rgba(30, 41, 59, 0.55);
    --border-color: rgba(255, 255, 255, 0.08);
    --text-primary: #f8fafc;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --primary-light: rgba(59, 130, 246, 0.15);
    
    --success: #10b981;
    --success-light: rgba(16, 185, 129, 0.12);
    
    --warning: #f59e0b;
    --warning-light: rgba(245, 158, 11, 0.12);
    
    --danger: #ef4444;
    --danger-light: rgba(239, 68, 68, 0.12);
    
    --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius-lg: 12px;
    --radius-md: 8px;
    --radius-sm: 4px;
    
    --shadow-main: 0 10px 30px -10px rgba(0, 0, 0, 0.5);
    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
}

/* Base resets & styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-sans);
    min-height: 100vh;
    overflow-x: hidden;
}

code, pre {
    font-family: var(--font-mono);
    font-size: 0.85rem;
}

/* App Container Layout */
.app-container {
    display: flex;
    min-height: 100vh;
}

/* Sidebar Styling */
.sidebar {
    width: 280px;
    background-color: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 24px;
    flex-shrink: 0;
}

.logo-area {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 36px;
    padding-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.logo-icon {
    font-size: 1.8rem;
}

.logo-text h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.logo-text p {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.nav-menu {
    display: flex;
    flex-direction: column;
    gap: 8px;
    flex-grow: 1;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    text-align: left;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: var(--transition-fast);
}

.nav-item .icon {
    font-size: 1.1rem;
    opacity: 0.8;
}

.nav-item:hover {
    color: var(--text-primary);
    background-color: rgba(255, 255, 255, 0.04);
}

.nav-item.active {
    color: var(--text-primary);
    background-color: var(--primary-light);
    border-left: 3px solid var(--primary);
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
}

/* Connection Status Area */
.connection-status-panel {
    background-color: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-top: auto;
}

.connection-status-panel h3 {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 1px;
    margin-bottom: 12px;
}

.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 8px;
}

.status-badge.connected {
    background-color: var(--success-light);
    color: var(--success);
}

.status-badge.connecting {
    background-color: var(--warning-light);
    color: var(--warning);
}

.status-badge.disconnected {
    background-color: var(--danger-light);
    color: var(--danger);
}

.status-badge .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: currentColor;
    box-shadow: 0 0 8px currentColor;
}

.status-url {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-muted);
    word-break: break-all;
    line-height: 1.4;
    margin-bottom: 6px;
}

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

/* Main Content Layout */
.main-content {
    flex-grow: 1;
    display: flex;
    flex-direction: column;
    max-height: 100vh;
    overflow-y: auto;
}

.main-header {
    background-color: rgba(15, 23, 42, 0.4);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 36px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.header-title h2 {
    font-size: 1.4rem;
    font-weight: 600;
}

.header-title p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 16px;
}

.api-badge {
    background-color: var(--success-light);
    color: var(--success);
    font-size: 0.8rem;
    font-weight: 500;
    padding: 6px 12px;
    border-radius: var(--radius-sm);
    border: 1px solid rgba(16, 185, 129, 0.2);
}

/* Button UI */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 16px;
    font-size: 0.9rem;
    font-weight: 500;
    border-radius: var(--radius-md);
    border: 1px solid transparent;
    cursor: pointer;
    transition: var(--transition-fast);
    outline: none;
}

.btn-primary {
    background-color: var(--primary);
    color: #ffffff;
}

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

.btn-secondary {
    background-color: rgba(255, 255, 255, 0.06);
    color: var(--text-primary);
    border-color: var(--border-color);
}

.btn-secondary:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

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

.btn-danger:hover {
    background-color: var(--danger);
    color: #ffffff;
}

.btn-success {
    background-color: var(--success-light);
    color: var(--success);
    border-color: rgba(16, 185, 129, 0.2);
}

.btn-success:hover {
    background-color: var(--success);
    color: #ffffff;
}

.btn-block {
    display: width;
    width: 100%;
}

.btn-sm {
    padding: 4px 10px;
    font-size: 0.8rem;
}

/* Panels */
.panel {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-main);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    backdrop-filter: blur(16px);
}

.panel-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.01);
}

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.panel-body {
    padding: 24px;
    flex-grow: 1;
}

.badge {
    background-color: rgba(255, 255, 255, 0.08);
    color: var(--text-secondary);
    padding: 3px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
}

/* Tab Management */
.tab-content {
    display: none;
    padding: 32px 36px;
    flex-grow: 1;
    overflow-y: auto;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

/* Dashboard Grid Layout */
.dashboard-grid {
    display: grid;
    grid-template-columns: 1.2fr 0.8fr;
    gap: 24px;
    align-items: start;
    flex-grow: 1;
}

.log-panel, .push-history-panel {
    height: calc(100vh - 180px);
}

.log-list, .push-list {
    flex-grow: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* Custom Scrollbars */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.2);
}

/* Empty State styling */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    padding: 40px;
}

.empty-state .sub {
    font-size: 0.8rem;
    margin-top: 8px;
    max-width: 280px;
}

/* Log and Push items */
.log-item, .push-item {
    background-color: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 14px;
    cursor: pointer;
    transition: var(--transition-fast);
}

.log-item:hover, .push-item:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background-color: rgba(255, 255, 255, 0.04);
}

.log-item-header, .push-item-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.log-meta, .push-meta {
    display: flex;
    align-items: center;
    gap: 8px;
}

.log-time, .push-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.log-endpoint {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    font-weight: 500;
}

.direction-in {
    color: var(--success);
}

.direction-out {
    color: var(--primary);
}

.badge-direction {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    padding: 2px 6px;
    border-radius: 4px;
}

.badge-direction.in {
    background-color: var(--success-light);
    color: var(--success);
}

.badge-direction.out {
    background-color: var(--primary-light);
    color: var(--primary);
}

.log-payload-preview {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    color: var(--text-secondary);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

/* Status codes */
.status-success {
    color: var(--success);
}

.status-fail {
    color: var(--danger);
}

.status-pending {
    color: var(--warning);
}

/* Forms */
.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 6px;
}

.form-control {
    width: 100%;
    background-color: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    padding: 10px 14px;
    font-family: var(--font-sans);
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition-fast);
}

.form-control:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px var(--primary-light);
}

.form-control-sm {
    padding: 6px 10px;
    font-size: 0.85rem;
}

.help-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 4px;
}

.form-row {
    display: flex;
    gap: 12px;
}

.flex-1 {
    flex: 1;
}

.checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-secondary);
    user-select: none;
}

/* Push Layout */
.push-layout {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 24px;
    flex-grow: 1;
}

.command-builder-panel {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
}

.dynamic-fields-container {
    background-color: rgba(0, 0, 0, 0.15);
    border-radius: var(--radius-md);
    padding: 16px;
    border: 1px solid var(--border-color);
    margin-top: 16px;
}

.json-preview-panel {
    height: calc(100vh - 180px);
}

.json-preview-body {
    background-color: rgba(0, 0, 0, 0.4);
    padding: 20px;
    overflow: auto;
}

.json-preview-body pre {
    height: 100%;
}

.json-preview-body code {
    color: #e2e8f0;
}

/* Config UI */
.mock-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
}

.full-width-panel {
    grid-column: span 2;
}

.config-row {
    display: flex;
    gap: 20px;
}

.json-editor {
    font-family: var(--font-mono);
    font-size: 0.8rem;
    line-height: 1.4;
    background-color: rgba(0, 0, 0, 0.4);
}

/* Device Simulator Visual representation */
.simulator-layout {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    height: calc(100vh - 180px);
}

.display-flex-center {
    display: flex;
    align-items: center;
    justify-content: center;
}

.vending-machine-visual {
    width: 320px;
    background: linear-gradient(135deg, #1e293b, #0f172a);
    border: 4px solid #334155;
    border-radius: 16px;
    padding: 20px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.8);
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.machine-head {
    border-bottom: 2px solid #334155;
    padding-bottom: 10px;
    text-align: center;
}

.machine-led {
    color: var(--primary);
    font-family: var(--font-mono);
    font-weight: 700;
    font-size: 0.9rem;
    letter-spacing: 2px;
    text-shadow: 0 0 8px rgba(59, 130, 246, 0.6);
}

.machine-screen {
    height: 200px;
    background-color: #020617;
    border: 3px solid #1e293b;
    border-radius: 8px;
    position: relative;
    overflow: hidden;
    padding: 16px;
}

.screen-content {
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    color: #38bdf8;
    text-shadow: 0 0 4px rgba(56, 189, 248, 0.3);
}

.screen-title {
    font-size: 1.2rem;
    font-weight: 700;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

.screen-machine-id {
    font-size: 0.8rem;
    color: #0284c7;
    font-family: var(--font-mono);
    margin-bottom: 4px;
}

.screen-status-msg {
    font-size: 0.85rem;
    color: #06b6d4;
}

.screen-inbox-alert {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 23, 42, 0.95);
    border: 2px solid var(--warning);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    padding: 16px;
    z-index: 10;
    animation: flashBorder 1.5s infinite alternate;
}

@keyframes flashBorder {
    from { border-color: rgba(245, 158, 11, 0.4); }
    to { border-color: rgba(245, 158, 11, 1); }
}

.screen-inbox-alert.hidden {
    display: none;
}

.alert-title {
    color: var(--warning);
    font-weight: 700;
    font-size: 1rem;
    margin-bottom: 4px;
}

.alert-body {
    font-size: 0.75rem;
    color: var(--text-primary);
    word-break: break-all;
    max-height: 70px;
    overflow-y: auto;
    margin-bottom: 12px;
}

.alert-actions {
    display: flex;
    gap: 8px;
    width: 100%;
    justify-content: center;
}

.machine-cup-dispenser {
    height: 90px;
    background-color: #020617;
    border-radius: 8px;
    border: 2px solid #1e293b;
    display: flex;
    align-items: center;
    justify-content: center;
}

.cup-dispenser-hole {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: radial-gradient(circle, #090d16 60%, #1e293b 100%);
    border: 1px solid #334155;
    position: relative;
}

.cup-dispenser-hole::after {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: #020617;
    top: 10px;
    left: 10px;
    box-shadow: inset 0 8px 12px rgba(0,0,0,0.9);
}

.simulator-section {
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 16px;
    margin-bottom: 16px;
}

.simulator-section:last-child {
    border-bottom: none;
    padding-bottom: 0;
    margin-bottom: 0;
}

.simulator-section h4 {
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}

.margin-top-5 {
    margin-top: 5px;
}
.margin-top-10 {
    margin-top: 10px;
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    z-index: 100;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
}

.modal.active {
    display: flex;
}

.modal-content {
    background-color: var(--bg-sidebar);
    border: 1px solid var(--border-color);
    width: 650px;
    max-width: 90%;
    border-radius: var(--radius-lg);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6);
    overflow: hidden;
}

.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background-color: rgba(255, 255, 255, 0.01);
}

.close-modal-btn {
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    transition: var(--transition-fast);
}

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

.modal-body {
    padding: 24px;
    max-height: 80vh;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.modal-body pre {
    background-color: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 12px;
    overflow-x: auto;
}

.modal-body code {
    color: #e2e8f0;
}

/* Utility layout helper */
.device-actions-panel {
    max-height: calc(100vh - 180px);
    overflow-y: auto;
}

.list-item-header-action {
    display: flex;
    align-items: center;
    gap: 12px;
}

.flash-new {
    animation: flashBg 1s ease-out;
}

@keyframes flashBg {
    0% { background-color: rgba(59, 130, 246, 0.25); border-color: var(--primary); }
    100% { background-color: rgba(255, 255, 255, 0.02); border-color: var(--border-color); }
}

.list-item-status-pill {
    font-size: 0.72rem;
    padding: 2px 8px;
    border-radius: 12px;
    font-weight: 600;
}
.list-item-status-pill.success {
    background-color: var(--success-light);
    color: var(--success);
}
.list-item-status-pill.fail {
    background-color: var(--danger-light);
    color: var(--danger);
}
.list-item-status-pill.pending {
    background-color: var(--warning-light);
    color: var(--warning);
}
