/* ==========================================================
   ORDERFLOW - CSS COMUNE (stili generali)
   ========================================================== */

:root {
    --bg: #d9d9d9;
    --window: #ffffff;

    --title: #f3f3f3;
    --menu: #fafafa;
    --toolbar: #f7f7f7;
    --header: #ededed;

    --border: #cfcfcf;
    --grid: #e8e8e8;

    --text: #333;
    --muted: #666;

    --accent: #b53f3f;
    --selected: #c96a6a;
    --hover: #737272;

    --sidebar-width: 15%;
    --main-width: 85%;
    --sidebar-bg: #f0f0f0;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: "Segoe UI", Tahoma, Arial, sans-serif;
    font-size: 12px;
    color: var(--text);
}

body {
    background: var(--bg);
    padding: 12px;
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.window {
    width: 100%;
    max-width: 1700px;
    height: 100vh;
    max-height: 840px;
    background: var(--window);
    border: 1px solid #ababaa;
    box-shadow: 0 3px 10px rgba(0, 0, 0, .15);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.main-layout {
    display: flex;
    flex: 1;
    min-height: 0;
    overflow: hidden;
}

.sidebar {
    width: var(--sidebar-width);
    min-width: 180px;
    max-width: 280px;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    flex-shrink: 0;
}

.main-content {
    width: var(--main-width);
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.sidebar-menu {
    padding: 8px 0;
    overflow-y: auto;
    flex: 1;
}

/* ==========================================================
   MENU ITEM PRINCIPALE (con supporto sottomenu)
   ========================================================== */
.sidebar-menu .menu-item {
    padding: 8px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    color: #444;
    border-left: 3px solid transparent;
    transition: all 0.2s ease;
    white-space: nowrap;
    position: relative;
}

.sidebar-menu .menu-item:hover {
    background: #e4e4e4;
    border-left-color: var(--hover);
}

.sidebar-menu .menu-item.active {
    background: #e8e8e8;
    border-left-color: var(--accent);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-menu .menu-item .icon {
    font-size: 14px;
    width: 20px;
    text-align: center;
    flex-shrink: 0;
}

.sidebar-menu .menu-item .label {
    flex: 1;
}

/* Indicatore di sottomenu (freccia) */
.sidebar-menu .menu-item .arrow {
    margin-left: auto;
    font-size: 10px;
    color: #999;
    transition: transform 0.3s ease;
    flex-shrink: 0;
}

.sidebar-menu .menu-item.open .arrow {
    transform: rotate(90deg);
}

/* ==========================================================
   SOTTOMENU (annidato)
   ========================================================== */
.sidebar-menu .submenu {
    overflow: hidden;
    max-height: 0;
    transition: max-height 0.3s ease, opacity 0.2s ease, padding 0.2s ease;
    opacity: 0;
    padding: 0;
    background: #e8e8e8;
    border-left: 1px solid var(--border);
    margin-left: 0;
}

.sidebar-menu .submenu.open {
    max-height: 500px;
    opacity: 1;
    padding: 4px 0;
}

.sidebar-menu .submenu .menu-item {
    padding: 6px 16px 6px 46px;
    font-size: 11px;
    border-left: 2px solid transparent;
    white-space: nowrap;
}

.sidebar-menu .submenu .menu-item:hover {
    background: #ddd;
    border-left-color: var(--hover);
}

.sidebar-menu .submenu .menu-item.active {
    background: #dcdcdc;
    border-left-color: var(--accent);
    color: var(--accent);
    font-weight: 500;
}

.sidebar-menu .submenu .menu-item .icon {
    font-size: 12px;
    width: 18px;
}

/* ==========================================================
   DIVIDER E TITOLI
   ========================================================== */
.sidebar-menu .menu-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 12px;
}

.sidebar-menu .menu-title {
    padding: 8px 16px 4px;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--muted);
    font-weight: 600;
    letter-spacing: 0.5px;
}

/* ==========================================================
   TITLEBAR
   ========================================================== */
.titlebar {
    height: 30px;
    min-height: 30px;
    background: var(--title);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 10px;
    flex-shrink: 0;
}

.title-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    width: 18px;
    height: 18px;
    background: #c0392b;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
    font-weight: 700;
    flex-shrink: 0;
    border-radius: 50%;
}

.window-title {
    font-size: 12px;
    color: #222;
}

.controls {
    display: flex;
    gap: 16px;
    color: #555;
    font-size: 13px;
}

/* ==========================================================
   TOOLBAR
   ========================================================== */
.toolbar {
    height: 38px;
    min-height: 38px;
    background: var(--toolbar);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 8px;
    flex-shrink: 0;
    overflow-x: auto;
}

.btn {
    width: 26px;
    min-width: 26px;
    height: 26px;
    border: 1px solid #d2d2d2;
    background: #fff;
    border-radius: 2px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: default;
    flex-shrink: 0;
}

.separator {
    width: 1px;
    height: 22px;
    background: #d6d6d6;
    margin: 0 2px;
    flex-shrink: 0;
}

.tabs {
    height: 34px;
    min-height: 34px;
    display: flex;
    align-items: flex-end;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    overflow-y: hidden;
    white-space: nowrap;
    flex-shrink: 0;
    padding: 0 4px;
}

.tab {
    padding: 8px 10px;
    color: #555;
    flex-shrink: 0;
    cursor: default;
    min-width: 80px;
}

.tab.active {
    color: var(--accent);
    font-weight: 600;
    border-bottom: 3px solid var(--selected);
}

a {
    text-decoration: none;
}

a:hover {
    font-weight: bold;
}

/* ==========================================================
   STATUSBAR
   ========================================================== */
.statusbar {
    height: 32px;
    min-height: 32px;
    background: #f5f5f5;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 4px 12px;
    color: #666;
    flex-shrink: 0;
    gap: 8px;
}

.status-left,
.status-right {
    display: flex;
    gap: 6px;
    align-items: center;
    flex-wrap: wrap;
}

.status-left span,
.status-right span {
    white-space: nowrap;
    padding: 2px 12px;
    border: 1px solid #bcbcbc;
    border-radius: 4px;
    background: #f0f0f0;
    height: 24px;
    display: flex;
    align-items: center;
    font-size: 11px;
    color: #444;
    box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.2s ease;
}

.status-left span:hover,
.status-right span:hover {
    background: #e8e8e8;
    border-color: #a0a0a0;
}

/* ==========================================================
   SCROLLBAR
   ========================================================== */
::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

::-webkit-scrollbar-thumb {
    background: #c2c2c2;
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: #a8a8a8;
}

/* ==========================================================
   STILI PER INPUT
   ========================================================== */
input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]) {
    height: 24px;
    border: 1px solid var(--border);
    background: #ffffff;
    padding: 0 6px;
    border-radius: 2px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: 13px;
    color: var(--text);
}

input:not([type="checkbox"]):not([type="radio"]):not([type="submit"]):not([type="button"]):not([type="reset"]):not([type="file"]):focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(181, 63, 63, 0.15);
}

input[readonly],
input[readonly]:focus {
    background: #fafafa;
    border-color: #a0a0a0;
    color: #555;
    cursor: none;
    box-shadow: none;
    border-style: solid;
    border-width: 1px;
    border-left-color: var(--hover);
    border-left-width: 3px;
    padding-left: 4px;
}

input[required]:not([type="checkbox"]):not([type="radio"]) {
    border-color: #d4a0a0;
    border-width: 1.5px;
}

input[required]:not([type="checkbox"]):not([type="radio"]):focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(181, 63, 63, 0.15);
}

input[required]:not([type="checkbox"]):not([type="radio"]):valid {
    border-color: #6a9e6a;
}

input[required]:not([type="checkbox"]):not([type="radio"]):invalid:not(:placeholder-shown) {
    border-color: #c0392b;
    background: #fff5f5;
}

.field.required label::after {
    content: ' *';
    color: var(--accent);
    font-weight: bold;
}

input:disabled {
    background: #f0f0f0;
    border-color: #d0d0d0;
    color: #999;
}

input.input-error {
    border-color: #c0392b;
    background: #fff5f5;
}

input.input-error:focus {
    border-color: #c0392b;
    box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.2);
}

/* ==========================================================
   STILI PER SELECT (uniformati agli input)
   ========================================================== */
select {
    height: 24px;
    border: 1px solid var(--border);
    background: #ffffff;
    padding: 0 6px;
    border-radius: 2px;
    outline: none;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
    width: 100%;
    box-sizing: border-box;
    font: inherit;
    font-size: 13px;
    color: var(--text);
    cursor: pointer;
    appearance: auto;
    -webkit-appearance: auto;
    -moz-appearance: auto;
}

select:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(181, 63, 63, 0.15);
}

select:disabled,
select[disabled] {
    background: #fafafa;
    border-color: #a0a0a0;
    color: #555;
}

select[readonly] {
    background: #fafafa;
    border-color: #a0a0a0;
    color: #555;
    border-left-color: var(--hover);
    border-left-width: 3px;
    padding-left: 4px;
    pointer-events: none;
}

select[required] {
    border-color: #d4a0a0;
    border-width: 1.5px;
}

select[required]:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(181, 63, 63, 0.15);
}

select[required]:valid {
    border-color: #6a9e6a;
}

select[required]:invalid:not(:placeholder-shown) {
    border-color: #c0392b;
    background: #fff5f5;
}

select.input-error {
    border-color: #c0392b;
    background: #fff5f5;
}

select.input-error:focus {
    border-color: #c0392b;
    box-shadow: 0 0 0 2px rgba(192, 57, 43, 0.2);
}

select option:first-child:not([value]) {
    color: #999;
}

/* Per i select nei contenitori .rigainput */
.rigainput select {
    height: 100%;
    border: none;
    background: transparent;
    padding: 0;
    outline: none;
    width: 100%;
    cursor: pointer;
    font-size: 13px;
}

.rigainput select:focus {
    border-color: transparent;
    box-shadow: none;
}

.rigainput select:disabled {
    background: transparent;
    border-color: transparent;
    color: #999;
}

/* ==========================================================
   BARRA AZIONI CONTESTUALE (es. licenze, form, liste)
   ========================================================== */
.licence-menu {
    background: var(--menu);
    border-bottom: 1px solid var(--border);
    padding: 6px 8px;
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    flex-shrink: 0;
}

.licence-menu .user-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-left: 8px;
}

/* ==========================================================
   BOTTONE AZIONE GENERICO (riutilizzabile)
   Esempio d'uso:
     <a href="..." class="btn-azione">✎ Modificar</a>
     <button type="submit" class="btn-azione">💾 Salvar</button>
   ========================================================== */

a.btn-azione,
button.btn-azione,
.btn-azione.btn-azione {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    gap: 4px !important;
    padding: 4px 12px !important;
    background: #fff !important;
    border: 1px solid var(--border) !important;
    border-radius: 3px !important;
    font-family: inherit !important;
    font-weight: 600 !important;
    font-size: 11px !important;
    line-height: 1.2 !important;
    color: var(--text) !important;
    text-decoration: none !important;
    cursor: pointer !important;
    white-space: nowrap !important;
    vertical-align: middle !important;
    box-sizing: border-box !important;
}

a.btn-azione:hover,
button.btn-azione:hover,
.btn-azione.btn-azione:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    font-weight: 600;
}

a.btn-azione:focus,
button.btn-azione:focus,
.btn-azione.btn-azione:focus {
    outline: none;
    box-shadow: 0 0 0 2px rgba(181, 63, 63, 0.25);
}

a.btn-azione:active,
button.btn-azione:active,
.btn-azione.btn-azione:active {
    background: var(--selected);
    border-color: var(--selected);
    color: #fff;
    transform: translateY(1px);
}

a.btn-azione:disabled,
button.btn-azione:disabled,
.btn-azione.btn-azione:disabled {
    background: #f0f0f0;
    border-color: #d0d0d0;
    color: #999;
    transform: none;
}

/* cursore personalizzato */
input[disabled]:hover,
select[disabled]:hover,
textarea[disabled]:hover,
input[readonly]:hover,
select[readonly]:hover,
textarea[readonly]:hover {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='red' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cline x1='18' y1='6' x2='6' y2='18'%3E%3C/line%3E%3Cline x1='6' y1='6' x2='18' y2='18'%3E%3C/line%3E%3C/svg%3E") 16 16, not-allowed;
}


/* ==========================================================
   MEDIA QUERIES COMUNI
   ========================================================== */
@media screen and (max-width: 1200px) {
    body {
        padding: 8px;
    }

    .window {
        max-height: 98vh;
    }

    .tab {
        padding: 8px 8px;
        font-size: 11px;
    }

    .sidebar {
        min-width: 140px;
        max-width: 220px;
    }

    .sidebar-menu .menu-item {
        padding: 6px 12px;
        font-size: 11px;
    }

    .sidebar-menu .submenu .menu-item {
        padding: 5px 12px 5px 38px;
        font-size: 10px;
    }

    .status-left span,
    .status-right span {
        padding: 1px 10px;
        font-size: 10px;
        height: 22px;
    }
}

@media screen and (max-width: 768px) {
    body {
        padding: 4px;
    }

    .window {
        max-height: 100vh;
        border-radius: 0;
    }

    .titlebar {
        padding: 0 6px;
    }

    .toolbar {
        gap: 4px;
        padding: 0 4px;
    }

    .btn {
        width: 22px;
        min-width: 22px;
        height: 22px;
        font-size: 11px;
    }

    .tab {
        padding: 6px 6px;
        font-size: 10px;
    }

    .status-left,
    .status-right {
        gap: 4px;
    }

    .status-left span,
    .status-right span {
        font-size: 9px;
        padding: 1px 8px;
        height: 20px;
        border-radius: 3px;
    }

    .statusbar {
        padding: 2px 6px;
        height: 28px;
        min-height: 28px;
    }

    .sidebar {
        min-width: 50px;
        max-width: 50px;
    }

    .sidebar-menu .menu-item .label {
        display: none;
    }

    .sidebar-menu .menu-item .arrow {
        display: none;
    }

    .sidebar-menu .menu-item {
        padding: 10px 0;
        justify-content: center;
    }

    .sidebar-menu .menu-title {
        display: none;
    }

    .sidebar-menu .menu-divider {
        margin: 4px 8px;
    }

    .sidebar-menu .submenu {
        max-height: 0 !important;
        opacity: 0 !important;
        padding: 0 !important;
    }

    .sidebar-menu .submenu .menu-item {
        display: none;
    }
}

@media screen and (max-width: 480px) {
    .btn {
        width: 20px;
        min-width: 20px;
        height: 20px;
        font-size: 10px;
    }

    .tab {
        padding: 4px 5px;
        font-size: 9px;
    }

    .status-left span,
    .status-right span {
        font-size: 8px;
        padding: 0 6px;
        height: 18px;
        border-radius: 2px;
    }

    .statusbar {
        padding: 2px 4px;
        gap: 4px;
        height: 26px;
        min-height: 26px;
    }

    .sidebar {
        display: none;
    }

    .main-content {
        width: 100%;
    }
}