:root {
    --bg: #f7f7f4;
    --surface: #ffffff;
    --ink: #202124;
    --muted: #687076;
    --line: #deded8;
    --accent: #146c5f;
    --accent-dark: #0f5148;
    --danger: #9d2f2f;
}

* {
    box-sizing: border-box;
}

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

a {
    color: var(--accent);
}

.topbar {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 14px;
    justify-content: space-between;
    min-height: 62px;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 40;
}

.topbar-main,
.topbar-actions {
    align-items: center;
    display: flex;
    gap: 12px;
}

.topbar-actions form {
    margin: 0;
}

.brand {
    color: var(--ink);
    font-weight: 800;
    text-decoration: none;
}

.menu-button {
    align-items: center;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 999px;
    box-shadow: 0 2px 10px rgba(32, 33, 36, 0.06);
    display: inline-flex;
    flex-direction: column;
    gap: 5px;
    height: 40px;
    justify-content: center;
    padding: 0;
    transition: border-color 0.16s ease, box-shadow 0.16s ease, transform 0.16s ease;
    width: 40px;
}

.menu-button:hover {
    background: #ffffff;
    border-color: #b9d4cc;
    box-shadow: 0 4px 14px rgba(20, 108, 95, 0.13);
    transform: translateY(-1px);
}

.menu-button span {
    background: var(--accent-dark);
    border-radius: 999px;
    display: block;
    height: 2px;
    width: 17px;
}

.menu-button span:nth-child(2) {
    width: 13px;
}

.icon-button {
    background: #eef1ef;
    border-radius: 8px;
    color: var(--ink);
    font-size: 24px;
    height: 38px;
    line-height: 1;
    padding: 0;
    width: 38px;
}

.menu-backdrop {
    background: rgba(32, 33, 36, 0.36);
    inset: 0;
    position: fixed;
    z-index: 60;
}

.offcanvas-menu {
    background: var(--surface);
    border-right: 1px solid var(--line);
    bottom: 0;
    display: flex;
    flex-direction: column;
    gap: 18px;
    left: 0;
    max-width: 86vw;
    padding: 18px;
    position: fixed;
    top: 0;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    width: 320px;
    z-index: 70;
}

.menu-is-open .offcanvas-menu {
    transform: translateX(0);
}

.menu-is-open {
    overflow: hidden;
}

.offcanvas-header {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.offcanvas-header div {
    display: grid;
    gap: 3px;
}

.offcanvas-header span,
.offcanvas-footer a {
    color: var(--muted);
    font-size: 13px;
}

.offcanvas-nav {
    display: grid;
    gap: 8px;
}

.offcanvas-nav a {
    background: #f3f6f4;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink);
    font-weight: 750;
    padding: 13px 14px;
    text-decoration: none;
}

.offcanvas-nav a:hover {
    border-color: #bfd7cf;
    color: var(--accent-dark);
}

.offcanvas-footer {
    border-top: 1px solid var(--line);
    display: grid;
    gap: 12px;
    margin-top: auto;
    padding-top: 16px;
}

.quota-alert {
    background: #f9e7e7;
    border: 1px solid #efb8b8;
    border-radius: 999px;
    color: var(--danger);
    font-size: 13px;
    font-weight: 800;
    padding: 6px 10px;
    text-decoration: none;
}

.shell {
    margin: 0 auto;
    max-width: 1180px;
    padding: 18px 14px 34px;
}

.article-shell {
    margin: 0 auto;
    max-width: 780px;
    padding: 40px 24px;
}

.page-heading {
    display: grid;
    gap: 20px;
    margin-bottom: 22px;
}

h1,
h2 {
    margin: 0 0 10px;
}

p {
    line-height: 1.6;
}

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.narrow {
    margin: 40px auto;
    max-width: 460px;
}

.form-grid {
    display: grid;
    gap: 16px;
}

.editor-grid {
    align-items: start;
    display: grid;
    gap: 22px;
}

.dashboard-grid {
    display: grid;
    gap: 18px;
    margin-bottom: 22px;
}

.usage-grid {
    display: grid;
    gap: 18px;
    margin-bottom: 22px;
}

.app-home-heading {
    align-items: end;
    display: grid;
    gap: 14px;
    margin-bottom: 18px;
}

.app-home-heading h1 {
    font-size: 30px;
}

.app-home-heading p {
    color: var(--muted);
    margin: 0;
}

.company-list {
    display: grid;
    gap: 12px;
}

.company-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 14px;
    padding: 15px;
}

.company-card-main {
    align-items: center;
    color: var(--ink);
    display: flex;
    gap: 12px;
    text-decoration: none;
}

.company-card-main strong {
    display: block;
    font-size: 18px;
}

.company-card-main em {
    color: var(--muted);
    display: block;
    font-size: 13px;
    font-style: normal;
    margin-top: 2px;
}

.company-avatar {
    align-items: center;
    background: #e7efec;
    border: 1px solid #c7dbd5;
    border-radius: 8px;
    color: var(--accent-dark);
    display: inline-flex;
    flex: 0 0 auto;
    font-weight: 900;
    height: 44px;
    justify-content: center;
    text-transform: uppercase;
    width: 44px;
}

.company-card-stats {
    color: var(--muted);
    display: flex;
    flex-wrap: wrap;
    font-size: 13px;
    gap: 8px;
}

.company-card-stats span {
    background: #f1f1ed;
    border-radius: 999px;
    padding: 5px 9px;
}

.subtle-danger {
    justify-self: start;
    padding: 8px 11px;
}

.empty-state {
    display: grid;
    gap: 10px;
    justify-items: start;
}

.ai-usage-home {
    background: #202124;
    border-radius: 8px;
    color: #f7f7f4;
    display: grid;
    gap: 14px;
    margin-top: 24px;
    padding: 18px;
}

.ai-usage-home h2,
.ai-usage-home p {
    margin: 0;
}

.ai-usage-home p {
    color: #c9cfca;
}

.ai-usage-home .usage-card strong {
    color: #fff;
    font-size: 18px;
}

.ai-usage-home .usage-meter {
    background: #3a3d3f;
}

.usage-card {
    display: grid;
    gap: 10px;
}

.usage-card strong {
    font-size: 24px;
}

.usage-card p {
    margin: 0;
}

.usage-meter {
    background: #ececea;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.usage-meter span {
    background: var(--accent);
    display: block;
    height: 100%;
}

.usage-note {
    margin-top: 22px;
}

.action-panel {
    color: var(--ink);
    display: grid;
    gap: 8px;
    min-height: 140px;
    text-decoration: none;
}

.action-panel:hover {
    border-color: var(--accent);
}

.workflow-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.inline-form {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.inline-form input {
    min-width: 220px;
    width: auto;
}

.regenerate-ped-form {
    background: #f8faf8;
    border: 1px solid var(--line);
    border-radius: 8px;
    margin-top: 4px;
    padding: 14px;
}

.workflow-strip {
    margin-bottom: 22px;
}

.workflow-strip ol {
    display: grid;
    gap: 8px;
    list-style: none;
    padding: 0;
}

.workflow-strip li {
    background: #ececea;
    border-radius: 8px;
    color: var(--muted);
    padding: 10px;
}

.workflow-strip li.is-done {
    background: #e8f5ef;
    color: #19573f;
}

label {
    color: var(--muted);
    display: grid;
    font-size: 14px;
    gap: 7px;
}

input,
textarea {
    border: 1px solid var(--line);
    border-radius: 6px;
    color: var(--ink);
    font: inherit;
    padding: 11px 12px;
    width: 100%;
}

textarea {
    resize: vertical;
}

button,
.button {
    align-items: center;
    background: var(--accent);
    border: 0;
    border-radius: 6px;
    color: #fff;
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    justify-content: center;
    padding: 10px 14px;
    text-decoration: none;
}

button:hover,
.button:hover {
    background: var(--accent-dark);
}

.ghost {
    background: #e7efec;
    color: var(--accent-dark);
}

.danger-button {
    background: #f9e7e7;
    color: var(--danger);
}

.danger-button:hover {
    background: #f2d2d2;
}

.link-button {
    background: transparent;
    color: var(--accent);
    padding: 0;
}

.article-editor {
    display: grid;
    gap: 10px;
}

.article-publish-panel {
    display: grid;
    gap: 16px;
    margin-top: 22px;
}

.article-publish-panel p {
    margin: 0;
}

.editor-toolbar {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: space-between;
}

.editor-toolbar > span {
    color: var(--muted);
    font-size: 14px;
}

.segmented-control {
    background: #ececea;
    border: 1px solid var(--line);
    border-radius: 7px;
    display: inline-flex;
    padding: 3px;
}

.segmented-control button {
    background: transparent;
    border-radius: 5px;
    color: var(--muted);
    font-size: 14px;
    padding: 7px 11px;
}

.segmented-control button:hover,
.segmented-control button.is-active {
    background: var(--surface);
    color: var(--accent-dark);
}

.rich-editor {
    border: 1px solid var(--line);
    border-radius: 6px;
    margin-top: 0;
    min-height: 520px;
    outline: none;
    padding: 18px;
}

.rich-editor:focus,
.html-editor:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(20, 108, 95, 0.12);
}

.html-editor {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace;
    min-height: 520px;
}

.is-hidden {
    display: none;
}

table {
    border-collapse: collapse;
    display: block;
    overflow-x: auto;
    width: 100%;
}

.responsive-table {
    border-collapse: separate;
    border-spacing: 0;
    display: grid;
    gap: 12px;
    overflow: visible;
}

.responsive-table thead {
    display: none;
}

.responsive-table tbody {
    display: grid;
    gap: 12px;
}

.responsive-table tr {
    background: var(--surface);
    border: 1px solid #c9d2ce;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(32, 33, 36, 0.06);
    display: grid;
    gap: 0;
    overflow: hidden;
}

.responsive-table td {
    align-items: start;
    border-bottom: 1px solid #dfe6e2;
    display: grid;
    gap: 5px;
    padding: 11px 12px;
}

.responsive-table td:last-child {
    border-bottom: 0;
}

.responsive-table td::before {
    color: var(--muted);
    content: attr(data-label);
    font-size: 12px;
    font-weight: 800;
    text-transform: uppercase;
}

.ped-table tr td:first-child {
    background: #e7efec;
    border-bottom-color: #bfd4cd;
}

.ped-table tr td:first-child::before {
    color: var(--accent-dark);
}

.ped-table tr td:first-child {
    color: var(--accent-dark);
    font-weight: 800;
}

.ped-table td[data-label="Titolo"],
.ped-table td[data-label="Brief"],
.ped-table td[data-label="Obiettivo"] {
    overflow-wrap: anywhere;
}

th,
td {
    border-bottom: 1px solid var(--line);
    padding: 12px 10px;
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 13px;
    text-transform: uppercase;
}

.badge {
    background: #edf3f1;
    border-radius: 999px;
    color: var(--accent-dark);
    display: inline-block;
    font-size: 13px;
    padding: 4px 9px;
}

.task-status-queued {
    background: #ececea;
    color: #585f63;
}

.task-status-working {
    background: #e4f0ff;
    color: #27598f;
}

.task-status-done {
    background: #e8f5ef;
    color: #19573f;
}

.task-status-failed {
    background: #f9e7e7;
    color: var(--danger);
}

.notice,
.error-box {
    border-radius: 8px;
    margin-bottom: 18px;
    padding: 14px 16px;
}

.notice {
    background: #e8f5ef;
    color: #19573f;
}

.error-box {
    background: #f9e7e7;
    color: var(--danger);
}

.sidebar {
    display: grid;
    gap: 18px;
}

.task-detail {
    display: grid;
    gap: 22px;
}

.task-state {
    align-items: center;
    display: flex;
    gap: 12px;
}

.task-message {
    background: #f8faf8;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.loader-row {
    align-items: center;
    display: flex;
    gap: 14px;
}

.spinner {
    animation: spin 0.9s linear infinite;
    border: 3px solid #d7e4e0;
    border-top-color: var(--accent);
    border-radius: 999px;
    display: inline-block;
    height: 34px;
    width: 34px;
}

.analysis-box {
    background: #f8faf8;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 18px;
}

.analysis-box p:last-child {
    margin-bottom: 0;
}

.modal-backdrop {
    align-items: center;
    background: rgba(32, 33, 36, 0.42);
    display: flex;
    inset: 0;
    justify-content: center;
    padding: 22px;
    position: fixed;
    z-index: 50;
}

.modal-backdrop.is-hidden {
    display: none;
}

.modal-panel {
    background: var(--surface);
    border-radius: 8px;
    box-shadow: 0 24px 80px rgba(32, 33, 36, 0.24);
    display: grid;
    gap: 18px;
    max-height: min(780px, 92vh);
    max-width: 760px;
    overflow-y: auto;
    padding: 24px;
    width: 100%;
}

.payload-preview {
    background: #202124;
    border-radius: 8px;
    color: #f7f7f4;
    overflow-x: auto;
    padding: 14px;
}

.progress-bar {
    background: #ececea;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.progress-bar span {
    background: var(--accent);
    display: block;
    height: 100%;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

fieldset {
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 10px;
    margin: 0;
    padding: 14px;
}

.check-row {
    align-items: center;
    color: var(--ink);
    display: flex;
    gap: 9px;
}

.check-row input {
    width: auto;
}

.hint,
.muted {
    color: var(--muted);
}

.link-preview {
    border-left: 3px solid var(--accent);
    display: grid;
    gap: 3px;
    padding-left: 10px;
}

.link-preview span {
    color: var(--muted);
    font-size: 13px;
    overflow-wrap: anywhere;
}

.seo-summary {
    background: #f8faf8;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: grid;
    gap: 12px;
    padding: 14px;
}

.featured-image-preview {
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    display: block;
    object-fit: cover;
    width: 100%;
}

.seo-row {
    align-items: baseline;
    display: flex;
    gap: 10px;
    justify-content: space-between;
}

.seo-row span {
    color: var(--muted);
    font-size: 13px;
}

.seo-row strong {
    font-size: 14px;
    text-align: right;
}

.keyword-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.keyword-cloud span {
    background: #e7efec;
    border: 1px solid #c7dbd5;
    border-radius: 999px;
    color: var(--accent-dark);
    font-size: 13px;
    padding: 5px 9px;
}

.keyword-cloud em {
    color: var(--muted);
    font-size: 13px;
}

.published-article h1 {
    font-size: clamp(34px, 6vw, 58px);
    line-height: 1.05;
}

.public-featured-image {
    aspect-ratio: 16 / 9;
    border-radius: 8px;
    display: block;
    margin-top: 24px;
    object-fit: cover;
    width: 100%;
}

.eyebrow {
    color: var(--accent);
    font-weight: 800;
    text-transform: uppercase;
}

.content {
    margin-top: 28px;
}

.content img {
    height: auto;
    max-width: 100%;
}

.tag-list {
    border-top: 1px solid var(--line);
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 32px;
    padding-top: 18px;
}

.tag-list span {
    background: #ececea;
    border-radius: 999px;
    padding: 5px 10px;
}

@media (min-width: 700px) {
    .shell {
        padding: 28px;
    }

    .app-home-heading,
    .page-heading {
        align-items: center;
        display: flex;
        justify-content: space-between;
    }

    .company-list {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .company-card {
        align-content: start;
        min-height: 170px;
    }

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

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

    .ai-usage-home {
        align-items: center;
        grid-template-columns: minmax(0, 1fr) 320px;
    }

    table {
        display: table;
    }

    .responsive-table {
        border-collapse: collapse;
        display: table;
        overflow-x: auto;
    }

    .responsive-table thead {
        display: table-header-group;
    }

    .responsive-table tbody {
        display: table-row-group;
    }

    .responsive-table tr {
        background: transparent;
        border: 0;
        border-radius: 0;
        box-shadow: none;
        display: table-row;
        overflow: visible;
    }

    .responsive-table td {
        border-bottom: 1px solid var(--line);
        display: table-cell;
        padding: 12px 10px;
    }

    .responsive-table td::before {
        content: none;
    }

    .ped-table tr td:first-child {
        background: transparent;
        border-bottom-color: var(--line);
        color: var(--ink);
        font-weight: 400;
    }
}

@media (min-width: 980px) {
    .topbar {
        padding: 14px 28px;
    }

    .panel {
        padding: 22px;
    }

    .editor-grid {
        grid-template-columns: minmax(0, 1fr) 340px;
    }

    .dashboard-grid {
        grid-template-columns: repeat(4, minmax(0, 1fr));
    }

    .workflow-strip ol {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }
}
