/* ============================================================
   Manufatto Win98 Desktop - Custom overrides & layout
   Base: 98.css via CDN (https://unpkg.com/98.css)
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600;700&display=swap');

/* ── Reset & base ─────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  width: 100%; height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.5;
  background: #008080;
  user-select: none;
  cursor: default;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Dragging cursor override */
body.dragging, body.dragging * {
  cursor: grabbing !important;
}

/* ── Animations ───────────────────────────────────────── */
@keyframes windowOpen {
  from { opacity: 0; transform: scale(0.92); }
  to   { opacity: 1; transform: scale(1); }
}

@keyframes windowClose {
  from { opacity: 1; transform: scale(1); }
  to   { opacity: 0; transform: scale(0.88); }
}

@keyframes windowMinimize {
  from { opacity: 1; transform: scale(1) translateY(0); }
  to   { opacity: 0; transform: scale(0.4) translateY(60vh); }
}

@keyframes menuSlideUp {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

@keyframes bootFadeOut {
  from { opacity: 1; }
  to   { opacity: 0; }
}

@keyframes cursorBlink {
  0%, 50% { opacity: 1; }
  51%, 100% { opacity: 0; }
}

/* ── Desktop surface ──────────────────────────────────── */
#desktop {
  position: fixed;
  top: 0; left: 0;
  width: 100vw;
  height: calc(100vh - 28px);
  background-color: #008080;
  background-image:
    radial-gradient(ellipse at 30% 40%, rgba(0,100,100,0.35) 0%, transparent 60%),
    radial-gradient(ellipse at 70% 70%, rgba(0,60,80,0.25) 0%, transparent 55%);
  overflow: hidden;
}

/* Wallpaper logo watermark */
#desktop::after {
  content: '';
  position: absolute;
  bottom: 20px; right: 30px;
  width: 180px; height: 60px;
  background: url('/manufatto-logo.png') center/contain no-repeat;
  opacity: 0.12;
  pointer-events: none;
}

/* ── Desktop icons grid ───────────────────────────────── */
#desktop-icons {
  position: absolute;
  top: 10px; left: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 10;
}

.desktop-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 72px;
  padding: 6px 4px;
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 0;
  text-align: center;
  transition: transform 0.15s ease;
}

.desktop-icon:hover,
.desktop-icon.selected {
  background: rgba(0, 0, 128, 0.5);
  border: 1px dotted rgba(255,255,255,0.6);
}

.desktop-icon:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
  background: rgba(0, 0, 128, 0.4);
}

.desktop-icon.icon-dragging {
  opacity: 0.6;
  z-index: 50;
  pointer-events: none;
}

.desktop-icon img {
  width: 32px; height: 32px;
  image-rendering: pixelated;
  display: block;
  margin: 0 auto 4px;
  pointer-events: none;
}

.desktop-icon span {
  color: #fff;
  font-size: 12px;
  line-height: 1.3;
  text-shadow: 1px 1px 1px #000, -1px -1px 1px #000, 1px -1px 1px #000, -1px 1px 1px #000;
  word-break: break-word;
  pointer-events: none;
}

/* ── Windows ──────────────────────────────────────────── */
.win98-window {
  position: absolute;
  min-width: 200px;
  min-height: 100px;
  display: none; /* shown by WindowManager */
  z-index: 100;
  box-shadow: 2px 2px 8px rgba(0,0,0,0.35);
  animation: windowOpen 0.2s ease-out;
}

.win98-window.win-closing {
  animation: windowClose 0.15s ease-in forwards;
}

.win98-window.win-minimizing {
  animation: windowMinimize 0.2s ease-in forwards;
}

.win98-window.active {
  z-index: 999;
  box-shadow: 3px 3px 12px rgba(0,0,0,0.45);
}

/* Inactive title bar dimming */
.win98-window:not(.active) .title-bar {
  background: linear-gradient(90deg, #808080, #b0b0b0);
}

.win98-window .title-bar {
  cursor: grab;
}

.win98-window .title-bar:active {
  cursor: grabbing;
}

.win98-window.maximized {
  position: fixed !important;
  top: 0 !important; left: 0 !important;
  width: 100vw !important;
  height: calc(100vh - 28px) !important;
  box-shadow: none;
}

/* Content areas — system font, medium weight for readability on gray */
.win98-window .window-body {
  font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
  font-size: 14px;
  font-weight: 500;
  line-height: 1.55;
  overflow: auto;
  max-height: calc(100vh - 120px);
  color: #000;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* Headings: system font, bold */
.win98-window h1, .win98-window h2, .win98-window h3 {
  font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
  font-weight: 700;
}

/* Tables */
.win98-window table {
  font-size: 13px;
  line-height: 1.45;
}

.win98-window table th,
.win98-window table td {
  padding: 5px 10px;
}

/* Fieldsets */
.win98-window fieldset {
  margin-bottom: 10px;
}

.win98-window fieldset legend {
  font-size: 14px;
  font-weight: 700;
}

/* Lists */
.win98-window ul {
  line-height: 1.65;
  font-size: 13px;
}

/* Small labels (progress, captions) — floor at 12px */
.win98-window label,
.win98-window .status-bar-field {
  font-size: 12px;
}

/* ── Taskbar ──────────────────────────────────────────── */
#taskbar {
  position: fixed;
  bottom: 0; left: 0;
  width: 100%;
  height: 28px;
  background: #c0c0c0;
  border-top: 2px solid #ffffff;
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 2px 4px;
  z-index: 2000;
  box-shadow: inset 0 1px 0 #dfdfdf;
}

#start-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px 2px 6px;
  font-weight: bold;
  font-size: 12px;
  white-space: nowrap;
  min-width: 54px;
  cursor: pointer;
  font-family: 'Arial', sans-serif;
}

#start-btn:hover {
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff, inset -2px -2px #a0a0a0, inset 2px 2px #f0f0f0;
}

#start-btn img {
  width: 16px; height: 16px;
}

.taskbar-separator {
  width: 2px;
  height: 22px;
  border-left: 1px solid #808080;
  border-right: 1px solid #ffffff;
  margin: 0 2px;
  flex-shrink: 0;
}

#taskbar-windows {
  display: flex;
  gap: 2px;
  flex: 1;
  overflow: hidden;
  align-items: center;
}

.taskbar-btn {
  height: 22px;
  max-width: 160px;
  padding: 0 8px;
  font-size: 12px;
  font-family: 'Arial', sans-serif;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  text-align: left;
  flex-shrink: 0;
}

.taskbar-btn:hover {
  box-shadow: inset -1px -1px #808080, inset 1px 1px #ffffff, inset -2px -2px #a0a0a0, inset 2px 2px #f0f0f0;
}

.taskbar-btn img {
  width: 14px; height: 14px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.taskbar-btn.active {
  box-shadow: inset -1px -1px #ffffff, inset 1px 1px #808080, inset -2px -2px #dfdfdf, inset 2px 2px #0a0a0a;
  background: repeating-linear-gradient(45deg, transparent, transparent 2px, rgba(0,0,0,0.03) 2px, rgba(0,0,0,0.03) 4px);
}

/* ── System tray ──────────────────────────────────────── */
#system-tray {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 2px 6px;
  border: 1px solid #808080;
  border-color: #808080 #ffffff #ffffff #808080;
  background: #c0c0c0;
  white-space: nowrap;
  flex-shrink: 0;
}

#system-tray .tray-icon {
  font-size: 14px;
  cursor: pointer;
}

#system-tray .tray-icon:hover {
  background: rgba(0,0,128,0.1);
}

#system-clock {
  font-size: 12px;
  font-family: 'Arial', sans-serif;
  cursor: default;
  min-width: 38px;
  text-align: center;
}

/* ── Start Menu ───────────────────────────────────────── */
#start-menu {
  position: fixed;
  bottom: 28px; left: 0;
  width: 220px;
  background: #c0c0c0;
  border: 2px solid;
  border-color: #ffffff #808080 #808080 #ffffff;
  box-shadow: 2px 2px 0 #000;
  display: none;
  z-index: 3000;
  flex-direction: row;
}

#start-menu.open {
  display: flex;
  animation: menuSlideUp 0.15s ease-out;
}

/* Vertical banner */
#start-menu-banner {
  width: 26px;
  background: linear-gradient(to bottom, #405189, #1a2a6c);
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  color: #fff;
  font-size: 14px;
  font-weight: bold;
  font-family: 'Arial', sans-serif;
  letter-spacing: 2px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-bottom: 8px;
  flex-shrink: 0;
}

#start-menu-items {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding: 2px 0;
}

.menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  font-size: 13px;
  font-family: 'Arial', sans-serif;
  cursor: pointer;
  position: relative;
  white-space: nowrap;
}

.menu-item:hover,
.menu-item:focus {
  background: #000080;
  color: #ffffff;
  outline: none;
}

.menu-item:hover .menu-item-arrow,
.menu-item:focus .menu-item-arrow {
  color: #ffffff;
}

.menu-item img {
  width: 16px; height: 16px;
  image-rendering: pixelated;
  flex-shrink: 0;
}

.menu-item-arrow {
  margin-left: auto;
  font-size: 10px;
  color: #000;
}

.menu-separator {
  height: 1px;
  background: #808080;
  box-shadow: 0 1px 0 #ffffff;
  margin: 3px 4px;
}

/* Submenus */
.menu-item .submenu {
  position: absolute;
  left: 100%;
  top: 0;
  width: 180px;
  background: #c0c0c0;
  border: 2px solid;
  border-color: #ffffff #808080 #808080 #ffffff;
  box-shadow: 2px 2px 0 #000;
  display: none;
  flex-direction: column;
  padding: 2px 0;
  z-index: 3001;
}

.menu-item:hover .submenu {
  display: flex;
}

/* ── Context menu (right-click) ───────────────────────── */
.context-menu {
  position: fixed;
  background: #c0c0c0;
  border: 2px solid;
  border-color: #ffffff #808080 #808080 #ffffff;
  box-shadow: 2px 2px 0 #000;
  padding: 2px 0;
  z-index: 4000;
  display: none;
  min-width: 160px;
}

.context-menu.visible {
  display: block;
}

.context-menu .menu-item {
  padding: 4px 20px 4px 8px;
  font-size: 12px;
}

.context-menu .menu-separator {
  margin: 2px 4px;
}

/* ── BSOD overlay ─────────────────────────────────────── */
#bsod {
  position: fixed;
  inset: 0;
  background: #0000AA;
  color: #ffffff;
  font-family: 'Courier New', monospace;
  font-size: 14px;
  line-height: 1.6;
  padding: 40px 60px;
  z-index: 9999;
  display: none;
  white-space: pre-wrap;
}

#bsod.visible {
  display: block;
}

#bsod h1 {
  background: #ffffff;
  color: #0000AA;
  font-size: 14px;
  font-weight: normal;
  font-family: 'Courier New', monospace;
  display: inline-block;
  padding: 0 4px;
  margin-bottom: 16px;
}

/* ── Boot screen ──────────────────────────────────────── */
#boot-screen {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 10000;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
}

#boot-screen.visible {
  display: flex;
}

#boot-screen.boot-fade-out {
  animation: bootFadeOut 0.5s ease-out forwards;
}

.boot-logo {
  margin-bottom: 24px;
}

.boot-logo h1 {
  font-family: 'Arial', sans-serif;
  font-size: 36px;
  font-weight: bold;
  color: #fff;
  text-align: center;
  margin-bottom: 4px;
}

.boot-logo h1 span {
  color: #008080;
}

.boot-logo p {
  font-family: 'Arial', sans-serif;
  font-size: 14px;
  color: #808080;
  text-align: center;
}

#boot-screen progress {
  width: 300px;
  margin-bottom: 24px;
}

.boot-log {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: #00ff00;
  line-height: 1.5;
  width: 500px;
  max-width: 90vw;
  height: 180px;
  overflow: hidden;
  white-space: pre-wrap;
  text-align: left;
}

.boot-log::after {
  content: '█';
  animation: cursorBlink 0.6s step-end infinite;
}

.boot-skip {
  position: absolute;
  bottom: 20px;
  font-family: 'Arial', sans-serif;
  font-size: 11px;
  color: #555;
}

/* ── Shutdown overlay ─────────────────────────────────── */
#shutdown-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  color: #fff;
  font-family: 'Arial', sans-serif;
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 8000;
}

#shutdown-overlay.visible {
  display: flex;
}

/* ── Modal dialogs (with overlay) ─────────────────────── */
.modal-dialog {
  position: fixed;
  inset: 0;
  z-index: 5000;
  display: none;
  align-items: center;
  justify-content: center;
}

.modal-dialog.visible,
.modal-dialog[style*="display: flex"] {
  display: flex;
}

.dialog-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.15);
}

.dialog-content {
  position: relative;
  z-index: 1;
}

/* ── Run dialog ───────────────────────────────────────── */
#run-dialog {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4000;
  display: none;
  width: 340px;
}

#run-dialog.visible {
  display: block;
}

/* ── Cestino dialog ───────────────────────────────────── */
#cestino-dialog {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  z-index: 4000;
  display: none;
  width: 280px;
}

#cestino-dialog.visible {
  display: block;
}

/* ── Button press feedback ────────────────────────────── */
button:active:not(:disabled) {
  transform: scale(0.97);
}

button:disabled {
  color: #808080 !important;
  cursor: default;
}

/* ── Focus visible for accessibility ──────────────────── */
button:focus-visible,
input:focus-visible {
  outline: 2px solid #000080;
  outline-offset: 1px;
}

/* ── Window content helpers ───────────────────────────── */
.win-hero {
  padding: 20px 24px;
}

.win-hero-logo {
  width: 80px;
  flex-shrink: 0;
  display: none; /* logo too small to be readable */
}

.win-hero-text h1 {
  font-size: 24px;
  font-weight: 800;
  color: #405189;
  margin-bottom: 8px;
  line-height: 1.3;
  font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
}

.win-hero-text p {
  font-size: 14.5px;
  color: #222;
  margin-bottom: 14px;
  line-height: 1.55;
  font-family: 'Segoe UI', 'Tahoma', 'Arial', sans-serif;
}

.win-hero-btns {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn-primary-98 {
  background: #405189 !important;
  color: #fff !important;
  font-weight: bold;
  border-color: #405189 #1a2a6c #1a2a6c #405189 !important;
  padding: 4px 14px;
}

.btn-primary-98:hover {
  background: #4a5f9e !important;
}

.btn-primary-98:active {
  box-shadow: inset -1px -1px #ffffff, inset 1px 1px #808080, inset -2px -2px #dfdfdf, inset 2px 2px #0a0a0a;
}

.boot-progress-wrap {
  margin-top: 10px;
}

.boot-progress-wrap label {
  font-size: 12px;
  color: #444;
  display: block;
  margin-bottom: 4px;
}

/* Module grid in Il Mio Computer */
.module-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 8px;
}

.module-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 8px 4px;
  cursor: pointer;
  text-align: center;
  border: 1px solid transparent;
  font-size: 12px;
  transition: background 0.1s;
}

.module-item:hover {
  background: rgba(0,0,128,0.08);
  border: 1px dotted #000080;
}

.module-item:active {
  background: rgba(0,0,128,0.15);
}

.module-item .mod-icon {
  font-size: 28px;
  margin-bottom: 4px;
  line-height: 1;
}

/* Flow diagram Fatture */
.flow-diagram {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 12px;
  flex-wrap: wrap;
}

.flow-step {
  background: #fff;
  border: 1px solid #808080;
  border-color: #808080 #fff #fff #808080;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  color: #405189;
  white-space: nowrap;
}

.flow-arrow {
  color: #405189;
  font-size: 16px;
}

/* Tree view extra */
.tree-icon { margin-right: 4px; }

/* CSS bar chart */
.bar-chart { padding: 8px; }

.bar-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.bar-label {
  width: 30px;
  font-size: 11px;
  text-align: right;
  flex-shrink: 0;
}

.bar-track {
  flex: 1;
  height: 16px;
  background: #c0c0c0;
  border: 1px solid #808080;
  border-color: #808080 #fff #fff #808080;
  position: relative;
}

.bar-fill {
  height: 100%;
  background: #405189;
  display: flex;
  align-items: center;
  padding-left: 4px;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  transition: width 1s ease;
}

/* IE toolbar */
.ie-toolbar {
  display: flex;
  gap: 2px;
  padding: 4px 2px;
  border-bottom: 1px solid #808080;
  align-items: center;
  flex-wrap: wrap;
}

.ie-address-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 6px;
  border-bottom: 1px solid #808080;
  font-size: 11px;
}

.ie-address-bar input {
  flex: 1;
  font-size: 11px;
  font-family: 'Arial', sans-serif;
}

.ie-content { padding: 20px; text-align: center; }
.ie-content .error-icon { font-size: 40px; margin-bottom: 10px; }
.ie-content h3 { font-size: 16px; margin-bottom: 8px; color: #000080; }
.ie-content p { font-size: 12px; color: #333; margin-bottom: 12px; }

/* Notepad content */
.notepad-content {
  padding: 8px;
  font-family: 'Courier New', Courier, monospace;
  font-size: 13px;
  line-height: 1.6;
  white-space: pre-wrap;
  border: none;
  outline: none;
  min-height: 200px;
  color: #000;
}

/* Contatti form-like layout */
.contatti-content { padding: 16px; }

.contatti-content h2 {
  font-size: 16px;
  font-weight: 700;
  margin-bottom: 12px;
  color: #405189;
  font-family: 'Poppins', sans-serif;
}

.contatti-content .cta-btn {
  display: block;
  width: 100%;
  padding: 8px;
  font-size: 14px;
  font-weight: bold;
  margin-bottom: 12px;
  cursor: pointer;
}

.info-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  margin-bottom: 6px;
}

/* ── Mobile fallback ──────────────────────────────────── */
.mobile-fallback {
  display: none;
}

@media (max-width: 767px) {
  html, body { overflow: auto; background: #008080; }
  #desktop, #taskbar, #start-menu, #boot-screen { display: none !important; }
  .mobile-fallback {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 16px 16px 40px;
    background: #008080;
    min-height: 100vh;
  }
  .mobile-fallback .window {
    width: 100%;
    max-width: 400px;
    box-shadow: 2px 2px 8px rgba(0,0,0,0.3);
  }
}
