* {
    box-sizing: border-box;
}

:root {
    --bg: #f3f5f7;
    --panel: #ffffff;
    --text: #17202a;
    --muted: #6b7280;
    --border: #e3e7eb;
    --dark: #17202a;

    --red: #d62828;
    --orange: #ef8d22;
    --green: #258a55;
    --blue: #1267b1;
}

body {
    margin: 0;
    font-family:
        Inter,
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        sans-serif;
    background: var(--bg);
    color: var(--text);
}

button,
input {
    font: inherit;
}

button,
a {
    -webkit-tap-highlight-color: transparent;
}

.eyebrow {
    font-size: 12px;
    font-weight: 800;
    letter-spacing: .12em;
    text-transform: uppercase;
    color: var(--muted);
}


/* LOGIN */

.login-body {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        linear-gradient(
            145deg,
            #eef1f4,
            #ffffff
        );
}

.login-shell {
    width: 100%;
    max-width: 440px;
}

.login-card {
    background: white;
    border: 1px solid var(--border);
    border-radius: 22px;
    padding: 38px;
    box-shadow:
        0 20px 60px rgba(0,0,0,.08);
}

.brand-mark {
    width: 68px;
    height: 68px;
    border-radius: 16px;
    background: var(--dark);
    color: white;
    display: grid;
    place-items: center;
    font-weight: 900;
    letter-spacing: .08em;
    margin-bottom: 28px;
}

.login-heading h1 {
    margin: 6px 0 8px;
    font-size: 28px;
}

.login-heading p {
    color: var(--muted);
    margin: 0 0 28px;
}

.login-form {
    display: grid;
    gap: 18px;
}

.login-form label {
    display: grid;
    gap: 7px;
    font-size: 13px;
    font-weight: 700;
}

.login-form input,
.search-form input {
    width: 100%;
    border: 1px solid #cfd5dc;
    border-radius: 10px;
    padding: 13px 14px;
    background: white;
    outline: none;
}

.login-form input:focus,
.search-form input:focus {
    border-color: var(--blue);
    box-shadow:
        0 0 0 3px rgba(18,103,177,.12);
}

.primary-button {
    border: 0;
    border-radius: 10px;
    background: var(--dark);
    color: white;
    padding: 14px;
    cursor: pointer;
    font-weight: 800;
}

.login-error {
    background: #fff0f0;
    border: 1px solid #ffd0d0;
    color: #a31818;
    padding: 12px 14px;
    border-radius: 10px;
    margin-bottom: 20px;
}


/* HEADER */

.topbar {
    min-height: 86px;
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px 30px;
}

.topbar h1 {
    margin: 3px 0 0;
    font-size: 23px;
}

.user-area {
    display: flex;
    align-items: center;
    gap: 18px;
}

.user-info {
    text-align: right;
}

.user-info strong,
.user-info span {
    display: block;
}

.user-info span {
    color: var(--muted);
    font-size: 12px;
    margin-top: 2px;
}

.logout-button {
    border: 1px solid var(--border);
    background: white;
    padding: 9px 13px;
    border-radius: 8px;
    cursor: pointer;
}


/* PAGE */

.page {
    width: min(1500px, calc(100% - 40px));
    margin: 28px auto 60px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.summary-card {
    background: white;
    border: 1px solid var(--border);
    border-top: 4px solid var(--dark);
    border-radius: 14px;
    padding: 20px;
}

.summary-card span {
    display: block;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

.summary-card strong {
    display: block;
    margin-top: 7px;
    font-size: 32px;
}

.summary-card.status-out,
.summary-card.status-low {
    border-top-color: var(--red);
}

.summary-card.status-warning {
    border-top-color: var(--orange);
}


/* TOOLBAR */

.toolbar {
    margin-top: 22px;
    background: white;
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 15px;
    display: flex;
    justify-content: space-between;
    gap: 15px;
}

.search-form {
    display: flex;
    gap: 9px;
    flex: 1;
    max-width: 800px;
}

.search-form button {
    border: 0;
    background: var(--dark);
    color: white;
    border-radius: 9px;
    padding: 0 18px;
    cursor: pointer;
}

.clear-search {
    display: flex;
    align-items: center;
    color: var(--muted);
    text-decoration: none;
    padding: 0 8px;
}

.actions {
    display: flex;
    gap: 8px;
}

.secondary-button {
    border: 1px solid var(--border);
    background: #fafafa;
    border-radius: 9px;
    padding: 10px 14px;
}

.secondary-button:disabled,
.movement-actions button:disabled {
    opacity: .55;
}


/* CONTENT */

.section-heading {
    margin: 30px 2px 14px;
    display: flex;
    align-items: end;
    justify-content: space-between;
}

.section-heading h2 {
    margin: 4px 0 0;
    font-size: 24px;
}

.result-count {
    color: var(--muted);
    font-size: 13px;
}

.container-list {
    display: grid;
    gap: 10px;
}

.container-card {
    position: relative;
    overflow: hidden;
    background: white;
    border: 1px solid var(--border);
    border-left: 5px solid var(--green);
    border-radius: 12px;
    padding: 14px 17px;
    display: grid;
    grid-template-columns:
        150px
        minmax(240px, 1fr)
        110px
        150px
        auto;
    align-items: center;
    gap: 18px;
}

.container-card.out,
.container-card.low {
    border-left-color: var(--red);
}

.container-card.warning {
    border-left-color: var(--orange);
}

.stock-indicator {
    display: flex;
    align-items: center;
    gap: 10px;
}

.status-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--green);
    flex: 0 0 auto;
}

.out .status-dot,
.low .status-dot {
    background: var(--red);
}

.warning .status-dot {
    background: var(--orange);
}

.stock-indicator small,
.position-box small,
.stock-box small {
    display: block;
    color: var(--muted);
    font-size: 10px;
    font-weight: 800;
    letter-spacing: .08em;
}

.stock-indicator strong {
    display: block;
    margin-top: 2px;
    font-size: 12px;
}

.article-data h3 {
    margin: 0 0 3px;
    font-size: 17px;
}

.article-data p {
    margin: 0 0 5px;
    color: #4b5563;
    font-size: 13px;
}

.article-code {
    color: var(--muted);
    font-size: 12px;
}

.position-box strong {
    display: inline-block;
    margin-top: 4px;
    padding: 5px 9px;
    border-radius: 7px;
    background: #eaf4ff;
    color: var(--blue);
}

.stock-box {
    text-align: right;
}

.stock-box strong {
    display: inline-block;
    margin-top: 2px;
    font-size: 22px;
}

.stock-box span {
    color: var(--muted);
    font-size: 11px;
}

.movement-actions {
    display: flex;
    gap: 7px;
}

.movement-actions button {
    border-radius: 8px;
    padding: 9px 11px;
    background: white;
}

.withdraw-button {
    border: 1px solid var(--red);
    color: var(--red);
}

.load-button {
    border: 1px solid var(--green);
    color: var(--green);
}


/* EMPTY */

.empty-state {
    min-height: 320px;
    background: white;
    border: 1px dashed #ccd2d9;
    border-radius: 14px;
    display: grid;
    place-items: center;
    align-content: center;
    text-align: center;
    padding: 30px;
}

.empty-state h2 {
    margin: 15px 0 4px;
}

.empty-state p {
    color: var(--muted);
    max-width: 550px;
}

.empty-icon {
    width: 65px;
    height: 65px;
    border-radius: 16px;
    background: #eef1f4;
    display: grid;
    place-items: center;
    font-weight: 900;
}


/* MOBILE */

@media (max-width: 900px) {

    .summary-grid {
        grid-template-columns: repeat(2, 1fr);
    }

    .toolbar {
        display: grid;
    }

    .search-form {
        max-width: none;
    }

    .container-card {
        grid-template-columns: 1fr 100px;
    }

    .stock-indicator {
        grid-column: 1 / -1;
    }

    .article-data {
        grid-column: 1 / -1;
    }

    .movement-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 600px) {

    .topbar {
        padding: 14px 16px;
    }

    .topbar h1 {
        font-size: 18px;
    }

    .user-info {
        display: none;
    }

    .page {
        width: calc(100% - 20px);
        margin-top: 15px;
    }

    .summary-grid {
        gap: 8px;
    }

    .summary-card {
        padding: 14px;
    }

    .summary-card strong {
        font-size: 27px;
    }

    .search-form {
        display: grid;
        grid-template-columns: 1fr auto;
    }

    .search-form input {
        grid-column: 1 / -1;
    }

    .search-form button {
        min-height: 42px;
    }

    .actions {
        overflow-x: auto;
    }

    .container-card {
        padding: 13px;
        gap: 12px;
    }

    .stock-box strong {
        font-size: 20px;
    }
}


/* ==========================================================
   DASHBOARD - ORDINAMENTO CASSONI
   ========================================================== */

.sort-header {
    display: grid;
    grid-template-columns: 1.05fr 2.15fr 1fr 1fr;
    gap: 16px;
    align-items: center;
    margin: 0 16px 8px 16px;
    padding: 0 20px;
}

.sort-header a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    width: fit-content;
    color: #667085;
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .08em;
    text-decoration: none;
    transition: color .15s ease;
}

.sort-header a:hover,
.sort-header a.active {
    color: #101828;
}

.sort-header a span {
    font-size: 13px;
    line-height: 1;
}

@media (max-width: 760px) {
    .sort-header {
        grid-template-columns: repeat(2, 1fr);
        gap: 8px 16px;
        margin: 0 8px 10px 8px;
        padding: 0 8px;
    }
}


/* ==========================================================
   DETTAGLIO / MODIFICA CASSONE
   ========================================================== */

.article-open {
    cursor: pointer;
    border-radius: 8px;
}

.article-open:hover h3 {
    text-decoration: underline;
}

.modal-open {
    overflow: hidden;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: rgba(15, 23, 42, .58);
    padding: 24px;
    overflow-y: auto;
}

.modal-backdrop[hidden] {
    display: none;
}

.modal-panel {
    width: min(680px, 100%);
    margin: 6vh auto;
    background: white;
    border-radius: 16px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, .24);
    overflow: hidden;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    padding: 22px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-header h2 {
    margin: 4px 0 0;
}

.modal-close {
    width: 38px;
    height: 38px;
    border: 1px solid var(--border);
    border-radius: 9px;
    background: white;
    font-size: 25px;
    line-height: 1;
    cursor: pointer;
}

#container-edit-form {
    padding: 24px;
}

.modal-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 18px;
}

.modal-grid label span,
.modal-stock > span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
}

.modal-grid input,
.modal-grid textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 11px 12px;
    font: inherit;
    background: white;
}

.modal-grid textarea {
    resize: vertical;
}

.modal-grid input:disabled,
.modal-grid textarea:disabled {
    background: #f5f6f7;
    color: #475467;
}

.modal-wide {
    grid-column: 1 / -1;
}

.modal-stock {
    align-self: end;
    padding: 10px 0;
}

.modal-stock strong {
    font-size: 28px;
}

.modal-stock small {
    color: var(--muted);
}

.modal-error {
    margin-top: 18px;
    padding: 11px 13px;
    border: 1px solid #fecaca;
    border-radius: 9px;
    background: #fef2f2;
    color: #b42318;
    font-size: 13px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 24px;
    padding-top: 18px;
    border-top: 1px solid var(--border);
}

.modal-footer button {
    border-radius: 9px;
    padding: 10px 16px;
    cursor: pointer;
}

.modal-save {
    border: 0;
    background: var(--dark);
    color: white;
}

.modal-save:disabled {
    opacity: .55;
}

@media (max-width: 600px) {
    .modal-backdrop {
        padding: 10px;
    }

    .modal-panel {
        margin: 2vh auto;
    }

    .modal-grid {
        grid-template-columns: 1fr;
    }

    .modal-wide {
        grid-column: auto;
    }
}


/* ==========================================================
   CARICO / PRELIEVO
   ========================================================== */

.movement-modal-panel {
    width: min(600px, 100%);
}

#movement-form {
    padding: 24px;
}

.movement-summary {
    display: grid;
    grid-template-columns: 2fr 1fr 1.2fr;
    gap: 18px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: #f8fafc;
}

.movement-summary span,
.movement-quantity > span {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 11px;
    font-weight: 800;
    letter-spacing: .07em;
    text-transform: uppercase;
}

.movement-summary strong {
    display: block;
    font-size: 18px;
}

.movement-summary small {
    display: block;
    margin-top: 4px;
    color: var(--muted);
}

.movement-quantity {
    display: block;
    margin-top: 22px;
}

.movement-quantity input {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 13px;
    font: inherit;
    font-size: 20px;
    font-weight: 700;
}

.movement-result-preview {
    margin-top: 14px;
    padding: 12px 14px;
    border-radius: 9px;
    background: #f5f6f7;
    color: var(--muted);
}

.movement-result-preview strong {
    color: var(--dark);
}

.movement-confirm {
    border: 0;
    border-radius: 9px;
    padding: 10px 16px;
    color: white;
    cursor: pointer;
}

.withdraw-confirm {
    background: var(--red);
}

.load-confirm {
    background: var(--green);
}

.movement-confirm:disabled {
    opacity: .55;
    cursor: wait;
}

@media (max-width: 600px) {
    .movement-summary {
        grid-template-columns: 1fr;
    }
}


/* ==========================================================
   NUOVO ARTICOLO
   ========================================================== */

#new-article-stock {
    font-size: 18px;
    font-weight: 700;
}

#new-article-position {
    text-transform: uppercase;
}


/* ==========================================================
   NUOVO ARTICOLO - LAYOUT CORRETTO
   ========================================================== */

#new-article-modal .modal-panel {
    width: min(680px, 100%);
}

#new-article-form {
    padding: 28px 24px 24px;
}

#new-article-form .modal-grid {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 18px;
    row-gap: 22px;
}

#new-article-form .modal-grid label {
    display: flex;
    flex-direction: column;
    min-width: 0;
    margin: 0;
}

#new-article-form .modal-grid label > span {
    display: block;
    margin: 0 0 7px 0;
    line-height: 1.2;
}

#new-article-form .modal-grid input,
#new-article-form .modal-grid textarea {
    display: block;
    width: 100%;
    box-sizing: border-box;
    margin: 0;
}

#new-article-form .modal-grid input {
    min-height: 46px;
}

#new-article-form .modal-grid textarea {
    min-height: 88px;
}

#new-article-form .modal-wide {
    grid-column: 1 / -1;
}

#new-article-form .modal-footer {
    margin-top: 26px;
    padding-top: 18px;
}

#new-article-stock {
    font-size: 18px;
    font-weight: 700;
}

#new-article-position {
    text-transform: uppercase;
}

@media (max-width: 600px) {

    #new-article-form {
        padding: 22px 18px 18px;
    }

    #new-article-form .modal-grid {
        grid-template-columns: 1fr;
        row-gap: 18px;
    }

    #new-article-form .modal-wide {
        grid-column: auto;
    }
}



/* ==========================================================
   LOG MOVIMENTI - POPUP
   ========================================================== */

#log-modal {
    padding: 24px;
}

#log-modal .log-modal-panel {
    width: min(1500px, 98vw);
    max-height: 92vh;
    display: flex;
    flex-direction: column;
}

.log-body {
    min-height: 0;
    padding: 22px 24px 24px;
    display: flex;
    flex-direction: column;
}

.log-toolbar {
    display: flex;
    align-items: end;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.log-search {
    flex: 1 1 620px;
    min-width: 0;
}

.log-search span {
    display: block;
    margin-bottom: 7px;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
}

.log-search input {
    display: block;
    width: 100%;
    min-height: 44px;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 10px 13px;
    font: inherit;
}

.log-search input:focus {
    outline: none;
    border-color: var(--dark);
}

.log-filters {
    display: flex;
    flex: 0 0 auto;
    gap: 7px;
}

.log-filter {
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 9px;
    padding: 8px 14px;
    background: white;
    color: var(--dark);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.log-filter:hover {
    background: #f5f6f7;
}

.log-filter.active {
    background: var(--dark);
    border-color: var(--dark);
    color: white;
}

.log-summary {
    display: flex;
    align-items: baseline;
    gap: 6px;
    margin-bottom: 12px;
    color: var(--muted);
    font-size: 13px;
}

.log-summary strong {
    color: var(--dark);
    font-size: 16px;
}

.log-table-wrap {
    min-height: 0;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: 10px;
}

.log-table {
    width: 100%;
    min-width: 1120px;
    border-collapse: collapse;
    background: white;
}

.log-table th,
.log-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: middle;
    white-space: nowrap;
}

.log-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: #f5f6f7;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: .03em;
}

.log-table td {
    font-size: 13px;
}

.log-table tbody tr:hover {
    background: #fafafa;
}

.log-table tbody tr:last-child td {
    border-bottom: 0;
}

.log-table .number-cell {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.log-date {
    font-variant-numeric: tabular-nums;
}

.log-article,
.log-quantity,
.log-operator {
    font-weight: 700;
}

.log-type {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 86px;
    border-radius: 999px;
    padding: 5px 9px;
    font-size: 11px;
    font-weight: 900;
    letter-spacing: .02em;
}

.log-type-withdraw {
    background: #ffe8e8;
    color: #a90000;
}

.log-type-load {
    background: #e7f6ec;
    color: #126b31;
}

.log-empty,
.log-loading {
    padding: 34px 20px !important;
    text-align: center !important;
    color: var(--muted);
}

@media (max-width: 800px) {

    #log-modal {
        padding: 10px;
    }

    #log-modal .log-modal-panel {
        width: 100%;
        max-height: 96vh;
    }

    .log-body {
        padding: 18px 14px;
    }

    .log-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .log-search {
        flex: 0 0 auto;
        width: 100%;
    }

    .log-filters {
        width: 100%;
    }

    .log-filter {
        flex: 1 1 0;
        padding-left: 8px;
        padding-right: 8px;
    }
}


/* ==========================================================
   LOG MOVIMENTI - DESKTOP REFINEMENT
   ========================================================== */

@media (min-width: 1000px) {

    #log-modal {
        padding: 18px;
    }

    #log-modal .log-modal-panel {
        width: min(1580px, calc(100vw - 36px));
        max-width: none;
    }

    .log-table-wrap {
        width: 100%;
        overflow-x: hidden;
    }

    .log-table {
        width: 100%;
        min-width: 0;
        table-layout: fixed;
    }

    .log-table th,
    .log-table td {
        box-sizing: border-box;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* Data / Ora */
    .log-table th:nth-child(1),
    .log-table td:nth-child(1) {
        width: 15%;
        padding-left: 16px;
    }

    /* Tipo */
    .log-table th:nth-child(2),
    .log-table td:nth-child(2) {
        width: 10%;
    }

    /* Articolo */
    .log-table th:nth-child(3),
    .log-table td:nth-child(3) {
        width: 15%;
    }

    /* Codice */
    .log-table th:nth-child(4),
    .log-table td:nth-child(4) {
        width: 13%;
    }

    /* Posizione */
    .log-table th:nth-child(5),
    .log-table td:nth-child(5) {
        width: 8%;
    }

    /* Quantità */
    .log-table th:nth-child(6),
    .log-table td:nth-child(6) {
        width: 9%;
    }

    /* Prima */
    .log-table th:nth-child(7),
    .log-table td:nth-child(7) {
        width: 7%;
    }

    /* Dopo */
    .log-table th:nth-child(8),
    .log-table td:nth-child(8) {
        width: 7%;
    }

    /* Operatore */
    .log-table th:nth-child(9),
    .log-table td:nth-child(9) {
        width: 16%;
        padding-right: 16px;
    }

    .log-date {
        white-space: nowrap;
    }

    .log-type {
        min-width: 78px;
    }
}


/* Manteniamo lo scroll orizzontale solo sugli schermi piccoli */

@media (max-width: 999px) {

    .log-table-wrap {
        overflow-x: auto;
    }

    .log-table {
        min-width: 1050px;
    }
}
