:root {
    --primary: #b71918;
    --secondary: #9d9d9d;
    --text-dark: #111;
    --bg-light: #f3f3f3;
    --bg-white: #fff;
    --footer-dark: #9d9d9d;
}

/* Reset e font di base */
body {
    margin: 0;
    padding: 0;
    color: var(--text-dark);
    font-family: "Segoe UI", Arial, sans-serif;
    background: var(--bg-white);
}

/* STILE MODULI GENERICI */
label {
    font-size: 0.97em;
    margin-bottom: 3px;
    margin-right: 14px;
    font-weight: 500;
    color: var(--text-dark, #111);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
input[type="search"],
input[type="url"],
input[type="date"],
input[type="time"],
input[type="file"],
input[type="color"],
textarea,
select {
    border: 1px solid var(--secondary, #9d9d9d);
    border-radius: 7px;
    background: var(--bg-white, #fff);
    color: var(--text-dark, #111);
    padding: 7px 10px;
    font-size: 0.97em;
    margin-bottom: 9px;
    box-sizing: border-box;
    min-height: 34px;
    height: 34px;
    vertical-align: middle;
    outline: none;
    transition: border 0.2s, box-shadow 0.2s;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

input[type='radio'],
input[type='checkbox'] {
    background: var(--bg-white, #fff);
    color: var(--text-dark, #111);
    padding: 7px 10px;
    font-size: 0.97em;
    margin-bottom: 9px;
    box-sizing: border-box;
    min-height: 34px;
    height: 34px;
    vertical-align: middle;
    outline: none;
    transition: border 0.2s, box-shadow 0.2s;
}

textarea {
    min-height: 5em;
    height: 9em;
    resize: vertical;
    font-family: inherit;
    line-height: 1.22;
}

select {
    min-width: 110px;
    height: 34px;
}

input:focus,
textarea:focus,
select:focus {
    border-color: var(--primary, #b71918);
    box-shadow: 0 0 0 2px rgba(183, 25, 24, 0.07);
}

input[type='radio']:focus,
input[type='checkbox']:focus {
    border: none;
    box-shadow: none;
}

#labelings-area,
#filtered-labelings-area {
    overflow-x: auto;
    white-space: nowrap;
    list-style: none;
    margin-block-start: 0;
    margin-block-end: 0;
    resize: vertical;
    min-height: 5em;
    height: 5em;
    overflow: auto;
    border: 1px solid var(--secondary, #9d9d9d);
    border-radius: 7px;
    background: var(--bg-white, #fff);
    color: var(--text-dark, #111);
    padding: 0;
    margin-bottom: 9px;
    box-sizing: border-box;
    font-size: 0.97em;
    font-family: inherit;
}

#labelings-area li,
#filtered-labelings-area li {
    display: table-caption;
    width: max-content;
    min-width: 100%;
    box-sizing: border-box;
    padding: 0 10px;
    margin: 0;
    border: none;
    cursor: pointer;
    transition: background 0.12s, color 0.12s;
    user-select: none;
    height: 1.3em;
    line-height: 1.3em;
    font-size: 0.97em;
    white-space: nowrap;
    font-family: inherit;
    background: transparent;
}

#labelings-area li.selected,
#labelings-area li:active,
#filtered-labelings-area li.selected,
#filtered-labelings-area li:active {
    background: #ffbdbd;
    color: #b71918;
}

#labelings-area li:last-child,
#filtered-labelings-area li:last-child {
    border-bottom: none;
}

.input-error {
    border: 1.5px solid #b8263c !important;
    background: #fff4f4 !important;
}

.form-error {
    color: #b8263c;
    font-size: 0.97em;
}

/* Pulsanti principali e secondari */
button,
.btn-primary {
    background: var(--primary, #b71918);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 0.97em;
    height: 34px;
    min-width: 34px;
    padding: 0 12px;
    cursor: pointer;
    margin-right: 10px;
    margin-bottom: 9px;
    transition: background 0.16s, box-shadow 0.16s;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

button.secondary,
.btn-secondary {
    background: var(--secondary, #9d9d9d);
    color: #fff;
    border: none;
    border-radius: 7px;
    font-size: 0.97em;
    height: 34px;
    min-width: 34px;
    padding: 0 12px;
    margin-right: 10px;
    margin-bottom: 9px;
    transition: background 0.16s, box-shadow 0.16s;
    font-weight: 500;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.04);
}

button:active,
button:focus,
.btn-primary:active,
.btn-primary:focus {
    background: #a11412;
}

button.secondary:active,
button.secondary:focus,
.btn-secondary:active,
.btn-secondary:focus {
    background: #7b7b7b;
}

button:disabled,
.btn-primary:disabled {
    background: #dd8080;
    cursor: auto;
}

.button-compute {
    width: 90%;
    margin: 0 auto;
    justify-content: center;
}

.button-save {
    margin: 0 0 0 auto;
}

/* HEADER */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--primary, #b71918);
    color: #fff;
    height: 44px;
    padding: 0 22px;
}

.header-left span {
    font-size: 1.2em;
    font-weight: 600;
    letter-spacing: 1px;
    line-height: 44px;
}

.header-right .logo {
    max-height: 30px;
    width: auto;
    margin-left: 14px;
    vertical-align: middle;
}

/* LAYOUT PRINCIPALE */
.main {
    display: flex;
    height: calc(100vh - 44px);
    width: 100vw;
    min-width: 900px;
    overflow: hidden;
}

.workarea {
    flex: 1 1 0;
    background: var(--bg-white);
    padding: 22px;
    box-sizing: border-box;
    display: flex;
    align-items: stretch;
    justify-content: center;
}

/* CYTOSCAPE */
#cy-container {
    position: relative;
    width: 100%;
    height: 100%;
    box-shadow: 2px 2px 8px #ccc;
}

#cy,
#cy-preview-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    display: block;
}

#cy {
    z-index: 1;
    background: #fff;
    border: 1px solid #ddd;
}

#cy-preview-canvas {
    z-index: 2;
    pointer-events: none;
}

/* wrapper esterno: sempre centrato sul nodo */
.node-html-label {
    position: absolute;
    transform: translate(-50%, -50%);
    /* centro del nodo */
    pointer-events: none;
    z-index: 10;
}

.node-html-label .node-label-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
    color: var(--bg-white);
    pointer-events: none;
}

/* Name (baseline per il centro del nodo) */
.node-label-name {
    font-size: 14px;
    font-weight: 500;
    line-height: 1.1;
}

/* Weight sotto il nome, dentro al nodo */
.node-label-weight {
    font-size: 8px;
    font-weight: 400;
    margin-top: 2px;
}

/* Strength: piccolo e “galleggiante” sopra, senza spostare il resto */
.node-label-strength {
    font-size: 8px;
    font-weight: 400;
    margin-bottom: -11px;
    /* niente margine che spinga il nome in basso */
    transform: translateY(-18px);
    /* alza solo la riga strength */
    color: var(--text-dark);
    background-color: #ffffffcc;
    padding: 0 2px;
    border-radius: 3px;
}



/* SIDEBAR */
.sidebar {
    width: 450px;
    min-width: 310px;
    background: var(--bg-light);
    display: flex;
    flex-direction: column;
    height: 100%;
    box-sizing: border-box;
    border-left: 1px solid var(--secondary);
    overflow-y: auto;
}

.sidebar-commands {
    flex: 1 1 auto;
    padding: 28px 28px 10px 28px;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.sidebar-commands #semantic-group-ext-based,
.sidebar-commands #semantic-group-gradual {
    /* Forza tutto come nel root sidebar-commands */
    display: contents;
    /* Gli elementi figli vengono resi come se fossero figli diretti: niente box nuovi! */
}

.semantic-title {
    font-size: 1em;
    font-weight: 500;
    background: linear-gradient(90deg, #f8d8d8 0%, #fafafa 60%, #f8d8d8 100%);
    color: #b71918;
    border-radius: 12px 12px 0 0;
    margin-bottom: 18px;
    margin-top: -3px;
    box-shadow: 0 2px 8px -6px #000000cc;
    padding: 7px 16px 10px 16px;
    text-align: center;
    border-top: 1px solid #fff;
    background-color: #b7191822;
}

span#semantic-title-ext-based,
span#semantic-title-gradual {
    display: block;
    font-size: x-large;
}

@media (max-width: 800px) {
    .semantic-title {
        font-size: 0.97em;
        padding: 5px 8px 8px 8px;
    }
}

.buttons-line {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 10px;
    margin-bottom: 16px;
    min-height: 34px;
}

.buttons-line-in-group {
    margin-bottom: 0;
}

.buttons-line label,
.buttons-line input,
.buttons-line select,
.buttons-line textarea,
.buttons-line button {
    margin-bottom: 0 !important;
    height: 34px !important;
    min-height: 34px !important;
    line-height: 34px !important;
    vertical-align: middle;
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
}

.buttons-line svg,
.buttons-line img {
    height: 22px;
    width: auto;
    vertical-align: middle;
    margin-left: 4px;
    margin-right: 4px;
}

.disabled-control {
    opacity: 0.5;
    background-color: #f5f5f5;
    cursor: not-allowed;
}

hr {
    border: none;
    border-top: 2px dashed var(--secondary, #9d9d9d);
    margin: 18px 0;
    opacity: 0.5;
}

.sidebar-footer {
    background: var(--footer-dark, #9d9d9d);
    color: #fff;
    padding: 14px 16px;
    font-size: 0.55em;
    letter-spacing: 0.5px;
    border-top: 1px solid #b6b6b6;
    text-align: right;
}

/* MODALI NODO E ARCO */
#node-modal-bg,
#edge-modal-bg {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.27);
    z-index: 2000;
}

#node-modal-content,
#edge-modal-content {
    background: var(--bg-light);
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    padding: 24px 28px 0 28px;
    border-radius: 8px;
    min-width: 320px;
    box-shadow: 0 4px 20px #0005;
}

.modal-header {
    background: var(--primary, #b71918);
    color: #fff;
    padding: 10px 20px;
    font-size: 1.14em;
    font-weight: 600;
    border-radius: 9px 9px 0 0;
    margin: -24px -28px 20px -28px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.modal-footer {
    padding: 14px 0 13px 22px;
    background: transparent;
    display: flex;
    justify-content: flex-end;
    min-height: 38px;
}

.modal-footer button {
    margin-bottom: 0;
    margin-left: 10px;
    height: 34px;
    min-width: 34px;
    font-size: 0.97em;
    border-radius: 7px;
}

/* MENU CONTESTUALE  NODO E ARCO */
#node-context-menu,
#edge-context-menu {
    display: none;
    position: absolute;
    background: #fff;
    border: 1px solid #d0d0d0;
    border-radius: 5px;
    min-width: 120px;
    box-shadow: 0 4px 16px #0002;
    z-index: 2100;
}

#node-context-menu>div,
#edge-context-menu>div {
    padding: 10px 20px;
    cursor: pointer;
}

#node-context-menu>div:not(:last-child),
#edge-context-menu>div:not(:last-child) {
    border-bottom: 1px solid #eee;
}

#ctx-delete,
#edge-ctx-delete {
    color: #d00;
}

#ctx-delete:hover,
#edge-ctx-delete:hover {
    background: #ffd2dd;
}

#ctx-edit:hover,
#edge-ctx-edit:hover {
    background: #e6f2ff;
}

/* TOOLTIP */
.cy-tooltip {
    position: absolute;
    background: var(--footer-dark, #9d9d9d);
    color: #fff;
    padding: 6px 12px;
    border-radius: 6px;
    pointer-events: none;
    z-index: 1000;
    font-size: 1rem;
}

.edge.preview {
    stroke-dasharray: 6 4;
}

node.pseudo {
    display: none;
}

/* Responsive base */
@media (max-width: 1090px) {
    .sidebar {
        width: 260px;
    }

    .main {
        min-width: 420px;
    }

    .workarea {
        padding: 10px;
    }
}

@media (max-width: 680px) {
    .modal-box {
        min-width: 90vw;
    }
}