.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: transparent;
  pointer-events: none;
}

.modal-layer {
  --win-fg-0: #e5f2ff;
  --win-fg-1: #a0a9b2;
  --win-fg-2: #5c6166;
  --win-bg-0: #29343f;
  --win-bg-1: #1e262e;
  --win-bg-2: #14191f;
  --win-bg-3: #0d1114;
  --win-red-0: #ff4d5b;

  position: fixed;
  inset: 0;
  z-index: 61;
  display: block;
  pointer-events: none;
  padding: 0;
}

.modal-card {
  position: absolute;
  width: min(780px, calc(var(--layout-vw) - 12px));
  height: min(520px, calc(var(--layout-vh) - var(--taskbar-space)));
  min-width: min(335px, calc(var(--layout-vw) - 12px));
  max-width: calc(var(--layout-vw) - 12px);
  min-height: min(220px, calc(var(--layout-vh) - var(--taskbar-space)));
  max-height: calc(var(--layout-vh) - var(--taskbar-space));
  overflow: hidden;
  border-radius: 0.42rem;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: linear-gradient(180deg, var(--win-bg-2) 0%, var(--win-bg-3) 100%);
  box-shadow: -0.3rem 0.3rem 0.9rem rgba(0, 0, 0, 0.36);
  backdrop-filter: blur(10px) saturate(1.05);
  pointer-events: auto;
  display: flex;
  flex-direction: column;
  resize: none;
}

/* Hide scrollbars in all app windows while preserving scroll behavior. */
.modal-card,
.modal-card * {
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.modal-card::-webkit-scrollbar,
.modal-card *::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.window-resize-handle {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 1.16rem;
  height: 1.16rem;
  border: none;
  padding: 0;
  margin: 0;
  background: transparent;
  cursor: nwse-resize;
  touch-action: none;
  z-index: 8;
}

.window-resize-handle::before {
  content: "";
  position: absolute;
  right: 0.16rem;
  bottom: 0.16rem;
  width: 0.62rem;
  height: 0.62rem;
  background:
    linear-gradient(135deg,
      transparent 0 34%,
      rgba(231, 239, 255, 0.78) 34% 40%,
      transparent 40% 56%,
      rgba(231, 239, 255, 0.68) 56% 62%,
      transparent 62% 78%,
      rgba(231, 239, 255, 0.58) 78% 84%,
      transparent 84% 100%);
}

.window-resize-handle:hover {
  background: rgba(255, 255, 255, 0.08);
}

.window-resize-handle:active {
  background: rgba(255, 255, 255, 0.14);
}
}

.modal-titlebar {
  height: 2.5rem;
  padding: 0.25rem 0 0.25rem 0.75rem;
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  background: var(--win-bg-1);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.3rem;
  cursor: move;
  user-select: none;
  touch-action: none;
  min-width: 0;
}

.modal-titlebar h2 {
  margin: 0;
  color: var(--win-fg-0);
  font-size: 0.82rem;
  font-weight: 500;
  letter-spacing: 0.005em;
  pointer-events: none;
  min-width: 0;
  flex: 1 1 auto;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.win-controls {
  display: inline-flex;
  align-items: stretch;
  flex: 0 0 auto;
}

.win-btn {
  width: 2.5rem;
  height: 2.5rem;
  border: none;
  background: transparent;
  color: var(--win-fg-0);
  font-size: 0.86rem;
  display: inline-grid;
  place-items: center;
}

.win-icon {
  width: 0.88rem;
  height: 0.88rem;
  display: block;
  pointer-events: none;
}

.win-icon path,
.win-icon rect {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.pdf-tab-close .win-icon,
.notes-tab-close .win-icon,
.explorer-tab-close .win-icon {
  width: 0.72rem;
  height: 0.72rem;
}

button.win-btn {
  cursor: pointer;
}

button.win-btn:hover {
  background: rgba(255, 255, 255, 0.05);
}

.win-close {
  color: var(--win-fg-0);
  background: transparent;
}

.win-close:hover {
  background: var(--win-red-0);
  color: #fff;
}

.win-close:active {
  background: rgba(255, 77, 91, 0.7);
  color: #fff;
}

.modal-body {
  padding: 0.56rem 0.66rem 0.68rem;
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  color: var(--win-fg-0);
  line-height: 1.45;
  background: var(--win-bg-2);
}

.modal-body p {
  margin: 0.5rem 0;
}

.modal-body input,
.modal-body textarea,
.modal-body select {
  font-size: 16px;
  color: var(--win-fg-0);
  background: var(--win-bg-1);
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
}

.modal-body .notes-editor {
  background: var(--win-bg-1) !important;
  color: var(--win-fg-0) !important;
  border: 1px solid rgba(255, 255, 255, 0.12) !important;
}

.modal-card a.folder-item {
  color: #c8ddff;
  border-bottom: 1px solid rgba(130, 168, 255, 0.24);
}

.modal-card a.mail-link {
  color: #c8ddff;
  border-bottom: 1px solid rgba(130, 168, 255, 0.3);
}

body.modal-open {
  overflow: hidden;
}

.modal-card[hidden] {
  display: none !important;
}

.modal-card.window-active {
  box-shadow: -0.45rem 0.45rem 1.2rem rgba(0, 0, 0, 0.48);
}

.modal-card.window-fade-in {
  animation: modal-window-fade-in var(--ui-fade-duration, 140ms) ease-out both;
}

.modal-card.window-fade-out {
  animation: modal-window-fade-out var(--ui-fade-duration, 140ms) ease-out both;
  pointer-events: none;
}

.modal-card.window-launching {
  animation: modal-window-launch var(--window-launch-duration, 480ms) cubic-bezier(0.2, 0.8, 0.2, 1);
  animation-fill-mode: both;
  will-change: opacity, transform;
  -webkit-backface-visibility: hidden;
  backface-visibility: hidden;
  -webkit-transform: translateZ(0);
}

@keyframes modal-window-launch {
  0% {
    opacity: 0;
    transform: translateY(8px) scale(0.985);
  }

  100% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes modal-window-fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes modal-window-fade-out {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
  }
}

@keyframes modal-window-launch-mobile {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}

@media (hover: none) and (pointer: coarse) {
  .modal-card.window-launching {
    animation-name: modal-window-launch-mobile;
    will-change: opacity;
  }
}

.modal-card.window-maximized {
  max-width: none;
  max-height: none;
  min-width: 0;
  min-height: 0;
  border-radius: 0;
  border: none;
  box-shadow: none;
  backdrop-filter: none;
  resize: none;
}

.modal-card.window-maximized .window-resize-handle {
  display: none;
}

@media (pointer: coarse) {
  .window-resize-handle {
    width: 1.7rem;
    height: 1.7rem;
  }

  .window-resize-handle::before {
    right: 0.24rem;
    bottom: 0.24rem;
    width: 0.88rem;
    height: 0.88rem;
  }
}

.snap-preview {
  position: fixed;
  z-index: 59;
  border: 1px solid rgba(92, 146, 255, 0.68);
  background: rgba(92, 146, 255, 0.16);
  pointer-events: none;
  border-radius: 0.55rem;
}

@media (prefers-reduced-motion: reduce) {
  .modal-card.window-launching {
    animation-duration: 220ms;
    animation-timing-function: linear;
  }
}
