:root {
  --bg: #f4f5f8;
  --panel: #ffffff;
  --panel-2: #f0f1f5;
  --border: #e1e3ea;
  --text: #1f2330;
  --muted: #646b7d;
  --accent: #5865f2;
  --accent-text: #ffffff;
  --accent-soft: #e8eafd;
  --ok: #1f9d55;
  --ok-soft: #e3f6ea;
  --warn: #b7791f;
  --warn-soft: #fbf1dc;
  --danger: #d93a3a;
  --danger-soft: #fce6e6;
  --sidebar: #1e1f29;
  --sidebar-text: #c9ccd6;
  --sidebar-active: #2d2f3d;
  --discord-bg: #313338;
  --discord-embed: #2b2d31;
  --discord-text: #dbdee1;
  --shadow: 0 1px 2px rgba(16, 20, 40, .06), 0 2px 8px rgba(16, 20, 40, .05);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #15161c;
    --panel: #1d1f27;
    --panel-2: #252833;
    --border: #2e3140;
    --text: #e6e8ef;
    --muted: #9aa0b2;
    --accent: #7983f5;
    --accent-soft: #272b4d;
    --ok: #4cc782;
    --ok-soft: #1b3326;
    --warn: #e0a84a;
    --warn-soft: #3a2f19;
    --danger: #f06b6b;
    --danger-soft: #3d1f22;
    --sidebar: #101117;
    --sidebar-active: #22242f;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.splash { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ------------------------------------------------ login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
  padding: 40px 32px; max-width: 400px; width: 100%; text-align: center;
}
.login-card h1 { margin: 16px 0 6px; font-size: 22px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.logo { width: 48px; height: 48px; border-radius: 12px; background: var(--accent); display: inline-grid; place-items: center; }
.logo svg { width: 26px; height: 26px; }

/* ------------------------------------------------ layout */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--sidebar); color: var(--sidebar-text); padding: 16px 12px; display: flex; flex-direction: column; gap: 16px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; font-weight: 650; font-size: 16px; padding: 4px 8px; }
.brand .logo { width: 30px; height: 30px; border-radius: 8px; }
.brand .logo svg { width: 18px; height: 18px; }
.guild-select { width: 100%; background: var(--sidebar-active); color: #fff; border: 1px solid #383b4c; border-radius: 8px; padding: 8px; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--sidebar-text); text-decoration: none;
}
.nav a:hover { background: var(--sidebar-active); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.nav svg { width: 18px; height: 18px; flex: none; opacity: .85; }
.user-box { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 8px; border-top: 1px solid #2c2e3b; padding-top: 14px; }
.user-box img { width: 32px; height: 32px; border-radius: 50%; }
.user-box .name { color: #fff; font-weight: 600; line-height: 1.2; }
.user-box button { margin-left: auto; background: none; border: 0; color: var(--sidebar-text); cursor: pointer; font-size: 12px; text-decoration: underline; }
.menu-toggle { display: none; }

.main { padding: 28px 32px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 22px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }

/* ------------------------------------------------ componenti */
.card { background: var(--panel); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { padding: 14px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.card-head h2 { margin: 0; font-size: 15px; }
.card-body { padding: 16px; }
.grid { display: grid; gap: 16px; }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { padding: 14px 16px; }
.stat .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--border); background: var(--panel);
  border-radius: 8px; padding: 7px 12px; cursor: pointer; text-decoration: none; color: var(--text); white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.big { padding: 11px 20px; font-size: 15px; font-weight: 600; }
.btn svg { width: 16px; height: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.programmato { background: var(--accent-soft); color: var(--accent); }
.badge.inviato { background: var(--ok-soft); color: var(--ok); }
.badge.in_pausa { background: var(--warn-soft); color: var(--warn); }
.badge.annullato { background: var(--panel-2); color: var(--muted); }
.badge.errore { background: var(--danger-soft); color: var(--danger); }
.chip { display: inline-flex; align-items: center; gap: 4px; padding: 1px 8px; border-radius: 99px; background: var(--panel-2); font-size: 12px; margin: 2px 4px 2px 0; }
.chip .dot { width: 8px; height: 8px; border-radius: 50%; }
.chip button { border: 0; background: none; cursor: pointer; padding: 0 0 0 2px; color: var(--muted); }
.muted { color: var(--muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.empty { color: var(--muted); padding: 24px; text-align: center; }

.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.tabs button { border: 1px solid transparent; background: none; padding: 6px 12px; border-radius: 99px; cursor: pointer; color: var(--muted); }
.tabs button.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; background: var(--panel-2); }
tr:last-child td { border-bottom: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }
.avatar { width: 28px; height: 28px; border-radius: 50%; vertical-align: middle; }
.cell-user { display: flex; align-items: center; gap: 10px; }
.snippet { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.list { list-style: none; margin: 0; padding: 0; }
.list li { display: flex; gap: 12px; align-items: center; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.list li:last-child { border-bottom: 0; }
.list .grow { flex: 1; min-width: 0; }
.list .title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.chart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 8px; }
.chart .col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; height: 100%; }
.chart .bars { flex: 1; width: 100%; display: flex; flex-direction: column-reverse; border-radius: 4px; overflow: hidden; }
.chart .ok { background: var(--accent); }
.chart .ko { background: var(--danger); }
.chart .lbl { font-size: 10px; color: var(--muted); }
.legend { display: flex; gap: 14px; font-size: 12px; color: var(--muted); }
.legend span::before { content: ""; display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; background: var(--accent); }
.legend span.ko::before { background: var(--danger); }

.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 12px 16px; }

/* ------------------------------------------------ form */
.editor { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.form { display: grid; gap: 14px; }
.field { display: grid; gap: 5px; }
.field > label, .field > .label { font-weight: 600; font-size: 13px; }
.field .hint { color: var(--muted); font-size: 12px; }
.row { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }
input[type=text], input[type=url], input[type=date], input[type=time], input[type=search], select, textarea {
  width: 100%; background: var(--panel); border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px;
}
textarea { min-height: 160px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: transparent; }
input[type=color] { width: 42px; height: 38px; padding: 2px; border: 1px solid var(--border); border-radius: 8px; background: var(--panel); }
.color-row { display: flex; gap: 8px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); font-weight: 700; margin: 6px 0 -4px; }
.picker { max-height: 160px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: 6px; display: grid; gap: 2px; }
.picker label { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border-radius: 6px; cursor: pointer; font-weight: 400; }
.picker label:hover { background: var(--panel-2); }
.suggest { border: 1px solid var(--border); border-radius: 8px; margin-top: 4px; max-height: 180px; overflow: auto; }
.suggest button { display: flex; width: 100%; gap: 8px; align-items: center; border: 0; background: none; padding: 6px 10px; cursor: pointer; text-align: left; }
.suggest button:hover { background: var(--panel-2); }
.thumb { max-width: 160px; max-height: 100px; border-radius: 6px; display: block; margin-top: 6px; }
.sticky { position: sticky; top: 16px; display: grid; gap: 16px; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 16px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.alert { padding: 10px 12px; border-radius: 8px; background: var(--danger-soft); color: var(--danger); }

/* ------------------------------------------------ anteprima stile Discord */
.dc { background: var(--discord-bg); color: var(--discord-text); border-radius: var(--radius); padding: 16px; display: flex; gap: 14px; font-size: 15px; line-height: 1.375; }
.dc-avatar { width: 40px; height: 40px; border-radius: 50%; background: var(--accent); flex: none; display: grid; place-items: center; }
.dc-avatar svg { width: 22px; height: 22px; }
.dc-main { min-width: 0; flex: 1; }
.dc-name { font-weight: 600; color: #fff; }
.dc-tag { background: #5865f2; color: #fff; font-size: 10px; font-weight: 700; padding: 1px 4px; border-radius: 3px; margin-left: 4px; vertical-align: 1px; }
.dc-time { font-size: 12px; color: #949ba4; margin-left: 6px; }
.dc-content { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 2px; }
.dc-mention { background: rgba(88, 101, 242, .3); color: #c9cdfb; border-radius: 3px; padding: 0 2px; font-weight: 500; }
.dc-embed { margin-top: 6px; background: var(--discord-embed); border-left: 4px solid #5865f2; border-radius: 4px; padding: 10px 14px 14px 12px; max-width: 520px; display: grid; grid-template-columns: 1fr auto; gap: 8px; }
.dc-embed .author { font-size: 13px; font-weight: 600; color: #fff; grid-column: 1; }
.dc-embed .title { font-weight: 700; color: #fff; grid-column: 1; }
.dc-embed .desc { font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; grid-column: 1; }
.dc-embed .thumb-img { grid-column: 2; grid-row: 1 / span 3; width: 80px; height: 80px; object-fit: cover; border-radius: 4px; }
.dc-embed .image { grid-column: 1 / -1; max-width: 100%; border-radius: 4px; margin-top: 4px; }
.dc-embed .foot { grid-column: 1 / -1; font-size: 12px; color: #b5bac1; }
.dc-attach { margin-top: 6px; max-width: 400px; border-radius: 8px; display: block; }
.dc code { background: #1e1f22; padding: 1px 4px; border-radius: 3px; font-size: 13px; }
.dc a { color: #00a8fc; }

/* ------------------------------------------------ toast / dialog */
#toasts { position: fixed; right: 16px; bottom: 16px; display: grid; gap: 8px; z-index: 50; }
.toast { background: var(--panel); border: 1px solid var(--border); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 14px; box-shadow: 0 6px 24px rgba(0,0,0,.18); max-width: 360px; }
.toast.error { border-left-color: var(--danger); }
dialog { border: 1px solid var(--border); border-radius: 14px; background: var(--panel); color: var(--text); padding: 0; width: min(460px, calc(100vw - 32px)); }
dialog::backdrop { background: rgba(10, 12, 20, .55); }
dialog .card-body { display: grid; gap: 14px; }
dialog h3 { margin: 0; }

@media (max-width: 1000px) {
  .editor, .grid-2 { grid-template-columns: 1fr; }
  .sticky { position: static; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .menu-toggle { display: inline-flex; }
  .main { padding: 16px; }
  .snippet { max-width: 180px; }
}

/* ------------------------------------------------ utilità */
.small { font-size: 12px; }
.note { margin: 20px 0 0; }
.mt { margin-top: 16px; }
.mt-8 { margin-top: 8px; }
.mb { margin-bottom: 16px; }
.check { display: flex; align-items: center; gap: 8px; }
[hidden] { display: none !important; }
.btn.menu-toggle { display: none; }
@media (max-width: 760px) { .btn.menu-toggle { display: inline-flex; } }
