/* AI mydesk – stile della piattaforma e componenti condivisi dai plugin.
   Linguaggio visivo moderno e minimale, ispirato a macOS: vetro smerigliato,
   angoli morbidi, tipografia di sistema, colori di sistema e ombre diffuse. */
:root {
  --ad-accent: #007aff;
  --ad-accent-hover: #0068d9;
  --ad-accent-soft: rgba(0, 122, 255, .12);
  --ad-danger: #ff3b30;
  --ad-text: #1d1d1f;
  --ad-muted: #86868b;
  --ad-border: rgba(0, 0, 0, .08);
  --ad-fill: rgba(118, 118, 128, .12);
  --ad-surface: #ffffff;
  --ad-surface-2: #f5f5f7;
  --ad-glass: rgba(255, 255, 255, .72);
  --ad-glass-strong: rgba(250, 250, 252, .86);
  --ad-radius: 12px;
  --ad-radius-sm: 8px;
  --ad-shadow: 0 0 0 .5px rgba(0, 0, 0, .12), 0 22px 70px rgba(0, 0, 0, .28);
  --ad-shadow-soft: 0 0 0 .5px rgba(0, 0, 0, .08), 0 10px 30px rgba(0, 0, 0, .14);
  --ad-blur: saturate(180%) blur(24px);
  --ad-font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", "Inter", "Segoe UI", Roboto, Arial, sans-serif;
  --ad-ease: cubic-bezier(.2, .8, .2, 1);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--ad-font);
  font-size: 14px;
  color: var(--ad-text);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  letter-spacing: -.005em;
  /* Wallpaper blu del marchio, morbido in stile macOS (i loghi bianchi risaltano) */
  background:
    radial-gradient(1100px 800px at 85% 10%, rgba(125, 211, 252, .55), transparent 60%),
    radial-gradient(1000px 800px at 10% 90%, rgba(88, 86, 214, .55), transparent 60%),
    radial-gradient(900px 700px at 15% 15%, rgba(56, 140, 255, .6), transparent 60%),
    linear-gradient(140deg, #1a6ff0 0%, #0b5ed7 45%, #0a3f9e 100%);
  background-attachment: fixed;
}
button, input, select, textarea { font-family: inherit; color: inherit; }
:focus-visible { outline: 3px solid rgba(0, 122, 255, .45); outline-offset: 1px; }

/* Logo "AI mydesk" in alto a destra sul desktop */
.ad-logo {
  position: fixed; right: 32px; top: 52px; width: 220px; height: auto;
  opacity: .92; filter: drop-shadow(0 4px 14px rgba(0, 20, 70, .25));
  user-select: none; pointer-events: none; z-index: 0;
}

/* ---------- Login ---------- */
.ad-login-wrap { height: 100%; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 20px; padding: 16px; }
.ad-login-logo {
  width: 260px; max-width: 80%; height: auto; filter: drop-shadow(0 6px 18px rgba(0, 20, 70, .3));
  animation: ad-pop .45s var(--ad-ease) both;
}
.ad-login {
  width: 360px; max-width: 100%;
  background: var(--ad-glass);
  -webkit-backdrop-filter: var(--ad-blur); backdrop-filter: var(--ad-blur);
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 22px;
  padding: 28px 32px 28px;
  box-shadow: 0 30px 80px rgba(40, 30, 90, .22), 0 1px 0 rgba(255, 255, 255, .7) inset;
  position: relative; z-index: 1;
  animation: ad-pop .45s var(--ad-ease) both;
}
.ad-login h1 { margin: 0; text-align: center; font-size: 22px; font-weight: 600; letter-spacing: -.02em; color: var(--ad-text); }
.ad-login .subtitle { margin: 4px 0 24px; text-align: center; font-size: 13px; color: var(--ad-muted); }
.ad-login .row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.ad-login label { font-size: 12px; font-weight: 500; color: #6e6e73; padding-left: 2px; }
.ad-login .field { position: relative; }
.ad-login input {
  width: 100%; height: 40px; padding: 0 12px; font-size: 15px;
  border: 1px solid rgba(0, 0, 0, .1); border-radius: 10px; background: rgba(255, 255, 255, .85);
  transition: border-color .15s, box-shadow .15s;
}
.ad-login input:focus { outline: none; border-color: var(--ad-accent); box-shadow: 0 0 0 4px rgba(0, 122, 255, .2); }
.ad-login input#password { padding-right: 40px; }
.ad-login .eye {
  position: absolute; right: 8px; top: 50%; transform: translateY(-50%);
  border: 0; background: none; cursor: pointer; color: var(--ad-muted); padding: 4px; line-height: 0; border-radius: 6px;
}
.ad-login .eye:hover { color: var(--ad-text); }
.ad-login .submit {
  width: 100%; height: 40px; margin-top: 8px; border: 0; border-radius: 10px; cursor: pointer;
  background: var(--ad-accent); color: #fff; font-size: 15px; font-weight: 600;
  transition: background .15s, transform .1s;
}
.ad-login .submit:hover { background: var(--ad-accent-hover); }
.ad-login .submit:active { transform: scale(.98); }
.ad-login .submit:disabled { opacity: .6; cursor: wait; }
.ad-login .error { color: var(--ad-danger); font-size: 13px; text-align: center; }
.ad-login .error:not(:empty) { margin: 2px 0 10px; }

/* ---------- Barra dei menu (in alto, traslucida) ---------- */
.ad-topbar {
  position: fixed; left: 0; right: 0; top: 0; height: 32px; z-index: 100000;
  background: rgba(0, 25, 80, .28);
  -webkit-backdrop-filter: var(--ad-blur); backdrop-filter: var(--ad-blur);
  border-bottom: .5px solid rgba(255, 255, 255, .12);
  color: #fff;
  display: flex; align-items: center; padding: 0 10px; gap: 8px;
}
.ad-topbar .home {
  width: 28px; height: 24px; line-height: 0; border: 0; background: none; padding: 2px;
  cursor: pointer; border-radius: 6px; display: flex; align-items: center; justify-content: center;
}
.ad-topbar .home img { width: 20px; height: 20px; display: block; }
.ad-topbar .home:hover, .ad-topbar .home[aria-expanded="true"] { background: rgba(255, 255, 255, .18); }
.ad-topbar .sep { width: 1px; height: 16px; background: rgba(255, 255, 255, .25); }
.ad-taskbar { display: flex; gap: 2px; flex: 1; overflow: hidden; align-items: center; }
.ad-task {
  border: 0; border-radius: 6px; background: none; color: #fff; height: 24px;
  padding: 0 10px; font-size: 13px; cursor: pointer; white-space: nowrap; max-width: 220px;
  overflow: hidden; text-overflow: ellipsis; transition: background .15s;
}
.ad-task:hover { background: rgba(255, 255, 255, .14); }
.ad-task.active { font-weight: 600; background: rgba(255, 255, 255, .2); }
.ad-task.minimized { color: rgba(255, 255, 255, .6); }
.ad-clock { font-size: 13px; color: #fff; padding: 0 6px; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ad-user { position: relative; }
.ad-user > button {
  border: 0; background: none; font-size: 13px; font-weight: 500; color: #fff; cursor: pointer;
  padding: 3px 8px; border-radius: 6px;
}
.ad-user > button:hover { background: rgba(255, 255, 255, .18); }
.ad-user-menu {
  position: absolute; right: 0; top: 30px; min-width: 220px; padding: 5px; color: var(--ad-text);
  background: var(--ad-glass-strong);
  -webkit-backdrop-filter: var(--ad-blur); backdrop-filter: var(--ad-blur);
  border-radius: 10px; box-shadow: var(--ad-shadow-soft);
  display: none;
}
.ad-user-menu.open { display: block; animation: ad-fade .12s ease-out both; }
.ad-user-menu .info { padding: 6px 10px 8px; font-size: 12px; color: var(--ad-muted); border-bottom: .5px solid rgba(0, 0, 0, .1); margin-bottom: 4px; }
.ad-user-menu button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 5px 10px;
  font-size: 13px; cursor: pointer; border-radius: 6px;
}
.ad-user-menu button:hover { background: var(--ad-accent); color: #fff; }

/* ---------- Sidebar a comparsa ---------- */
.ad-sidebar {
  position: fixed; left: 8px; top: 40px; bottom: 8px; width: 250px; z-index: 100001;
  background: var(--ad-glass-strong);
  -webkit-backdrop-filter: var(--ad-blur); backdrop-filter: var(--ad-blur);
  border-radius: 14px; box-shadow: var(--ad-shadow);
  transform: translateX(calc(-100% - 16px)); transition: transform .3s var(--ad-ease);
  display: flex; flex-direction: column; overflow: hidden;
}
.ad-sidebar.open { transform: translateX(0); }
.ad-sidebar-head { padding: 20px 20px 12px; font-size: 20px; font-weight: 600; letter-spacing: -.02em; color: var(--ad-text); }
.ad-sidebar-head .ai { color: var(--ad-accent); }
.ad-sidebar nav { padding: 4px 10px; }
.ad-sidebar nav button {
  display: block; width: 100%; text-align: left; border: 0; background: none; padding: 8px 12px; border-radius: 8px;
  font-size: 14px; color: var(--ad-text); cursor: pointer;
}
.ad-sidebar nav button:hover, .ad-sidebar nav button:focus-visible { background: rgba(0, 0, 0, .06); outline: none; }
.ad-sidebar-backdrop { position: fixed; inset: 32px 0 0 0; z-index: 100000; background: rgba(0, 10, 40, .2); display: none; }
.ad-sidebar-backdrop.open { display: block; animation: ad-fade .2s ease-out both; }

/* ---------- Icone del desktop (stile "app icon") ---------- */
.ad-desktop { position: fixed; left: 0; right: 0; top: 32px; bottom: 0; }
.ad-icon {
  position: absolute; width: 112px; padding: 8px 4px 6px; text-align: center; color: #fff; cursor: default;
  user-select: none; touch-action: none; border-radius: 12px; transition: background .15s;
}
.ad-icon:hover { background: rgba(255, 255, 255, .1); }
.ad-icon.selected { background: rgba(255, 255, 255, .18); }
.ad-icon.dragging { opacity: .8; z-index: 5; transition: none; }
.ad-icon .img {
  width: 64px; height: 64px; margin: 0 auto 6px; pointer-events: none; padding: 10px;
  border-radius: 15px;
  background: linear-gradient(160deg, #5ac8fa 0%, #007aff 60%, #3a5bd9 100%);
  box-shadow: 0 0 0 .5px rgba(255, 255, 255, .25), 0 6px 16px rgba(0, 20, 70, .35), 0 1px 0 rgba(255, 255, 255, .35) inset;
  transition: transform .2s var(--ad-ease);
}
.ad-icon:hover .img { transform: translateY(-2px) scale(1.04); }
.ad-icon .img svg { width: 100%; height: 100%; display: block; }
.ad-icon .label {
  display: inline-block; font-size: 12px; font-weight: 500; line-height: 1.3; padding: 1px 6px; border-radius: 5px;
  text-shadow: 0 1px 3px rgba(0, 20, 70, .55);
}
.ad-icon.selected .label { background: var(--ad-accent); color: #fff; text-shadow: none; }
.ad-empty {
  position: absolute; left: 24px; top: 24px; font-size: 14px; color: var(--ad-text);
  background: var(--ad-glass); -webkit-backdrop-filter: var(--ad-blur); backdrop-filter: var(--ad-blur);
  padding: 12px 16px; border-radius: 12px; box-shadow: var(--ad-shadow-soft);
}

/* ---------- Finestre ---------- */
.ad-window {
  position: absolute; background: var(--ad-surface); border-radius: var(--ad-radius); display: flex; flex-direction: column;
  box-shadow: var(--ad-shadow); min-width: 320px; min-height: 200px; overflow: hidden;
  animation: ad-pop .25s var(--ad-ease) both;
}
.ad-window.inactive { box-shadow: 0 0 0 .5px rgba(0, 0, 0, .1), 0 10px 30px rgba(0, 0, 0, .14); }
.ad-window.maximized { border-radius: 0; animation: none; }
.ad-window.minimized { display: none; }
.ad-titlebar {
  height: 40px; flex: 0 0 40px; display: flex; align-items: center; padding: 0 14px; gap: 8px;
  background: var(--ad-surface-2); border-bottom: .5px solid rgba(0, 0, 0, .1);
  cursor: default; user-select: none; touch-action: none; position: relative;
}
.ad-window.inactive .ad-titlebar { background: #fafafa; }
.ad-titlebar .title {
  position: absolute; left: 90px; right: 90px; text-align: center; pointer-events: none;
  color: var(--ad-text); font-size: 13px; font-weight: 600;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.ad-window.inactive .ad-titlebar .title { color: var(--ad-muted); }
/* Pulsanti "semaforo": chiudi (rosso), riduci (giallo), ingrandisci (verde) */
.ad-titlebar .lights { display: flex; gap: 8px; position: relative; z-index: 1; }
.ad-titlebar .wbtn {
  width: 12px; height: 12px; border-radius: 50%; border: 0; padding: 0; cursor: pointer;
  font-size: 10px; font-weight: 700; line-height: 12px; text-align: center; color: transparent;
  box-shadow: inset 0 0 0 .5px rgba(0, 0, 0, .15);
}
.ad-titlebar .wbtn[data-action="close"] { background: #ff5f57; }
.ad-titlebar .wbtn[data-action="minimize"] { background: #febc2e; }
.ad-titlebar .wbtn[data-action="maximize"] { background: #28c840; }
.ad-titlebar .lights:hover .wbtn, .ad-titlebar .wbtn:focus-visible { color: rgba(0, 0, 0, .55); }
.ad-window.inactive .ad-titlebar .lights:not(:hover) .wbtn { background: #dcdcdc; }
.ad-window-body { flex: 1; overflow: auto; position: relative; background: var(--ad-surface); }
.ad-resize { position: absolute; right: 0; bottom: 0; width: 16px; height: 16px; cursor: nwse-resize; touch-action: none; z-index: 2; }
.ad-window.maximized .ad-resize { display: none; }
.ad-window-body .muted { color: var(--ad-muted); }
.ad-loading, .ad-error { padding: 28px; color: var(--ad-muted); }
.ad-error { color: var(--ad-danger); }

/* ---------- Componenti condivisi per i plugin ---------- */
/* Schede come "segmented control" */
.ad-tabs {
  display: inline-flex; flex-wrap: wrap; gap: 2px; margin: 16px 24px 0; padding: 2px;
  background: var(--ad-fill); border-radius: 9px;
}
.ad-tabs button {
  border: 0; background: none; padding: 5px 16px; font-size: 13px; font-weight: 500; color: var(--ad-text);
  cursor: pointer; border-radius: 7px; transition: background .15s, box-shadow .15s;
}
.ad-tabs button:hover:not(.active) { background: rgba(0, 0, 0, .04); }
.ad-tabs button.active { background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .12), 0 0 0 .5px rgba(0, 0, 0, .04); }
.ad-pane { padding: 18px 24px 24px; }
.ad-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.ad-toolbar .spacer { flex: 1; }
.ad-btn {
  border: 0; background: var(--ad-accent); color: #fff; border-radius: var(--ad-radius-sm); padding: 6px 14px;
  font-size: 13px; font-weight: 500; cursor: pointer; transition: background .15s, transform .1s;
  box-shadow: 0 1px 2px rgba(0, 0, 0, .08);
}
.ad-btn:hover { background: var(--ad-accent-hover); }
.ad-btn:active { transform: scale(.97); }
.ad-btn.secondary { background: #fff; color: var(--ad-text); box-shadow: 0 0 0 .5px rgba(0, 0, 0, .18), 0 1px 2px rgba(0, 0, 0, .06); }
.ad-btn.secondary:hover { background: var(--ad-surface-2); }
.ad-btn.danger { background: var(--ad-danger); }
.ad-btn.danger:hover { background: #e0322a; }
.ad-btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.ad-input, .ad-select, .ad-textarea {
  border: 1px solid rgba(0, 0, 0, .12); border-radius: var(--ad-radius-sm); padding: 6px 10px; font-size: 13px;
  background: #fff; transition: border-color .15s, box-shadow .15s;
}
.ad-input:focus, .ad-select:focus, .ad-textarea:focus { outline: none; border-color: var(--ad-accent); box-shadow: 0 0 0 3px rgba(0, 122, 255, .2); }
.ad-input:disabled, .ad-select:disabled, .ad-textarea:disabled { background: var(--ad-surface-2); color: var(--ad-muted); }
.ad-textarea { width: 100%; min-height: 160px; resize: vertical; }
.ad-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; }
.ad-table th {
  text-align: left; vertical-align: bottom; padding: 8px 12px; font-size: 11px; font-weight: 600; color: var(--ad-muted);
  text-transform: uppercase; letter-spacing: .04em; border-bottom: .5px solid rgba(0, 0, 0, .12);
}
.ad-table th.sortable { cursor: pointer; white-space: nowrap; }
.ad-table th.sortable:hover { color: var(--ad-text); }
.ad-table th.sortable::after { content: " ⇅"; color: #c7c7cc; font-size: 11px; }
.ad-table th.sort-asc::after { content: " ↑"; color: var(--ad-accent); }
.ad-table th.sort-desc::after { content: " ↓"; color: var(--ad-accent); }
.ad-table td { padding: 10px 12px; border-bottom: .5px solid rgba(0, 0, 0, .06); }
.ad-table tbody tr { transition: background .1s; }
.ad-table tbody tr:nth-child(even) { background: #fafafc; }
.ad-table tbody tr:hover { background: var(--ad-accent-soft); }
.ad-table .center { text-align: center; }
.ad-table .muted { color: var(--ad-muted); }
.ad-table .iconbtn {
  border: 0; background: none; cursor: pointer; font-size: 15px; color: var(--ad-muted); padding: 2px 6px; border-radius: 6px;
}
.ad-table .iconbtn:hover { color: var(--ad-accent); background: var(--ad-accent-soft); }
.ad-footer { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; flex-wrap: wrap; font-size: 13px; color: var(--ad-muted); }
.ad-pager { display: flex; gap: 2px; padding: 2px; background: var(--ad-fill); border-radius: 9px; }
.ad-pager button {
  border: 0; background: none; padding: 4px 10px; min-width: 30px; cursor: pointer; font-size: 13px; color: var(--ad-text); border-radius: 7px;
}
.ad-pager button:hover:not(:disabled):not(.current) { background: rgba(0, 0, 0, .05); }
.ad-pager button.current { background: #fff; color: var(--ad-accent); font-weight: 600; box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.ad-pager button:disabled { color: #c7c7cc; cursor: default; }
.ad-badge {
  display: inline-block; font-size: 11px; font-weight: 500; padding: 1px 8px; border-radius: 999px;
  background: var(--ad-accent-soft); color: var(--ad-accent); margin-left: 6px; vertical-align: middle;
}
.ad-badge.off { background: rgba(255, 59, 48, .12); color: var(--ad-danger); }

/* Dialog interno a una finestra (stile "sheet") */
.ad-modal-back {
  position: absolute; inset: 0; background: rgba(0, 0, 0, .18); display: flex; align-items: flex-start; justify-content: center;
  padding-top: 32px; z-index: 10; animation: ad-fade .15s ease-out both;
}
.ad-modal {
  background: var(--ad-surface); width: 460px; max-width: calc(100% - 24px); border-radius: 14px; box-shadow: var(--ad-shadow);
  animation: ad-sheet .25s var(--ad-ease) both; overflow: hidden;
}
.ad-modal h3 { margin: 0; padding: 18px 20px 6px; font-size: 15px; font-weight: 600; letter-spacing: -.01em; }
.ad-modal .content { padding: 12px 20px; max-height: 60vh; overflow: auto; }
.ad-modal .actions { padding: 12px 20px 18px; display: flex; justify-content: flex-end; gap: 8px; }
.ad-form-row { display: flex; align-items: center; margin-bottom: 12px; gap: 10px; }
.ad-form-row > label:first-child { width: 120px; color: #6e6e73; font-size: 13px; }
.ad-form-row .ad-input { flex: 1; }
.ad-form-error { color: var(--ad-danger); min-height: 18px; font-size: 13px; }
.ad-checklist { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 6px; flex: 1; font-size: 13px; }
.ad-checklist input[type=checkbox], .ad-form-row input[type=checkbox] { accent-color: var(--ad-accent); }
.ad-toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: rgba(40, 40, 45, .82); color: #fff;
  -webkit-backdrop-filter: var(--ad-blur); backdrop-filter: var(--ad-blur);
  padding: 10px 18px; border-radius: 999px; z-index: 200000; font-size: 13px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(0, 0, 0, .25); animation: ad-toast .3s var(--ad-ease) both;
}

/* Scrollbar sottili */
.ad-window-body::-webkit-scrollbar, .ad-modal .content::-webkit-scrollbar { width: 10px; height: 10px; }
.ad-window-body::-webkit-scrollbar-thumb, .ad-modal .content::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .2); border-radius: 10px; border: 3px solid transparent; background-clip: content-box;
}

/* ---------- Animazioni ---------- */
@keyframes ad-pop { from { opacity: 0; transform: scale(.96); } to { opacity: 1; transform: none; } }
@keyframes ad-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes ad-sheet { from { opacity: 0; transform: translateY(-12px); } to { opacity: 1; transform: none; } }
@keyframes ad-toast { from { opacity: 0; transform: translate(-50%, 12px); } to { opacity: 1; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
