/*
 * Educational Network Simulator - GPLv3
 */

:root {
  --ns-bg: #f3f4f6;
  --ns-surface: #ffffff;
  --ns-border: #d1d5db;
  --ns-border-strong: #9ca3af;
  --ns-text: #111827;
  --ns-text-muted: #4b5563;
  --ns-accent: #2563eb;
  --ns-accent-hover: #1d4ed8;
  --ns-accent-soft: #dbeafe;
  --ns-danger: #dc2626;
  --ns-success: #16a34a;
  --ns-warning: #b45309;
  --ns-radius: 8px;
  --ns-shadow: 0 10px 30px rgba(17, 24, 39, 0.18), 0 2px 6px rgba(17, 24, 39, 0.08);
  --ns-font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ns-toolbar-h: 52px;
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  font-family: var(--ns-font);
  font-size: 14px;
  color: var(--ns-text);
  background: var(--ns-bg);
}

#ns-app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* ---------- Toolbar ---------- */

#ns-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  padding: 6px 10px;
  background: var(--ns-surface);
  border-bottom: 1px solid var(--ns-border);
  flex: 0 0 auto;
  min-height: var(--ns-toolbar-h);
  z-index: 20;
}

.ns-group {
  display: flex;
  align-items: center;
  gap: 2px;
  padding-right: 10px;
  border-right: 1px solid var(--ns-border);
}
.ns-group:last-child { border-right: 0; padding-right: 0; }
.ns-group.ns-right { margin-left: auto; border-right: 0; gap: 8px; }

.ns-brand .ns-title {
  font-weight: 700;
  font-size: 15px;
  white-space: nowrap;
  color: var(--ns-text);
}

.ns-tool {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 38px;
  min-width: 38px;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: var(--ns-radius);
  background: transparent;
  color: var(--ns-text);
  font: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.ns-tool:hover { background: var(--ns-bg); border-color: var(--ns-border); }
.ns-tool:active { background: var(--ns-accent-soft); }
.ns-tool:focus-visible, .ns-menu-item:focus-visible, .ns-window button:focus-visible, .ns-window input:focus-visible, .ns-window select:focus-visible, .ns-window textarea:focus-visible {
  outline: 2px solid var(--ns-accent);
  outline-offset: 1px;
}
.ns-tool img { width: 26px; height: 26px; object-fit: contain; }
.ns-tool.ns-active { background: var(--ns-accent-soft); border-color: var(--ns-accent); }
.ns-tool-symbol { font-size: 20px; line-height: 1; width: 20px; text-align: center; }

.ns-readout {
  min-width: 46px;
  text-align: center;
  font-variant-numeric: tabular-nums;
  color: var(--ns-text-muted);
  font-size: 13px;
}
.ns-readout-btn {
  border: 0;
  background: transparent;
  font: inherit;
  font-size: 13px;
  cursor: pointer;
  height: 38px;
  border-radius: var(--ns-radius);
}
.ns-readout-btn:hover { background: var(--ns-bg); }

.ns-lang {
  font: inherit;
  font-size: 13px;
  height: 32px;
  padding: 0 6px;
  border: 1px solid var(--ns-border);
  border-radius: 6px;
  background: var(--ns-surface);
  color: var(--ns-text);
  cursor: pointer;
}

.ns-status {
  font-size: 12px;
  color: var(--ns-text-muted);
  white-space: nowrap;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
}
.ns-status::before { content: "\25CF  "; }
.ns-status.ns-status-ok::before { color: var(--ns-success); }
.ns-status.ns-status-error { color: var(--ns-danger); font-weight: 600; }
.ns-status.ns-status-error::before { color: var(--ns-danger); }

@media (max-width: 1180px) {
  .ns-add-group .ns-tool-label { display: none; }
}
@media (max-width: 900px) {
  .ns-tool-label { display: none; }
  .ns-brand { display: none; }
  .ns-status { max-width: 140px; }
}
@media (max-width: 700px) {
  #ns-toolbar {
    flex-wrap: nowrap;
    overflow-x: auto;
    overflow-y: hidden;
    gap: 6px;
    padding: 4px 6px;
    scrollbar-width: thin;
  }
  .ns-group { flex: 0 0 auto; padding-right: 6px; }
  .ns-group.ns-right { margin-left: 0; }
  .ns-tool { height: 40px; min-width: 40px; padding: 0 6px; }
  .ns-status { display: none; }
}

/* ---------- Drawing area ---------- */

#simcontainer {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: #dddddd;
}
#simcontainer.ns-dragover { outline: 4px dashed var(--ns-accent); outline-offset: -8px; }

#simcanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

#ns-hint {
  position: absolute;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--ns-success);
  color: #fff;
  font-weight: 600;
  box-shadow: var(--ns-shadow);
  pointer-events: none;
  display: none;
}
#ns-hint.ns-visible { display: block; }

#ns-empty {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 24px;
  color: var(--ns-text-muted);
  font-size: 16px;
  pointer-events: none;
}
#ns-empty.ns-visible { display: flex; }

#ns-loading {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--ns-bg);
  color: var(--ns-text-muted);
  font-size: 16px;
  z-index: 1000;
}

/* ---------- Context menus ---------- */

.ns-menu {
  position: fixed;
  z-index: 300;
  min-width: 220px;
  max-width: 320px;
  max-height: calc(100vh - 16px);
  overflow-y: auto;
  padding: 4px;
  background: var(--ns-surface);
  border: 1px solid var(--ns-border);
  border-radius: var(--ns-radius);
  box-shadow: var(--ns-shadow);
}
.ns-menu-title {
  padding: 6px 10px 8px;
  font-weight: 700;
  border-bottom: 1px solid var(--ns-border);
  margin-bottom: 4px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.ns-menu-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 6px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  font: inherit;
  color: var(--ns-text);
  text-align: left;
  cursor: pointer;
}
.ns-menu-item:hover, .ns-menu-item:focus { background: var(--ns-accent-soft); }
.ns-menu-item img { width: 24px; height: 24px; object-fit: contain; flex: 0 0 auto; }

/* ---------- Dialog windows ---------- */

.ns-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(17, 24, 39, 0.35);
}

.ns-window {
  position: fixed;
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 24px);
  background: var(--ns-surface);
  border-radius: 12px;
  box-shadow: var(--ns-shadow);
  overflow: hidden;
}
.ns-window.ns-centered {
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
}
.ns-window-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 10px 10px 16px;
  background: var(--ns-accent);
  color: #fff;
  font-weight: 700;
  cursor: move;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  flex: 0 0 auto;
}
.ns-window-close {
  border: 0;
  background: transparent;
  color: #fff;
  font-size: 22px;
  line-height: 1;
  width: 32px;
  height: 32px;
  border-radius: 6px;
  cursor: pointer;
}
.ns-window-close:hover { background: rgba(255, 255, 255, 0.2); }
.ns-window-content {
  padding: 14px 16px;
  overflow: auto;
  flex: 1 1 auto;
  min-height: 0;
}
.ns-window-controls {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px 16px;
  border-top: 1px solid var(--ns-border);
  background: var(--ns-bg);
  flex: 0 0 auto;
}
.ns-window-controls p { margin: 0; display: flex; gap: 8px; }

.ns-window input[type=button], .ns-window input[type=submit], .ns-window button:not(.ns-window-close):not(.ns-icon-btn) {
  font: inherit;
  padding: 7px 14px;
  border: 1px solid var(--ns-border-strong);
  border-radius: 6px;
  background: var(--ns-surface);
  color: var(--ns-text);
  cursor: pointer;
}
.ns-window input[type=button]:hover, .ns-window button:not(.ns-window-close):not(.ns-icon-btn):hover { background: var(--ns-bg); }
.ns-window .ns-primary, .ns-window input.ns-primary[type=button] {
  background: var(--ns-accent);
  border-color: var(--ns-accent);
  color: #fff;
}
.ns-window .ns-primary:hover, .ns-window input.ns-primary[type=button]:hover { background: var(--ns-accent-hover); }

.ns-window input[type=text], .ns-window input[type=number], .ns-window select, .ns-window textarea {
  font: inherit;
  padding: 6px 8px;
  border: 1px solid var(--ns-border-strong);
  border-radius: 6px;
  background: #fff;
  color: var(--ns-text);
  min-width: 0;
}
.ns-window input.ns-invalid { border-color: var(--ns-danger); background: #fef2f2; }

.ns-form {
  display: grid;
  grid-template-columns: minmax(110px, max-content) 1fr;
  gap: 8px 12px;
  align-items: center;
}
.ns-form input, .ns-form select { width: 100%; }

.ns-inline {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
}
.ns-inline input[type=text] { flex: 1 1 auto; }
.ns-grow { flex: 1 1 auto; }

.ns-help { color: var(--ns-text-muted); font-size: 13px; margin: 10px 0; }
.ns-list { margin: 6px 0; padding-left: 20px; }
.ns-list li { margin: 4px 0; }

.ns-radio { display: flex; align-items: center; gap: 6px; padding: 3px 0; cursor: pointer; }

.ns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 4px 0 8px;
}
.ns-table th, .ns-table td {
  border: 1px solid var(--ns-border);
  padding: 4px 6px;
  text-align: left;
  vertical-align: middle;
}
.ns-table th { background: var(--ns-bg); font-weight: 600; }
.ns-table td input[type=text] { width: 100%; }
.ns-table .ns-controls-col { width: 1%; white-space: nowrap; text-align: center; }
.ns-table .ns-new-row td { background: #f9fafb; }

.ns-icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  cursor: pointer;
  vertical-align: middle;
}
.ns-icon-btn:hover { background: var(--ns-bg); border-color: var(--ns-border); }
.ns-icon-btn img { width: 22px; height: 22px; object-fit: contain; }
.ns-icon-btn.ns-primary { background: var(--ns-accent); }
.ns-icon-btn.ns-primary img { filter: brightness(0) invert(1); width: 16px; height: 16px; }

.ns-console {
  height: 240px;
  overflow-y: auto;
  padding: 8px 10px;
  background: #111827;
  color: #e5e7eb;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}

.ns-code {
  width: 100%;
  min-height: 260px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  resize: vertical;
}

.ns-browser {
  border: 1px solid var(--ns-border);
  border-radius: 6px;
  min-height: 280px;
  display: flex;
  background: #fff;
}
.ns-browser-frame { border: 0; width: 100%; min-height: 280px; flex: 1 1 auto; }
.ns-browser-status { padding: 14px; color: var(--ns-text-muted); font-style: italic; }

/* ---------- Notifications ---------- */

#ns-toasts {
  position: fixed;
  right: 12px;
  bottom: 12px;
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-width: min(420px, calc(100vw - 24px));
}
.ns-toast {
  position: relative;
  padding: 10px 36px 10px 14px;
  border-radius: var(--ns-radius);
  background: var(--ns-surface);
  border: 1px solid #bfdbfe;
  background: #eff6ff;
  box-shadow: var(--ns-shadow);
  white-space: pre-line;
  font-size: 13px;
}
.ns-toast-success { border-color: #bbf7d0; background: #f0fdf4; }
.ns-toast-warning { border-color: #fde68a; background: #fffbeb; }
.ns-toast-error { border-color: #fecaca; background: #fef2f2; }
.ns-toast-close {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: 0;
  background: transparent;
  font-size: 18px;
  cursor: pointer;
  color: var(--ns-text-muted);
  border-radius: 4px;
}
.ns-toast-close:hover { background: var(--ns-bg); }

@media (prefers-reduced-motion: no-preference) {
  .ns-toast { animation: ns-toast-in 160ms ease-out; }
  @keyframes ns-toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
}

.ns-confirm-text { margin: 4px 0; line-height: 1.5; }

/* ---------- Disabled toolbar buttons ---------- */
.ns-tool:disabled { opacity: 0.35; cursor: default; background: transparent; border-color: transparent; }

/* ---------- Message inspector / problems tooltip ---------- */
.ns-inspector { min-width: 260px; max-width: 340px; padding: 6px 8px 4px; }
.ns-inspector .ns-menu-title { display: flex; justify-content: space-between; align-items: center; padding-right: 0; }
.ns-inspector-close {
  border: 0; background: transparent; font-size: 18px; line-height: 1;
  width: 26px; height: 26px; border-radius: 4px; cursor: pointer; color: var(--ns-text-muted);
}
.ns-inspector-close:hover { background: var(--ns-bg); }
.ns-inspector table { border-collapse: collapse; width: 100%; font-size: 12px; }
.ns-inspector th { text-align: left; font-weight: 600; color: var(--ns-text-muted); padding: 3px 10px 3px 2px; white-space: nowrap; vertical-align: top; }
.ns-inspector td { padding: 3px 2px; font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; word-break: break-all; }
.ns-inspector .ns-help { margin: 6px 2px 2px; font-size: 12px; }

.ns-tooltip {
  position: fixed; z-index: 400; display: none; max-width: 340px;
  padding: 8px 10px; border-radius: var(--ns-radius);
  background: #fffbeb; border: 1px solid #fcd34d; box-shadow: var(--ns-shadow);
  font-size: 12px; pointer-events: none;
}
.ns-tooltip ul, .ns-menu-warning ul { margin: 4px 0 0; padding-left: 18px; }
.ns-tooltip li, .ns-menu-warning li { margin: 2px 0; }
.ns-menu-warning {
  margin: 0 2px 4px; padding: 6px 8px; border-radius: 6px;
  background: #fffbeb; border: 1px solid #fcd34d; font-size: 12px;
}

/* ---------- Review of several files ---------- */
#ns-review {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 4px 6px;
  background: var(--ns-surface); border: 1px solid var(--ns-border); border-radius: 999px;
  box-shadow: var(--ns-shadow); z-index: 10; max-width: calc(100% - 20px);
}
#ns-review button {
  border: 0; background: transparent; width: 32px; height: 32px; border-radius: 999px;
  cursor: pointer; font-size: 15px; color: var(--ns-text); flex: 0 0 auto;
}
#ns-review button:hover:not(:disabled) { background: var(--ns-accent-soft); }
#ns-review button:disabled { opacity: 0.3; cursor: default; }
.ns-review-label { font-weight: 600; font-size: 13px; padding: 0 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
