:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-light: #eef2ff;
    --bg-main: #f8fafc;
    --bg-sidebar: #1e293b;
    --bg-card: #ffffff;
    --text-main: #1e293b;
    --text-muted: #64748b;
    --text-light: #f8fafc;
    --border-color: #e2e8f0;
    --status-ok: #10b981;
    --status-warn: #f59e0b;
    --status-crit: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
    --transition: all 0.2s ease;
}

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

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

/* Dashboard Layout */
.dashboard-layout {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 260px;
    background-color: var(--bg-sidebar);
    color: var(--text-light);
    display: flex;
    flex-direction: column;
    transition: var(--transition);
    z-index: 1000;
}

.sidebar-brand {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
}

.brand-logo {
    width: 32px;
    height: 32px;
    background: var(--primary);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
}

.brand-name {
    font-weight: 700;
    font-size: 1.25rem;
    letter-spacing: -0.5px;
}

.brand-version {
    font-size: 0.7rem;
    opacity: 0.6;
    font-weight: normal;
    margin-left: 4px;
}

.sidebar-nav {
    flex: 1;
    padding: 20px 0;
    overflow-y: auto;
}

.nav-group {
    margin-bottom: 24px;
}

.nav-group-title {
    display: block;
    padding: 0 24px 12px 24px;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: rgba(255,255,255,0.4);
    font-weight: 600;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 24px;
    color: rgba(255,255,255,0.7);
    text-decoration: none;
    font-size: 0.9rem;
    transition: var(--transition);
    border-left: 4px solid transparent;
}

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

.nav-item.active {
    background: rgba(255,255,255,0.1);
    color: var(--text-light);
    border-left-color: var(--primary);
}

.nav-item i {
    width: 20px;
    text-align: center;
    font-size: 1rem;
}

.sidebar-footer {
    padding: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(0,0,0,0.2);
    padding: 12px;
    border-radius: 12px;
}

.user-profile img {
    width: 36px;
    height: 36px;
    border-radius: 50%;
}

.user-info {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.user-name {
    font-size: 0.85rem;
    font-weight: 600;
}

.user-role {
    font-size: 0.7rem;
    color: rgba(255,255,255,0.5);
}

.logout-btn {
    color: rgba(255,255,255,0.5);
    transition: var(--transition);
}

.logout-btn:hover {
    color: #ef4444;
}

/* Main Wrapper */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Top Header */
.top-header {
    height: 64px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 32px;
}

.header-left .breadcrumb {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.breadcrumb-item {
    cursor: pointer;
    transition: var(--transition);
}

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

.breadcrumb-item.active {
    color: var(--text-main);
    font-weight: 600;
}

.breadcrumb-separator {
    color: var(--border-color);
}

.header-right {
    display: flex;
    align-items: center;
    gap: 20px;
}

.system-status-pill {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--primary-light);
    color: var(--primary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.status-dot.online {
    background: var(--status-ok);
    box-shadow: 0 0 4px var(--status-ok);
}

.timestamp {
    font-size: 0.85rem;
    color: var(--text-muted);
    font-variant-numeric: tabular-nums;
}

.notification-btn {
    position: relative;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    transition: var(--transition);
}

.notification-btn:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: var(--status-crit);
    color: white;
    font-size: 0.65rem;
    padding: 2px 5px;
    border-radius: 10px;
    font-weight: 700;
}

/* Content Area */
.content-area {
    flex: 1;
    overflow-y: auto;
    padding: 32px;
    background: var(--bg-main);
}

.hmi-layer {
    display: none;
    animation: fadeIn 0.3s ease;
}

.hmi-layer.active {
    display: block;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Page Header */
.page-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 32px;
}

.header-title-area h1 {
    font-size: 1.875rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 4px;
}

.header-title-area p {
    color: var(--text-muted);
    font-size: 0.95rem;
}

.highlight {
    color: var(--primary);
    font-weight: 600;
}

/* Buttons */
.btn-primary {
    background: var(--primary);
    color: white;
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-primary:hover {
    background: var(--primary-dark);
    box-shadow: var(--shadow-md);
}

.btn-secondary {
    background: white;
    color: var(--text-main);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 8px;
}

.btn-secondary:hover {
    background: var(--bg-main);
    border-color: var(--text-muted);
}

.btn-outline {
    background: transparent;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-outline:hover {
    color: var(--text-main);
    border-color: var(--text-muted);
}

/* Metrics Grid */
.metrics-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 24px;
    margin-bottom: 32px;
}

.stat-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.stat-label {
    font-size: 0.875rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.stat-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
    margin-bottom: 8px;
}

.stat-unit {
    font-size: 1rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-left: 2px;
}

.stat-trend {
    font-size: 0.75rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 4px;
}

.stat-trend.positive { color: var(--status-ok); }
.stat-trend.warning { color: var(--status-warn); }
.stat-trend.stable { color: var(--text-muted); }

/* Grid Section */
.grid-section {
    background: var(--bg-card);
    padding: 24px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 24px;
}

.section-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-main);
}

.filter-select {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    font-size: 0.875rem;
    color: var(--text-muted);
    cursor: pointer;
}

/* Status Grid */
.status-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 20px;
}

.string-card {
    background: var(--bg-main);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.string-card:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.card-id {
    font-weight: 600;
    font-size: 0.85rem;
}

.badge {
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    text-transform: uppercase;
}

.badge-ok { background: var(--status-ok); color: white; }
.badge-warn { background: var(--status-warn); color: white; }
.badge-crit { background: var(--status-crit); color: white; }

.card-body {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.card-main-val {
    font-size: 1.25rem;
    font-weight: 700;
}

.card-sub-val {
    font-size: 0.85rem;
    color: var(--text-muted);
}

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 32px;
}

.panel-card {
    background: var(--bg-card);
    padding: 24px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

.panel-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.panel-header h2 {
    font-size: 1.125rem;
    font-weight: 600;
}

.telemetry-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 24px;
}

.telemetry-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.telemetry-item label {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.telemetry-item .val {
    font-size: 1.25rem;
    font-weight: 700;
}

.telemetry-item .unit {
    font-size: 0.9rem;
    color: var(--text-muted);
    font-weight: 500;
}

.topology-container {
    position: relative;
    background: #f1f5f9;
    border-radius: 12px;
    padding: 20px;
    min-height: 200px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.topology-grid {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 12px;
    margin-bottom: 20px;
}

.node {
    aspect-ratio: 1;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 0.8rem;
    cursor: pointer;
    transition: var(--transition);
}

.node:hover {
    border-color: var(--primary);
    background: var(--primary-light);
}

.node-ok { border-color: var(--status-ok); color: var(--status-ok); }
.node-warn { border-color: var(--status-warn); color: var(--status-warn); }
.node-crit { border-color: var(--status-crit); color: var(--status-crit); }

.topology-legend {
    font-size: 0.75rem;
    color: var(--text-muted);
    text-align: center;
}

/* Config Wrapper */
.config-wrapper {
    max-width: 800px;
    margin: 0 auto;
}

.config-card {
    background: var(--bg-card);
    padding: 32px;
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
}

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

.config-section:last-of-type {
    border-bottom: none;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
}

.section-title h3 {
    font-size: 1rem;
    font-weight: 600;
}

.info-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border-color);
}

.info-label {
    color: var(--text-muted);
    font-size: 0.85rem;
}

.info-value {
    font-weight: 600;
    font-size: 0.85rem;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 20px;
}

.form-group {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.form-group input, .form-group select {
    padding: 10px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    font-size: 0.9rem;
}

.config-footer {
    display: flex;
    justify-content: flex-end;
    gap: 16px;
    margin-top: 32px;
}

/* Utility */
@media (max-width: 1024px) {
    .detail-grid {
        grid-template-columns: 1fr;
    }
    .form-grid {
        grid-template-columns: 1fr;
    }
}

/* Topology Flow */
.topology-flow {
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 40px 20px;
    gap: 20px;
}

.flow-node {
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 12px;
    padding: 15px;
    text-align: center;
    min-width: 120px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
}

.flow-node:hover {
    border-color: var(--primary);
    transform: scale(1.05);
}

.node-label {
    font-weight: 700;
    font-size: 0.9rem;
    color: var(--text-main);
    margin-bottom: 4px;
}

.node-id {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-family: monospace;
}

.flow-line {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--text-muted);
    font-size: 0.7rem;
    font-weight: 600;
    position: relative;
}

.flow-arrow {
    width: 40px;
    height: 4px;
    background: var(--border-color);
    position: relative;
}

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

/* Emergency Stop */
.estop-btn {
    background: #dc2626;
    color: white;
    border: 4px solid #991b1b;
    border-radius: 50px;
    padding: 12px;
    font-weight: 800;
    cursor: pointer;
    width: 100%;
    margin-bottom: 20px;
    transition: var(--transition);
    box-shadow: 0 4px 0 #7f1d1d;
}

.estop-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #7f1d1d;
}

/* Industrial Controls */
.mode-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-muted);
}

.mode-selector select {
    padding: 4px 8px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 20px;
    padding: 20px 0;
}

.control-item {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.control-item label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.btn-industrial {
    background: #475569;
    color: white;
    border: none;
    padding: 8px;
    border-radius: 4px;
    font-weight: 700;
    cursor: pointer;
}

.industrial-switch {
    position: relative;
    width: 50px;
    height: 24px;
}

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

.industrial-switch label {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: #ccc;
    transition: .4s;
    border-radius: 34px;
}

.industrial-switch label:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 4px;
    bottom: 4px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

.industrial-switch input:checked + label {
    background-color: var(--status-ok);
}

.industrial-switch input:checked + label:before {
    transform: translateX(26px);
}

.toggle-group {
    display: flex;
    background: #e2e8f0;
    padding: 4px;
    border-radius: 8px;
}

.toggle-btn {
    flex: 1;
    border: none;
    padding: 6px;
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    border-radius: 6px;
    background: transparent;
    color: var(--text-muted);
}

.toggle-btn.active {
    background: white;
    color: var(--primary);
    box-shadow: var(--shadow-sm);
}
