@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&family=JetBrains+Mono:wght@400;500;600;700&display=swap');

:root {
    /* Dark Industrial Palette */
    --bg-main: #0f1419;
    --bg-panel: #1a2332;
    --bg-header: #141c28;
    --bg-card: #1e2d3d;
    --bg-input: #0d1520;
    --bg-module: #162030;

    --text-main: #e0e6ed;
    --text-muted: #7a8fa6;
    --text-bright: #ffffff;

    /* Accent Colors */
    --accent-primary: #00b4d8;
    --accent-teal: #00d4aa;
    --accent-blue: #3b82f6;
    --accent-amber: #f59e0b;
    --accent-red: #ef4444;
    --accent-green: #22c55e;
    --accent-purple: #a855f7;

    --border-color: #2a3a4e;
    --border-glow: rgba(0, 180, 216, 0.3);

    /* Button */
    --btn-bg: #1e2d3d;
    --btn-border: #3a4f65;
    --btn-hover: #253d52;
    --btn-active: #0d1520;

    /* LED */
    --led-off: #2a3a4e;
    --led-on: #22c55e;

    /* Ladder */
    --ladder-line: #4a6580;
    --ladder-active: #22c55e;

    /* Shadows & Effects */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px rgba(0, 180, 216, 0.15);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background-color: var(--bg-main);
    background-image:
        radial-gradient(ellipse at 20% 50%, rgba(0, 180, 216, 0.04) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 20%, rgba(0, 212, 170, 0.03) 0%, transparent 50%);
    color: var(--text-main);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* ══════════════════════ SCROLLBAR ══════════════════════ */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--bg-main); }
::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-primary); }

/* ══════════════════════ HEADER ══════════════════════ */
header {
    background: linear-gradient(135deg, var(--bg-header) 0%, #1a2740 100%);
    padding: 0.75rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    box-shadow: var(--shadow-md), inset 0 -1px 0 rgba(0, 180, 216, 0.1);
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
}

.logo {
    display: flex;
    align-items: center;
    gap: 15px;
}

.logo img {
    height: 48px;
    filter: brightness(1.1);
    transition: transform 0.3s ease;
}
.logo img:hover {
    transform: scale(1.05);
}

.logo h1 {
    font-size: 1.3rem;
    font-weight: 800;
    letter-spacing: 1.5px;
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-teal));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 2px;
}

.logo p {
    font-size: 0.7rem;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    font-weight: 500;
}

.header-right {
    text-align: right;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 6px;
}

.header-right h2 {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text-main);
    letter-spacing: 0.3px;
}

.header-right p {
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Navigation links */
.nav-links {
    display: flex;
    gap: 6px;
}

.nav-link {
    text-decoration: none;
    padding: 6px 16px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.8rem;
    letter-spacing: 0.5px;
    transition: all 0.3s ease;
    border: 1px solid transparent;
}

.nav-link.active {
    background: linear-gradient(135deg, var(--accent-primary), var(--accent-teal));
    color: var(--bg-main);
    box-shadow: 0 2px 12px rgba(0, 180, 216, 0.3);
}

.nav-link.inactive {
    background: var(--bg-card);
    color: var(--text-muted);
    border-color: var(--border-color);
}

.nav-link.inactive:hover {
    color: var(--accent-primary);
    border-color: var(--accent-primary);
    background: rgba(0, 180, 216, 0.08);
    transform: translateY(-1px);
}

/* ══════════════════════ MAIN ══════════════════════ */
main {
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 2rem;
    max-width: 1500px;
    margin: 0 auto;
    width: 100%;
}

/* ══════════════════════ MODULE ══════════════════════ */
.module {
    background: linear-gradient(145deg, var(--bg-panel) 0%, var(--bg-module) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    transition: box-shadow 0.3s ease, border-color 0.3s ease;
    animation: moduleSlideIn 0.6s ease-out both;
}

.module:hover {
    border-color: rgba(0, 180, 216, 0.25);
    box-shadow: var(--shadow-lg), var(--shadow-glow);
}

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

.module:nth-child(2) { animation-delay: 0.15s; }
.module:nth-child(3) { animation-delay: 0.3s; }
.module:nth-child(4) { animation-delay: 0.45s; }

.module-header {
    background: linear-gradient(90deg, rgba(0, 180, 216, 0.08) 0%, transparent 100%);
    padding: 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.module-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--accent-primary);
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.module-header h3::before {
    content: '';
    display: inline-block;
    width: 4px;
    height: 18px;
    background: linear-gradient(180deg, var(--accent-primary), var(--accent-teal));
    border-radius: 2px;
}

.status-indicator {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background-color: var(--led-on);
    box-shadow: 0 0 8px var(--led-on);
    animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
    0%, 100% { box-shadow: 0 0 6px var(--led-on); }
    50% { box-shadow: 0 0 14px var(--led-on), 0 0 28px rgba(34, 197, 94, 0.2); }
}

/* ══════════════════════ MODULE CONTENT ══════════════════════ */
.module-content {
    display: grid;
    grid-template-columns: 280px 1fr;
    grid-template-rows: auto auto;
    gap: 1.25rem;
    padding: 1.25rem;
}

/* ══════════════════════ HMI PANEL ══════════════════════ */
.hmi-panel {
    background: linear-gradient(180deg, var(--bg-card) 0%, rgba(14, 25, 38, 0.9) 100%);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    grid-row: span 2;
    box-shadow: var(--shadow-sm);
}

h4 {
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-primary);
    margin-bottom: 0.4rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 1.5px;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.input-group label {
    font-size: 0.78rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

input[type="number"] {
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.6rem;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--accent-teal);
    width: 100%;
    transition: all 0.3s ease;
    outline: none;
}

input[type="number"]:focus {
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(0, 180, 216, 0.15);
}

input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button {
    opacity: 0.5;
}

.button-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.momentary-btn {
    background: linear-gradient(180deg, var(--bg-card) 0%, var(--btn-bg) 100%);
    color: var(--text-main);
    border: 1px solid var(--btn-border);
    border-radius: var(--radius-sm);
    padding: 0.55rem 0.8rem;
    font-size: 0.78rem;
    font-weight: 600;
    font-family: 'Inter', sans-serif;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
    transition: all 0.2s ease;
    letter-spacing: 0.2px;
    position: relative;
    overflow: hidden;
}

.momentary-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: -100%;
    width: 100%;
    height: 100%;
    background: linear-gradient(90deg, transparent, rgba(0, 180, 216, 0.08), transparent);
    transition: left 0.5s ease;
}

.momentary-btn:hover {
    border-color: var(--accent-primary);
    color: var(--text-bright);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.momentary-btn:hover::before {
    left: 100%;
}

.momentary-btn:active {
    background: var(--btn-active);
    box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.4);
    transform: translateY(0);
    border-color: var(--accent-teal);
}

/* ══════════════════════ DISPLAYS ══════════════════════ */
.displays {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: auto;
}

.display-box {
    background: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: border-color 0.3s ease;
}

.display-box:hover {
    border-color: rgba(0, 180, 216, 0.3);
}

.display-box .label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0.3px;
}

.display-box .value {
    font-family: 'JetBrains Mono', monospace;
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--accent-primary);
    text-shadow: 0 0 10px rgba(0, 180, 216, 0.3);
}

/* ══════════════════════ LED ══════════════════════ */
.led {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background-color: var(--led-off);
    border: 2px solid #3a4f65;
    box-shadow: inset 0 1px 3px rgba(0, 0, 0, 0.4);
    transition: all 0.25s ease;
}

.led.active {
    background-color: var(--led-on);
    border-color: rgba(34, 197, 94, 0.5);
    box-shadow:
        inset 0 1px 3px rgba(255, 255, 255, 0.2),
        0 0 8px var(--led-on),
        0 0 20px rgba(34, 197, 94, 0.3);
    animation: led-pulse 1.5s infinite;
}

@keyframes led-pulse {
    0%, 100% { box-shadow: inset 0 1px 3px rgba(255,255,255,0.2), 0 0 8px var(--led-on), 0 0 20px rgba(34,197,94,0.3); }
    50% { box-shadow: inset 0 1px 3px rgba(255,255,255,0.2), 0 0 12px var(--led-on), 0 0 30px rgba(34,197,94,0.4); }
}

/* ══════════════════════ LADDER LOGIC ══════════════════════ */
.logic-diagram {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 0;
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

.network-title {
    padding: 8px 14px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--accent-primary);
    border-bottom: 1px solid var(--border-color);
    font-family: 'Inter', sans-serif;
    background: linear-gradient(90deg, rgba(0, 180, 216, 0.06) 0%, transparent 100%);
    letter-spacing: 0.5px;
    text-transform: uppercase;
}

.ladder-network {
    position: relative;
    height: 180px;
    min-width: 600px;
    font-family: 'JetBrains Mono', monospace;
}

.power-rail {
    position: absolute;
    left: 20px;
    top: 10px;
    bottom: 10px;
    width: 3px;
    background: linear-gradient(180deg, var(--accent-primary), var(--accent-teal));
    border-radius: 2px;
    box-shadow: 0 0 8px rgba(0, 180, 216, 0.3);
}

.wire {
    position: absolute;
    height: 2px;
    background-color: var(--ladder-line);
    transition: all 0.3s ease;
}

.wire.active {
    background-color: var(--ladder-active);
    box-shadow: 0 0 6px var(--ladder-active);
    height: 2px;
}

.instruction-box {
    position: absolute;
    left: 250px;
    top: 40px;
    width: 120px;
    height: 100px;
    border: 2px solid var(--accent-primary);
    background: var(--bg-input);
    z-index: 2;
    border-radius: var(--radius-sm);
    box-shadow: 0 0 12px rgba(0, 180, 216, 0.1);
}

.box-title {
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    font-weight: 700;
    padding: 3px 0;
    font-family: 'Inter', sans-serif;
    font-size: 0.85rem;
    color: var(--accent-primary);
    background: linear-gradient(180deg, rgba(0, 180, 216, 0.1) 0%, transparent 100%);
    border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}

.pin-label {
    position: absolute;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-muted);
}

.pin-left { left: 6px; }
.pin-right { right: 6px; }
.pin-y1 { top: 25px; }
.pin-y2 { top: 55px; }
.pin-y3 { top: 85px; }

.contact-symbol {
    position: absolute;
    background-color: var(--bg-card);
    padding: 0 4px;
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--ladder-line);
    transform: translateY(-50%);
    z-index: 2;
    transition: all 0.25s ease;
    border-radius: 2px;
}

.contact-symbol.active {
    color: var(--ladder-active);
    text-shadow: 0 0 8px rgba(34, 197, 94, 0.5);
}

.tag-address {
    position: absolute;
    color: var(--accent-primary);
    font-weight: 600;
    font-size: 0.75rem;
    font-family: 'JetBrains Mono', monospace;
}

.online-box {
    position: absolute;
    border: 1px solid rgba(34, 197, 94, 0.4);
    color: var(--accent-green);
    padding: 2px 6px;
    font-size: 0.7rem;
    background-color: rgba(34, 197, 94, 0.08);
    border-radius: var(--radius-sm);
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
}

/* ══════════════════════ TIMING DIAGRAM ══════════════════════ */
.timing-diagram {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
}

canvas {
    width: 100%;
    background-color: var(--bg-input);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    margin-top: 0.5rem;
}

/* ══════════════════════ EXPLANATION ══════════════════════ */
.explanation {
    grid-column: 1 / -1;
    background: linear-gradient(135deg, rgba(0, 180, 216, 0.06) 0%, rgba(0, 212, 170, 0.04) 100%);
    border-left: 4px solid var(--accent-primary);
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    padding: 1rem 1.25rem;
    font-size: 0.85rem;
    line-height: 1.7;
    color: var(--text-muted);
}

.explanation strong {
    color: var(--accent-primary);
    font-weight: 700;
}

.explanation em {
    color: var(--accent-amber);
    font-style: italic;
}

/* ══════════════════════ RESPONSIVE ══════════════════════ */
@media (max-width: 1024px) {
    .module-content {
        grid-template-columns: 1fr;
    }
    .hmi-panel {
        grid-row: auto;
    }
    header {
        padding: 0.5rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }
    .header-right {
        align-items: center;
        text-align: center;
    }
    main {
        padding: 1rem;
    }
}

@media (max-width: 600px) {
    .module-content {
        padding: 0.75rem;
        gap: 0.75rem;
    }
    .ladder-network {
        min-width: 500px;
    }
}
