/* Modula - interfaccia della piattaforma */
:root {
  --primary: #4f46e5;
  --primary-soft: color-mix(in srgb, var(--primary) 10%, white);
  --ink: #1d2433;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f6f7fb;
  --card: #fff;
  --ok: #12805c;
  --ok-bg: #e7f6ef;
  --err: #c0362c;
  --err-bg: #fdecea;
  --warn-bg: #fff6e0;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px; line-height: 1.5; color: var(--ink); background: var(--bg);
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 26px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; }
p { margin: 0 0 1em; }
small, .muted { color: var(--muted); }
code { background: #eef0f4; padding: 1px 5px; border-radius: 4px; font-size: 13px; }

/* barra superiore */
.topbar {
  position: sticky; top: 0; z-index: 20; background: #fff; border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; color: var(--ink); }
.brand:hover { text-decoration: none; }
.brand img { height: 32px; width: auto; }
.brand .dot { width: 30px; height: 30px; border-radius: 9px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 15px; }
.nav { display: flex; gap: 4px; flex: 1; }
.nav a { padding: 8px 12px; border-radius: 8px; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--bg); color: var(--ink); text-decoration: none; }
.nav a.active { background: var(--primary-soft); color: var(--primary); }
.userbox { display: flex; align-items: center; gap: 12px; font-size: 14px; }
.userbox form { margin: 0; }
.impersonating { background: #fff3cd; color: #7a5b00; text-align: center; padding: 8px; font-size: 14px; }
.impersonating form { display: inline; }

.container { max-width: 1200px; margin: 0 auto; padding: 28px 24px 60px; }
.container.wide { max-width: none; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 22px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* schede */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 22px; margin-bottom: 20px; }
.card h2 { margin-bottom: 14px; }
.card-tight { padding: 14px 16px; }
.grid { display: grid; gap: 18px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
@media (max-width: 900px) { .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; } }

.stat { padding: 18px 20px; }
.stat b { display: block; font-size: 28px; }
.stat span { color: var(--muted); font-size: 14px; }

/* moduli (form) */
label { display: block; font-weight: 600; font-size: 14px; margin-bottom: 6px; }
.field { margin-bottom: 16px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: 13px; margin-top: 4px; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid #cfd4dc; border-radius: 8px; font: inherit; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 35%, transparent); border-color: var(--primary); }
textarea { min-height: 90px; resize: vertical; }
input[type=color] { width: 54px; height: 40px; padding: 2px; border: 1px solid #cfd4dc; border-radius: 8px; background: #fff; }
.check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 4px; }
.row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.row > .field { flex: 1; min-width: 160px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; padding: 9px 16px; border-radius: 8px; border: 1px solid transparent;
  background: var(--primary); color: #fff; font: inherit; font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { filter: brightness(1.07); text-decoration: none; }
.btn-light { background: #fff; color: var(--ink); border-color: #cfd4dc; }
.btn-light:hover { background: var(--bg); filter: none; }
.btn-danger { background: var(--err); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; padding: 6px 8px; }
.btn-ghost:hover { background: var(--bg); color: var(--ink); filter: none; }
.btn-sm { padding: 6px 11px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.inline { display: inline; margin: 0; }

/* avvisi */
.alert { padding: 12px 16px; border-radius: 10px; margin-bottom: 16px; font-size: 14px; }
.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--err-bg); color: var(--err); }
.alert-warn { background: var(--warn-bg); color: #7a5b00; }
.alert ul { margin: 0; padding-left: 18px; }
.flash-stack { position: fixed; top: 72px; right: 20px; z-index: 50; display: flex; flex-direction: column; gap: 8px; max-width: 380px; }
.flash-stack .alert { box-shadow: var(--shadow); margin: 0; animation: flashIn .25s ease; }
@keyframes flashIn { from { transform: translateY(-8px); opacity: 0; } }

/* tabelle */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: #eef0f4; color: var(--muted); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-err { background: var(--err-bg); color: var(--err); }
.badge-primary { background: var(--primary-soft); color: var(--primary); }

/* pagine di accesso */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 30px 16px; background: linear-gradient(160deg, var(--primary-soft), var(--bg) 60%); }
.auth-card { width: 100%; max-width: 420px; }
.auth-card .brand { justify-content: center; margin-bottom: 22px; font-size: 20px; }
.auth-foot { text-align: center; margin-top: 14px; font-size: 14px; color: var(--muted); }

/* landing */
.hero { max-width: 760px; margin: 0 auto; padding: 90px 24px 40px; text-align: center; }
.hero h1 { font-size: 44px; letter-spacing: -.02em; margin-bottom: 16px; }
.hero p { font-size: 18px; color: var(--muted); }
.hero .actions { display: flex; gap: 12px; justify-content: center; margin-top: 26px; }
.features { max-width: 1000px; margin: 0 auto; padding: 20px 24px 80px; }

/* elenco app */
.app-card { display: flex; flex-direction: column; gap: 12px; }
.app-card .head { display: flex; gap: 14px; align-items: center; }
.app-icon { width: 54px; height: 54px; border-radius: 14px; object-fit: cover; flex: none; background: #eee; }
.app-card .meta { color: var(--muted); font-size: 13px; }
.app-card .actions { display: flex; gap: 8px; margin-top: auto; }
.new-app { display: grid; place-items: center; border: 2px dashed #cfd4dc; background: transparent; box-shadow: none; min-height: 170px; }

/* costruttore */
.builder { display: grid; grid-template-columns: 300px minmax(0, 1fr) 360px; height: calc(100vh - 60px); }
.builder.no-preview { grid-template-columns: 300px minmax(0, 1fr); }
.builder aside { background: #fff; border-right: 1px solid var(--line); overflow-y: auto; display: flex; flex-direction: column; }
.builder .side-head { padding: 16px; border-bottom: 1px solid var(--line); }
.builder .side-head h2 { margin: 0; font-size: 17px; display: flex; align-items: center; gap: 10px; }
.builder .side-head .app-icon { width: 34px; height: 34px; border-radius: 9px; }
.builder .tabs { display: flex; border-bottom: 1px solid var(--line); }
.builder .tabs button { flex: 1; padding: 11px 6px; border: 0; background: none; font: inherit; font-size: 13px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.builder .tabs button.on { color: var(--primary); border-bottom-color: var(--primary); }
.side-pane { display: none; padding: 12px; }
.side-pane.on { display: block; }
.page-list { list-style: none; margin: 0; padding: 0; }
.page-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 10px; cursor: pointer; border: 1px solid transparent; }
.page-item:hover { background: var(--bg); }
.page-item.on { background: var(--primary-soft); border-color: color-mix(in srgb, var(--primary) 25%, transparent); }
.page-item.off .page-title { opacity: .5; text-decoration: line-through; }
.page-item img, .page-item .ion { width: 30px; height: 30px; border-radius: 8px; object-fit: contain; flex: none; background: #475467; padding: 4px; color: #fff; display: grid; place-items: center; font-size: 18px; }
.page-title { flex: 1; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.page-item .handle { cursor: grab; color: #b0b6c2; font-size: 16px; padding: 0 2px; }
.page-item.dragging { opacity: .4; }
.feature-list { display: grid; gap: 8px; }
.feature-btn { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; padding: 10px; border: 1px solid var(--line); border-radius: 10px; background: #fff; font: inherit; cursor: pointer; }
.feature-btn:hover { border-color: var(--primary); }
.feature-btn img { width: 36px; height: 36px; object-fit: contain; background: #475467; border-radius: 9px; padding: 5px; }
.feature-btn b { display: block; font-size: 14px; }
.feature-btn small { font-size: 12px; }
.builder main { overflow: hidden; display: flex; flex-direction: column; background: var(--bg); }
.editor-head { display: flex; align-items: center; gap: 10px; padding: 12px 18px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.editor-head input[type=text] { max-width: 280px; padding: 7px 10px; font-weight: 600; }
.editor-head .spacer { flex: 1; }
.editor-frame { flex: 1; width: 100%; border: 0; background: #fff; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px; max-width: 420px; }
.empty .big { font-size: 44px; margin-bottom: 8px; }
.preview { background: #eceef3; border-left: 1px solid var(--line); display: flex; flex-direction: column; align-items: center; padding: 16px 0; overflow-y: auto; }
.preview .bar { display: flex; gap: 8px; margin-bottom: 12px; font-size: 13px; }
.phone { width: 320px; height: 640px; border-radius: 38px; background: #111; padding: 12px; box-shadow: 0 20px 40px rgba(0, 0, 0, .18); flex: none; }
.phone iframe { width: 100%; height: 100%; border: 0; border-radius: 28px; background: #fff; }
.settings-pane .field { margin-bottom: 12px; }
.settings-pane label { font-size: 13px; }
.icon-picker { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-picker label { margin: 0; cursor: pointer; }
.icon-picker input { display: none; }
.icon-picker span { display: grid; place-items: center; width: 40px; height: 40px; border: 2px solid var(--line); border-radius: 10px; background: #fff; font-size: 20px; color: #555; }
.icon-picker span img { width: 28px; height: 28px; object-fit: contain; background: #475467; border-radius: 6px; padding: 3px; }
.icon-picker input:checked + span { border-color: var(--primary); background: var(--primary-soft); }
dialog { border: 0; border-radius: 14px; padding: 0; box-shadow: 0 25px 60px rgba(0, 0, 0, .25); max-width: 520px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(16, 24, 40, .45); }
dialog .dlg-body { padding: 22px; }
dialog .dlg-foot { padding: 14px 22px; background: var(--bg); display: flex; justify-content: flex-end; gap: 8px; }
@media (max-width: 1250px) { .builder { grid-template-columns: 280px minmax(0, 1fr); } .builder .preview { display: none; } }
@media (max-width: 800px) {
  .builder { grid-template-columns: 1fr; height: auto; }
  .builder aside { border-right: 0; border-bottom: 1px solid var(--line); max-height: none; }
  .editor-frame { min-height: 80vh; }
  .topbar { padding: 0 14px; gap: 10px; overflow-x: auto; }
  .nav a { padding: 6px 8px; }
}

.install { max-width: 720px; margin: 40px auto; padding: 0 16px; }
.req { list-style: none; padding: 0; margin: 0 0 10px; display: grid; gap: 6px; font-size: 14px; }
.req li::before { content: "✔"; color: var(--ok); margin-right: 8px; font-weight: 700; }
.req li.ko::before { content: "✖"; color: var(--err); }
.log { background: #0f172a; color: #cbd5e1; padding: 12px 14px; border-radius: 8px; font: 13px/1.6 ui-monospace, Menlo, monospace; max-height: 260px; overflow: auto; }
.module-feats { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
.module-feats span { display: inline-flex; align-items: center; gap: 6px; background: var(--bg); border-radius: 8px; padding: 3px 9px; font-size: 13px; }
.module-feats img { width: 20px; height: 20px; background: #475467; border-radius: 5px; padding: 2px; }
details.plan-edit summary { cursor: pointer; color: var(--primary); font-weight: 600; font-size: 14px; }
.footer { text-align: center; color: var(--muted); font-size: 13px; padding: 20px; }
#btn-icon img { background: #475467; border-radius: 7px; padding: 3px; }
