/* ==========================================================================
   Portale Algoritmi — Università "Magna Græcia" di Catanzaro
   Palette derivata dall'identità istituzionale (web.unicz.it):
   blu #0848ca, oro #fcb205, inchiostro #141414.
   ========================================================================== */

:root {
  --brand:        #0848ca;
  --brand-dark:   #06349a;
  --brand-light:  #e8edfd;
  --gold:         #fcb205;
  --gold-dark:    #d99700;

  --bg:           #f4f6fb;
  --surface:      #ffffff;
  --surface-alt:  #f8fafc;
  --sidebar-bg:   #0b1a3d;
  --sidebar-fg:   #c7d2e8;
  --sidebar-fg-strong: #ffffff;
  --sidebar-hover: rgba(255, 255, 255, .08);

  --text:         #141414;
  --text-muted:   #5e6b7f;
  --border:       #e2e8f2;
  --border-strong:#cbd5e6;

  --ok:           #1f8a4c;
  --ok-bg:        #e6f5ec;
  --warn:         #b26a00;
  --warn-bg:      #fdf2df;
  --danger:       #c02626;
  --danger-bg:    #fdeaea;
  --info:         #1f6699;
  --info-bg:      #e7f1f9;

  --accent-blue:   #0848ca;
  --accent-teal:   #0d8a8a;
  --accent-violet: #6b3fc4;
  --accent-amber:  #d99700;
  --accent-rose:   #c0316b;
  --accent-green:  #1f8a4c;

  --radius:      10px;
  --radius-sm:   6px;
  --shadow:      0 1px 2px rgba(16, 24, 40, .06), 0 4px 12px rgba(16, 24, 40, .05);
  --shadow-lg:   0 8px 28px rgba(16, 24, 40, .12);
  --sidebar-w:   264px;
  --sidebar-w-collapsed: 68px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "Cascadia Mono", Consolas, "SF Mono", "Liberation Mono", monospace;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0e1420;
    --surface:     #161d2c;
    --surface-alt: #1c2434;
    --sidebar-bg:  #080d18;
    --sidebar-fg:  #97a5bf;
    --sidebar-hover: rgba(255, 255, 255, .06);
    --brand-light: #17224a;
    --text:        #e6ebf5;
    --text-muted:  #94a2ba;
    --border:      #26314a;
    --border-strong: #34415e;
    --ok-bg:       #10301f;
    --warn-bg:     #33260c;
    --danger-bg:   #3a1717;
    --info-bg:     #10283c;
    --accent-blue:   #5b8cff;
    --accent-teal:   #2bb6b6;
    --accent-violet: #a487f0;
    --accent-amber:  #f3b73f;
    --accent-rose:   #ec6b9c;
    --accent-green:  #45c67c;
    --shadow:      0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
    --shadow-lg:   0 8px 28px rgba(0, 0, 0, .45);
  }
}

:root[data-theme="dark"] {
  --bg:          #0e1420;
  --surface:     #161d2c;
  --surface-alt: #1c2434;
  --sidebar-bg:  #080d18;
  --sidebar-fg:  #97a5bf;
  --sidebar-hover: rgba(255, 255, 255, .06);
  --brand-light: #17224a;
  --text:        #e6ebf5;
  --text-muted:  #94a2ba;
  --border:      #26314a;
  --border-strong: #34415e;
  --ok-bg:       #10301f;
  --warn-bg:     #33260c;
  --danger-bg:   #3a1717;
  --info-bg:     #10283c;
  --accent-blue:   #5b8cff;
  --accent-teal:   #2bb6b6;
  --accent-violet: #a487f0;
  --accent-amber:  #f3b73f;
  --accent-rose:   #ec6b9c;
  --accent-green:  #45c67c;
  --shadow:      0 1px 2px rgba(0, 0, 0, .3), 0 4px 12px rgba(0, 0, 0, .25);
  --shadow-lg:   0 8px 28px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3 { margin: 0 0 .4em; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.55rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.02rem; }
p  { margin: 0 0 1em; }

code, pre, .mono { font-family: var(--mono); font-size: .86em; }

.icon { width: 1.15em; height: 1.15em; fill: none; stroke: currentColor;
        stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: 0 0 auto; }

/* ==========================================================================
   Layout
   ========================================================================== */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex: 0 0 var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  transition: width .18s ease, flex-basis .18s ease;
  z-index: 30;
}

body.sidebar-collapsed .sidebar {
  width: var(--sidebar-w-collapsed);
  flex-basis: var(--sidebar-w-collapsed);
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .7rem;
  padding: 1.1rem 1rem;
  border-bottom: 1px solid rgba(255, 255, 255, .08);
  min-height: 68px;
}

.brand-mark {
  width: 38px; height: 38px; flex: 0 0 38px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--brand) 0%, var(--brand-dark) 60%, var(--gold) 190%);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: .82rem; letter-spacing: .04em;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .16);
}

.brand-text { min-width: 0; }
.brand-text strong { display: block; color: var(--sidebar-fg-strong); font-size: .96rem; line-height: 1.2; }
.brand-text span { display: block; font-size: .72rem; color: var(--sidebar-fg); opacity: .8;
                   white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

body.sidebar-collapsed .brand-text,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .sidebar-footer .user-meta { display: none; }

.sidebar-nav { padding: .8rem .6rem; flex: 1 1 auto; overflow-y: auto; }
.nav-section { font-size: .68rem; text-transform: uppercase; letter-spacing: .09em;
               color: var(--sidebar-fg); opacity: .55; padding: .9rem .7rem .35rem; }
body.sidebar-collapsed .nav-section { text-align: center; font-size: 0; padding: .7rem 0 .2rem; }

.nav-item {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem .7rem; margin-bottom: .18rem;
  border-radius: var(--radius-sm);
  color: var(--sidebar-fg); font-size: .92rem;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-fg-strong); text-decoration: none; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-item.active .icon { color: var(--gold); }
body.sidebar-collapsed .nav-item { justify-content: center; padding: .65rem 0; }

.sidebar-footer { padding: .8rem; border-top: 1px solid rgba(255, 255, 255, .08); }
.run-mode {
  display: flex; align-items: center; gap: .45rem;
  font-size: .72rem; letter-spacing: .02em;
  color: var(--sidebar-fg); opacity: .8;
  padding: 0 .1rem .6rem;
}
.user-chip { display: flex; align-items: center; gap: .65rem; }
.avatar {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%;
  background: var(--gold); color: #241a00;
  display: grid; place-items: center; font-weight: 700; font-size: .8rem;
}
.user-meta { min-width: 0; }
.user-meta strong { display: block; color: var(--sidebar-fg-strong); font-size: .85rem;
                    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-meta span { font-size: .72rem; opacity: .75; }

.main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex; align-items: center; gap: .8rem;
  padding: .75rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
  min-height: 62px;
}
.topbar h1 { margin: 0; font-size: 1.12rem; }
.topbar .spacer { flex: 1 1 auto; }
.breadcrumb { font-size: .78rem; color: var(--text-muted); }

.icon-button {
  display: inline-grid; place-items: center;
  width: 38px; height: 38px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--surface);
  color: var(--text); cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.icon-button:hover { background: var(--surface-alt); border-color: var(--border-strong); }

.content { padding: 1.5rem; flex: 1 1 auto; max-width: 1400px; width: 100%; }

/* ==========================================================================
   Componenti
   ========================================================================== */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1.15rem;
}
.card-header { display: flex; align-items: center; gap: .7rem; margin-bottom: .9rem; }
.card-header h2, .card-header h3 { margin: 0; }
.card-header .spacer { flex: 1 1 auto; }

.grid { display: grid; gap: 1.15rem; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-cards { grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); }

/* Tile statistiche */
.tile {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.05rem 1.15rem;
  display: flex; align-items: center; gap: .95rem;
}
.tile::before {
  content: ""; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--tile-color, var(--brand));
}
.tile-icon {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 10px;
  display: grid; place-items: center;
  background: color-mix(in srgb, var(--tile-color, var(--brand)) 14%, transparent);
  color: var(--tile-color, var(--brand));
}
.tile-icon .icon { width: 22px; height: 22px; }
.tile-value { font-size: 1.7rem; font-weight: 700; line-height: 1.1; }
.tile-label { font-size: .8rem; color: var(--text-muted); }

.accent-blue   { --tile-color: var(--accent-blue); }
.accent-teal   { --tile-color: var(--accent-teal); }
.accent-violet { --tile-color: var(--accent-violet); }
.accent-amber  { --tile-color: var(--accent-amber); }
.accent-rose   { --tile-color: var(--accent-rose); }
.accent-green  { --tile-color: var(--accent-green); }

/* Card algoritmo */
.algo-card {
  position: relative; overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem;
  display: flex; flex-direction: column; gap: .7rem;
  transition: transform .14s ease, box-shadow .14s ease;
}
.algo-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lg); }
.algo-card::before {
  content: ""; position: absolute; inset: 0 0 auto 0; height: 4px;
  background: var(--tile-color, var(--brand));
}
.algo-acronym {
  display: inline-flex; align-items: center; justify-content: center;
  padding: .3rem .65rem; border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--tile-color, var(--brand)) 14%, transparent);
  color: var(--tile-color, var(--brand));
  font-weight: 700; font-size: .95rem; letter-spacing: .01em;
}
.algo-card p { margin: 0; color: var(--text-muted); font-size: .88rem; }
.algo-card .algo-desc {
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.algo-footer { margin-top: auto; padding-top: .6rem; display: flex; align-items: center; gap: .6rem;
               border-top: 1px solid var(--border); }

/* Badge */
.badge {
  display: inline-flex; align-items: center; gap: .35rem;
  padding: .18rem .55rem; border-radius: 999px;
  font-size: .74rem; font-weight: 600; letter-spacing: .01em;
  background: var(--surface-alt); color: var(--text-muted);
  border: 1px solid var(--border);
}
.badge-ok      { background: var(--ok-bg);     color: var(--ok);     border-color: transparent; }
.badge-warn    { background: var(--warn-bg);   color: var(--warn);   border-color: transparent; }
.badge-danger  { background: var(--danger-bg); color: var(--danger); border-color: transparent; }
.badge-info    { background: var(--info-bg);   color: var(--info);   border-color: transparent; }
.badge-brand   { background: var(--brand-light); color: var(--brand); border-color: transparent; }

.dot { width: .5rem; height: .5rem; border-radius: 50%; background: currentColor; }
.dot-pulse { animation: pulse 1.3s ease-in-out infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* Bottoni */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  padding: .55rem 1rem; border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: .9rem; font-weight: 550; cursor: pointer;
  transition: background .12s ease, border-color .12s ease, opacity .12s ease;
}
.btn:hover { background: var(--surface-alt); text-decoration: none; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { background: #a11f1f; border-color: #a11f1f; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-alt); color: var(--text); }
.btn-sm { padding: .35rem .7rem; font-size: .82rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; }

/* Form */
.field { margin-bottom: 1.05rem; }
.field label { display: block; font-weight: 600; font-size: .87rem; margin-bottom: .3rem; }
.field .help { font-size: .8rem; color: var(--text-muted); margin-top: .3rem; }
.required { color: var(--danger); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="file"], select, textarea {
  width: 100%; padding: .55rem .7rem;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font: inherit; font-size: .92rem;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid color-mix(in srgb, var(--brand) 45%, transparent);
  outline-offset: 1px; border-color: var(--brand);
}
textarea { resize: vertical; min-height: 90px; }
textarea.code { font-family: var(--mono); font-size: .82rem; line-height: 1.5; min-height: 340px; }

.checkbox { display: flex; align-items: flex-start; gap: .55rem; font-size: .9rem; }
.checkbox input { width: auto; margin-top: .25rem; }

.field-group { border: 1px solid var(--border); border-radius: var(--radius);
               padding: 1.1rem 1.15rem .3rem; margin-bottom: 1.15rem; background: var(--surface-alt); }
.field-group > legend, .field-group > .legend {
  font-weight: 650; font-size: .92rem; padding: 0 .4rem; color: var(--text);
}
.field-row { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }

/* Tabelle */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .88rem; }
th, td { padding: .65rem .85rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { background: var(--surface-alt); font-weight: 650; font-size: .78rem;
     text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); white-space: nowrap; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-alt); }
td.actions { text-align: right; white-space: nowrap; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* Avvisi */
.alert {
  display: flex; align-items: flex-start; gap: .65rem;
  padding: .8rem 1rem; border-radius: var(--radius);
  border: 1px solid transparent; margin-bottom: 1.15rem; font-size: .9rem;
}
.alert-success { background: var(--ok-bg);     color: var(--ok);     border-color: color-mix(in srgb, var(--ok) 25%, transparent); }
.alert-warning { background: var(--warn-bg);   color: var(--warn);   border-color: color-mix(in srgb, var(--warn) 25%, transparent); }
.alert-danger  { background: var(--danger-bg); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-info    { background: var(--info-bg);   color: var(--info);   border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert ul { margin: .35rem 0 0; padding-left: 1.1rem; }

/* Console log */
.console {
  background: #0b1220; color: #d7e2f5;
  border-radius: var(--radius); border: 1px solid var(--border);
  padding: .9rem 1rem; overflow-x: auto; max-height: 460px; overflow-y: auto;
  font-family: var(--mono); font-size: .8rem; line-height: 1.5;
  white-space: pre; margin: 0;
}
.console.empty { color: #7d8aa5; font-style: italic; white-space: normal; }

/* Liste descrittive */
.definition { display: grid; grid-template-columns: minmax(140px, auto) 1fr; gap: .45rem 1rem; font-size: .88rem; margin: 0; }
.definition dt { color: var(--text-muted); }
.definition dd { margin: 0; word-break: break-word; }

.empty-state { text-align: center; padding: 2.6rem 1rem; color: var(--text-muted); }
.empty-state .icon { width: 40px; height: 40px; opacity: .35; margin-bottom: .6rem; }

.page-head { display: flex; align-items: flex-start; gap: 1rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.page-head .spacer { flex: 1 1 auto; }
.page-head p { margin: .2rem 0 0; color: var(--text-muted); font-size: .9rem; }

.filters { display: flex; flex-wrap: wrap; gap: .7rem; align-items: flex-end; }
.filters .field { margin-bottom: 0; min-width: 170px; }

.inline-form { display: inline; }

/* Login */
.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 1.5rem;
  background: linear-gradient(150deg, var(--sidebar-bg) 0%, #12275c 55%, var(--brand-dark) 100%);
}
.login-card {
  width: min(420px, 100%); background: var(--surface);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 2rem;
}
.login-head { text-align: center; margin-bottom: 1.5rem; }
.login-head .brand-mark { width: 52px; height: 52px; margin: 0 auto .8rem; font-size: 1rem; }
.login-head h1 { font-size: 1.25rem; margin-bottom: .2rem; }
.login-head p { color: var(--text-muted); font-size: .85rem; margin: 0; }
.login-foot { margin-top: 1.3rem; text-align: center; font-size: .78rem; color: var(--text-muted); }

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 900px) {
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    transform: translateX(-100%);
    transition: transform .2s ease;
    box-shadow: var(--shadow-lg);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  body.sidebar-collapsed .sidebar { width: var(--sidebar-w); flex-basis: var(--sidebar-w); }
  body.sidebar-collapsed .brand-text,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .sidebar-footer .user-meta { display: block; }
  body.sidebar-collapsed .nav-item { justify-content: flex-start; padding: .6rem .7rem; }
  .content { padding: 1rem; }
  .topbar { padding: .7rem 1rem; }
  .scrim { position: fixed; inset: 0; background: rgba(8, 13, 24, .5); z-index: 25; }
  body:not(.sidebar-open) .scrim { display: none; }
}

@media (min-width: 901px) {
  .scrim { display: none; }
}

@media print {
  .sidebar, .topbar, .btn, .btn-row { display: none !important; }
  .content { padding: 0; }
  .card { box-shadow: none; border-color: #ccc; }
}
