/* ====================================================
   Network Lab — стилистика (живая схема + тёмный терминал)
   Полностью адаптивно: ПК / планшет / телефон (Android/iOS).
   ==================================================== */
:root {
  --term-bg: #1f1d1a;
  --term-fg: #e8e6e1;
  --term-dim: #8a8983;
  --nl-up: #43b581;
  --nl-down: #c96442;
}

.nl-app {
  display: grid;
  grid-template-columns: 240px 1fr 340px;
  height: calc(100vh - 52px);
  min-height: 560px;
  background: var(--bg);
  position: relative;
}

/* ===== SIDEBAR (уроки) ===== */
.nl-sidebar {
  background: var(--bg-soft);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; overflow: hidden; min-width: 0;
}
.nl-sidebar-header { padding: 16px 18px 12px; border-bottom: 1px solid var(--border); }
.nl-sidebar-header h2 { font-size: 15px; font-weight: 600; margin: 0 0 10px; }
.nl-progress { font-size: 12px; color: var(--text-muted); }
.nl-progress-bar { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; margin-bottom: 6px; }
#nl-progress-fill { height: 100%; background: var(--accent); width: 0%; transition: width .3s ease; }
#nl-progress-text { font-family: var(--font-mono); font-size: 11px; }
#nl-lessons-list { flex: 1; overflow-y: auto; padding: 8px 0; }
.nl-lesson-item {
  display: grid; grid-template-columns: 22px 1fr; gap: 8px; align-items: center;
  padding: 9px 18px; cursor: pointer; border-left: 2px solid transparent;
  font-size: 13.5px; color: var(--text); transition: background .1s;
}
.nl-lesson-item:hover { background: var(--bg-elevated); }
.nl-lesson-item.active { background: var(--accent-soft); border-left-color: var(--accent); color: var(--accent); font-weight: 500; }
.nl-lesson-item .nl-check { font-size: 13px; color: var(--text-dim); text-align: center; }
.nl-lesson-item.completed .nl-check { color: var(--success); }
.nl-lesson-item.completed .nl-check::after { content: "✓"; }
.nl-lesson-item:not(.completed):not(.active) .nl-check::after { content: "○"; }
.nl-lesson-item.active:not(.completed) .nl-check::after { content: "▸"; color: var(--accent); }
.nl-sidebar-actions { display: flex; gap: 6px; padding: 12px 14px; border-top: 1px solid var(--border); }
.nl-sidebar-actions .btn { font-size: 12px; padding: 6px 10px; flex: 1; justify-content: center; }

/* ===== MAIN (схема + терминал) ===== */
.nl-main { display: flex; flex-direction: column; overflow: hidden; min-width: 0; background: var(--bg); }
.nl-toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 14px; border-bottom: 1px solid var(--border); background: var(--bg-soft);
}
.nl-toolbar label { font-size: 12px; color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; }
.nl-toolbar select {
  font-family: inherit; font-size: 13px; padding: 6px 10px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg-elevated); color: var(--text); cursor: pointer; max-width: 100%;
}
.nl-toolbar .grow { flex: 1; min-width: 8px; }
.nl-burger { display: none; }

/* Схема */
.nl-diagram-wrap {
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  padding: 10px 14px; flex: 0 0 auto;
}
.nl-svg { width: 100%; height: auto; max-height: 30vh; display: block; }

/* Терминал */
.nl-terminal-wrap { flex: 1 1 auto; display: flex; flex-direction: column; background: var(--term-bg); overflow: hidden; min-height: 0; }
.nl-term-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: #15130f; border-bottom: 1px solid #2a2724; user-select: none;
}
.nl-dots { display: flex; gap: 6px; }
.nl-dots span { width: 12px; height: 12px; border-radius: 50%; }
.nl-dots .r { background: #ff5f57; } .nl-dots .y { background: #febc2e; } .nl-dots .g { background: #28c840; }
.nl-term-title { font-family: var(--font-mono); font-size: 12px; color: var(--term-dim); }
#nl-terminal { flex: 1; padding: 14px 18px; overflow-y: auto; font-family: var(--font-mono);
  font-size: 13.5px; line-height: 1.55; color: var(--term-fg); cursor: text; -webkit-overflow-scrolling: touch; }
#nl-terminal:focus { outline: none; }
#nl-output { white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere; }
.nl-line { display: block; }
.nl-prompt-line { display: flex; align-items: baseline; line-height: 1.55; }
#nl-prompt { white-space: pre-wrap; user-select: none; flex: 0 0 auto; }
/* Настоящий <input> — надёжная клавиатура на планшетах/телефонах (iOS/Android) */
#nl-input {
  flex: 1 1 auto; min-width: 0; margin-left: 6px;
  background: transparent; border: none; outline: none; padding: 0;
  color: var(--term-fg); font-family: var(--font-mono); font-size: inherit; line-height: inherit;
  caret-color: var(--nl-up); -webkit-appearance: none; appearance: none; border-radius: 0;
}
#nl-input::placeholder { color: var(--term-dim); }

/* цвета вывода */
.nl-title { color: #79c0ff; font-weight: 700; }
.nl-dim { color: var(--term-dim); }
.nl-sys { color: #d2a8ff; }
.nl-ok { color: var(--nl-up); font-weight: 600; }
.nl-bad { color: #f88379; font-weight: 600; }
.nl-hint { color: #e6c44d; }
.nl-edit { color: #56d4dd; }

/* мобильная панель клавиш */
.nl-keybar { display: none; gap: 6px; padding: 8px 10px; background: #15130f; border-top: 1px solid #2a2724; flex-wrap: wrap; }
.nl-keybar button {
  font-family: var(--font-mono); font-size: 13px; padding: 9px 12px; border-radius: 8px;
  border: 1px solid #33302b; background: #26231f; color: var(--term-fg); cursor: pointer; flex: 1; min-width: 44px;
}
.nl-keybar button:active { background: #33302b; }

/* ===== СХЕМА (SVG) ===== */
.nl-link { stroke: var(--text-dim); stroke-width: 3; stroke-linecap: round; }
.nl-link.up { stroke: var(--nl-up); stroke-width: 3.5; }
.nl-link.down { stroke: var(--text-dim); stroke-dasharray: 2 7; opacity: .6; }
.nl-conn { stroke: var(--bg-soft); stroke-width: 1.5; }
.nl-conn.up { fill: var(--nl-up); }
.nl-conn.down { fill: var(--text-dim); }
.nl-card { fill: var(--bg-elevated); stroke: var(--border); stroke-width: 1.5; transition: stroke .2s; }
.nl-node.host .nl-card { fill: var(--bg-soft); }
.nl-node.active .nl-card { stroke: var(--accent); stroke-width: 2.5; }
.nl-node:hover .nl-card { stroke: var(--accent); }
.nl-node-name { font-size: 13.5px; font-weight: 700; fill: var(--text); }
.nl-node-host { font-size: 10px; font-family: var(--font-mono); fill: var(--text-muted); }
.nl-pc-ip { font-size: 11px; fill: var(--text-muted); font-family: var(--font-mono); font-weight: 600; }
.nl-console-badge { font-size: 10.5px; fill: var(--accent); font-weight: 700; letter-spacing: .02em; }
/* подписи портов и IP */
.nl-port-name { font-size: 10px; font-family: var(--font-mono); fill: var(--text-muted); }
.nl-ip-pill { fill: var(--nl-up); opacity: .16; }
.nl-ip-text { font-size: 10.5px; font-family: var(--font-mono); fill: var(--nl-up); font-weight: 700; }
.nl-ip-none { font-size: 9.5px; font-family: var(--font-mono); fill: var(--text-dim); font-style: italic; }
/* иконки */
.nl-ic-mon { fill: #55585f; }
.nl-ic-stand { fill: var(--text-muted); }
.nl-ic-router-base { fill: #22456b; }
.nl-ic-router-top { fill: #4a86c8; }
.nl-ic-arrow { stroke: #fff; stroke-width: 2; stroke-linecap: round; }
.nl-ic-arrow-h { fill: #fff; }
/* пакет */
.nl-packet { fill: var(--nl-up); }
.nl-packet.bad { fill: #f0685c; }
.nl-packet-halo { fill: var(--nl-up); opacity: .28; }
.nl-packet-halo.bad { fill: #f0685c; opacity: .28; }
.nl-boom { fill: none; stroke: #f0685c; stroke-width: 3; animation: nlboom .75s ease-out forwards; }
@keyframes nlboom { from { r: 6; opacity: 1; } to { r: 34; opacity: 0; } }

/* ===== LESSON PANE ===== */
.nl-lesson { background: var(--bg-elevated); border-left: 1px solid var(--border); display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
#nl-lesson-content { flex: 1; overflow-y: auto; padding: 22px 24px 40px; line-height: 1.62; font-size: 14px; }
#nl-lesson-content h2 { font-size: 19px; margin: 0 0 8px; }
#nl-lesson-content h3 { font-size: 17px; margin: 18px 0 8px; }
#nl-lesson-content h4 { font-size: 14px; margin: 16px 0 6px; }
#nl-lesson-content p { margin: 0 0 10px; }
#nl-lesson-content ul, #nl-lesson-content ol { padding-left: 20px; margin: 0 0 10px; }
#nl-lesson-content li { margin-bottom: 4px; }
#nl-lesson-content code { font-size: 12.5px; padding: 1px 5px; background: var(--bg-soft); border-radius: 4px; font-family: var(--font-mono); overflow-wrap: anywhere; }
#nl-lesson-content pre { font-size: 12.5px; padding: 12px 14px; margin: 10px 0; background: var(--term-bg); color: var(--term-fg); border-radius: 8px; overflow-x: auto; }
#nl-lesson-content pre code { background: none; color: inherit; }
#nl-lesson-content .callout { padding: 12px 14px; margin: 12px 0; font-size: 13px; border-radius: 8px; background: var(--bg-soft); border: 1px solid var(--border); }
#nl-lesson-content .callout.warning { border-color: #d2a24c66; }
#nl-lesson-content .callout.danger { border-color: #c9644266; }
#nl-lesson-content .callout.info { border-color: #4c86d266; }
#nl-lesson-content .callout-label { font-size: 11.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); margin-bottom: 4px; }
#nl-lesson-content .callout p { margin-bottom: 0; font-size: 13px; }
#nl-lesson-content .nl-cmd { display: block; background: var(--term-bg); color: var(--term-fg); font-family: var(--font-mono);
  font-size: 12.5px; padding: 8px 12px; border-radius: 8px; margin: 8px 0; white-space: pre-wrap; word-break: break-word; }
#nl-lesson-content .nl-cmd b { color: #79c0ff; }

/* Задание */
.nl-task { border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--bg-soft); padding: 13px 15px; margin: 13px 0; }
.nl-task-title { display: flex; align-items: flex-start; gap: 8px; font-weight: 500; margin-bottom: 6px; font-size: 13.5px; }
.nl-task-title::before { content: "○"; color: var(--text-dim); font-size: 16px; line-height: 1.2; }
.nl-task.done { background: var(--success-soft); border-color: var(--success); }
.nl-task.done .nl-task-title::before { content: "✓"; color: var(--success); font-weight: 700; }
.nl-task-status { font-size: 12px; color: var(--text-muted); font-family: var(--font-mono); }
.nl-task.done .nl-task-status { color: var(--success); }

/* Flash */
.nl-flash { position: fixed; top: 68px; right: 20px; background: var(--success); color: #fff; padding: 10px 18px;
  border-radius: var(--radius-sm); font-weight: 500; font-size: 14px; z-index: 1000; box-shadow: var(--shadow-lg);
  animation: nlslide .3s, nlfade .3s 1.8s forwards; }
@keyframes nlslide { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes nlfade { to { opacity: 0; transform: translateX(120%); } }

/* ===== АДАПТИВНОСТЬ ===== */
@media (max-width: 1200px) { .nl-app { grid-template-columns: 210px 1fr 300px; } }

@media (max-width: 960px) {
  /* планшет: прячем боковую панель уроков в off-canvas, схема+терминал+урок стекируются */
  .nl-app { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; min-height: 0; }
  .nl-sidebar {
    position: fixed; top: 52px; left: 0; bottom: 0; width: 280px; max-width: 86vw; z-index: 60;
    transform: translateX(-100%); transition: transform .25s ease; border-right: 1px solid var(--border);
    box-shadow: var(--shadow-lg);
  }
  .nl-sidebar.open { transform: none; }
  .nl-burger { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; padding: 7px 12px;
    border: 1px solid var(--border); border-radius: 8px; background: var(--bg-elevated); color: var(--text); cursor: pointer; }
  .nl-main { min-height: 70vh; }
  .nl-svg { max-height: 34vh; }
  .nl-lesson { border-left: none; border-top: 1px solid var(--border); }
  #nl-lesson-content { max-height: none; }
}

@media (max-width: 640px) {
  #nl-terminal { font-size: 13px; padding: 12px 14px; }
  .nl-keybar { display: flex; }
  .nl-svg { max-height: 38vh; }
  .nl-toolbar { padding: 8px 12px; gap: 8px; }
  .nl-toolbar label span.t { display: none; }
  #nl-lesson-content { padding: 18px 16px 32px; }
}

/* На телефоне терминал должен быть комфортной высоты */
@media (max-width: 960px) {
  .nl-terminal-wrap { min-height: 340px; }
}
