/* =========================================================
   FieroPiccio — design system
   Tema chiaro di default, scuro da sistema o dal pulsante
   ========================================================= */

:root {
    --bg: #f4f5f7;
    --bg-glow: rgba(232, 101, 15, 0.09);
    --surface: #ffffff;
    --surface-2: #eef0f3;
    --border: #e1e4e9;
    --border-strong: #c9ced6;
    --text: #14171c;
    --muted: #5e6674;
    --faint: #8b93a0;
    --accent: #e0600c;
    --accent-hover: #c75207;
    --accent-soft: rgba(224, 96, 12, 0.11);
    --on-accent: #ffffff;
    --ok: #15a34a;
    --warn: #d68a06;
    --crit: #dc2c2c;
    --icon-tile: #f1f3f5;
    --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 10px 28px -14px rgba(16, 24, 40, 0.18);
    --show-light: inline-block;
    --show-dark: none;

    --radius: 14px;
    --radius-sm: 10px;
    --font: "Geist", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
    --mono: "Geist Mono", ui-monospace, "SFMono-Regular", Consolas, monospace;
    color-scheme: light;
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #0b0d11;
        --bg-glow: rgba(255, 138, 61, 0.09);
        --surface: #13161b;
        --surface-2: #1b1f26;
        --border: #242932;
        --border-strong: #353b46;
        --text: #e8eaee;
        --muted: #99a1af;
        --faint: #6a7280;
        --accent: #ff8a3d;
        --accent-hover: #ffa062;
        --accent-soft: rgba(255, 138, 61, 0.13);
        --on-accent: #1c0f05;
        --ok: #3ecf8e;
        --warn: #f5b041;
        --crit: #ff6068;
        --icon-tile: #eceef1;
        --shadow: 0 10px 30px -16px rgba(0, 0, 0, 0.7);
        --show-light: none;
        --show-dark: inline-block;
        color-scheme: dark;
    }
}

:root[data-theme="dark"] {
    --bg: #0b0d11;
    --bg-glow: rgba(255, 138, 61, 0.09);
    --surface: #13161b;
    --surface-2: #1b1f26;
    --border: #242932;
    --border-strong: #353b46;
    --text: #e8eaee;
    --muted: #99a1af;
    --faint: #6a7280;
    --accent: #ff8a3d;
    --accent-hover: #ffa062;
    --accent-soft: rgba(255, 138, 61, 0.13);
    --on-accent: #1c0f05;
    --ok: #3ecf8e;
    --warn: #f5b041;
    --crit: #ff6068;
    --icon-tile: #eceef1;
    --shadow: 0 10px 30px -16px rgba(0, 0, 0, 0.7);
    --show-light: none;
    --show-dark: inline-block;
    color-scheme: dark;
}

/* ---------- base ---------- */

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

html {
    -webkit-text-size-adjust: 100%;
}

body {
    min-height: 100vh;
    font-family: var(--font);
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background:
        radial-gradient(1100px 420px at 50% -120px, var(--bg-glow), transparent 70%),
        var(--bg);
    background-attachment: fixed;
    -webkit-font-smoothing: antialiased;
}

a {
    color: inherit;
}

img {
    display: block;
    max-width: 100%;
}

:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

.only-light {
    display: var(--show-light);
}

.only-dark {
    display: var(--show-dark);
}

.mono {
    font-family: var(--mono);
}

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

/* ---------- layout ---------- */

.page {
    max-width: 1120px;
    margin: 0 auto;
    padding: 20px 16px 56px;
}

@media (min-width: 720px) {
    .page {
        padding: 28px 28px 72px;
    }
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 36px;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
}

.brand-mark {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    border-radius: 9px;
    background: var(--accent);
    color: var(--on-accent);
    font-family: var(--mono);
    font-size: 13px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.brand-name {
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.01em;
}

.tag {
    font-size: 12px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 999px;
    background: var(--accent-soft);
    color: var(--accent);
}

/* ---------- buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    height: 36px;
    padding: 0 14px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: 500 14px/1 var(--font);
    text-decoration: none;
    cursor: pointer;
    transition: background-color .15s, border-color .15s, color .15s;
}

.btn:hover:not(:disabled) {
    border-color: var(--border-strong);
    background: var(--surface-2);
}

.btn:disabled {
    opacity: .35;
    cursor: default;
}

.btn .icon {
    width: 16px;
    height: 16px;
}

.btn-icon {
    width: 36px;
    padding: 0;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: var(--on-accent);
    font-weight: 600;
}

.btn-primary:hover:not(:disabled) {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}

.btn-danger:hover:not(:disabled) {
    color: var(--crit);
    border-color: var(--crit);
    background: transparent;
}

.btn-block {
    width: 100%;
    height: 42px;
}

/* ---------- forms ---------- */

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field>span {
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

.input {
    width: 100%;
    height: 40px;
    padding: 0 12px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font: 400 15px var(--font);
    transition: border-color .15s, box-shadow .15s;
}

.input::placeholder {
    color: var(--faint);
}

.input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-soft);
}

input[type=file].input {
    height: auto;
    padding: 8px;
    font-size: 13px;
    color: var(--muted);
}

input[type=file].input::file-selector-button {
    margin-right: 10px;
    padding: 6px 10px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    font: 500 13px var(--font);
    cursor: pointer;
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    font-size: 14px;
    border: 1px solid transparent;
}

.alert-ok {
    color: var(--ok);
    background: color-mix(in srgb, var(--ok) 10%, transparent);
    border-color: color-mix(in srgb, var(--ok) 25%, transparent);
}

.alert-error {
    color: var(--crit);
    background: color-mix(in srgb, var(--crit) 10%, transparent);
    border-color: color-mix(in srgb, var(--crit) 25%, transparent);
}

/* ---------- surfaces ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.section-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}

.section-title {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 600;
    letter-spacing: .06em;
    text-transform: uppercase;
    color: var(--muted);
}

.count {
    font-family: var(--mono);
    font-size: 12px;
    font-weight: 500;
    padding: 1px 7px;
    border-radius: 999px;
    background: var(--surface-2);
    color: var(--muted);
    letter-spacing: 0;
}

/* ---------- home: intestazione ---------- */

.hero {
    margin-bottom: 28px;
}

.hero h1 {
    font-size: clamp(26px, 4.4vw, 36px);
    font-weight: 600;
    letter-spacing: -0.03em;
    line-height: 1.15;
}

.hero p {
    margin-top: 6px;
    color: var(--muted);
}

.hero .mono {
    color: var(--text);
}

/* ---------- home: widget di sistema ---------- */

.widgets {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
    margin-bottom: 12px;
}

/* ---------- home: dettagli di sistema ---------- */

.info {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 4px 16px;
    padding: 12px 18px;
    margin-bottom: 40px;
}

.info-item {
    display: grid;
    grid-template-columns: 16px auto 1fr;
    align-items: center;
    gap: 10px;
    padding: 6px 0;
    min-width: 0;
}

.info-item[hidden] {
    display: none;
}

.info-item .icon {
    width: 16px;
    height: 16px;
    color: var(--faint);
}

.info-item dt {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
}

.info-item dd {
    font-family: var(--mono);
    font-size: 13px;
    text-align: right;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.info-item dd[data-level="ok"] {
    color: var(--ok);
}

.info-item dd[data-level="warn"] {
    color: var(--warn);
}

.info-item dd[data-level="crit"] {
    color: var(--crit);
    font-weight: 600;
}

.widget {
    --level: var(--faint);
    padding: 16px 18px 18px;
}

.widget[data-level="ok"] {
    --level: var(--ok);
}

.widget[data-level="warn"] {
    --level: var(--warn);
}

.widget[data-level="crit"] {
    --level: var(--crit);
}

.widget-label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    font-weight: 500;
    color: var(--muted);
}

.widget-label .icon {
    width: 16px;
    height: 16px;
    color: var(--level);
}

.widget-value {
    margin: 10px 0 12px;
    font-family: var(--mono);
    font-size: 30px;
    font-weight: 500;
    letter-spacing: -0.03em;
    line-height: 1;
    font-variant-numeric: tabular-nums;
}

.widget-value small {
    font-size: 15px;
    color: var(--muted);
    margin-left: 2px;
}

.meter {
    height: 6px;
    border-radius: 999px;
    background: var(--surface-2);
    overflow: hidden;
}

.meter>span {
    display: block;
    height: 100%;
    width: 0;
    border-radius: inherit;
    background: var(--level);
    transition: width .6s ease, background-color .3s;
}

.widget-foot {
    margin-top: 10px;
    font-size: 12px;
    color: var(--faint);
    font-family: var(--mono);
}

.live {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 500;
    color: var(--muted);
    letter-spacing: 0;
    text-transform: none;
}

.live::before {
    content: "";
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--faint);
}

.live[data-state="ok"]::before {
    background: var(--ok);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--ok) 20%, transparent);
}

.live[data-state="error"] {
    color: var(--crit);
}

.live[data-state="error"]::before {
    background: var(--crit);
}

/* ---------- home: ricerca ---------- */

.search {
    position: relative;
    width: 100%;
    max-width: 300px;
}

.search .icon {
    position: absolute;
    left: 11px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    color: var(--faint);
    pointer-events: none;
}

.search .input {
    height: 36px;
    padding: 0 34px 0 34px;
    font-size: 14px;
}

.search kbd {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font: 500 11px var(--mono);
    padding: 1px 6px;
    border-radius: 5px;
    border: 1px solid var(--border);
    color: var(--faint);
    pointer-events: none;
}

@media (max-width: 560px) {
    .search {
        max-width: none;
    }

    .search kbd {
        display: none;
    }
}

/* ---------- home: app ---------- */

.apps {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 12px;
}

.app {
    position: relative;
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 14px;
    text-decoration: none;
    transition: transform .15s ease, border-color .15s, box-shadow .15s;
}

.app:hover {
    transform: translateY(-2px);
    border-color: var(--border-strong);
}

.app[hidden] {
    display: none;
}

.app-icon {
    display: grid;
    place-items: center;
    width: 52px;
    height: 52px;
    flex-shrink: 0;
    border-radius: 12px;
    background: var(--icon-tile);
}

.app-icon img {
    width: 34px;
    height: 34px;
    object-fit: contain;
}

.app-icon-letter {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 22px;
    font-weight: 600;
}

.app-body {
    min-width: 0;
    flex: 1;
}

.app-title,
.app-desc,
.app-host {
    display: block;
}

.app-title {
    font-weight: 600;
    letter-spacing: -0.01em;
}

.app-desc {
    font-size: 13px;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-host {
    margin-top: 2px;
    font-family: var(--mono);
    font-size: 11.5px;
    color: var(--faint);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.app-arrow {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 16px;
    height: 16px;
    color: var(--faint);
    opacity: 0;
    transform: translate(-3px, 3px);
    transition: opacity .15s, transform .15s, color .15s;
}

.app:hover .app-arrow,
.app:focus-visible .app-arrow {
    opacity: 1;
    transform: none;
    color: var(--accent);
}

.empty {
    padding: 36px 20px;
    text-align: center;
    color: var(--muted);
    border: 1px dashed var(--border-strong);
    border-radius: var(--radius);
}

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

/* ---------- login ---------- */

.auth {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px 16px;
}

.auth-card {
    width: 100%;
    max-width: 380px;
    padding: 28px;
}

.auth-card .brand {
    margin-bottom: 28px;
}

.auth-card h1 {
    font-size: 22px;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.auth-card .sub {
    margin: 4px 0 22px;
    color: var(--muted);
    font-size: 14px;
}

.auth-card form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.auth-card .btn-block {
    margin-top: 6px;
}

.auth-corner {
    position: fixed;
    top: 16px;
    right: 16px;
}

/* ---------- admin ---------- */

.admin-grid {
    display: grid;
    gap: 16px;
    align-items: start;
}

@media (min-width: 900px) {
    .admin-grid {
        grid-template-columns: 360px 1fr;
    }

    .admin-grid .editor {
        position: sticky;
        top: 20px;
    }
}

.editor {
    padding: 20px;
}

.editor h2,
.list-panel h2 {
    font-size: 15px;
    font-weight: 600;
    letter-spacing: -0.01em;
}

.editor form {
    display: flex;
    flex-direction: column;
    gap: 14px;
    margin-top: 16px;
}

.editor .actions {
    display: flex;
    gap: 8px;
    margin-top: 4px;
}

.editor .actions .btn-primary {
    flex: 1;
}

.list-panel {
    padding: 8px;
}

.list-panel h2 {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 12px 10px;
}

.rows {
    list-style: none;
}

.row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: var(--radius-sm);
}

.row+.row {
    border-top: 1px solid var(--border);
}

.row.editing {
    background: var(--accent-soft);
    border-color: transparent;
}

.row .app-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
}

.row .app-icon img {
    width: 26px;
    height: 26px;
}

.row .app-icon-letter {
    font-size: 17px;
}

.row .app-host a {
    color: inherit;
    text-decoration: none;
}

.row .app-host a:hover {
    color: var(--accent);
}

.row-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}

.row-actions .btn {
    width: 32px;
    height: 32px;
    padding: 0;
    border-color: transparent;
    background: transparent;
    color: var(--muted);
}

.row-actions .btn:hover:not(:disabled) {
    color: var(--text);
    border-color: var(--border);
    background: var(--surface);
}

.row-actions .btn-danger:hover:not(:disabled) {
    color: var(--crit);
    border-color: var(--crit);
}

.list-empty {
    padding: 8px 12px 16px;
    color: var(--muted);
    font-size: 14px;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

@media (max-width: 560px) {
    .row {
        flex-wrap: wrap;
    }

    .row-actions {
        width: 100%;
        justify-content: flex-end;
    }

    .topbar .btn-label {
        display: none;
    }
}
